10 #define BLITZ_STRING_H
26 #define BBSTRING_SIZE_CALC(len) (sizeof (BBString) + (len) * sizeof (BBChar))
36 #define BBSTRING_SIZE(str) BBSTRING_SIZE_CALC((str)->length)
38 #ifndef BB_ENABLE_EXPERIMENTAL
44 # define BBSTRING_MAX_LENGTH ((BBSize)(BBSIZE_MAX / sizeof (BBChar) - sizeof (BBString)) / 2)
46 # define BBSTRING_MAX_LENGTH ((BBSize)(BBSIZE_MAX / sizeof (BBChar)) - sizeof (BBString))
47 #endif // BB_ENABLE_EXPERIMENTAL
67 #define BBSTRING_ALLOC(len) \
71 BBSTRING_SIZE_CALC(len), \
86 #define BBSTRING_NEW(len) \
88 const BBSize _len = (len); \
89 BBString *_str = BBSTRING_ALLOC(_len); \
90 _str->length = _len; \
102 #define BBSTRING_FROMBUFFER(buffer, len) \
104 const BBSize _len = (len); \
105 BB_ASSERT(_len > 0 && _len < BBSTRING_MAX_LENGTH, "Invalid buffer length"); \
106 BBString *_str = BBSTRING_ALLOC(_len); \
107 _str->length = _len; \
108 memcpy(_str->buf, (buffer), _len * sizeof (BBChar)); \
172 #ifdef BB_INCLUDE_INTERNALS
185 BBBool bb_strbuf_equals(
const BBChar * restrict str_buf,
186 const BBChar * restrict cmp_buf,
187 const BBSize len) __attribute__ ((pure));
189 #define BBSTRING_MAX_MATCHES(str, sub) (((str)->length / (sub)->length) + 1)
191 BBSize bb_strbuf_findall(
const BBChar * restrict str_buf,
193 const BBChar * restrict sub_buf,
195 BBSize *
const matches)
196 __attribute__ ((nonnull (1, 3, 5)));
198 #endif // BB_INCLUDE_INTERNALS
210 #define BBNULLSTRING (&bbEmptyString)
381 BBString* bbStringFromCString(
const char *c_str);
401 BBString* bbStringFromUTF8String(
const char *utf8_str);
533 BBInt bbStringAsc(
const BBString *str) __attribute__ ((pure));
541 #define BBSTRING_NOTFOUND (-1)
668 char* bbStringToCString(
const BBString *str);
691 char* bbStringToUTF8String(
const BBString *str);
815 BBBool bbStringIsLower(
const BBString *str) __attribute__ ((pure));
825 BBBool bbStringIsUpper(
const BBString *str) __attribute__ ((pure));
835 BBBool bbStringIsASCII(
const BBString *str) __attribute__ ((pure));
839 char* bbTmpCString(
const BBString *str);
841 char* bbTmpUTF8String(
const BBString *str);
845 #endif // BLITZ_STRING_H