98 String (
const char* text,
size_t maxChars);
103 String (
const wchar_t* text);
108 String (
const wchar_t* text,
size_t maxChars);
145 String (
const std::string&);
152 static String charToString (juce_wchar character);
169 #if (JUCE_STRING_UTF_TYPE == 32)
171 #elif (JUCE_STRING_UTF_TYPE == 16)
173 #elif (DOXYGEN || JUCE_STRING_UTF_TYPE == 8)
176 #error "You must set the value of JUCE_STRING_UTF_TYPE to be either 8, 16, or 32!"
181 int hashCode()
const noexcept;
184 int64 hashCode64()
const noexcept;
187 size_t hash()
const noexcept;
190 int length()
const noexcept;
204 String& operator+= (
const char* textToAppend);
206 String& operator+= (
const wchar_t* textToAppend);
210 String& operator+= (
int numberToAppend);
212 String& operator+= (
long numberToAppend);
214 String& operator+= (int64 numberToAppend);
216 String& operator+= (uint64 numberToAppend);
218 String& operator+= (
char characterToAppend);
220 String& operator+= (
wchar_t characterToAppend);
221 #if ! JUCE_NATIVE_WCHAR_IS_UTF32
223 String& operator+= (juce_wchar characterToAppend);
231 void append (
const String& textToAppend,
size_t maxCharsToTake);
238 void appendCharPointer (CharPointerType startOfTextToAppend,
239 CharPointerType endOfTextToAppend);
246 template <
class CharPo
inter>
248 CharPointer endOfTextToAppend)
250 jassert (startOfTextToAppend.getAddress() !=
nullptr && endOfTextToAppend.getAddress() !=
nullptr);
252 size_t extraBytesNeeded = 0, numChars = 1;
254 for (
auto t = startOfTextToAppend; t != endOfTextToAppend && ! t.isEmpty(); ++numChars)
255 extraBytesNeeded += CharPointerType::getBytesRequiredFor (t.getAndAdvance());
257 if (extraBytesNeeded > 0)
259 auto byteOffsetOfNull = getByteOffsetOfEnd();
261 preallocateBytes (byteOffsetOfNull + extraBytesNeeded);
262 CharPointerType (addBytesToPointer (text.getAddress(), (
int) byteOffsetOfNull))
263 .writeWithCharLimit (startOfTextToAppend, (
int) numChars);
268 void appendCharPointer (CharPointerType textToAppend);
275 template <
class CharPo
inter>
278 if (textToAppend.getAddress() !=
nullptr)
280 size_t extraBytesNeeded = 0, numChars = 1;
282 for (
auto t = textToAppend; numChars <= maxCharsToTake && ! t.isEmpty(); ++numChars)
283 extraBytesNeeded += CharPointerType::getBytesRequiredFor (t.getAndAdvance());
285 if (extraBytesNeeded > 0)
287 auto byteOffsetOfNull = getByteOffsetOfEnd();
289 preallocateBytes (byteOffsetOfNull + extraBytesNeeded);
290 CharPointerType (addBytesToPointer (text.getAddress(), (
int) byteOffsetOfNull))
291 .writeWithCharLimit (textToAppend, (
int) numChars);
297 template <
class CharPo
inter>
300 appendCharPointer (textToAppend, std::numeric_limits<size_t>::max());
310 bool isEmpty() const noexcept {
return text.isEmpty(); }
316 bool isNotEmpty() const noexcept {
return ! text.isEmpty(); }
319 void clear() noexcept;
322 bool equalsIgnoreCase (const
String& other) const noexcept;
325 bool equalsIgnoreCase (
StringRef other) const noexcept;
328 bool equalsIgnoreCase (const
wchar_t* other) const noexcept;
331 bool equalsIgnoreCase (const
char* other) const noexcept;
337 int compare (const
String& other) const noexcept;
343 int compare (const
char* other) const noexcept;
349 int compare (const
wchar_t* other) const noexcept;
355 int compareIgnoreCase (const
String& other) const noexcept;
365 int compareNatural (
StringRef other,
bool isCaseSensitive = false) const noexcept;
371 bool startsWith (
StringRef text) const noexcept;
377 bool startsWithChar (juce_wchar character) const noexcept;
383 bool startsWithIgnoreCase (
StringRef text) const noexcept;
389 bool endsWith (
StringRef text) const noexcept;
395 bool endsWithChar (juce_wchar character) const noexcept;
401 bool endsWithIgnoreCase (
StringRef text) const noexcept;
407 bool contains (
StringRef text) const noexcept;
412 bool containsChar (juce_wchar character) const noexcept;
417 bool containsIgnoreCase (
StringRef text) const noexcept;
425 bool containsWholeWord (
StringRef wordToLookFor) const noexcept;
433 bool containsWholeWordIgnoreCase (
StringRef wordToLookFor) const noexcept;
442 int indexOfWholeWord (
StringRef wordToLookFor) const noexcept;
451 int indexOfWholeWordIgnoreCase (
StringRef wordToLookFor) const noexcept;
459 bool containsAnyOf (
StringRef charactersItMightContain) const noexcept;
468 bool containsOnly (
StringRef charactersItMightContain) const noexcept;
477 bool containsNonWhitespaceChars() const noexcept;
486 bool matchesWildcard (
StringRef wildcard,
bool ignoreCase) const noexcept;
496 int indexOfChar (juce_wchar characterToLookFor) const noexcept;
505 int indexOfChar (
int startIndex, juce_wchar characterToLookFor) const noexcept;
519 int indexOfAnyOf (
StringRef charactersToLookFor,
521 bool ignoreCase = false) const noexcept;
528 int indexOf (
StringRef textToLookFor) const noexcept;
537 int indexOf (
int startIndex,
StringRef textToLookFor) const noexcept;
544 int indexOfIgnoreCase (
StringRef textToLookFor) const noexcept;
553 int indexOfIgnoreCase (
int startIndex,
StringRef textToLookFor) const noexcept;
559 int lastIndexOfChar (juce_wchar character) const noexcept;
566 int lastIndexOf (
StringRef textToLookFor) const noexcept;
573 int lastIndexOfIgnoreCase (
StringRef textToLookFor) const noexcept;
587 int lastIndexOfAnyOf (
StringRef charactersToLookFor,
588 bool ignoreCase = false) const noexcept;
605 juce_wchar operator[] (
int index) const noexcept;
610 juce_wchar getLastCharacter() const noexcept;
623 String substring (
int startIndex,
int endIndex) const;
633 String substring (
int startIndex) const;
644 String dropLastCharacters (
int numberToDrop) const;
653 String getLastCharacters (
int numCharacters) const;
672 bool includeSubStringInResult,
673 bool ignoreCase) const;
684 bool includeSubStringInResult,
685 bool ignoreCase) const;
701 bool includeSubStringInResult,
702 bool ignoreCase) const;
712 bool includeSubStringInResult,
713 bool ignoreCase) const;
743 String toUpperCase() const;
746 String toLowerCase() const;
764 String replaceSection (
int startIndex,
765 int numCharactersToReplace,
777 bool ignoreCase = false) const;
788 bool ignoreCase = false) const;
791 String replaceCharacter (juce_wchar characterToReplace,
792 juce_wchar characterToInsertInstead) const;
805 StringRef charactersToInsertInstead) const;
834 String initialSectionContainingOnly (
StringRef permittedCharacters) const;
842 String initialSectionNotContaining (
StringRef charactersToStopAt) const;
851 bool isQuotedString() const;
876 String quoted (juce_wchar quoteCharacter = '"') const;
886 int numberOfTimesToRepeat);
891 String paddedLeft (juce_wchar padCharacter,
int minimumLength) const;
896 String paddedRight (juce_wchar padCharacter,
int minimumLength) const;
906 static
String createStringFromData (const
void* data,
int size);
919 template <typename... Args>
920 static
String formatted (const
String& formatStr, Args... args) {
return formattedRaw (formatStr.toRawUTF8(), args...); }
923 CharPointerType
begin()
const {
return getCharPointer(); }
949 CharPointerType
end()
const {
return begin().findTerminatingNull(); }
957 explicit String (
int decimalInteger);
962 explicit String (
unsigned int decimalInteger);
967 explicit String (
short decimalInteger);
972 explicit String (
unsigned short decimalInteger);
977 explicit String (int64 largeIntegerValue);
982 explicit String (uint64 largeIntegerValue);
987 explicit String (
long decimalInteger);
992 explicit String (
unsigned long decimalInteger);
998 explicit String (
float floatValue);
1004 explicit String (
double doubleValue);
1016 String (
float floatValue,
int numberOfDecimalPlaces,
bool useScientificNotation =
false);
1027 String (
double doubleValue,
int numberOfDecimalPlaces,
bool useScientificNotation =
false);
1032 explicit String (
bool) =
delete;
1040 int getIntValue() const noexcept;
1045 int64 getLargeIntValue() const noexcept;
1057 int getTrailingIntValue() const noexcept;
1064 float getFloatValue() const noexcept;
1071 double getDoubleValue() const noexcept;
1082 int getHexValue32() const noexcept;
1093 int64 getHexValue64() const noexcept;
1096 template <typename IntegerType>
1097 static
String toHexString (IntegerType number) {
return createHex (number); }
1108 static String toHexString (
const void* data,
int size,
int groupSize = 1);
1115 template <
typename DecimalType>
1118 jassert (numberOfSignificantFigures > 0);
1120 if (exactlyEqual (number, DecimalType()))
1122 if (numberOfSignificantFigures > 1)
1126 for (
int i = 2; i < numberOfSignificantFigures; ++i)
1135 auto numDigitsBeforePoint = (int) std::ceil (std::log10 (number < 0 ? -number : number));
1137 auto shift = numberOfSignificantFigures - numDigitsBeforePoint;
1138 auto factor = std::pow (10.0, shift);
1139 auto rounded = std::round (number * factor) / factor;
1141 std::stringstream ss;
1142 ss << std::fixed << std::setprecision (std::max (shift, 0)) << rounded;
1179 const char* toRawUTF8()
const;
1216 const wchar_t* toWideCharPointer()
const;
1219 std::string toStdString()
const;
1225 static String fromUTF8 (
const char* utf8buffer,
int bufferSizeBytes = -1);
1231 size_t getNumBytesAsUTF8() const noexcept;
1249 size_t copyToUTF8 (
CharPointer_UTF8::CharType* destBuffer,
size_t maxBufferSizeBytes) const noexcept;
1266 size_t copyToUTF16 (
CharPointer_UTF16::CharType* destBuffer,
size_t maxBufferSizeBytes) const noexcept;
1283 size_t copyToUTF32 (
CharPointer_UTF32::CharType* destBuffer,
size_t maxBufferSizeBytes) const noexcept;
1300 void preallocateBytes (
size_t numBytesNeeded);
1305 void swapWith (
String& other) noexcept;
1308 #if JUCE_MAC || JUCE_IOS || DOXYGEN
1310 static String fromCFString (CFStringRef cfString);
1316 CFStringRef toCFString()
const;
1320 String convertToPrecomposedUnicode()
const;
1326 int getReferenceCount() const noexcept;
1329 #if JUCE_ALLOW_STATIC_NULL_VARIABLES && ! defined (DOXYGEN)
1330 [[deprecated (
"This was a static empty string object, but is now deprecated as it's too easy to accidentally "
1331 "use it indirectly during a static constructor, leading to hard-to-find order-of-initialisation "
1332 "problems. If you need an empty String object, just use String() or {}. For returning an empty "
1333 "String from a function by reference, use a function-local static String object and return that.")]]
1334 static const String empty;
1339 CharPointerType text;
1342 struct PreallocationBytes
1344 explicit PreallocationBytes (
size_t)
noexcept;
1348 explicit String (
const PreallocationBytes&);
1349 size_t getByteOffsetOfEnd() const noexcept;
1354 operator
bool() const noexcept {
return false; }
1357 static String formattedRaw (
const char*, ...);
1359 static String createHex (uint8);
1360 static String createHex (uint16);
1361 static String createHex (uint32);
1362 static String createHex (uint64);
1364 template <
typename Type>
1365 static String createHex (Type n) {
return createHex (
static_cast<typename TypeHelpers::UnsignedTypeWithSize<(
int) sizeof (n)
>::type> (n)); }