26JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4514 4996)
30#if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
31 #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
34#if JUCE_NATIVE_WCHAR_IS_UTF8
36#elif JUCE_NATIVE_WCHAR_IS_UTF16
51 using CharType = String::CharPointerType::CharType;
54 size_t allocatedNumBytes =
sizeof (CharType);
55 CharType text[1] { 0 };
65 using CharType = StringHolder::CharType;
69 numBytes = (numBytes + 3) & ~(
size_t) 3;
70 auto* bytes =
new char [
sizeof (
StringHolder) -
sizeof (CharType) + numBytes];
73 s->allocatedNumBytes = numBytes;
77 template <
class CharPo
inter>
80 if (text.getAddress() ==
nullptr || text.isEmpty())
89 template <
class CharPo
inter>
92 if (text.getAddress() ==
nullptr || text.isEmpty() || maxChars == 0)
99 while (numChars < maxChars && !
end.isEmpty())
105 auto dest = createUninitialisedBytes (
bytesNeeded);
110 template <
class CharPo
inter>
113 if (start.getAddress() ==
nullptr || start.isEmpty())
120 while (e <
end && ! e.isEmpty())
126 auto dest = createUninitialisedBytes (
bytesNeeded);
133 if (start.getAddress() ==
nullptr || start.isEmpty())
136 auto numBytes = (
size_t) (
reinterpret_cast<const char*
> (
end.getAddress())
137 -
reinterpret_cast<const char*
> (start.getAddress()));
138 auto dest = createUninitialisedBytes (numBytes +
sizeof (CharType));
139 memcpy (dest.getAddress(), start, numBytes);
140 dest.getAddress()[numBytes /
sizeof (CharType)] = 0;
144 static CharPointerType createFromFixedLength (
const char*
const src,
const size_t numChars)
146 auto dest = createUninitialisedBytes (numChars *
sizeof (CharType) +
sizeof (CharType));
154 auto* b = bufferFromText (text);
156 if (! isEmptyString (b))
162 if (! isEmptyString (b))
163 if (--(b->refCount) == -1)
164 delete[]
reinterpret_cast<char*
> (b);
169 release (bufferFromText (text));
174 return bufferFromText (text)->refCount + 1;
180 auto* b = bufferFromText (text);
182 if (isEmptyString (b))
184 auto newText = createUninitialisedBytes (numBytes);
189 if (b->allocatedNumBytes >= numBytes && b->refCount <= 0)
192 auto newText = createUninitialisedBytes (
jmax (b->allocatedNumBytes, numBytes));
193 memcpy (
newText.getAddress(), text.getAddress(), b->allocatedNumBytes);
199 static size_t getAllocatedNumBytes (
const CharPointerType text)
noexcept
201 return bufferFromText (text)->allocatedNumBytes;
215 return other == &emptyString;
218 void compileTimeChecks()
221 #if JUCE_NATIVE_WCHAR_IS_UTF8
222 static_assert (
sizeof (wchar_t) == 1,
"JUCE_NATIVE_WCHAR_IS_* macro has incorrect value");
223 #elif JUCE_NATIVE_WCHAR_IS_UTF16
224 static_assert (
sizeof (wchar_t) == 2,
"JUCE_NATIVE_WCHAR_IS_* macro has incorrect value");
225 #elif JUCE_NATIVE_WCHAR_IS_UTF32
226 static_assert (
sizeof (wchar_t) == 4,
"JUCE_NATIVE_WCHAR_IS_* macro has incorrect value");
228 #error "native wchar_t size is unknown"
240 StringHolderUtils::release (text);
245 StringHolderUtils::retain (text);
255 StringHolderUtils::release (text);
256 text = emptyString.text;
261 StringHolderUtils::retain (
other.text);
262 StringHolderUtils::release (text.atomicSwap (
other.text));
268 other.text = emptyString.text;
277inline String::PreallocationBytes::PreallocationBytes (
const size_t num) noexcept : numBytes (num) {}
280 : text (StringHolderUtils::createUninitialisedBytes (
preallocationSize.numBytes +
sizeof (CharPointerType::CharType)))
286 text = StringHolderUtils::makeUniqueWithByteSize (text,
numBytesNeeded +
sizeof (CharPointerType::CharType));
291 return StringHolderUtils::getReferenceCount (text);
369namespace NumberToStringConverters
373 charsNeededForInt = 32,
374 charsNeededForDouble = 48
377 template <
typename Type>
378 static char* printDigits (
char* t, Type v)
noexcept
384 *--t =
static_cast<char> (
'0' + (
char) (v % 10));
393 static char* numberToString (
char* t,
int64 n)
noexcept
396 return printDigits (t,
static_cast<uint64> (n));
400 t = printDigits (t,
static_cast<uint64> (-(n + 1)) + 1);
405 static char* numberToString (
char* t,
uint64 v)
noexcept
407 return printDigits (t, v);
410 static char* numberToString (
char* t,
int n)
noexcept
413 return printDigits (t,
static_cast<unsigned int> (n));
417 t = printDigits (t,
static_cast<unsigned int> (-(n + 1)) + 1);
422 static char* numberToString (
char* t,
unsigned int v)
noexcept
424 return printDigits (t, v);
427 static char* numberToString (
char* t,
long n)
noexcept
430 return printDigits (t,
static_cast<unsigned long> (n));
432 t = printDigits (t,
static_cast<unsigned long> (-(n + 1)) + 1);
437 static char* numberToString (
char* t,
unsigned long v)
noexcept
439 return printDigits (t, v);
444 explicit StackArrayStream (
char* d)
448 setp (d, d + charsNeededForDouble);
471 StackArrayStream
strm (buffer);
473 jassert (len <= charsNeededForDouble);
477 template <
typename IntegerType>
480 char buffer [charsNeededForInt];
482 auto* start = numberToString (
end, number);
483 return StringHolderUtils::createFromFixedLength (start, (
size_t) (
end - start - 1));
488 char buffer [charsNeededForDouble];
491 return StringHolderUtils::createFromFixedLength (start, len);
496String::String (
int number) : text (NumberToStringConverters::createFromInteger (number)) {}
497String::String (
unsigned int number) : text (NumberToStringConverters::createFromInteger (number)) {}
498String::String (
short number) : text (NumberToStringConverters::createFromInteger ((
int) number)) {}
502String::String (
long number) : text (NumberToStringConverters::createFromInteger (number)) {}
503String::String (
unsigned long number) : text (NumberToStringConverters::createFromInteger (number)) {}
513 return (
int) text.
length();
518 return (
size_t) (((
char*) text.findTerminatingNull().getAddress()) - (
char*) text.getAddress());
521size_t String::getByteOffsetOfEnd()
const noexcept
523 return findByteOffsetOfEnd (text);
528 jassert (index == 0 || (index > 0 && index <= (
int) text.lengthUpTo ((
size_t) index + 1)));
532template <
typename Type>
535 template <
typename CharPo
inter>
540 while (! t.isEmpty())
541 result = ((Type)
multiplier) * result + (Type) t.getAndAdvance();
546 enum {
multiplier =
sizeof (Type) > 4 ? 101 : 31 };
556JUCE_API
bool JUCE_CALLTYPE operator== (
const String& s1,
const char* s2)
noexcept {
return s1.compare (s2) == 0; }
557JUCE_API
bool JUCE_CALLTYPE operator!= (
const String& s1,
const char* s2)
noexcept {
return s1.compare (s2) != 0; }
558JUCE_API
bool JUCE_CALLTYPE operator== (
const String& s1,
const wchar_t* s2)
noexcept {
return s1.compare (s2) == 0; }
559JUCE_API
bool JUCE_CALLTYPE operator!= (
const String& s1,
const wchar_t* s2)
noexcept {
return s1.compare (s2) != 0; }
575 return t !=
nullptr ? text.compareIgnoreCase (castToCharPointer_wchar_t (t)) == 0
587 return text.compareIgnoreCase (t.text) == 0;
592 return text ==
other.text
593 || text.compareIgnoreCase (
other.text) == 0;
605 auto c1 = s1.getAndAdvance();
608 auto c2 = s2.getAndAdvance();
615 if (
c1 !=
c2 && bias == 0)
616 bias =
c1 <
c2 ? -1 : 1;
626 auto c1 = s1.getAndAdvance();
629 auto c2 = s2.getAndAdvance();
635 if (
c1 <
c2)
return -1;
636 if (
c1 >
c2)
return 1;
646 const bool hasSpace1 = s1.isWhitespace();
647 const bool hasSpace2 = s2.isWhitespace();
651 if (s1.isEmpty())
return -1;
652 if (s2.isEmpty())
return 1;
659 if (
hasSpace1) s1 = s1.findEndOfWhitespace();
660 if (
hasSpace2) s2 = s2.findEndOfWhitespace();
662 if (s1.isDigit() && s2.isDigit())
664 auto result = (*s1 ==
'0' || *s2 ==
'0') ? stringCompareLeft (s1, s2)
665 : stringCompareRight (s1, s2);
671 auto c1 = s1.getAndAdvance();
672 auto c2 = s2.getAndAdvance();
674 if (
c1 !=
c2 && ! isCaseSensitive)
693 return c1 <
c2 ? -1 : 1;
702 return naturalStringCompare (getCharPointer(),
other.text, isCaseSensitive);
768 const char asString[] = {
ch, 0 };
774 const wchar_t asString[] = {
ch, 0 };
778#if ! JUCE_NATIVE_WCHAR_IS_UTF32
787namespace StringHelpers
789 template <
typename T>
790 inline String& operationAddAssign (String& str,
const T number)
792 char buffer [(
sizeof (T) * 8) / 2];
794 auto* start = NumberToStringConverters::numberToString (
end, number);
796 #if JUCE_STRING_UTF_TYPE == 8
799 str.appendCharPointer (CharPointer_ASCII (start), CharPointer_ASCII (
end));
826#if ! JUCE_NATIVE_WCHAR_IS_UTF32
860 #if (JUCE_STRING_UTF_TYPE == 8)
867 stream.
write (temp, numBytes);
876 return text.indexOf (character);
883 for (
int i = 0; ! t.isEmpty(); ++i)
887 if (t.getAndAdvance() == character)
904 for (
int i = 0; ! t.isEmpty(); ++i)
905 if (t.getAndAdvance() == character)
915 for (
int i = 0; ! t.isEmpty(); ++i)
933 return other.isEmpty() ? 0 : text.indexOf (
other.text);
948 for (
int i = startIndex; --i >= 0;)
956 auto found = t.indexOf (
other.text);
957 return found >= 0 ? found + startIndex : found;
967 for (
int i = startIndex; --i >= 0;)
976 return found >= 0 ? found + startIndex : found;
981 if (
other.isNotEmpty())
983 auto len =
other.length();
984 int i = length() - len;
988 for (
auto n = text + i; i >= 0; --i)
990 if (n.compareUpTo (
other.text, len) == 0)
1003 if (
other.isNotEmpty())
1005 auto len =
other.length();
1006 int i = length() - len;
1010 for (
auto n = text + i; i >= 0; --i)
1012 if (n.compareIgnoreCaseUpTo (
other.text, len) == 0)
1028 for (
int i = 0; ! t.isEmpty(); ++i)
1037 return indexOf (
other) >= 0;
1042 return text.indexOf (character) >= 0;
1047 return indexOfIgnoreCase (t) >= 0;
1052 if (
word.isNotEmpty())
1058 for (
int i = 0; i <=
end; ++i)
1061 && (i == 0 || ! (t - 1).isLetterOrDigit())
1062 && ! (t +
wordLen).isLetterOrDigit())
1074 if (
word.isNotEmpty())
1080 for (
int i = 0; i <=
end; ++i)
1082 if (t.compareIgnoreCaseUpTo (
word.text,
wordLen) == 0
1083 && (i == 0 || ! (t - 1).isLetterOrDigit())
1084 && ! (t +
wordLen).isLetterOrDigit())
1105template <
typename CharPo
inter>
1112 auto wc = wildcard.getAndAdvance();
1115 return wildcard.isEmpty() || matchesAnywhere (wildcard, test, ignoreCase);
1117 if (! characterMatches (
wc, test.getAndAdvance(), ignoreCase))
1127 return (
wc ==
tc) || (
wc ==
'?' &&
tc != 0)
1131 static bool matchesAnywhere (
const CharPointer wildcard,
CharPointer test,
const bool ignoreCase)
noexcept
1133 for (; ! test.isEmpty(); ++test)
1134 if (matches (wildcard, test, ignoreCase))
1153 auto n = result.text;
1179 auto n = result.text;
1206 auto n = result.text;
1236 for (
int i = 0; i < index; ++i)
1267 auto* dest = (
char*) result.text.
getAddress();
1318 : source (s), allocatedBytes (StringHolderUtils::getAllocatedNumBytes (s))
1328 if (bytesWritten > allocatedBytes)
1330 allocatedBytes +=
jmax ((
size_t) 8, allocatedBytes / 16);
1341 size_t allocatedBytes, bytesWritten = 0;
1364 return std::move (builder.result);
1389 return std::move (builder.result);
1395 return text.compareUpTo (
other.text,
other.length()) == 0;
1400 return text.compareIgnoreCaseUpTo (
other.text,
other.length()) == 0;
1407 return *text == character;
1417 auto t = text.findTerminatingNull();
1418 return *--t == character;
1423 auto end = text.findTerminatingNull();
1440 auto end = text.findTerminatingNull();
1471 return std::move (builder.result);
1489 return std::move (builder.result);
1544 while (--start >= 0)
1605static bool isQuoteCharacter (
juce_wchar c)
noexcept
1607 return c ==
'"' || c ==
'\'';
1617 if (! isQuoteCharacter (*text))
1621 return substring (1, len - (isQuoteCharacter (text[len - 1]) ? 1 : 0));
1646 if (! (--
end).isWhitespace())
1754 return std::move (builder.result);
1775 return std::move (builder.result);
1780 for (
auto t = text; ! t.
isEmpty(); ++t)
1789 for (
auto t = text; ! t.
isEmpty(); ++t)
1798 for (
auto t = text; ! t.isEmpty();)
1799 if (
chars.text.indexOf (t.getAndAdvance()) < 0)
1807 for (
auto t = text; ! t.isEmpty();)
1808 if (
chars.text.indexOf (t.getAndAdvance()) >= 0)
1816 for (
auto t = text; ! t.
isEmpty(); ++t)
1817 if (! t.isWhitespace())
1823String String::formattedRaw (
const char*
pf, ...)
1825 size_t bufferSize = 256;
1833 JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE (
"-Wdeprecated-declarations")
1838 int num = (
int) vsnprintf (temp.get(), bufferSize - 1,
pf, args);
1839 if (num >=
static_cast<int> (bufferSize))
1844 const int num = (
int)
1850 (temp.get(), bufferSize - 1,
wideCharVersion.toWideCharPointer(), args);
1854 JUCE_END_IGNORE_WARNINGS_GCC_LIKE
1859 return String (temp.get());
1863 if (num == 0 || bufferSize > 65536)
1899static const char hexDigits[] =
"0123456789abcdef";
1901template <
typename Type>
1902static String hexToString (Type v)
1904 String::CharPointerType::CharType buffer[32];
1911 *--t = hexDigits [(
int) (v & 15)];
1912 v =
static_cast<Type
> (v >> 4);
1920String String::createHex (
uint8 n) {
return hexToString (n); }
1921String String::createHex (
uint16 n) {
return hexToString (n); }
1922String String::createHex (
uint32 n) {
return hexToString (n); }
1923String String::createHex (
uint64 n) {
return hexToString (n); }
1930 int numChars = (size * 2) + 2;
1934 String s (PreallocationBytes ((
size_t) numChars *
sizeof (CharPointerType::CharType)));
1936 auto* data =
static_cast<const unsigned char*
> (d);
1939 for (
int i = 0; i < size; ++i)
1941 const unsigned char nextByte = *data++;
1957static String getStringFromWindows1252Codepage (
const char* data,
size_t num)
1961 for (
size_t i = 0; i < num; ++i)
1972 if (size <= 0 || data ==
nullptr)
1981 const int numChars = size / 2 - 1;
1989 for (
int i = 0; i < numChars; ++i)
1994 for (
int i = 0; i < numChars; ++i)
1999 return std::move (builder.result);
2002 auto* start = (
const char*) data;
2014 return getStringFromWindows1252Codepage (start, (
size_t) size);
2020template <
class CharPo
interType_Src,
class CharPo
interType_Dest>
2025 auto& source =
const_cast<String&
> (s);
2027 using DestChar =
typename CharPointerType_Dest::CharType;
2029 if (source.isEmpty())
2033 auto extraBytesNeeded = CharPointerType_Dest::getBytesRequiredFor (text) +
sizeof (
typename CharPointerType_Dest::CharType);
2034 auto endOffset = (text.sizeInBytes() + 3) & ~3u;
2037 text = source.getCharPointer();
2090template <
class CharPo
interType_Src,
class CharPo
interType_Dest>
2097 if (buffer ==
nullptr)
2098 return CharPointerType_Dest::getBytesRequiredFor (source) +
sizeof (
typename CharPointerType_Dest::CharType);
2127 if (buffer !=
nullptr)
2142JUCE_END_IGNORE_WARNINGS_MSVC
2150 #if JUCE_STRING_UTF_TYPE != 8
2156 #if JUCE_STRING_UTF_TYPE != 8
2162 #if JUCE_NATIVE_WCHAR_IS_UTF8
2189static String reduceLengthOfFloatString (
const String& input)
2193 auto trimStart =
end;
2194 auto trimEnd = trimStart;
2200 for (
auto c =
end - 1; c > start; --c)
2210 if (trimStart == c + 1 && trimStart !=
end && *trimStart ==
'0')
2239 trimEnd = trimStart;
2245 if (trimStart == trimEnd)
2249 return String (start, trimStart) + String (trimEnd,
end);
2260static String serialiseDouble (
double input)
2265 return reduceLengthOfFloatString ({ input, 15,
true });
2270 return { input, 1 };
2303#if JUCE_ALLOW_STATIC_NULL_VARIABLES
2305JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE (
"-Wdeprecated-declarations")
2306JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996)
2308const String String::empty;
2310JUCE_END_IGNORE_WARNINGS_GCC_LIKE
2311JUCE_END_IGNORE_WARNINGS_MSVC
2319#define STRINGIFY2(X) #X
2320#define STRINGIFY(X) STRINGIFY2(X)
2329 template <
class CharPo
interType>
2332 static void test (UnitTest& test, Random& r)
2334 String s (createRandomWideCharString (r));
2336 typename CharPointerType::CharType buffer [300];
2338 memset (buffer, 0xff,
sizeof (buffer));
2339 CharPointerType (buffer).writeAll (s.toUTF32());
2340 test.expectEquals (String (CharPointerType (buffer)), s);
2342 memset (buffer, 0xff,
sizeof (buffer));
2343 CharPointerType (buffer).writeAll (s.toUTF16());
2344 test.expectEquals (String (CharPointerType (buffer)), s);
2346 memset (buffer, 0xff,
sizeof (buffer));
2347 CharPointerType (buffer).writeAll (s.toUTF8());
2348 test.expectEquals (String (CharPointerType (buffer)), s);
2350 test.expect (CharPointerType::isValidString (buffer, (
int) strlen ((
const char*) buffer)));
2364 buffer[i] = (
juce_wchar) (1 + r.nextInt (0x10ffff - 1));
2369 buffer[i] = (
juce_wchar) (1 + r.nextInt (0xff));
2372 return CharPointer_UTF32 (buffer);
2375 void runTest()
override
2377 Random r = getRandom();
2380 beginTest (
"Basics");
2382 expect (String().length() == 0);
2383 expect (String() == String());
2384 String s1, s2 (
"abcd");
2385 expect (s1.isEmpty() && ! s1.isNotEmpty());
2386 expect (s2.isNotEmpty() && ! s2.isEmpty());
2387 expect (s2.length() == 4);
2389 expect (s2 == s1 && s1 == s2);
2390 expect (s1 ==
"abcd" && s1 ==
L"abcd");
2391 expect (String (
"abcd") == String (
L"abcd"));
2392 expect (String (
"abcdefg", 4) ==
L"abcd");
2393 expect (String (
"abcdefg", 4) == String (
L"abcdefg", 4));
2396 expect (s2 +
"e" ==
"abcde" && s2 +
'e' ==
"abcde");
2397 expect (s2 +
L'e' ==
"abcde" && s2 +
L"e" ==
"abcde");
2399 expect (s1.startsWith (
"ab") && s1.startsWith (
"abcd") && ! s1.startsWith (
"abcde"));
2400 expect (s1.startsWithIgnoreCase (
"aB") && s1.endsWithIgnoreCase (
"CD"));
2401 expect (s1.endsWith (
"bcd") && ! s1.endsWith (
"aabcd"));
2402 expectEquals (s1.indexOf (String()), 0);
2403 expectEquals (s1.indexOfIgnoreCase (String()), 0);
2404 expect (s1.startsWith (String()) && s1.endsWith (String()) && s1.contains (String()));
2405 expect (s1.contains (
"cd") && s1.contains (
"ab") && s1.contains (
"abcd"));
2406 expect (s1.containsChar (
'a'));
2407 expect (! s1.containsChar (
'x'));
2408 expect (! s1.containsChar (0));
2409 expect (String (
"abc foo bar").containsWholeWord (
"abc") && String (
"abc foo bar").containsWholeWord (
"abc"));
2413 beginTest (
"Operations");
2415 String s (
"012345678");
2416 expect (s.hashCode() != 0);
2417 expect (s.hashCode64() != 0);
2418 expect (s.hashCode() != (s + s).hashCode());
2419 expect (s.hashCode64() != (s + s).hashCode64());
2420 expect (s.compare (String (
"012345678")) == 0);
2421 expect (s.compare (String (
"012345679")) < 0);
2422 expect (s.compare (String (
"012345676")) > 0);
2423 expect (String (
"a").compareNatural (
"A") == 0);
2424 expect (String (
"A").compareNatural (
"B") < 0);
2425 expect (String (
"a").compareNatural (
"B") < 0);
2426 expect (String (
"10").compareNatural (
"2") > 0);
2427 expect (String (
"Abc 10").compareNatural (
"aBC 2") > 0);
2428 expect (String (
"Abc 1").compareNatural (
"aBC 2") < 0);
2431 expect (s.getLastCharacter() == s [s.length() - 1]);
2433 expect (s.substring (0, 3) ==
L"012");
2434 expect (s.substring (0, 100) == s);
2435 expect (s.substring (-1, 100) == s);
2436 expect (s.substring (3) ==
"345678");
2437 expect (s.indexOf (String (
L"45")) == 4);
2438 expect (String (
"444445").indexOf (
"45") == 4);
2439 expect (String (
"444445").lastIndexOfChar (
'4') == 4);
2440 expect (String (
"45454545x").lastIndexOf (String (
L"45")) == 6);
2441 expect (String (
"45454545x").lastIndexOfAnyOf (
"456") == 7);
2442 expect (String (
"45454545x").lastIndexOfAnyOf (String (
L"456x")) == 8);
2443 expect (String (
"abABaBaBa").lastIndexOfIgnoreCase (
"aB") == 6);
2444 expect (s.indexOfChar (
L'4') == 4);
2445 expect (s + s ==
"012345678012345678");
2446 expect (s.startsWith (s));
2447 expect (s.startsWith (s.substring (0, 4)));
2448 expect (s.startsWith (s.dropLastCharacters (4)));
2449 expect (s.endsWith (s.substring (5)));
2450 expect (s.endsWith (s));
2451 expect (s.contains (s.substring (3, 6)));
2452 expect (s.contains (s.substring (3)));
2453 expect (s.startsWithChar (s[0]));
2454 expect (s.endsWithChar (s.getLastCharacter()));
2455 expect (s [s.length()] == 0);
2456 expect (String (
"abcdEFGH").toLowerCase() == String (
"abcdefgh"));
2457 expect (String (
"abcdEFGH").toUpperCase() == String (
"ABCDEFGH"));
2459 expect (String (StringRef (
"abc")) ==
"abc");
2460 expect (String (StringRef (
"abc")) == StringRef (
"abc"));
2461 expect (String (
"abc") + StringRef (
"def") ==
"abcdef");
2463 expect (String (
"0x00").getHexValue32() == 0);
2464 expect (String (
"0x100").getHexValue32() == 256);
2467 s2 << ((
int) 4) << ((
short) 5) <<
"678" <<
L"9" <<
'0';
2469 expect (s2 ==
"1234567890xyz");
2471 expect (s2 ==
"1234567890xyz123");
2473 expect (s2 ==
"1234567890xyz123123");
2474 s2 << StringRef (
"def");
2475 expect (s2 ==
"1234567890xyz123123def");
2480 expect (
numStr ==
"32767");
2484 expect (
numStr ==
"-32768");
2489 expect (
numStr ==
"32767");
2494 expect (
numStr ==
"-32768");
2499 expect (
numStr ==
"2147483647");
2503 expect (
numStr ==
"-2147483648");
2508 expect (
numStr ==
"2147483647");
2513 expect (
numStr ==
"-2147483648");
2518 expect (
numStr ==
"4294967295");
2527 expect (
numStr ==
"9223372036854775807");
2531 expect (
numStr ==
"-9223372036854775808");
2536 expect (
numStr ==
"9223372036854775807");
2541 expect (
numStr ==
"-9223372036854775808");
2546 expect (
numStr ==
"18446744073709551615");
2555 expect (
numStr ==
"18446744073709551615");
2568 beginTest (
"Numeric conversions");
2569 expect (String().getIntValue() == 0);
2570 expectEquals (String().getDoubleValue(), 0.0);
2571 expectEquals (String().getFloatValue(), 0.0f);
2572 expect (s.getIntValue() == 12345678);
2573 expect (s.getLargeIntValue() == (
int64) 12345678);
2574 expectEquals (s.getDoubleValue(), 12345678.0);
2575 expectEquals (s.getFloatValue(), 12345678.0f);
2576 expect (String (-1234).getIntValue() == -1234);
2577 expect (String ((
int64) -1234).getLargeIntValue() == -1234);
2578 expectEquals (String (-1234.56).getDoubleValue(), -1234.56);
2579 expectEquals (String (-1234.56f).getFloatValue(), -1234.56f);
2584 expect ((
"xyz" + s).getTrailingIntValue() == s.getIntValue());
2585 expect (String (
"xyz-5").getTrailingIntValue() == -5);
2586 expect (String (
"-12345").getTrailingIntValue() == -12345);
2587 expect (s.getHexValue32() == 0x12345678);
2588 expect (s.getHexValue64() == (
int64) 0x12345678);
2599 unsigned char data[] = { 1, 2, 3, 4, 0xa, 0xb, 0xc, 0xd };
2604 expectEquals (String (12345.67, 4), String (
"12345.6700"));
2605 expectEquals (String (12345.67, 6), String (
"12345.670000"));
2606 expectEquals (String (2589410.5894, 7), String (
"2589410.5894000"));
2607 expectEquals (String (12345.67, 8), String (
"12345.67000000"));
2608 expectEquals (String (1
e19, 4), String (
"10000000000000000000.0000"));
2609 expectEquals (String (1e-34, 36), String (
"0.000000000000000000000000000000000100"));
2610 expectEquals (String (1.39, 1), String (
"1.4"));
2612 expectEquals (String (12345.67, 4,
true), String (
"1.2346e+04"));
2613 expectEquals (String (12345.67, 6,
true), String (
"1.234567e+04"));
2614 expectEquals (String (2589410.5894, 7,
true), String (
"2.5894106e+06"));
2615 expectEquals (String (12345.67, 8,
true), String (
"1.23456700e+04"));
2616 expectEquals (String (1
e19, 4,
true), String (
"1.0000e+19"));
2617 expectEquals (String (1e-34, 5,
true), String (
"1.00000e-34"));
2618 expectEquals (String (1.39, 1,
true), String (
"1.4e+00"));
2620 beginTest (
"Subsections");
2623 expect (s3.equalsIgnoreCase (
"ABCdeFGhiJ"));
2624 expect (s3.compareIgnoreCase (
L"ABCdeFGhiJ") == 0);
2625 expect (s3.containsIgnoreCase (s3.substring (3)));
2626 expect (s3.indexOfAnyOf (
"xyzf", 2,
true) == 5);
2627 expect (s3.indexOfAnyOf (String (
L"xyzf"), 2,
false) == -1);
2628 expect (s3.indexOfAnyOf (
"xyzF", 2,
false) == 5);
2629 expect (s3.containsAnyOf (String (
L"zzzFs")));
2630 expect (s3.startsWith (
"abcd"));
2631 expect (s3.startsWithIgnoreCase (String (
L"abCD")));
2632 expect (s3.startsWith (String()));
2633 expect (s3.startsWithChar (
'a'));
2634 expect (s3.endsWith (String (
"HIJ")));
2635 expect (s3.endsWithIgnoreCase (String (
L"Hij")));
2636 expect (s3.endsWith (String()));
2637 expect (s3.endsWithChar (
L'J'));
2638 expect (s3.indexOf (
"HIJ") == 7);
2639 expect (s3.indexOf (String (
L"HIJK")) == -1);
2640 expect (s3.indexOfIgnoreCase (
"hij") == 7);
2641 expect (s3.indexOfIgnoreCase (String (
L"hijk")) == -1);
2642 expect (s3.toStdString() == s3.toRawUTF8());
2645 s4.append (String (
"xyz123"), 3);
2646 expect (s4 == s3 +
"xyz");
2648 expect (String (1234) < String (1235));
2649 expect (String (1235) > String (1234));
2650 expect (String (1234) >= String (1234));
2651 expect (String (1234) <= String (1234));
2652 expect (String (1235) >= String (1234));
2653 expect (String (1234) <= String (1235));
2655 String
s5 (
"word word2 word3");
2656 expect (
s5.containsWholeWord (String (
"word2")));
2657 expect (
s5.indexOfWholeWord (
"word2") == 5);
2658 expect (
s5.containsWholeWord (String (
L"word")));
2659 expect (
s5.containsWholeWord (
"word3"));
2660 expect (
s5.containsWholeWord (
s5));
2661 expect (
s5.containsWholeWordIgnoreCase (String (
L"Word2")));
2662 expect (
s5.indexOfWholeWordIgnoreCase (
"Word2") == 5);
2663 expect (
s5.containsWholeWordIgnoreCase (String (
L"Word")));
2664 expect (
s5.containsWholeWordIgnoreCase (
"Word3"));
2665 expect (!
s5.containsWholeWordIgnoreCase (String (
L"Wordx")));
2666 expect (!
s5.containsWholeWordIgnoreCase (
"xWord2"));
2667 expect (
s5.containsNonWhitespaceChars());
2668 expect (
s5.containsOnly (
"ordw23 "));
2669 expect (! String (
" \n\r\t").containsNonWhitespaceChars());
2671 expect (
s5.matchesWildcard (String (
L"wor*"),
false));
2672 expect (
s5.matchesWildcard (
"wOr*",
true));
2673 expect (
s5.matchesWildcard (String (
L"*word3"),
true));
2674 expect (
s5.matchesWildcard (
"*word?",
true));
2675 expect (
s5.matchesWildcard (String (
L"Word*3"),
true));
2676 expect (!
s5.matchesWildcard (String (
L"*34"),
true));
2677 expect (String (
"xx**y").matchesWildcard (
"*y",
true));
2678 expect (String (
"xx**y").matchesWildcard (
"x*y",
true));
2679 expect (String (
"xx**y").matchesWildcard (
"xx*y",
true));
2680 expect (String (
"xx**y").matchesWildcard (
"xx*",
true));
2681 expect (String (
"xx?y").matchesWildcard (
"x??y",
true));
2682 expect (String (
"xx?y").matchesWildcard (
"xx?y",
true));
2683 expect (! String (
"xx?y").matchesWildcard (
"xx?y?",
true));
2684 expect (String (
"xx?y").matchesWildcard (
"xx??",
true));
2686 expectEquals (
s5.fromFirstOccurrenceOf (String(),
true,
false),
s5);
2687 expectEquals (
s5.fromFirstOccurrenceOf (
"xword2",
true,
false),
s5.substring (100));
2688 expectEquals (
s5.fromFirstOccurrenceOf (String (
L"word2"),
true,
false),
s5.substring (5));
2689 expectEquals (
s5.fromFirstOccurrenceOf (
"Word2",
true,
true),
s5.substring (5));
2690 expectEquals (
s5.fromFirstOccurrenceOf (
"word2",
false,
false),
s5.getLastCharacters (6));
2691 expectEquals (
s5.fromFirstOccurrenceOf (
"Word2",
false,
true),
s5.getLastCharacters (6));
2693 expectEquals (
s5.fromLastOccurrenceOf (String(),
true,
false),
s5);
2694 expectEquals (
s5.fromLastOccurrenceOf (
"wordx",
true,
false),
s5);
2695 expectEquals (
s5.fromLastOccurrenceOf (
"word",
true,
false),
s5.getLastCharacters (5));
2696 expectEquals (
s5.fromLastOccurrenceOf (
"worD",
true,
true),
s5.getLastCharacters (5));
2697 expectEquals (
s5.fromLastOccurrenceOf (
"word",
false,
false),
s5.getLastCharacters (1));
2698 expectEquals (
s5.fromLastOccurrenceOf (
"worD",
false,
true),
s5.getLastCharacters (1));
2700 expect (
s5.upToFirstOccurrenceOf (String(),
true,
false).isEmpty());
2701 expectEquals (
s5.upToFirstOccurrenceOf (
"word4",
true,
false),
s5);
2702 expectEquals (
s5.upToFirstOccurrenceOf (
"word2",
true,
false),
s5.substring (0, 10));
2703 expectEquals (
s5.upToFirstOccurrenceOf (
"Word2",
true,
true),
s5.substring (0, 10));
2704 expectEquals (
s5.upToFirstOccurrenceOf (
"word2",
false,
false),
s5.substring (0, 5));
2705 expectEquals (
s5.upToFirstOccurrenceOf (
"Word2",
false,
true),
s5.substring (0, 5));
2707 expectEquals (
s5.upToLastOccurrenceOf (String(),
true,
false),
s5);
2708 expectEquals (
s5.upToLastOccurrenceOf (
"zword",
true,
false),
s5);
2709 expectEquals (
s5.upToLastOccurrenceOf (
"word",
true,
false),
s5.dropLastCharacters (1));
2710 expectEquals (
s5.dropLastCharacters (1).upToLastOccurrenceOf (
"word",
true,
false),
s5.dropLastCharacters (1));
2711 expectEquals (
s5.upToLastOccurrenceOf (
"Word",
true,
true),
s5.dropLastCharacters (1));
2712 expectEquals (
s5.upToLastOccurrenceOf (
"word",
false,
false),
s5.dropLastCharacters (5));
2713 expectEquals (
s5.upToLastOccurrenceOf (
"Word",
false,
true),
s5.dropLastCharacters (5));
2715 expectEquals (
s5.replace (
"word",
"xyz",
false), String (
"xyz xyz2 xyz3"));
2716 expect (
s5.replace (
"Word",
"xyz",
true) ==
"xyz xyz2 xyz3");
2717 expect (
s5.dropLastCharacters (1).replace (
"Word", String (
"xyz"),
true) ==
L"xyz xyz2 xyz");
2718 expect (
s5.replace (
"Word",
"",
true) ==
" 2 3");
2719 expectEquals (
s5.replace (
"Word2",
"xyz",
true), String (
"word xyz word3"));
2720 expect (
s5.replaceCharacter (
L'w',
'x') !=
s5);
2721 expectEquals (
s5.replaceCharacter (
'w',
L'x').replaceCharacter (
'x',
'w'),
s5);
2722 expect (
s5.replaceCharacters (
"wo",
"xy") !=
s5);
2723 expectEquals (
s5.replaceCharacters (
"wo",
"xy").replaceCharacters (
"xy",
"wo"),
s5);
2724 expectEquals (
s5.retainCharacters (
"1wordxya"), String (
"wordwordword"));
2725 expect (
s5.retainCharacters (String()).isEmpty());
2726 expect (
s5.removeCharacters (
"1wordxya") ==
" 2 3");
2727 expectEquals (
s5.removeCharacters (String()),
s5);
2728 expect (
s5.initialSectionContainingOnly (
"word") ==
L"word");
2729 expect (String (
"word").initialSectionContainingOnly (
"word") ==
L"word");
2730 expectEquals (
s5.initialSectionNotContaining (String (
"xyz ")), String (
"word"));
2731 expectEquals (
s5.initialSectionNotContaining (String (
";[:'/")),
s5);
2732 expect (!
s5.isQuotedString());
2733 expect (
s5.quoted().isQuotedString());
2734 expect (!
s5.quoted().unquoted().isQuotedString());
2735 expect (! String (
"x'").isQuotedString());
2736 expect (String (
"'x").isQuotedString());
2738 String
s6 (
" \t xyz \t\r\n");
2739 expectEquals (
s6.trim(), String (
"xyz"));
2740 expect (
s6.trim().trim() ==
"xyz");
2741 expectEquals (
s5.trim(),
s5);
2742 expectEquals (
s6.trimStart().trimEnd(),
s6.trim());
2743 expectEquals (
s6.trimStart().trimEnd(),
s6.trimEnd().trimStart());
2744 expectEquals (
s6.trimStart().trimStart().trimEnd().trimEnd(),
s6.trimEnd().trimStart());
2745 expect (
s6.trimStart() !=
s6.trimEnd());
2746 expectEquals ((
"\t\r\n " +
s6 +
"\t\n \r").trim(),
s6.trim());
2751 beginTest (
"UTF conversions");
2753 TestUTFConversion <CharPointer_UTF32>::test (*
this, r);
2754 TestUTFConversion <CharPointer_UTF8>::test (*
this, r);
2755 TestUTFConversion <CharPointer_UTF16>::test (*
this, r);
2759 beginTest (
"StringArray");
2762 s.addTokens (
"4,3,2,1,0",
";,",
"x");
2763 expectEquals (s.size(), 5);
2765 expectEquals (s.joinIntoString (
"-"), String (
"4-3-2-1-0"));
2767 expectEquals (s.joinIntoString (
"--"), String (
"4--3--1--0"));
2768 expectEquals (s.joinIntoString (StringRef()), String (
"4310"));
2770 expectEquals (s.joinIntoString (
"x"), String());
2773 toks.addTokens (
"x,,",
";,",
"");
2774 expectEquals (
toks.size(), 3);
2775 expectEquals (
toks.joinIntoString (
"-"), String (
"x--"));
2778 toks.addTokens (
",x,",
";,",
"");
2779 expectEquals (
toks.size(), 3);
2780 expectEquals (
toks.joinIntoString (
"-"), String (
"-x-"));
2783 toks.addTokens (
"x,'y,z',",
";,",
"'");
2784 expectEquals (
toks.size(), 3);
2785 expectEquals (
toks.joinIntoString (
"-"), String (
"x-'y,z'-"));
2796 expect (! v2.equals (v1));
2797 expect (! v1.equals (v2));
2798 expect (v2.equals (
v3));
2799 expect (!
v3.equals (v1));
2800 expect (! v1.equals (
v3));
2801 expect (v1.equals (
v4));
2802 expect (
v4.equals (v1));
2803 expect (
v5.equals (
v4));
2804 expect (
v4.equals (
v5));
2805 expect (! v2.equals (
v4));
2806 expect (!
v4.equals (v2));
2810 beginTest (
"Significant figures");
2853 beginTest (
"Float trimming");
2856 StringPairArray
tests;
2857 tests.set (
"1",
"1");
2858 tests.set (
"1.0",
"1.0");
2859 tests.set (
"-1",
"-1");
2860 tests.set (
"-100",
"-100");
2861 tests.set (
"110",
"110");
2862 tests.set (
"9090",
"9090");
2863 tests.set (
"1000.0",
"1000.0");
2864 tests.set (
"1.0",
"1.0");
2865 tests.set (
"-1.00",
"-1.0");
2866 tests.set (
"1.20",
"1.2");
2867 tests.set (
"1.300",
"1.3");
2868 tests.set (
"1.301",
"1.301");
2869 tests.set (
"1e",
"1");
2870 tests.set (
"-1e+",
"-1");
2871 tests.set (
"1e-",
"1");
2872 tests.set (
"1e0",
"1");
2873 tests.set (
"1e+0",
"1");
2874 tests.set (
"1e-0",
"1");
2875 tests.set (
"1e000",
"1");
2876 tests.set (
"1e+000",
"1");
2877 tests.set (
"-1e-000",
"-1");
2878 tests.set (
"1e100",
"1e100");
2879 tests.set (
"100e100",
"100e100");
2880 tests.set (
"100.0e0100",
"100.0e100");
2881 tests.set (
"-1e1",
"-1e1");
2882 tests.set (
"1e10",
"1e10");
2883 tests.set (
"-1e+10",
"-1e10");
2884 tests.set (
"1e-10",
"1e-10");
2885 tests.set (
"1e0010",
"1e10");
2886 tests.set (
"1e-0010",
"1e-10");
2887 tests.set (
"1e-1",
"1e-1");
2888 tests.set (
"-1.0e1",
"-1.0e1");
2889 tests.set (
"1.0e-1",
"1.0e-1");
2890 tests.set (
"1.00e-1",
"1.0e-1");
2891 tests.set (
"1.001e1",
"1.001e1");
2892 tests.set (
"1.010e+1",
"1.01e1");
2893 tests.set (
"-1.1000e1",
"-1.1e1");
2895 for (
auto& input :
tests.getAllKeys())
2896 expectEquals (reduceLengthOfFloatString (input),
tests[input]);
2903 tests[1.01] =
"1.01";
2904 tests[0.76378] =
"7.6378e-1";
2905 tests[-10] =
"-1.0e1";
2906 tests[10.01] =
"1.001e1";
2907 tests[10691.01] =
"1.069101e4";
2908 tests[0.0123] =
"1.23e-2";
2909 tests[-3.7e-27] =
"-3.7e-27";
2910 tests[1e+40] =
"1.0e40";
2912 for (
auto& test :
tests)
2913 expectEquals (reduceLengthOfFloatString (String (test.first, 15,
true)), test.second);
2918 beginTest (
"Serialisation");
2920 std::map <double, String>
tests;
2922 tests[364] =
"364.0";
2924 tests[12345678901] =
"1.2345678901e10";
2926 tests[1234567890123456.7] =
"1.234567890123457e15";
2927 tests[12345678.901234567] =
"1.234567890123457e7";
2928 tests[1234567.8901234567] =
"1.234567890123457e6";
2929 tests[123456.78901234567] =
"123456.7890123457";
2930 tests[12345.678901234567] =
"12345.67890123457";
2931 tests[1234.5678901234567] =
"1234.567890123457";
2932 tests[123.45678901234567] =
"123.4567890123457";
2933 tests[12.345678901234567] =
"12.34567890123457";
2934 tests[1.2345678901234567] =
"1.234567890123457";
2935 tests[0.12345678901234567] =
"0.1234567890123457";
2936 tests[0.012345678901234567] =
"0.01234567890123457";
2937 tests[0.0012345678901234567] =
"0.001234567890123457";
2938 tests[0.00012345678901234567] =
"0.0001234567890123457";
2939 tests[0.000012345678901234567] =
"0.00001234567890123457";
2940 tests[0.0000012345678901234567] =
"1.234567890123457e-6";
2941 tests[0.00000012345678901234567] =
"1.234567890123457e-7";
2943 for (
auto& test :
tests)
2945 expectEquals (serialiseDouble (test.first), test.second);
2946 expectEquals (serialiseDouble (-test.first),
"-" + test.second);
2951 beginTest (
"Loops");
2953 String str (CharPointer_UTF8 (
"\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf"));
2958 expectEquals (c,
parts[index++]);
static Type swapIfLittleEndian(Type value) noexcept
Swaps the byte order of a signed or unsigned integer if the CPU is little-endian.
static Type swapIfBigEndian(Type value) noexcept
Swaps the byte order of a signed or unsigned integer if the CPU is big-endian.
Wraps a pointer to a null-terminated ASCII character string, and provides various methods to operate ...
static bool isValidString(const CharType *dataToTest, int maxBytesToRead)
Returns true if this data contains a valid string in this encoding.
Wraps a pointer to a null-terminated UTF-16 character string, and provides various methods to operate...
static bool canRepresent(juce_wchar character) noexcept
Returns true if the given unicode character can be represented in this encoding.
static bool isByteOrderMarkBigEndian(const void *possibleByteOrder) noexcept
Returns true if the first pair of bytes in this pointer are the UTF16 byte-order mark (big endian).
static bool isByteOrderMarkLittleEndian(const void *possibleByteOrder) noexcept
Returns true if the first pair of bytes in this pointer are the UTF16 byte-order mark (little endian)...
Wraps a pointer to a null-terminated UTF-32 character string, and provides various methods to operate...
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
void writeAll(const CharPointer src) noexcept
Copies a source string to this pointer, advancing this pointer as it goes.
CharPointer_UTF8 findTerminatingNull() const noexcept
Returns a pointer to the null character that terminates this string.
juce_wchar getAndAdvance() noexcept
Returns the character that this pointer is currently pointing to, and then advances the pointer to po...
double getDoubleValue() const noexcept
Parses this string as a floating point double.
void writeNull() const noexcept
Writes a null character to this string (leaving the pointer's position unchanged).
bool isEmpty() const noexcept
Returns true if this pointer is pointing to a null character.
juce_wchar toUpperCase() const noexcept
Returns an upper-case version of the first character of this string.
static size_t getBytesRequiredFor(const juce_wchar charToWrite) noexcept
Returns the number of bytes that would be needed to represent the given unicode character in this enc...
int64 getIntValue64() const noexcept
Parses this string as a 64-bit integer.
int getIntValue32() const noexcept
Parses this string as a 32-bit integer.
static bool isByteOrderMark(const void *possibleByteOrder) noexcept
Returns true if the first three bytes in this pointer are the UTF8 byte-order mark (BOM).
void writeWithCharLimit(const CharPointer src, const int maxChars) noexcept
Copies a source string to this pointer, advancing this pointer as it goes.
static bool isValidString(const CharType *dataToTest, int maxBytesToRead)
Returns true if this data contains a valid string in this encoding.
juce_wchar toLowerCase() const noexcept
Returns a lower-case version of the first character of this string.
CharPointer_UTF8 findEndOfWhitespace() const noexcept
Returns the first non-whitespace character in the string.
void write(const juce_wchar charToWrite) noexcept
Writes a unicode character to this string, and advances this pointer to point to the next position.
CharType * getAddress() const noexcept
Returns the address that this pointer is pointing to.
size_t length() const noexcept
Returns the number of characters in this string.
static int indexOfIgnoreCase(CharPointerType1 haystack, const CharPointerType2 needle) noexcept
Finds the character index of a given substring in another string, using a case-independent match.
static juce_wchar toLowerCase(juce_wchar character) noexcept
Converts a character to lower-case.
static bool isDigit(char character) noexcept
Checks whether a character is a digit.
static bool isLetterOrDigit(char character) noexcept
Checks whether a character is alphabetic or numeric.
static juce_wchar toUpperCase(juce_wchar character) noexcept
Converts a character to upper-case.
static juce_wchar getUnicodeCharFromWindows1252Codepage(uint8 windows1252Char) noexcept
Converts a byte of Windows 1252 codepage to unicode.
Very simple container class to hold a pointer to some data on the heap.
This class is used for represent a new-line character sequence.
The base class for streams that write data to some kind of destination.
virtual bool write(const void *dataToWrite, size_t numberOfBytes)=0
Writes a block of data to the stream.
A simple class for holding temporary references to a string literal or String.
StringRef() noexcept
Creates a StringRef pointer to an empty string.
int length() const noexcept
Returns the number of characters in the string.
String::CharPointerType text
The text that is referenced.
CharPointerType getCharPointer() const noexcept
Returns the character pointer currently being used to store this string.
bool equalsIgnoreCase(const String &other) const noexcept
Case-insensitive comparison with another string.
static String repeatedString(StringRef stringToRepeat, int numberOfTimesToRepeat)
Creates a string which is a version of a string repeated and joined together.
int indexOfChar(juce_wchar characterToLookFor) const noexcept
Searches for a character inside this string.
String upToFirstOccurrenceOf(StringRef substringToEndWith, bool includeSubStringInResult, bool ignoreCase) const
Returns the start of this string, up to the first occurrence of a substring.
int length() const noexcept
Returns the number of characters in the string.
String trim() const
Returns a copy of this string with any whitespace characters removed from the start and end.
int compareNatural(StringRef other, bool isCaseSensitive=false) const noexcept
Compares two strings, taking into account textual characteristics like numbers and spaces.
bool endsWithChar(juce_wchar character) const noexcept
Tests whether the string ends with a particular character.
String trimCharactersAtStart(StringRef charactersToTrim) const
Returns a copy of this string, having removed a specified set of characters from its start.
String toUpperCase() const
Returns an upper-case version of this string.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
String() noexcept
Creates an empty string.
CharPointer_UTF16 toUTF16() const
Returns a pointer to a UTF-16 version of this string.
bool isQuotedString() const
Checks whether the string might be in quotation marks.
void append(const String &textToAppend, size_t maxCharsToTake)
Appends a string to the end of this one.
~String() noexcept
Destructor.
float getFloatValue() const noexcept
Parses this string as a floating point number.
const char * toRawUTF8() const
Returns a pointer to a UTF-8 version of this string.
static String toDecimalStringWithSignificantFigures(DecimalType number, int numberOfSignificantFigures)
Returns a string containing a decimal with a set number of significant figures.
bool containsIgnoreCase(StringRef text) const noexcept
Tests whether the string contains another substring.
bool startsWithChar(juce_wchar character) const noexcept
Tests whether the string begins with a particular character.
bool startsWith(StringRef text) const noexcept
Tests whether the string begins with another string.
int64 hashCode64() const noexcept
Generates a probably-unique 64-bit hashcode from this string.
bool containsChar(juce_wchar character) const noexcept
Tests whether the string contains a particular character.
String paddedLeft(juce_wchar padCharacter, int minimumLength) const
Returns a copy of this string with the specified character repeatedly added to its beginning until th...
bool startsWithIgnoreCase(StringRef text) const noexcept
Tests whether the string begins with another string.
int compareIgnoreCase(const String &other) const noexcept
Case-insensitive comparison with another string.
String removeCharacters(StringRef charactersToRemove) const
Returns a version of this string with a set of characters removed.
bool endsWithIgnoreCase(StringRef text) const noexcept
Tests whether the string ends with another string.
bool matchesWildcard(StringRef wildcard, bool ignoreCase) const noexcept
Returns true if the string matches this simple wildcard expression.
void appendCharPointer(CharPointerType startOfTextToAppend, CharPointerType endOfTextToAppend)
Appends a string to the end of this one.
String quoted(juce_wchar quoteCharacter='"') const
Adds quotation marks around a string.
String & operator+=(const String &stringToAppend)
Appends another string at the end of this one.
int indexOf(StringRef textToLookFor) const noexcept
Searches for a substring within this string.
size_t getNumBytesAsUTF8() const noexcept
Returns the number of bytes required to represent this string as UTF8.
String initialSectionContainingOnly(StringRef permittedCharacters) const
Returns a section from the start of the string that only contains a certain set of characters.
static String createStringFromData(const void *data, int size)
Creates a string from data in an unknown format.
int lastIndexOf(StringRef textToLookFor) const noexcept
Searches for a substring inside this string (working backwards from the end of the string).
String retainCharacters(StringRef charactersToRetain) const
Returns a version of this string that only retains a fixed set of characters.
void clear() noexcept
Resets this string to be empty.
int indexOfAnyOf(StringRef charactersToLookFor, int startIndex=0, bool ignoreCase=false) const noexcept
Returns the index of the first character that matches one of the characters passed-in to this method.
size_t copyToUTF16(CharPointer_UTF16::CharType *destBuffer, size_t maxBufferSizeBytes) const noexcept
Copies the string to a buffer as UTF-16 characters.
void preallocateBytes(size_t numBytesNeeded)
Increases the string's internally allocated storage.
int lastIndexOfAnyOf(StringRef charactersToLookFor, bool ignoreCase=false) const noexcept
Returns the index of the last character in this string that matches one of the characters passed-in t...
size_t hash() const noexcept
Generates a probably-unique hashcode from this string.
String dropLastCharacters(int numberToDrop) const
Returns a version of this string with a number of characters removed from the end.
juce_wchar operator[](int index) const noexcept
Returns the character at this index in the string.
bool contains(StringRef text) const noexcept
Tests whether the string contains another substring.
String trimStart() const
Returns a copy of this string with any whitespace characters removed from the start.
String trimEnd() const
Returns a copy of this string with any whitespace characters removed from the end.
String toLowerCase() const
Returns an lower-case version of this string.
String replaceFirstOccurrenceOf(StringRef stringToReplace, StringRef stringToInsertInstead, bool ignoreCase=false) const
Replaces the first occurrence of a substring with another string.
CharPointerType end() const
Returns an iterator pointing at the terminating null of the string.
double getDoubleValue() const noexcept
Parses this string as a floating point number.
int getTrailingIntValue() const noexcept
Parses a decimal number from the end of the string.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
int indexOfWholeWord(StringRef wordToLookFor) const noexcept
Finds an instance of another substring if it exists as a distinct word.
int lastIndexOfChar(juce_wchar character) const noexcept
Searches for a character inside this string (working backwards from the end of the string).
size_t copyToUTF32(CharPointer_UTF32::CharType *destBuffer, size_t maxBufferSizeBytes) const noexcept
Copies the string to a buffer as UTF-32 characters.
const wchar_t * toWideCharPointer() const
Returns a pointer to a wchar_t version of this string.
size_t copyToUTF8(CharPointer_UTF8::CharType *destBuffer, size_t maxBufferSizeBytes) const noexcept
Copies the string to a buffer as UTF-8 characters.
String replace(StringRef stringToReplace, StringRef stringToInsertInstead, bool ignoreCase=false) const
Replaces all occurrences of a substring with another string.
int lastIndexOfIgnoreCase(StringRef textToLookFor) const noexcept
Searches for a substring inside this string (working backwards from the end of the string).
String getLastCharacters(int numCharacters) const
Returns a number of characters from the end of the string.
String replaceCharacters(StringRef charactersToReplace, StringRef charactersToInsertInstead) const
Replaces a set of characters with another set.
String upToLastOccurrenceOf(StringRef substringToFind, bool includeSubStringInResult, bool ignoreCase) const
Returns the start of this string, up to the last occurrence of a substring.
String unquoted() const
Removes quotation marks from around the string, (if there are any).
String trimCharactersAtEnd(StringRef charactersToTrim) const
Returns a copy of this string, having removed a specified set of characters from its end.
bool containsWholeWord(StringRef wordToLookFor) const noexcept
Tests whether the string contains another substring as a distinct word.
static String charToString(juce_wchar character)
Creates a string from a single character.
String paddedRight(juce_wchar padCharacter, int minimumLength) const
Returns a copy of this string with the specified character repeatedly added to its end until the tota...
String replaceCharacter(juce_wchar characterToReplace, juce_wchar characterToInsertInstead) const
Returns a string with all occurrences of a character replaced with a different one.
juce_wchar getLastCharacter() const noexcept
Returns the final character of the string.
String substring(int startIndex, int endIndex) const
Returns a subsection of the string.
String fromLastOccurrenceOf(StringRef substringToFind, bool includeSubStringInResult, bool ignoreCase) const
Returns a section of the string starting from the last occurrence of a given substring.
int hashCode() const noexcept
Generates a probably-unique 32-bit hashcode from this string.
bool containsNonWhitespaceChars() const noexcept
Returns true if this string contains any non-whitespace characters.
String replaceSection(int startIndex, int numCharactersToReplace, StringRef stringToInsert) const
Replaces a sub-section of the string with another string.
String & operator=(const String &other) noexcept
Replaces this string's contents with another string.
String initialSectionNotContaining(StringRef charactersToStopAt) const
Returns a section from the start of the string that only contains a certain set of characters.
static String fromUTF8(const char *utf8buffer, int bufferSizeBytes=-1)
Creates a String from a UTF-8 encoded buffer.
int64 getLargeIntValue() const noexcept
Reads the value of the string as a decimal number (up to 64 bits in size).
CharPointer_UTF8 CharPointerType
This is the character encoding type used internally to store the string.
int64 getHexValue64() const noexcept
Parses the string as a hexadecimal number.
bool containsAnyOf(StringRef charactersItMightContain) const noexcept
Looks for any of a set of characters in the string.
bool endsWith(StringRef text) const noexcept
Tests whether the string ends with another string.
int indexOfIgnoreCase(StringRef textToLookFor) const noexcept
Searches for a substring within this string.
bool containsWholeWordIgnoreCase(StringRef wordToLookFor) const noexcept
Tests whether the string contains another substring as a distinct word.
CharPointer_UTF8 toUTF8() const
Returns a pointer to a UTF-8 version of this string.
int getReferenceCount() const noexcept
Returns the number of String objects which are currently sharing the same internal data as this one.
int indexOfWholeWordIgnoreCase(StringRef wordToLookFor) const noexcept
Finds an instance of another substring if it exists as a distinct word.
int compare(const String &other) const noexcept
Case-sensitive comparison with another string.
int getIntValue() const noexcept
Reads the value of the string as a decimal number (up to 32 bits in size).
bool containsOnly(StringRef charactersItMightContain) const noexcept
Looks for a set of characters in the string.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
CharPointer_UTF32 toUTF32() const
Returns a pointer to a UTF-32 version of this string.
String fromFirstOccurrenceOf(StringRef substringToStartFrom, bool includeSubStringInResult, bool ignoreCase) const
Returns a section of the string starting from a given substring.
void swapWith(String &other) noexcept
Swaps the contents of this string with another one.
int getHexValue32() const noexcept
Parses the string as a hexadecimal number.
unsigned short uint16
A platform-independent 16-bit unsigned integer type.
bool operator>(const var &v1, const var &v2)
Compares the values of two var objects, using the var::equals() comparison.
NewLine newLine
A predefined object representing a new-line, which can be written to a string or stream.
bool operator<=(const var &v1, const var &v2)
Compares the values of two var objects, using the var::equals() comparison.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr bool exactlyEqual(Type a, Type b)
Equivalent to operator==, but suppresses float-equality warnings.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
RangedDirectoryIterator end(const RangedDirectoryIterator &)
Returns a default-constructed sentinel value.
signed short int16
A platform-independent 16-bit signed integer type.
signed int int32
A platform-independent 32-bit signed integer type.
int getAddressDifference(Type1 *pointer1, Type2 *pointer2) noexcept
A handy function which returns the difference between any two pointers, in bytes.
bool operator>=(const var &v1, const var &v2)
Compares the values of two var objects, using the var::equals() comparison.
OutputStream &JUCE_CALLTYPE operator<<(OutputStream &stream, const BigInteger &value)
Writes a BigInteger to an OutputStream as a UTF8 decimal string.
signed char int8
A platform-independent 8-bit signed integer type.
unsigned long long uint64
A platform-independent 64-bit unsigned integer type.
Type * addBytesToPointer(Type *basePointer, IntegerType bytes) noexcept
A handy function which adds a number of bytes to any type of pointer and returns the result.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
constexpr int numElementsInArray(Type(&)[N]) noexcept
Handy function for getting the number of elements in a simple const C array.
long long int64
A platform-independent 64-bit integer type.
void zeromem(void *memory, size_t numBytes) noexcept
Fills a block of memory with zeros.
Parses a character string, to read a hexadecimal value.