str.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef VSFTP_STR_H
  2. #define VSFTP_STR_H
  3. /* TODO - document these functions ;-) */
  4. #ifndef VSF_FILESIZE_H
  5. #include "filesize.h"
  6. #endif
  7. struct mystr
  8. {
  9. char* PRIVATE_HANDS_OFF_p_buf;
  10. /* Internally, EXCLUDES trailing null */
  11. unsigned int PRIVATE_HANDS_OFF_len;
  12. unsigned int PRIVATE_HANDS_OFF_alloc_bytes;
  13. };
  14. #define INIT_MYSTR \
  15. { (void*)0, 0, 0 }
  16. #ifdef VSFTP_STRING_HELPER
  17. #define str_alloc_memchunk private_str_alloc_memchunk
  18. #endif
  19. void private_str_alloc_memchunk(struct mystr* p_str, const char* p_src,
  20. unsigned int len);
  21. void str_alloc_text(struct mystr* p_str, const char* p_src);
  22. /* NOTE: String buffer data does NOT include terminating character */
  23. void str_alloc_alt_term(struct mystr* p_str, const char* p_src, char term);
  24. void str_alloc_ulong(struct mystr* p_str, unsigned long the_ulong);
  25. void str_alloc_filesize_t(struct mystr* p_str, filesize_t the_filesize);
  26. void str_copy(struct mystr* p_dest, const struct mystr* p_src);
  27. const char* str_strdup(const struct mystr* p_str);
  28. void str_empty(struct mystr* p_str);
  29. void str_free(struct mystr* p_str);
  30. void str_trunc(struct mystr* p_str, unsigned int trunc_len);
  31. void str_reserve(struct mystr* p_str, unsigned int res_len);
  32. int str_isempty(const struct mystr* p_str);
  33. unsigned int str_getlen(const struct mystr* p_str);
  34. const char* str_getbuf(const struct mystr* p_str);
  35. int str_strcmp(const struct mystr* p_str1, const struct mystr* p_str2);
  36. int str_equal(const struct mystr* p_str1, const struct mystr* p_str2);
  37. int str_equal_text(const struct mystr* p_str, const char* p_text);
  38. void str_append_str(struct mystr* p_str, const struct mystr* p_other);
  39. void str_append_text(struct mystr* p_str, const char* p_src);
  40. void str_append_ulong(struct mystr* p_str, unsigned long the_long);
  41. void str_append_filesize_t(struct mystr* p_str, filesize_t the_filesize);
  42. void str_append_char(struct mystr* p_str, char the_char);
  43. void str_append_double(struct mystr* p_str, double the_double);
  44. void str_upper(struct mystr* p_str);
  45. void str_rpad(struct mystr* p_str, const unsigned int min_width);
  46. void str_lpad(struct mystr* p_str, const unsigned int min_width);
  47. void str_replace_char(struct mystr* p_str, char from, char to);
  48. void str_replace_text(struct mystr* p_str, const char* p_from,
  49. const char* p_to);
  50. void str_split_char(struct mystr* p_src, struct mystr* p_rhs, char c);
  51. void str_split_char_reverse(struct mystr* p_src, struct mystr* p_rhs, char c);
  52. void str_split_text(struct mystr* p_src, struct mystr* p_rhs,
  53. const char* p_text);
  54. void str_split_text_reverse(struct mystr* p_src, struct mystr* p_rhs,
  55. const char* p_text);
  56. struct str_locate_result
  57. {
  58. int found;
  59. unsigned int index;
  60. char char_found;
  61. };
  62. struct str_locate_result str_locate_char(
  63. const struct mystr* p_str, char look_char);
  64. struct str_locate_result str_locate_str(
  65. const struct mystr* p_str, const struct mystr* p_look_str);
  66. struct str_locate_result str_locate_str_reverse(
  67. const struct mystr* p_str, const struct mystr* p_look_str);
  68. struct str_locate_result str_locate_text(
  69. const struct mystr* p_str, const char* p_text);
  70. struct str_locate_result str_locate_text_reverse(
  71. const struct mystr* p_str, const char* p_text);
  72. struct str_locate_result str_locate_chars(
  73. const struct mystr* p_str, const char* p_chars);
  74. void str_left(const struct mystr* p_str, struct mystr* p_out,
  75. unsigned int chars);
  76. void str_right(const struct mystr* p_str, struct mystr* p_out,
  77. unsigned int chars);
  78. void str_mid_to_end(const struct mystr* p_str, struct mystr* p_out,
  79. unsigned int indexx);
  80. char str_get_char_at(const struct mystr* p_str, const unsigned int indexx);
  81. int str_contains_space(const struct mystr* p_str);
  82. int str_all_space(const struct mystr* p_str);
  83. int str_contains_unprintable(const struct mystr* p_str);
  84. void str_replace_unprintable(struct mystr* p_str, char new_char);
  85. int str_atoi(const struct mystr* p_str);
  86. filesize_t str_a_to_filesize_t(const struct mystr* p_str);
  87. unsigned int str_octal_to_uint(const struct mystr* p_str);
  88. /* PURPOSE: Extract a line of text (delimited by \n or EOF) from a string
  89. * buffer, starting at character position 'p_pos'. The extracted line will
  90. * not contain the '\n' terminator.
  91. *
  92. * RETURNS: 0 if no more lines are available, 1 otherwise.
  93. * The extracted text line is stored in 'p_line_str', which is
  94. * emptied if there are no more lines. 'p_pos' is updated to point to the
  95. * first character after the end of the line just extracted.
  96. */
  97. int str_getline(const struct mystr* p_str, struct mystr* p_line_str,
  98. unsigned int* p_pos);
  99. /* PURPOSE: Detect whether or not a string buffer contains a specific line
  100. * of text (delimited by \n or EOF).
  101. *
  102. * RETURNS: 1 if there is a matching line, 0 otherwise.
  103. */
  104. int str_contains_line(const struct mystr* p_str,
  105. const struct mystr* p_line_str);
  106. #endif /* VSFTP_STR_H */