|
75 | 75 | kMCStringFlagIsUnicode = 1 << 0, |
76 | 76 | // If set then the string is mutable. |
77 | 77 | kMCStringFlagIsMutable = 1 << 1, |
| 78 | +#ifndef NATIVE_STRING |
| 79 | + // If set then the native and unicode strings are equivalent |
| 80 | + kMCStringFlagIsNative = 1 << 2, |
| 81 | +#endif |
78 | 82 | }; |
79 | 83 |
|
| 84 | +#ifdef NATIVE_STRING |
| 85 | +typedef char_t strchar_t; |
| 86 | +#define MCStrCharFold(x) MCNativeCharFold(x) |
| 87 | +#define MCStrCharLowercase(x) MCNativeCharLowercase(x) |
| 88 | +#define MCStrCharUppercase(x) MCNativeCharUppercase(x) |
| 89 | +#define MCStrCharMapToNative(x) (x) |
| 90 | +#define MCStrCharMapFromNative(x) (x) |
| 91 | +#define MCStrCharsMapFromUnicode(x, y, z, w) MCUnicodeCharsMapToNative(x, y, z, w, '?') |
| 92 | +#define MCStrCharsMapFromNative(x, y, z) MCMemoryCopy(x, y, z * sizeof(strchar_t)) |
| 93 | +#define MCStrCharsHashExact(x, y) MCNativeCharsHashExact(x, y) |
| 94 | +#define MCStrCharsHashCaseless(x, y) MCNativeCharsHashCaseless(x, y) |
| 95 | +#define MCStrCharsEqualExact(x, y, z, w) MCNativeCharsEqualExact(x, y, z, w) |
| 96 | +#define MCStrCharsEqualCaseless(x, y, z, w) MCNativeCharsEqualCaseless(x, y, z, w) |
| 97 | +#define MCStrCharsCompareExact(x, y, z, w) MCNativeCharsCompareExact(x, y, z, w) |
| 98 | +#define MCStrCharsCompareCaseless(x, y, z, w) MCNativeCharsCompareCaseless(x, y, z, w) |
| 99 | +#define MCStrCharsSharedPrefixExact(x, y, z, w) MCNativeCharsSharedPrefixExact(x, y, z, w) |
| 100 | +#define MCStrCharsSharedPrefixCaseless(x, y, z, w) MCNativeCharsSharedPrefixCaseless(x, y, z, w) |
| 101 | +#define MCStrCharsSharedSuffixExact(x, y, z, w) MCNativeCharsSharedSuffixExact(x, y, z, w) |
| 102 | +#define MCStrCharsSharedSuffixCaseless(x, y, z, w) MCNativeCharsSharedSuffixCaseless(x, y, z, w) |
| 103 | +#define MCStrCharsLowercase(x, y) MCNativeCharsLowercase(x, y) |
| 104 | +#define MCStrCharsUppercase(x, y) MCNativeCharsUppercase(x, y) |
| 105 | +#else |
| 106 | +typedef unichar_t strchar_t; |
| 107 | +#define MCStrCharFold(x) MCUnicodeCharFold(x) |
| 108 | +#define MCStrCharLowercase(x) MCUnicodeCharLowercase(x) |
| 109 | +#define MCStrCharUppercase(x) MCUnicodeCharUppercase(x) |
| 110 | +#define MCStrCharMapToNative(x) MCUnicodeCharMapToNativeLossy(x) |
| 111 | +#define MCStrCharMapFromNative(x) MCUnicodeCharMapFromNative(x) |
| 112 | +#define MCStrCharsMapFromUnicode(x, y, z, w) (MCMemoryCopy(z, x, y * sizeof(strchar_t)), w = y) |
| 113 | +#define MCStrCharsMapFromNative(x, y, z) MCUnicodeCharsMapFromNative(y, z, x) |
| 114 | +#define MCStrCharsHashExact(x, y) MCUnicodeCharsHashExact(x, y) |
| 115 | +#define MCStrCharsHashCaseless(x, y) MCUnicodeCharsHashCaseless(x, y) |
| 116 | +#define MCStrCharsEqualExact(x, y, z, w) MCUnicodeCharsEqualExact(x, y, z, w) |
| 117 | +#define MCStrCharsEqualCaseless(x, y, z, w) MCUnicodeCharsEqualCaseless(x, y, z, w) |
| 118 | +#define MCStrCharsCompareExact(x, y, z, w) MCUnicodeCharsCompareExact(x, y, z, w) |
| 119 | +#define MCStrCharsCompareCaseless(x, y, z, w) MCUnicodeCharsCompareCaseless(x, y, z, w) |
| 120 | +#define MCStrCharsSharedPrefixExact(x, y, z, w) MCUnicodeCharsSharedPrefixExact(x, y, z, w) |
| 121 | +#define MCStrCharsSharedPrefixCaseless(x, y, z, w) MCUnicodeCharsSharedPrefixCaseless(x, y, z, w) |
| 122 | +#define MCStrCharsSharedSuffixExact(x, y, z, w) MCUnicodeCharsSharedSuffixExact(x, y, z, w) |
| 123 | +#define MCStrCharsSharedSuffixCaseless(x, y, z, w) MCUnicodeCharsSharedSuffixCaseless(x, y, z, w) |
| 124 | +#define MCStrCharsLowercase(x, y) MCUnicodeCharsLowercase(x, y) |
| 125 | +#define MCStrCharsUppercase(x, y) MCUnicodeCharsUppercase(x, y) |
| 126 | +#endif |
| 127 | + |
| 128 | +#ifdef NATIVE_STRING |
80 | 129 | struct __MCString: public __MCValue |
81 | 130 | { |
82 | 131 | uindex_t char_count; |
83 | | - char_t *chars; |
| 132 | + strchar_t *chars; |
84 | 133 | uindex_t capacity; |
85 | 134 | }; |
| 135 | +#else |
| 136 | +struct __MCString: public __MCValue |
| 137 | +{ |
| 138 | + uindex_t char_count; |
| 139 | + strchar_t *chars; |
| 140 | + char_t *native_chars; |
| 141 | + uindex_t capacity; |
| 142 | +}; |
| 143 | +#endif |
86 | 144 |
|
87 | 145 | ////////// |
88 | 146 |
|
@@ -296,15 +354,44 @@ hash_t MCUnicodeCharsHashCaseless(const unichar_t *chars, uindex_t char_count); |
296 | 354 | bool MCUnicodeCharsEqualExact(const unichar_t *left, uindex_t left_length, const unichar_t *right, uindex_t right_length); |
297 | 355 | bool MCUnicodeCharsEqualCaseless(const unichar_t *left, uindex_t left_length, const unichar_t *right, uindex_t right_length); |
298 | 356 |
|
| 357 | +compare_t MCUnicodeCharsCompareExact(const unichar_t *left, uindex_t left_length, const unichar_t *right, uindex_t right_length); |
| 358 | +compare_t MCUnicodeCharsCompareCaseless(const unichar_t *left, uindex_t left_length, const unichar_t *right, uindex_t right_length); |
| 359 | + |
| 360 | +// Return the number of characters of prefix that are equal to those at the |
| 361 | +// beginning of string. |
| 362 | +uindex_t MCUnicodeCharsSharedPrefixExact(const unichar_t *string, uindex_t left_length, const unichar_t *suffix, uindex_t right_length); |
| 363 | +uindex_t MCUnicodeCharsSharedPrefixCaseless(const unichar_t *string, uindex_t left_length, const unichar_t *suffix, uindex_t right_length); |
| 364 | + |
| 365 | +// Return the number of characters of suffix that are equal to those at the |
| 366 | +// end of string. |
| 367 | +uindex_t MCUnicodeCharsSharedSuffixExact(const unichar_t *string, uindex_t left_length, const unichar_t *suffix, uindex_t right_length); |
| 368 | +uindex_t MCUnicodeCharsSharedSuffixCaseless(const unichar_t *string, uindex_t left_length, const unichar_t *suffix, uindex_t right_length); |
| 369 | + |
| 370 | +// Lowercase all the characters in-place. |
| 371 | +void MCUnicodeCharsLowercase(unichar_t *chars, uindex_t char_count); |
| 372 | + |
| 373 | +// Uppercase all the characters in-place. |
| 374 | +void MCUnicodeCharsUppercase(unichar_t *chars, uindex_t char_count); |
| 375 | + |
| 376 | +bool MCUnicodeCharsEqualExact(const unichar_t *left, uindex_t left_length, const unichar_t *right, uindex_t right_length); |
| 377 | +bool MCUnicodeCharsEqualCaseless(const unichar_t *left, uindex_t left_length, const unichar_t *right, uindex_t right_length); |
| 378 | + |
299 | 379 | bool MCUnicodeCharsMapToNative(const unichar_t *uchars, uindex_t uchar_count, char_t *nchars, uindex_t& r_nchar_count, char_t invalid); |
300 | 380 | void MCUnicodeCharsMapFromNative(const char_t *chars, uindex_t char_count, unichar_t *uchars); |
301 | 381 |
|
302 | 382 | uindex_t MCUnicodeCharsMapToUTF8(const unichar_t *wchars, uindex_t wchar_count, byte_t *utf8bytes, uindex_t utf8byte_count); |
303 | 383 | uindex_t MCUnicodeCharsMapFromUTF8(const byte_t *utf8bytes, uindex_t utf8byte_count, unichar_t *wchars, uindex_t wchar_count); |
304 | 384 |
|
305 | 385 | bool MCUnicodeCharMapToNative(unichar_t uchar, char_t& r_nchar); |
| 386 | +char_t MCUnicodeCharMapToNativeLossy(unichar_t nchar); |
306 | 387 | unichar_t MCUnicodeCharMapFromNative(char_t nchar); |
307 | 388 |
|
| 389 | +unichar_t MCUnicodeCharFold(unichar_t); |
| 390 | + |
| 391 | +unichar_t MCUnicodeCharLowercase(unichar_t); |
| 392 | + |
| 393 | +unichar_t MCUnicodeCharUppercase(unichar_t); |
| 394 | + |
308 | 395 | //////////////////////////////////////////////////////////////////////////////// |
309 | 396 |
|
310 | 397 | #endif |
0 commit comments