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 BBBool bb_strbuf_equals(str_buf, cmp_buf, len)
195 const
BBChar * restrict str_buf;
196 const
BBChar * restrict cmp_buf;
199 --str_buf; --cmp_buf;
201 for (BBSize pos = 0; pos < len; ++pos)
203 if (*++str_buf != *++cmp_buf) {
209 } __attribute__ ((pure))
222 inline
BBChar* bb_strbuf_copy(str_buf, dst_buf, len)
223 const
BBChar * restrict str_buf;
224 BBChar * restrict dst_buf;
227 return memcpy(dst_buf, str_buf, len *
sizeof (
BBChar));
230 #define BBSTRING_MAX_MATCHES(str, sub) (((str)->length / (sub)->length) + 1)
232 BBSize bb_strbuf_findall(
const BBChar * restrict str_buf,
234 const BBChar * restrict sub_buf,
236 BBSize *
const matches)
237 __attribute__ ((nonnull(1,3,5)));
239 #endif // BB_ENABLE_HELPER
413 BBString* bbStringFromCString(
const char *c_str);
433 BBString* bbStringFromUTF8String(
const char *utf8_str);
565 BBInt bbStringAsc(
const BBString *str) __attribute__ ((pure));
573 #define BBSTRING_NOTFOUND (-1)
700 char* bbStringToCString(
const BBString *str);
723 char* bbStringToUTF8String(
const BBString *str);
847 BBBool bbStringIsLower(
const BBString *str) __attribute__ ((pure));
857 BBBool bbStringIsUpper(
const BBString *str) __attribute__ ((pure));
867 BBBool bbStringIsASCII(
const BBString *str) __attribute__ ((pure));
871 char* bbTmpCString(
const BBString *str);
873 char* bbTmpUTF8String(
const BBString *str);
877 #endif // BLITZ_STRING_H