DString.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef SCUFCONT_DSTRING_H_
  2. #define SCUFCONT_DSTRING_H_
  3. #include <stdbool.h>
  4. #include <stddef.h>
  5. #include "scufcont.h"
  6. #define SCDSTRING_FMT(dstr) (int) (dstr).len, (dstr).data
  7. #define SCDString_is_null(dstr) ((dstr)->data == NULL)
  8. #define SCDString_c_str(dstr) ((dstr)->data)
  9. typedef struct {
  10. char* data;
  11. size_t len;
  12. size_t capacity;
  13. } SCDString;
  14. ScufContResult SCDString_alloc(SCDString* dstr, const char* str, const size_t len);
  15. ScufContResult SCDString_reserve(SCDString* dstr, const size_t new_capacity);
  16. void SCDString_free(SCDString* dstr);
  17. bool SCDString_equal(const SCDString* s1, const SCDString* s2);
  18. bool SCDString_equal_c_str(const SCDString* s1, const char* s2);
  19. bool SCDString_equal_next_chars_c_str(
  20. const SCDString* dstr,
  21. const char* str,
  22. const size_t str_len,
  23. const size_t s
  24. );
  25. ScufContResult SCDString_concat_c_str(
  26. SCDString* dstr,
  27. const char* str,
  28. const size_t str_len
  29. );
  30. ScufContResult SCDString_alloc_concat_c_strs(
  31. SCDString* dstr,
  32. const char* s1,
  33. const size_t s1_len,
  34. const char* s2,
  35. const size_t s2_len
  36. );
  37. ScufContResult SCDString_split(
  38. const SCDString* dstr,
  39. const char* delim,
  40. SCDString** split_arr,
  41. size_t* arr_len
  42. );
  43. void SCDString_split_arr_free(SCDString** arr, const size_t arr_len);
  44. #endif // SCUFCONT_DSTRING_H_