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)); \
179 #define BBNULLSTRING (&bbEmptyString)
181 #ifdef BB_ENABLE_HELPER
194 inline BBChar* bb_strbuf_copy(str_buf, dst_buf, len)
195 const
BBChar * restrict str_buf;
196 BBChar * restrict dst_buf;
199 return memcpy(dst_buf, str_buf, len *
sizeof (
BBChar));
200 } __attribute__ ((nonnull (1,2)))
213 bool bb_strbuf_equals(const
BBChar * restrict str_buf,
214 const
BBChar * restrict cmp_buf,
215 BBSize len) __attribute__ ((pure));
217 #define BBSTRING_MAX_MATCHES(str, sub) (((str)->length / (sub)->length) + 1)
219 BBSize bb_strbuf_findall(
220 const BBChar * restrict str_buf,
222 const BBChar * restrict sub_buf,
224 BBSize *
const matches
225 ) __attribute__ ((pure, nonnull(1,3)));
227 #endif // BB_ENABLE_HELPER
401 BBString* bbStringFromCString(
const char *c_str);
421 BBString* bbStringFromUTF8String(
const char *utf8_str);
553 BBInt bbStringAsc(
const BBString *str) __attribute__ ((pure));
561 #define BBSTRING_NOTFOUND (-1)
688 char* bbStringToCString(
const BBString *str);
711 char* bbStringToUTF8String(
const BBString *str);
835 BBBool bbStringIsLower(
const BBString *str) __attribute__ ((pure));
845 BBBool bbStringIsUpper(
const BBString *str) __attribute__ ((pure));
855 BBBool bbStringIsASCII(
const BBString *str) __attribute__ ((pure));
859 char* bbTmpCString(
const BBString *str);
861 char* bbTmpUTF8String(
const BBString *str);
865 #endif // BLITZ_STRING_H