You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fstring.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Functions for handling with fixed size strings
  3. */
  4. #ifndef FSTRING_H
  5. #define FSTRING_H
  6. #include <sys/types.h>
  7. #include "config.h"
  8. #ifdef HAVE_STDINT_H
  9. #include <stdint.h>
  10. #endif
  11. #include "mem_pool.h"
  12. #define update_buf_size(x) (x)->free = (x)->buf->size - ((x)->pos - (x)->buf->begin); (x)->buf->len = (x)->pos - (x)->buf->begin
  13. typedef struct f_str_s {
  14. char *begin;
  15. size_t len;
  16. size_t size;
  17. } f_str_t;
  18. typedef struct f_str_buf_s {
  19. f_str_t *buf;
  20. char *pos;
  21. size_t free;
  22. } f_str_buf_t;
  23. typedef struct f_tok_s {
  24. f_str_t word;
  25. size_t pos;
  26. } f_tok_t;
  27. /*
  28. * Search first occurence of character in string
  29. */
  30. ssize_t fstrchr (f_str_t *src, char c);
  31. /*
  32. * Search last occurence of character in string
  33. */
  34. ssize_t fstrrchr (f_str_t *src, char c);
  35. /*
  36. * Search for pattern in orig
  37. */
  38. ssize_t fstrstr (f_str_t *orig, f_str_t *pattern);
  39. /*
  40. * Split string by tokens
  41. * word contains parsed word
  42. */
  43. int fstrtok (f_str_t *text, const char *sep, f_tok_t *state);
  44. /*
  45. * Copy one string into other
  46. */
  47. size_t fstrcpy (f_str_t *dest, f_str_t *src);
  48. /*
  49. * Concatenate two strings
  50. */
  51. size_t fstrcat (f_str_t *dest, f_str_t *src);
  52. /*
  53. * Push one character to fstr
  54. */
  55. int fstrpush (f_str_t *dest, char c);
  56. /*
  57. * Allocate memory for f_str_t
  58. */
  59. f_str_t* fstralloc (memory_pool_t *pool, size_t len);
  60. /*
  61. * Truncate string to its len
  62. */
  63. f_str_t* fstrtruncate (memory_pool_t *pool, f_str_t *orig);
  64. /*
  65. * Enlarge string to new size
  66. */
  67. f_str_t* fstrgrow (memory_pool_t *pool, f_str_t *orig, size_t newlen);
  68. /*
  69. * Return specified character
  70. */
  71. #define fstridx(str, pos) *((str)->begin + (pos))
  72. /*
  73. * Return fast hash value for fixed string
  74. */
  75. uint32_t fstrhash (f_str_t *str);
  76. #endif