52#pragma warning (disable : 4244)
53#pragma warning (disable : 4267)
54#pragma warning (disable : 4996)
59#define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
60#define realloc(p,s) _realloc_dbg(p,s, _NORMAL_BLOCK, __FILE__, __LINE__)
61#define free(p) _free_dbg(p, _NORMAL_BLOCK)
67#ifndef kPrintfBufferSize
68#define kPrintfBufferSize 4096
72#include <CoreFoundation/CoreFoundation.h>
73#include <CoreFoundation/CFString.h>
74#include <CoreFoundation/CFStringEncodingExt.h>
77#if defined (__GNUC__) && (__GNUC__ >= 4) && !__LP64__
79#pragma GCC diagnostic ignored "-Wformat"
82#define SMTG_ENABLE_DEBUG_CFALLOCATOR 0
83#define SMTG_DEBUG_CFALLOCATOR (DEVELOPMENT && SMTG_ENABLE_DEBUG_CFALLOCATOR)
85#if SMTG_DEBUG_CFALLOCATOR
86#include <libkern/OSAtomic.h>
91#if SMTG_DEBUG_CFALLOCATOR
92static CFAllocatorRef kCFAllocator =
NULL;
94struct CFStringDebugAllocator : CFAllocatorContext
96 CFStringDebugAllocator ()
102 copyDescription =
nullptr;
103 allocate = allocateCallBack;
104 reallocate = reallocateCallBack;
105 deallocate = deallocateCallBack;
106 preferredSize = preferredSizeCallBack;
108 numAllocations = allocationSize = numDeallocations = 0;
109 cfAllocator = CFAllocatorCreate (kCFAllocatorUseContext,
this);
112 if (dladdr ((
const void*)CFStringDebugAllocator::allocateCallBack, &
info))
114 moduleName =
info.dli_fname;
116 kCFAllocator = cfAllocator;
119 ~CFStringDebugAllocator ()
121 kCFAllocator = kCFAllocatorDefault;
122 CFRelease (cfAllocator);
123 FDebugPrint (
"CFStringDebugAllocator (%s):\n", moduleName.text8 ());
124 FDebugPrint (
"\tNumber of allocations : %u\n", numAllocations);
125 FDebugPrint (
"\tNumber of deallocations: %u\n", numDeallocations);
126 FDebugPrint (
"\tAllocated Bytes : %u\n", allocationSize);
130 CFAllocatorRef cfAllocator;
131 volatile int64_t numAllocations;
132 volatile int64_t numDeallocations;
133 volatile int64_t allocationSize;
135 void* doAllocate (CFIndex allocSize, CFOptionFlags
hint)
137 void* ptr = CFAllocatorAllocate (kCFAllocatorDefault, allocSize,
hint);
138 OSAtomicIncrement64 (&numAllocations);
139 OSAtomicAdd64 (allocSize, &allocationSize);
142 void* doReallocate (
void* ptr, CFIndex newsize, CFOptionFlags
hint)
144 void* newPtr = CFAllocatorReallocate (kCFAllocatorDefault, ptr, newsize,
hint);
147 void doDeallocate (
void* ptr)
149 CFAllocatorDeallocate (kCFAllocatorDefault, ptr);
150 OSAtomicIncrement64 (&numDeallocations);
152 CFIndex getPreferredSize (CFIndex
size, CFOptionFlags
hint)
154 return CFAllocatorGetPreferredSizeForSize (kCFAllocatorDefault,
size,
hint);
157 static void* allocateCallBack (CFIndex allocSize, CFOptionFlags
hint,
void*
info)
159 return static_cast<CFStringDebugAllocator*
> (
info)->doAllocate (allocSize,
hint);
161 static void* reallocateCallBack (
void* ptr, CFIndex newsize, CFOptionFlags
hint,
void*
info)
163 return static_cast<CFStringDebugAllocator*
> (
info)->doReallocate (ptr, newsize,
hint);
166 static void deallocateCallBack (
void* ptr,
void*
info)
168 static_cast<CFStringDebugAllocator*
> (
info)->doDeallocate (ptr);
170 static CFIndex preferredSizeCallBack (CFIndex
size, CFOptionFlags
hint,
void*
info)
172 return static_cast<CFStringDebugAllocator*
> (
info)->getPreferredSize (
size,
hint);
175static CFStringDebugAllocator gDebugAllocator;
178static const CFAllocatorRef kCFAllocator = ::kCFAllocatorDefault;
185 if (encoding == 0xFFFF)
186 encoding = kCFStringEncodingASCII;
188 return (
void*)CFStringCreateWithCString (Steinberg::kCFAllocator, source, encoding);
190 return (
void*)CFStringCreateWithCString (Steinberg::kCFAllocator,
"", encoding);
197 CFRange range = {0, CFStringGetLength ((CFStringRef)cfStr)};
198 bool result = CFStringGetBytes ((CFStringRef)cfStr, range, encoding,
'?',
false, (UInt8*)dest, destSize, &usedBytes);
205#define stricmp16 wcsicmp
206#define strnicmp16 wcsnicmp
207#define strrchr16 wcsrchr
208#define sprintf16 swprintf
209#define snprintf16 snwprintf
210#define vsnprintf16 vsnwprintf
211#define vsprintf16 wvsprintf
212#define vfprintf16 vfwprintf
213#define sscanf16 swscanf
214#define toupper16 towupper
215#define tolower16 towlower
216#define isupper16 iswupper
217#define islower16 iswlower
218#define isspace16 iswspace
219#define isalpha16 iswalpha
220#define isdigit16 iswdigit
221#define isalnum16 iswalnum
223#define stricmp _stricmp
224#define strnicmp _strnicmp
225#define snprintf _snprintf
226#define vsnprintf _vsnprintf
227#define snwprintf _snwprintf
228#define vsnwprintf _vsnwprintf
243using ConverterFacet = std::codecvt_utf8_utf16<char16_t>;
244using Converter = std::wstring_convert<ConverterFacet, char16_t>;
247static ConverterFacet& converterFacet ()
249 static ConverterFacet gFacet;
254static Converter& converter ()
256 static Converter gConverter;
263 return ::strcasecmp (s1, s2);
269 return ::strncasecmp (s1, s2,
n);
275 auto str1 = converter ().to_bytes (s1);
276 auto str2 = converter ().to_bytes (s2);
277 return stricasecmp (str1.data (), str2.data ());
283 auto str1 = converter ().to_bytes (s1);
284 auto str2 = converter ().to_bytes (s2);
285 return strnicasecmp (str1.data (), str2.data (),
n);
291 assert(
false &&
"DEPRECATED No Linux implementation");
300 auto format_utf8 = converter ().to_bytes(
format);
303 auto tmp_str = converter ().from_bytes (str8, str8 + len);
304 auto target_len = std::min (tmp_str.size (), maxlen - 1);
305 tmp_str.copy (wcs, target_len);
306 wcs[target_len] =
'\0';
308 return tmp_str.size ();
314 assert(
false &&
"DEPRECATED No Linux implementation");
319#define tstrtoi64 strtoll
320#define stricmp strcasecmp
321#define strnicmp strncasecmp
331 if (
static_cast<CFIndex
> (
size) < str2Len)
333 CFStringRef cfStr1 = CFStringCreateWithCharactersNoCopy (Steinberg::kCFAllocator, (UniChar*)str1, str1Len, kCFAllocatorNull);
334 CFStringRef cfStr2 = CFStringCreateWithCharactersNoCopy (Steinberg::kCFAllocator, (UniChar*)str2, str2Len, kCFAllocatorNull);
335 CFComparisonResult
result = CFStringCompareWithOptions (cfStr1, cfStr2, CFRangeMake (0,
size), kCFCompareCaseInsensitive);
340 case kCFCompareEqualTo:
return 0;
341 case kCFCompareLessThan:
return -1;
342 case kCFCompareGreaterThan:
350 CFStringRef cfStr1 = CFStringCreateWithCharactersNoCopy (Steinberg::kCFAllocator, (UniChar*)str1, str1Len, kCFAllocatorNull);
351 CFStringRef cfStr2 = CFStringCreateWithCharactersNoCopy (Steinberg::kCFAllocator, (UniChar*)str2, str2Len, kCFAllocatorNull);
352 CFComparisonResult
result = CFStringCompare (cfStr1, cfStr2, kCFCompareCaseInsensitive);
357 case kCFCompareEqualTo:
return 0;
358 case kCFCompareLessThan:
return -1;
359 case kCFCompareGreaterThan:
375 return stricmp16 (str1, str1Len, str2, str2Len);
396 CFStringFindAndReplace (formatString, CFSTR(
"%s"), CFSTR(
"%S"), CFRangeMake (0, CFStringGetLength (formatString)), 0);
397 CFStringRef resultString = CFStringCreateWithFormatAndArguments (Steinberg::kCFAllocator, 0, formatString, ap);
398 CFRelease (formatString);
402 res.fromCFStringRef (resultString);
404 CFRelease (resultString);
477 case FVariant::kString8:
478 buffer8 = (char8*)var.getString8 ();
479 len = buffer8 ? strlen8 (buffer8) : 0;
483 case FVariant::kString16:
484 buffer16 = (char16*)var.getString16 ();
485 len = buffer16 ? strlen16 (buffer16) : 0;
527 return buffer8[index] == dest[0];
536 if (
len == 0|| idx >=
len)
539 if ((idx +
n >
len) ||
n < 0)
570 if ((idx +
n >
len) ||
n < 0)
598 if ((idx +
n >
len) ||
n < 0)
628 iStr->setText16 (
text16 ());
643 string.setText16 (
text16 ());
645 string.setText8 (
text8 ());
670 return strcmp (*
this, str);
677 return strncmp (*
this, str,
n);
689 return stricmp16 (*
this, str);
696 return strnicmp16 (*
this, str,
n);
740 return strcmp (toCompare, str);
742 return stricmp (toCompare, str);
747 return strncmp (toCompare, str,
n);
771 return stricmp16 (toCompare, str.
text16 ());
778 return strnicmp16 (toCompare, str.
text16 (),
n);
941 if (endIndex > -1 && (
uint32)endIndex <
len)
942 endLength = endIndex + 1;
958 for (
i = startIndex;
i < endLength;
i++)
964 for (
i = startIndex;
i < endLength;
i++)
985 for (
i = startIndex;
i < endLength;
i++)
991 for (
i = startIndex;
i < endLength;
i++)
1014 if (endIndex > -1 && (
uint32)endIndex <
len)
1015 endLength = endIndex + 1;
1032 for (
i = startIndex;
i < endLength;
i++)
1041 for (
i = startIndex;
i < endLength;
i++)
1054 if (endIndex > -1 && (
uint32)endIndex <
len)
1055 endLength = endIndex + 1;
1060 char8 dest[8] = {0};
1073 for (
i = startIndex;
i < endLength;
i++)
1082 for (
i = startIndex;
i < endLength;
i++)
1106 if (startIndex < 0 || startIndex > (
int32)
len)
1113 for (
i = startIndex;
i >= 0;
i--)
1122 for (
i = startIndex;
i >= 0;
i--)
1140 char8 dest[8] = {0};
1147 if (startIndex < 0 || startIndex > (
int32)
len)
1154 for (
i = startIndex;
i >= 0;
i--)
1163 for (
i = startIndex;
i >= 0;
i--)
1180 if (startIndex < 0 || startIndex >= (
int32)
len)
1181 startIndex =
len - 1;
1189 for (
i = startIndex;
i >= 0;
i--)
1195 for (
i = startIndex;
i >= 0;
i--)
1207 if (startIndex < 0 || startIndex >= (
int32)
len)
1208 startIndex =
len - 1;
1216 for (
i = startIndex;
i >= 0;
i--)
1222 for (
i = startIndex;
i >= 0;
i--)
1253 int32 next = startIndex;
1274 char8 dest[8] = {0};
1281 int32 next = startIndex;
1325 for (
i = 0;
i <= len1 &&
i <= len2;
i++)
1333 for (
i = 0;
i <= len1 &&
i <= len2;
i++)
1344 for (
i = 0;
i <= len1 &&
i <= len2;
i++)
1352 for (
i = 0;
i <= len1 &&
i <= len2;
i++)
1427 if (sscanf (
text,
"%" FORMAT_INT64A, &
value) == 1)
1429 else if (scanToEnd ==
false)
1453 if (sscanf (
text,
"%" FORMAT_UINT64A, &
value) == 1)
1455 else if (scanToEnd ==
false)
1500 if (sscanf (
text,
"%x", &
v) == 1)
1505 else if (scanToEnd ==
false)
1551 if ((pos = str.
findNext (offset,
',')) >= 0 && ((
uint32)pos) >= offset)
1556 while (txt && txt[0])
1558 if (sscanf (txt,
"%lf", &
value) == 1)
1560 else if (scanToEnd ==
false)
1571 WCHAR temp[2] = {
c, 0};
1572 ::CharLowerW (temp);
1576 UniChar characters [2] = {0};
1578 CFMutableStringRef str = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocator, characters, 1, 2, kCFAllocatorNull);
1581 CFStringLowercase (str,
NULL);
1583 if (characters[1] == 0)
1584 return characters[0];
1588 assert(
false &&
"DEPRECATED No Linux implementation");
1591 return towlower (
c);
1599 WCHAR temp[2] = {
c, 0};
1600 ::CharUpperW (temp);
1604 UniChar characters [2] = {0};
1606 CFMutableStringRef str = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocator, characters, 1, 2, kCFAllocatorNull);
1609 CFStringUppercase (str,
NULL);
1611 if (characters[1] == 0)
1612 return characters[0];
1616 assert(
false &&
"DEPRECATED No Linux implementation");
1619 return towupper (
c);
1626 if ((
c >=
'A') && (
c <=
'Z'))
1627 return c + (
'a' -
'A');
1629 CHAR temp[2] = {
c, 0};
1630 ::CharLowerA (temp);
1633 return static_cast<char8> (tolower (
c));
1640 if ((
c >=
'a') && (
c <=
'z'))
1641 return c - (
'a' -
'A');
1643 CHAR temp[2] = {
c, 0};
1644 ::CharUpperA (temp);
1647 return static_cast<char8> (toupper (
c));
1654 return isspace (character) != 0;
1685 return isalpha (character) != 0;
1691 return iswalpha (character) != 0;
1697 return isalnum (character) != 0;
1703 return iswalnum (character) != 0;
1709 return isdigit (character) != 0;
1715 return iswdigit (character) != 0;
1721 return character >= 0;
1727 return character < 128;
1733 return toUpper (character) == character;
1739 return toUpper (character) == character;
1745 return toLower (character) == character;
1751 return toLower (character) == character;
1824 for (
i = 0;
i <
len;
i++)
1830 for (
i = 0;
i <
len;
i++)
1839uint32 kDefaultSystemEncoding = kCFStringEncodingMacRoman;
1841static CFStringEncoding MBCodePageToCFStringEncoding (
uint32 codePage)
1845 case kCP_ANSI:
return kDefaultSystemEncoding;
1847 case kCP_ANSI_WEL:
return kCFStringEncodingWindowsLatin1;
1848 case kCP_MAC_CEE:
return kCFStringEncodingMacCentralEurRoman;
1849 case kCP_Utf8:
return kCFStringEncodingUTF8;
1850 case kCP_ShiftJIS:
return kCFStringEncodingShiftJIS_X0213_00;
1853 return kCFStringEncodingASCII;
1860 if (source ==
nullptr || source[0] == 0)
1862 if (dest && charCount > 0)
1870 result = MultiByteToWideChar (sourceCodePage, MB_ERR_INVALID_CHARS, source, -1, dest, charCount);
1875 (CFStringRef)::toCFStringRef (source, MBCodePageToCFStringEncoding (sourceCodePage));
1878 CFRange range = {0, CFStringGetLength (cfStr)};
1880 if (CFStringGetBytes (cfStr, range, kCFStringEncodingUnicode,
' ',
false, (UInt8*)dest,
1881 charCount * 2, &usedBytes) > 0)
1885 dest[usedBytes / 2] = 0;
1895 if (dest ==
nullptr)
1897 auto state = std::mbstate_t ();
1898 auto maxChars = charCount ? charCount : std::numeric_limits<int32>::max () - 1;
1899 result = converterFacet ().length (state, source, source + strlen (source), maxChars);
1903 auto utf16Str = converter ().from_bytes (source);
1904 if (!utf16Str.empty ())
1906 result = std::min<int32> (charCount, utf16Str.size ());
1914 assert(
false &&
"DEPRECATED No Linux implementation");
1927 return WideCharToMultiByte (destCodePage, 0, wideString, -1, dest, charCount,
nullptr,
nullptr);
1931 if (wideString != 0)
1935 CFStringRef cfStr = CFStringCreateWithCharactersNoCopy (kCFAllocator, (
const UniChar*)wideString,
strlen16 (wideString), kCFAllocatorNull);
1938 if (fromCFStringRef (dest, charCount, cfStr, MBCodePageToCFStringEncoding (destCodePage)))
1945 return static_cast<int32> (CFStringGetMaximumSizeForEncoding (
strlen16 (wideString), MBCodePageToCFStringEncoding (destCodePage)));
1954 if (dest ==
nullptr)
1956 auto maxChars = charCount ? charCount :
tstrlen (wideString);
1957 result = converterFacet ().max_length () * maxChars;
1961 auto utf8Str = converter ().to_bytes (wideString);
1962 if (!utf8Str.empty ())
1964 result = std::min<int32> (charCount, utf8Str.size ());
1972 if (dest ==
nullptr)
1979 for (;
i < charCount; ++
i)
1981 if (wideString[
i] == 0)
1983 if (wideString[
i] <= 0x007F)
1984 dest[
i] = wideString[
i];
1994 assert(
false &&
"DEPRECATED No Linux implementation");
1999#warning DEPRECATED No Linux implementation
2000 assert(
false &&
"DEPRECATED No Linux implementation");
2017 return (normCharCount ==
len);
2026 CFStringRef cfStr = (CFStringRef)toCFStringRef ();
2027 CFIndex charCount = CFStringGetLength (cfStr);
2029 return (charCount ==
len);
2049 assign (str,
n, isTerminated);
2058 assign (str,
n, isTerminated);
2066 assign (str,
n, isTerminated);
2109#if SMTG_CPP11_STDLIBSUPPORT
2113 *
this = std::move (str);
2125 str.buffer =
nullptr;
2150 bytesNeeded +=
sizeof (
char16);
2172#define SMTG_STRING_CHECK_CONVERSION 1
2173#define SMTG_STRING_CHECK_CONVERSION_NO_BREAK 1
2175#if SMTG_STRING_CHECK_CONVERSION_NO_BREAK
2176 #define SMTG_STRING_CHECK_MSG FDebugPrint
2178 #define SMTG_STRING_CHECK_MSG FDebugBreak
2186#if DEVELOPMENT && SMTG_STRING_CHECK_CONVERSION
2187 int debugLen =
length ();
2188 int debugNonASCII = 0;
2195 String* backUp =
nullptr;
2196 if (debugNonASCII > 0)
2201 bool result =
const_cast <String&
> (*this).toMultiByte (destCodePage);
2203#if DEVELOPMENT && SMTG_STRING_CHECK_CONVERSION
2209 if (temp != *backUp)
2215 SMTG_STRING_CHECK_MSG (
"Indirect string potential conversion information loss ! %d/%d non ASCII chars result: \"%s\"\n", debugNonASCII, debugLen,
buffer8);
2276 if (normCharCount ==
len)
2280 uint32 converterCount =
static_cast<uint32> (FoldString (MAP_PRECOMPOSED,
buffer16,
len, newString, normCharCount + 1));
2281 if (converterCount != normCharCount)
2286 newString [converterCount] = 0;
2296 CFMutableStringRef origStr = (CFMutableStringRef)toCFStringRef (0xFFFF,
true);
2299 CFStringNormalizationForm normForm = kCFStringNormalizationFormD;
2302 case kUnicodeNormC: normForm = kCFStringNormalizationFormC;
break;
2303 case kUnicodeNormD: normForm = kCFStringNormalizationFormD;
break;
2304 case kUnicodeNormKC: normForm = kCFStringNormalizationFormKC;
break;
2305 case kUnicodeNormKD: normForm = kCFStringNormalizationFormKD;
break;
2307 CFStringNormalize (origStr, normForm);
2308 bool result = fromCFStringRef (origStr);
2309 CFRelease (origStr);
2339 size_t newCharSize = wide ?
sizeof (
char16) :
sizeof (
char8);
2342 size_t newBufferSize = (newLength + 1) * newCharSize;
2343 size_t oldBufferSize = (
len + 1) * oldCharSize;
2349 if (newBufferSize != oldBufferSize)
2351 void* newstr = realloc (
buffer, newBufferSize);
2352 if (newstr ==
nullptr)
2360 else if (wide && newCharSize != oldCharSize)
2365 void* newstr =
malloc (newBufferSize);
2366 if (newstr ==
nullptr)
2401 if (index ==
len &&
c == 0)
2453 if (index ==
len &&
c == 0)
2484 char8 dest[8] = {0};
2516 uint32 stringLength = (
uint32)((str) ? strlen (str) : 0);
2623 uint32 stringLength = (
uint32)((str) ? strlen (str) : 0);
2629 if (!
resize (newlen,
false))
2664 if (!
resize (newlen,
true))
2698 if (!
resize (newlen,
false))
2729 if (!
resize (newlen,
true))
2767 uint32 stringLength = (
uint32)((str) ? strlen (str) : 0);
2773 if (!
resize (newlen,
false))
2807 if (!
resize (newlen,
true))
2837 if (idx >
len || str ==
nullptr)
2845 if (tmp.
length () == 0 || n2 == 0)
2850 if (n1 < 0 || idx + n1 >
len)
2855 uint32 stringLength = (
uint32)((str) ? strlen (str) : 0);
2856 n2 = n2 < 0 ? stringLength : Min<uint32> (n2, stringLength);
2860 if (!
resize (newlen,
false))
2878 if (idx >
len || str ==
nullptr)
2887 if (n1 < 0 || idx + n1 >
len)
2893 n2 = n2 < 0 ? stringLength : Min<uint32> (n2, stringLength);
2897 if (!
resize (newlen,
true))
2915 if (toReplace ==
nullptr || toReplaceWith ==
nullptr)
2923 int32 toReplaceLen =
static_cast<int32> (strlen (toReplace));
2924 int32 toReplaceWithLen =
static_cast<int32> (strlen (toReplaceWith));
2927 replace (idx, toReplaceLen, toReplaceWith, toReplaceWithLen);
2931 idx =
findNext (idx + toReplaceWithLen , toReplace, -1,
m);
2943 if (toReplace ==
nullptr || toReplaceWith ==
nullptr)
2955 replace (idx, toReplaceLen, toReplaceWith, toReplaceWithLen);
2959 idx =
findNext (idx + toReplaceWithLen, toReplace, -1,
m);
2971 bool anyReplace =
false;
2975 const T* rep = toReplace;
2999 String toReplaceW (toReplace);
3003 char8 src[] = {toReplaceBy, 0};
3012 if (toReplaceBy == 0)
3026 String toReplaceA (toReplace);
3030 if (toReplaceA.
length () > 1)
3032 SMTG_WARNING(
"cannot replace non ASCII chars on non Wide String")
3036 char16 src[] = {toReplaceBy, 0};
3037 char8 dest[8] = {0};
3044 if (toReplaceBy == 0)
3045 toReplaceBy =
STR16 (
' ');
3058 if ((idx +
n >
len) ||
n < 0)
3081 bool removed =
false;
3082 while (!removed || allOccurences)
3094template <
class T,
class F>
3097 uint32 toRemoveAtHead = 0;
3098 uint32 toRemoveAtTail = 0;
3102 while ((*
p) && ((func (*
p) != 0) == funcResult))
3105 toRemoveAtHead =
static_cast<uint32> (
p - str);
3107 if (toRemoveAtHead <
length)
3111 while (((func (*
p) != 0) == funcResult) && (
p > str))
3118 uint32 newLength =
length - (toRemoveAtHead + toRemoveAtTail);
3122 memmove (str, str + toRemoveAtHead, newLength *
sizeof (T));
3163 if (newLength !=
len)
3173template <
class T,
class F>
3180 if ((func (*
p) != 0) == funcResult)
3182 size_t toMove =
length - (
p - str);
3183 memmove (
p,
p + 1, toMove *
sizeof (T));
3226 if (newLength !=
len)
3242 const T* rem = toRemove;
3255 size_t toMove =
length - (
p - str);
3256 memmove (
p,
p + 1, toMove *
sizeof (T));
3268 if (
isEmpty () || toRemove ==
nullptr)
3281 if (newLength !=
len)
3283 resize (newLength,
false);
3292 if (
isEmpty () || toRemove ==
nullptr)
3305 if (newLength !=
len)
3307 resize (newLength,
true);
3379 char16* pointPtr = strrchr16 (
string,
STR (
'.'));
3385 while (pointPtr < (
string + index))
3387 if (
string[index] == zero)
3403 char8* pointPtr = strrchr (
string,
'.');
3408 while (pointPtr < (
string + index))
3410 if (
string[index] ==
'0')
3434 if (!applyOnlyFormat)
3437 if (separator != 0 && index > 0 &&
testChar (index - 1, separator) ==
true)
3443 if (number < minNumber)
3450 if (separator &&
isEmpty () ==
false)
3466 if (separator &&
isEmpty () ==
false)
3503 CFMutableStringRef cfStr = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocator, (UniChar*)
buffer16,
len,
len+1, kCFAllocatorNull);
3504 CFStringLowercase (cfStr,
NULL);
3548 CFMutableStringRef cfStr = CFStringCreateMutableWithExternalCharactersNoCopy (kCFAllocator, (UniChar*)
buffer16,
len,
len+1, kCFAllocatorNull);
3549 CFStringUppercase (cfStr,
NULL);
3635 void* tmp =
s.buffer;
3637 bool tmpWide =
s.isWide;
3678 void* passed =
pass ();
3750bool String::fromCFStringRef (
const void* cfStr,
uint32 encoding)
3755 CFStringRef strRef = (CFStringRef)cfStr;
3758 CFRange range = { 0, CFStringGetLength (strRef)};
3760 if (
resize (
static_cast<int32> (range.length + 1),
true))
3762 if (encoding == 0xFFFF)
3763 encoding = kCFStringEncodingUnicode;
3764 if (CFStringGetBytes (strRef, range, encoding,
' ',
false, (UInt8*)
buffer16, range.length * 2, &usedBytes) > 0)
3776 if (encoding == 0xFFFF)
3777 encoding = kCFStringEncodingASCII;
3778 int32 len =
static_cast<int32> (CFStringGetLength (strRef) * 2);
3781 if (CFStringGetCString (strRef,
buffer8,
len, encoding))
3793void* ConstString::toCFStringRef (
uint32 encoding,
bool mutableCFString)
const
3795 if (mutableCFString)
3797 CFMutableStringRef str = CFStringCreateMutable (kCFAllocator, 0);
3800 CFStringAppendCharacters (str, (
const UniChar *)
buffer16,
len);
3805 if (encoding == 0xFFFF)
3806 encoding = kCFStringEncodingASCII;
3807 CFStringAppendCString (str,
buffer8, encoding);
3815 if (encoding == 0xFFFF)
3816 encoding = kCFStringEncodingUnicode;
3817 return (
void*)CFStringCreateWithBytes (kCFAllocator, (
const unsigned char*)
buffer16,
len * 2, encoding,
false);
3821 if (encoding == 0xFFFF)
3822 encoding = kCFStringEncodingASCII;
3824 return (
void*)CFStringCreateWithCString (kCFAllocator,
buffer8, encoding);
3826 return (
void*)CFStringCreateWithCString (kCFAllocator,
"", encoding);
3840 for (
h = 0; *
s !=
'\0';
s++)
3841 h = (64 *
h + *
s) %
m;
3852 for (
h = 0; *
s != 0;
s++)
3853 h = (64 *
h + *
s) %
m;
3861 if (s1 ==
nullptr && s2 ==
nullptr)
3863 else if (s1 ==
nullptr)
3865 else if (s2 ==
nullptr)
3872 int32 s1LeadingZeros = 0;
3878 int32 s2LeadingZeros = 0;
3885 int32 countS1Digits = 0;
3888 int32 countS2Digits = 0;
3892 if (countS1Digits != countS2Digits)
3893 return countS1Digits - countS2Digits;
3895 for (
int32 i = 0;
i < countS1Digits;
i++)
3899 return (
int32)(*s1 - *s2);
3904 if (s1LeadingZeros != s2LeadingZeros)
3905 return s1LeadingZeros - s2LeadingZeros;
3909 if (caseSensitive ==
false)
3911 T srcToUpper =
static_cast<T
> (toupper (*s1));
3912 T dstToUpper =
static_cast<T
> (toupper (*s2));
3913 if (srcToUpper != dstToUpper)
3914 return (
int32)(srcToUpper - dstToUpper);
3916 else if (*s1 != *s2)
3917 return (
int32)(*s1 - *s2);
3924 if (*s1 == 0 && *s2 == 0)
3931 return (
int32)(*s1 - *s2);
#define nullptr
Definition DistrhoDefines.h:75
uint8_t a
Definition Spc_Cpu.h:141
int32_t int32
Definition basics.h:89
static bool isCharLower(char8 character)
Definition fstring.cpp:1743
virtual const char8 * text8() const
Returns pointer to string of type char8.
Definition fstring.h:492
int32 getFirstDifferent(const ConstString &str, CompareMode=kCaseSensitive) const
Returns position of first different character.
Definition fstring.cpp:1297
int64 getTrailingNumber(int64 fallback=0) const
Returns result of scanInt64 or the fallback.
Definition fstring.cpp:1790
bool testChar16(uint32 index, char16 c) const
Definition fstring.cpp:517
bool isAsciiString() const
Checks if all characters in string are in ascii range.
Definition fstring.cpp:1819
virtual const tchar * text() const
Returns pointer to string of type tchar.
Definition fstring.h:482
static bool scanUInt32_16(const char16 *text, uint32 &value, bool scanToEnd=true)
Converts string of type char16 to int32 value.
Definition fstring.h:597
static bool scanInt32_8(const char8 *text, int32 &value, bool scanToEnd=true)
Converts string of type char8 to int32 value.
Definition fstring.h:549
static bool isCharSpace(char8 character)
Returns true if character is a space.
Definition fstring.cpp:1652
static bool scanUInt64_16(const char16 *text, uint64 &value, bool scanToEnd=true)
Converts string of type char16 to uint64 value.
Definition fstring.cpp:1463
static int32 wideStringToMultiByte(char8 *dest, const char16 *source, int32 char8Count, uint32 destCodePage=kCP_Default)
If dest is zero, this returns the maximum number of bytes needed to convert source.
Definition fstring.cpp:1924
CompareMode
Definition fstring.h:170
@ kCaseSensitive
Comparison is done with regard to character's case.
Definition fstring.h:171
bool endsWith(const ConstString &str, CompareMode m=kCaseSensitive) const
Check if this ends with str.
Definition fstring.cpp:883
int32 naturalCompare(const ConstString &str, CompareMode mode=kCaseSensitive) const
Definition fstring.cpp:801
bool isDigit(uint32 index) const
Returns true if character at position is a digit.
Definition fstring.cpp:1755
uint32 len
Definition fstring.h:295
static bool scanHex_16(const char16 *text, uint8 &value, bool scanToEnd=true)
Converts string of type char16 to hex/unit8 value.
Definition fstring.cpp:1513
bool testChar8(uint32 index, char8 c) const
Returns true if character is equal at position 'index'.
Definition fstring.cpp:500
bool scanInt32(int32 &value, uint32 offset=0, bool scanToEnd=true) const
Converts string to int32 value starting at offset.
Definition fstring.cpp:1399
static bool scanHex_8(const char8 *text, uint8 &value, bool scanToEnd=true)
Converts string of type char8 to hex/unit8 value.
Definition fstring.cpp:1495
bool scanHex(uint8 &value, uint32 offset=0, bool scanToEnd=true) const
Converts string to hex/uint8 value starting at offset.
Definition fstring.cpp:1387
static bool isCharUpper(char8 character)
Definition fstring.cpp:1731
bool scanUInt32(uint32 &value, uint32 offset=0, bool scanToEnd=true) const
Converts string to uint32 value starting at offset.
Definition fstring.cpp:1411
bool extract(String &result, uint32 idx, int32 n=-1) const
Get n characters long substring starting at index (n=-1: until end).
Definition fstring.cpp:534
static char8 toLower(char8 c)
Converts to lower case.
Definition fstring.cpp:1624
static bool isCharAlphaNum(char8 character)
Returns true if character is an alphanumeric character.
Definition fstring.cpp:1695
int32 copyTo8(char8 *str, uint32 idx=0, int32 n=-1) const
Definition fstring.cpp:551
int32 countOccurences(char8 c, uint32 startIndex, CompareMode=kCaseSensitive) const
Counts occurences of c within this starting at index.
Definition fstring.cpp:1241
bool isWideString() const
Returns true if string is wide.
Definition fstring.h:276
bool startsWith(const ConstString &str, CompareMode m=kCaseSensitive) const
Check if this starts with str.
Definition fstring.cpp:834
char8 * buffer8
Definition fstring.h:292
int32 getTrailingNumberIndex(uint32 width=0) const
Returns start index of trailing number.
Definition fstring.cpp:1767
int32 copyTo(tchar *str, uint32 idx=0, int32 n=-1) const
Definition fstring.cpp:607
bool scanUInt64(uint64 &value, uint32 offset=0, bool scanToEnd=true) const
Converts string to uint64 value starting at offset.
Definition fstring.cpp:1375
ConstString(const char8 *str, int32 length=-1)
Assign from string of type char8 (length=-1: all).
Definition fstring.cpp:439
ConstString()
Definition fstring.cpp:492
bool isEmpty() const
Return true if string is empty.
Definition fstring.h:129
static int32 multiByteToWideString(char16 *dest, const char8 *source, int32 wcharCount, uint32 sourceCodePage=kCP_Default)
If dest is zero, this returns the maximum number of bytes needed to convert source.
Definition fstring.cpp:1858
bool contains(const ConstString &str, CompareMode m=kCaseSensitive) const
Check if this contains str.
Definition fstring.cpp:932
bool testChar(uint32 index, char8 c) const
Definition fstring.h:152
void toVariant(FVariant &var) const
Definition fstring.cpp:1806
static bool scanInt64_8(const char8 *text, int64 &value, bool scanToEnd=true)
Converts string of type char8 to int64 value.
Definition fstring.cpp:1423
static bool isCharAscii(char8 character)
Returns true if character is in ASCII range.
Definition fstring.cpp:1719
int32 findNext(int32 startIndex, const ConstString &str, int32 n=-1, CompareMode=kCaseSensitive, int32 endIndex=-1) const
Definition fstring.cpp:938
int32 findFirst(const ConstString &str, int32 n=-1, CompareMode m=kCaseSensitive, int32 endIndex=-1) const
Definition fstring.h:204
static bool scanInt64_16(const char16 *text, int64 &value, bool scanToEnd=true)
Converts string of type char16 to int64 value.
Definition fstring.cpp:1437
static bool isCharDigit(char8 character)
Returns true if character is a number.
Definition fstring.cpp:1707
static bool isCharAlpha(char8 character)
Returns true if character is an alphabetic character.
Definition fstring.cpp:1683
bool isNormalized(UnicodeNormalization=kUnicodeNormC)
On PC only kUnicodeNormC is working.
Definition fstring.cpp:2007
int32 findPrev(int32 startIndex, const ConstString &str, int32 n=-1, CompareMode=kCaseSensitive) const
Definition fstring.cpp:1173
bool scanFloat(double &value, uint32 offset=0, bool scanToEnd=true) const
Converts string to double value starting at offset.
Definition fstring.cpp:1535
bool scanInt64(int64 &value, uint32 offset=0, bool scanToEnd=true) const
Converts string to int64 value starting at offset.
Definition fstring.cpp:1363
int32 copyTo16(char16 *str, uint32 idx=0, int32 n=-1) const
Definition fstring.cpp:579
static bool scanUInt64_8(const char8 *text, uint64 &value, bool scanToEnd=true)
Converts string of type char8 to uint64 value.
Definition fstring.cpp:1449
int32 compareAt(uint32 index, const ConstString &str, int32 n=-1, CompareMode m=kCaseSensitive) const
Compare n characters of str with n characters of this starting at index (return: see above).
Definition fstring.cpp:709
int32 compare(const ConstString &str, int32 n, CompareMode m=kCaseSensitive) const
Compare n characters of str with n characters of this (return: see above).
Definition fstring.cpp:651
static bool scanUInt32_8(const char8 *text, uint32 &value, bool scanToEnd=true)
Converts string of type char8 to int32 value.
Definition fstring.h:585
virtual const char16 * text16() const
Returns pointer to string of type char16.
Definition fstring.h:498
virtual int32 length() const
Return length of string.
Definition fstring.h:128
char16 * buffer16
Definition fstring.h:293
static char8 toUpper(char8 c)
Converts to upper case.
Definition fstring.cpp:1638
void * buffer
Definition fstring.h:291
uint32 isWide
Definition fstring.h:296
static bool scanInt32_16(const char16 *text, int32 &value, bool scanToEnd=true)
Converts string of type char16 to int32 value.
Definition fstring.h:561
Definition funknown.h:403
@ kString8
Definition fvariant.h:42
@ kFloat
Definition fvariant.h:41
@ kInteger
Definition fvariant.h:40
@ kString16
Definition fvariant.h:45
const char8 * getString8() const
Definition fvariant.h:141
double getFloat() const
Definition fvariant.h:135
int64 getInt() const
Definition fvariant.h:134
const char16 * getString16() const
Definition fvariant.h:142
void setString8(const char8 *v)
Definition fvariant.h:111
uint16 getType() const
Definition fvariant.h:146
void setString16(const char16 *v)
Definition fvariant.h:117
void setOwner(bool state)
Definition fvariant.h:150
Definition ipersistent.h:80
Definition istringresult.h:50
virtual bool PLUGIN_API isWideString() const =0
virtual const char8 *PLUGIN_API getText8()=0
virtual const char16 *PLUGIN_API getText16()=0
Definition istringresult.h:32
String & printf(const char8 *format,...)
Print formatted data into string.
Definition fstring.cpp:3314
String & assign(const ConstString &str, int32 n=-1)
Assign n characters of str (-1: all).
Definition fstring.cpp:2500
CharGroup
Definition fstring.h:396
@ kNotAlphaNum
Definition fstring.h:396
@ kNotAlpha
Definition fstring.h:396
@ kSpace
Definition fstring.h:396
bool checkToMultiByte(uint32 destCodePage=kCP_Default) const
Definition fstring.cpp:2181
bool replaceChars8(const char8 *toReplace, char8 toReplaceBy)
Returns true when any replacement was done.
Definition fstring.cpp:2992
const char8 * text8() const SMTG_OVERRIDE
Returns pointer to string of type char8.
Definition fstring.h:621
void swapContent(String &s)
Swaps ownership of the strings pointed to.
Definition fstring.cpp:3633
void toUpper()
Upper case the string.
Definition fstring.cpp:3540
bool normalize(UnicodeNormalization=kUnicodeNormC)
On PC only kUnicodeNormC is working.
Definition fstring.cpp:2262
bool fromAttributes(IAttributes *a, IAttrID attrID)
Assigns string from FAttributes.
Definition fstring.cpp:3613
bool fromVariant(const FVariant &var)
Assigns string from FVariant.
Definition fstring.cpp:3573
~String()
Definition fstring.cpp:2103
String & vprintf(const char8 *format, va_list args)
Definition fstring.cpp:3339
bool removeChars8(const char8 *which)
Remove all occurrences of each char in 'which'.
Definition fstring.cpp:3266
bool toAttributes(IAttributes *a, IAttrID attrID)
Definition fstring.cpp:3622
String()
Definition fstring.cpp:2038
String & insertAt(uint32 idx, const ConstString &str, int32 n=-1)
Insert n characters of str at position idx (n=-1: all).
Definition fstring.cpp:2745
bool removeChars16(const char16 *which)
Remove all occurrences of each char in 'which'.
Definition fstring.cpp:3290
const String & fromPascalString(const unsigned char *buf)
Pascal string conversion.
Definition fstring.cpp:3734
void * pass()
Definition fstring.cpp:3667
bool setChar16(uint32 index, char16 c)
Definition fstring.cpp:2451
bool toWideString(uint32 sourceCodePage=kCP_Default)
Converts to wide string according to sourceCodePage.
Definition fstring.cpp:2141
bool toMultiByte(uint32 destCodePage=kCP_Default)
Definition fstring.cpp:2225
void take(String &str)
Take ownership of the string of 'str'.
Definition fstring.cpp:3647
String & printFloat(double value)
Definition fstring.cpp:3372
unsigned char * toPascalString(unsigned char *buf)
Pascal string conversion.
Definition fstring.cpp:3704
String & printInt64(int64 value)
Definition fstring.cpp:3357
String & append(const ConstString &str, int32 n=-1)
Append n characters of str to this (n=-1: all).
Definition fstring.cpp:2597
String & operator=(const char8 *str)
Assign from a string of type char8.
Definition fstring.h:341
const char16 * text16() const SMTG_OVERRIDE
Returns pointer to string of type char16.
Definition fstring.h:630
bool incrementTrailingNumber(uint32 width=2, tchar separator=STR(' '), uint32 minNumber=1, bool applyOnlyFormat=false)
Definition fstring.cpp:3424
bool resize(uint32 newSize, bool wide, bool fill=false)
Definition fstring.cpp:2329
void toVariant(FVariant &var) const
Definition fstring.cpp:3600
String & remove(uint32 index=0, int32 n=-1)
Remove n characters from string starting at index (n=-1: until end).
Definition fstring.cpp:3053
bool setChar8(uint32 index, char8 c)
Definition fstring.cpp:2399
void fromUTF8(const char8 *utf8String)
Assigns from UTF8 string.
Definition fstring.cpp:2255
void passToVariant(FVariant &var)
Pass ownership of buffer to Variant - sets Variant ownership.
Definition fstring.cpp:3676
void tryFreeBuffer()
Definition fstring.cpp:2319
bool removeSubString(const ConstString &subString, bool allOccurences=true)
Definition fstring.cpp:3079
bool replaceChars16(const char16 *toReplace, char16 toReplaceBy)
Definition fstring.cpp:3019
void updateLength()
Call this when the string is truncated outside (not recommended though).
Definition fstring.cpp:2132
void toLower()
Lower case the string.
Definition fstring.cpp:3495
String & replace(uint32 idx, int32 n1, const ConstString &str, int32 n2=-1)
Replace n1 characters of this (starting at idx) with n2 characters of str (n1,n2=-1: until end).
Definition fstring.cpp:2824
bool setChar(uint32 index, char8 c)
Definition fstring.h:336
void removeChars(CharGroup mode=kSpace)
Removes all of group.
Definition fstring.cpp:3192
const char8 *PLUGIN_API getText8() SMTG_OVERRIDE
Definition fstring.cpp:3967
void PLUGIN_API take(void *s, bool _isWide) SMTG_OVERRIDE
Definition fstring.cpp:3979
void PLUGIN_API setText8(const char8 *text) SMTG_OVERRIDE
Definition fstring.cpp:3955
const char16 *PLUGIN_API getText16() SMTG_OVERRIDE
Definition fstring.cpp:3973
void PLUGIN_API setText(const char8 *text) SMTG_OVERRIDE
Definition fstring.cpp:3949
void PLUGIN_API setText16(const char16 *text) SMTG_OVERRIDE
Definition fstring.cpp:3961
bool PLUGIN_API isWideString() const SMTG_OVERRIDE
Definition fstring.cpp:3985
String trim() const
Definition String.cpp:1540
unsigned * m
Definition inflate.c:1559
unsigned v[N_MAX]
Definition inflate.c:1584
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
#define SMTG_WARNING(s)
Definition fdebug.h:197
#define NEW
Definition fdebug.h:212
#define SMTG_ASSERT(f)
Definition fdebug.h:196
#define STR(x)
Definition fstrdefs.h:39
#define STR16(x)
Definition fstrdefs.h:35
#define SMTG_STRING_CHECK_MSG
Definition fstring.cpp:2176
#define kPrintfBufferSize
Definition fstring.cpp:68
static PuglViewHint int value
Definition pugl.h:1708
static PuglViewHint hint
Definition pugl.h:1707
static int width
Definition pugl.h:1593
struct backing_store_struct * info
Definition jmemsys.h:183
int marker
Definition jpeglib.h:950
int version
Definition jpeglib.h:901
Definition baseiids.cpp:43
static uint32 performTrim(T *str, uint32 length, F func, bool funcResult)
Definition fstring.cpp:3095
unsigned long long uint64
Definition ftypes.h:67
int16 char16
Definition ftypes.h:101
static bool performReplace(T *str, const T *toReplace, T toReplaceBy)
Definition fstring.cpp:2969
int int32
Definition ftypes.h:50
static const uint32 kPrintfBufferSize
Definition fstrdefs.h:286
int32 strlen8(const char8 *str)
Definition fstrdefs.h:125
static uint32 performRemoveChars(T *str, uint32 length, const T *toRemove)
Definition fstring.cpp:3235
FIDString IAttrID
Definition ipersistent.h:62
static const char16 kEmptyString16[]
Definition fstrdefs.h:104
char char8
Definition ftypes.h:93
int32 strncmp16(const char16 *first, const char16 *last, uint32 count)
Definition fstrdefs.h:186
static const bool kWideStringDefault
Definition fstring.h:57
@ kResultTrue
Definition funknown.h:194
static const char8 kEmptyString8[]
Definition fstrdefs.h:103
long long int64
Definition ftypes.h:66
int32 strcmp16(const char16 *src, const char16 *dst)
Definition fstrdefs.h:150
int32 strnatcmp16(const char16 *s1, const char16 *s2, bool caseSensitive)
Definition fstring.cpp:3941
char16 tchar
Definition ftypes.h:105
int32 strlen16(const char16 *str)
Definition fstrdefs.h:126
uint32 hashString8(const char8 *s, uint32 m)
Definition fstring.cpp:3835
MBCodePage
Definition fstring.h:66
@ kCP_MAC_ROMAN
Default Mac codepage.
Definition fstring.h:68
@ kCP_ShiftJIS
Shifted Japan Industrial Standard Encoding.
Definition fstring.h:73
@ kCP_US_ASCII
US-ASCII (7-bit).
Definition fstring.h:74
@ kCP_Default
Default ANSI codepage.
Definition fstring.h:76
@ kCP_MAC_CEE
Mac Central European Encoding.
Definition fstring.h:71
@ kCP_ANSI_WEL
West European Latin Encoding.
Definition fstring.h:70
@ kCP_ANSI
Default ANSI codepage.
Definition fstring.h:67
@ kCP_Utf8
UTF8 Encoding.
Definition fstring.h:72
static bool isCaseSensitive(ConstString::CompareMode mode)
Definition fstring.cpp:431
unsigned char uint8
Definition ftypes.h:40
int32 tstrlen(const tchar *str)
Definition fstrdefs.h:124
UnicodeNormalization
Definition fstring.h:80
@ kUnicodeNormKD
Unicode normalization form KD, compatibility decomposition.
Definition fstring.h:84
@ kUnicodeNormKC
Unicode normalization form KC, compatibility composition.
Definition fstring.h:83
@ kUnicodeNormD
Unicode normalization Form D, canonical decomposition.
Definition fstring.h:82
@ kUnicodeNormC
Unicode normalization Form C, canonical composition.
Definition fstring.h:81
static uint32 performRemove(T *str, uint32 length, F func, bool funcResult)
Definition fstring.cpp:3174
uint32 hashString16(const char16 *s, uint32 m)
Definition fstring.cpp:3847
int32 tstrnatcmp(const T *s1, const T *s2, bool caseSensitive=true)
Definition fstring.cpp:3859
int32 strnatcmp8(const char8 *s1, const char8 *s2, bool caseSensitive)
Definition fstring.cpp:3935
unsigned int uint32
Definition ftypes.h:51
png_uint_32 length
Definition png.c:2247
png_structrp int mode
Definition png.h:1139
#define stricmp(x, y)
Definition swell-types.h:68
#define strnicmp(x, y, z)
Definition swell-types.h:71
char CHAR
Definition swell-types.h:188
int n
Definition crypt.c:458
uch * p
Definition crypt.c:594
return c
Definition crypt.c:175
memcpy(hh, h, RAND_HEAD_LEN)
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
int result
Definition process.c:1455
else sprintf(d_t_str, LoadFarString(shtYMDHMTime), yr%100, monthstr, dy, hh, mm)
_WDL_CSTRING_PREFIX void INT_PTR const char * format
Definition wdlcstring.h:263