123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /*
- * Functions for handling with fixed size strings
- */
-
- #ifndef FSTRING_H
- #define FSTRING_H
-
- #include <sys/types.h>
- #include "config.h"
-
- #ifdef HAVE_STDINT_H
- #include <stdint.h>
- #endif
- #include "mem_pool.h"
-
- #define update_buf_size(x) (x)->free = (x)->buf->size - ((x)->pos - (x)->buf->begin); (x)->buf->len = (x)->pos - (x)->buf->begin
-
- typedef struct f_str_s {
- char *begin;
- size_t len;
- size_t size;
- } f_str_t;
-
- typedef struct f_str_buf_s {
- f_str_t *buf;
- char *pos;
- size_t free;
- } f_str_buf_t;
-
- typedef struct f_tok_s {
- f_str_t word;
- size_t pos;
- } f_tok_t;
-
- /*
- * Search first occurence of character in string
- */
- ssize_t fstrchr (f_str_t *src, char c);
-
- /*
- * Search last occurence of character in string
- */
- ssize_t fstrrchr (f_str_t *src, char c);
-
- /*
- * Search for pattern in orig
- */
- ssize_t fstrstr (f_str_t *orig, f_str_t *pattern);
-
- /*
- * Split string by tokens
- * word contains parsed word
- */
- int fstrtok (f_str_t *text, const char *sep, f_tok_t *state);
-
- /*
- * Copy one string into other
- */
- size_t fstrcpy (f_str_t *dest, f_str_t *src);
-
- /*
- * Concatenate two strings
- */
- size_t fstrcat (f_str_t *dest, f_str_t *src);
-
- /*
- * Push one character to fstr
- */
- int fstrpush (f_str_t *dest, char c);
-
- /*
- * Allocate memory for f_str_t
- */
- f_str_t* fstralloc (memory_pool_t *pool, size_t len);
-
- /*
- * Truncate string to its len
- */
- f_str_t* fstrtruncate (memory_pool_t *pool, f_str_t *orig);
-
- /*
- * Enlarge string to new size
- */
- f_str_t* fstrgrow (memory_pool_t *pool, f_str_t *orig, size_t newlen);
-
- /*
- * Return specified character
- */
- #define fstridx(str, pos) *((str)->begin + (pos))
-
- /*
- * Return fast hash value for fixed string
- */
- uint32_t fstrhash (f_str_t *str);
-
- #endif
|