str.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #pragma once
  2. #include "pocketpy/common/vector.h"
  3. #include "pocketpy/common/utils.h"
  4. #include "pocketpy/pocketpy.h"
  5. #include <stdarg.h>
  6. /* string */
  7. typedef struct c11_string {
  8. // int size | char[] | '\0'
  9. int size;
  10. char data[]; // flexible array member
  11. } c11_string;
  12. /* bytes */
  13. typedef struct c11_bytes {
  14. int size;
  15. unsigned char data[]; // flexible array member
  16. } c11_bytes;
  17. bool c11_bytes__eq(c11_bytes* self, c11_bytes* other);
  18. int c11_sv__cmp(c11_sv self, c11_sv other);
  19. int c11_sv__cmp2(c11_sv self, const char* other);
  20. bool c11__streq(const char* a, const char* b);
  21. bool c11__sveq(c11_sv a, c11_sv b);
  22. bool c11__sveq2(c11_sv a, const char* b);
  23. c11_string* c11_string__new(const char* data);
  24. c11_string* c11_string__new2(const char* data, int size);
  25. c11_string* c11_string__new3(const char* fmt, ...);
  26. void c11_string__ctor(c11_string* self, const char* data);
  27. void c11_string__ctor2(c11_string* self, const char* data, int size);
  28. void c11_string__ctor3(c11_string* self, int size);
  29. c11_string* c11_string__copy(c11_string* self);
  30. void c11_string__delete(c11_string* self);
  31. c11_sv c11_string__sv(c11_string* self);
  32. int c11_sv__u8_length(c11_sv self);
  33. c11_sv c11_sv__u8_getitem(c11_sv self, int i);
  34. c11_string* c11_sv__u8_slice(c11_sv self, int start, int stop, int step);
  35. // general string operations
  36. c11_sv c11_sv__slice(c11_sv sv, int start);
  37. c11_sv c11_sv__slice2(c11_sv sv, int start, int stop);
  38. c11_sv c11_sv__strip(c11_sv sv, c11_sv chars, bool left, bool right);
  39. int c11_sv__index(c11_sv self, char c);
  40. int c11_sv__rindex(c11_sv self, char c);
  41. int c11_sv__index2(c11_sv self, c11_sv sub, int start);
  42. int c11_sv__count(c11_sv self, c11_sv sub);
  43. bool c11_sv__startswith(c11_sv self, c11_sv prefix);
  44. bool c11_sv__endswith(c11_sv self, c11_sv suffix);
  45. c11_string* c11_sv__replace(c11_sv self, char old, char new_);
  46. c11_string* c11_sv__replace2(c11_sv self, c11_sv old, c11_sv new_);
  47. c11_vector /* T=c11_sv */ c11_sv__split(c11_sv self, char sep);
  48. c11_vector /* T=c11_sv */ c11_sv__split2(c11_sv self, c11_sv sep);
  49. // misc
  50. int c11__unicode_index_to_byte(const char* data, int i);
  51. int c11__byte_index_to_unicode(const char* data, int n);
  52. bool c11__is_unicode_Lo_char(int c);
  53. int c11__u8_header(unsigned char c, bool suppress);
  54. int c11__u8_value(int u8bytes, const char* data);
  55. int c11__u32_to_u8(uint32_t utf32_char, char utf8_output[4]);
  56. char* c11_strdup(const char* str);
  57. unsigned char* c11_memdup(const unsigned char* data, int size);
  58. typedef enum IntParsingResult {
  59. IntParsing_SUCCESS,
  60. IntParsing_FAILURE,
  61. IntParsing_OVERFLOW,
  62. } IntParsingResult;
  63. IntParsingResult c11__parse_uint(c11_sv text, int64_t* out, int base);