88 String (
const char* text,
size_t maxChars);
93 String (
const wchar_t* text);
98 String (
const wchar_t* text,
size_t maxChars);
135 String (
const std::string&);
142 static String charToString (juce_wchar character);
159 #if (JUCE_STRING_UTF_TYPE == 32) 161 #elif (JUCE_STRING_UTF_TYPE == 16) 163 #elif (DOXYGEN || JUCE_STRING_UTF_TYPE == 8) 166 #error "You must set the value of JUCE_STRING_UTF_TYPE to be either 8, 16, or 32!" 171 int hashCode() const noexcept;
174 int64 hashCode64() const noexcept;
177 size_t hash() const noexcept;
180 int length() const noexcept;
194 String& operator+= (const
char* textToAppend);
196 String& operator+= (const
wchar_t* textToAppend);
200 String& operator+= (
int numberToAppend);
202 String& operator+= (
long numberToAppend);
204 String& operator+= (int64 numberToAppend);
206 String& operator+= (uint64 numberToAppend);
208 String& operator+= (
char characterToAppend);
210 String& operator+= (
wchar_t characterToAppend);
211 #if ! JUCE_NATIVE_WCHAR_IS_UTF32 213 String& operator+= (juce_wchar characterToAppend);
221 void append (
const String& textToAppend,
size_t maxCharsToTake);
236 template <
class CharPo
inter>
238 CharPointer endOfTextToAppend)
240 jassert (startOfTextToAppend.getAddress() !=
nullptr && endOfTextToAppend.getAddress() !=
nullptr);
242 size_t extraBytesNeeded = 0, numChars = 1;
244 for (
auto t = startOfTextToAppend; t != endOfTextToAppend && ! t.isEmpty(); ++numChars)
245 extraBytesNeeded += CharPointerType::getBytesRequiredFor (t.getAndAdvance());
247 if (extraBytesNeeded > 0)
249 auto byteOffsetOfNull = getByteOffsetOfEnd();
251 preallocateBytes (byteOffsetOfNull + extraBytesNeeded);
253 .writeWithCharLimit (startOfTextToAppend, (
int) numChars);
265 template <
class CharPo
inter>
268 if (textToAppend.getAddress() !=
nullptr)
270 size_t extraBytesNeeded = 0, numChars = 1;
272 for (
auto t = textToAppend; numChars <= maxCharsToTake && ! t.isEmpty(); ++numChars)
273 extraBytesNeeded += CharPointerType::getBytesRequiredFor (t.getAndAdvance());
275 if (extraBytesNeeded > 0)
277 auto byteOffsetOfNull = getByteOffsetOfEnd();
279 preallocateBytes (byteOffsetOfNull + extraBytesNeeded);
281 .writeWithCharLimit (textToAppend, (
int) numChars);
287 template <
class CharPo
inter>
290 appendCharPointer (textToAppend, std::numeric_limits<size_t>::max());
309 void clear() noexcept;
312 bool equalsIgnoreCase (
const String& other)
const noexcept;
315 bool equalsIgnoreCase (
StringRef other)
const noexcept;
318 bool equalsIgnoreCase (
const wchar_t* other)
const noexcept;
321 bool equalsIgnoreCase (
const char* other)
const noexcept;
327 int compare (
const String& other)
const noexcept;
333 int compare (
const char* other)
const noexcept;
339 int compare (
const wchar_t* other)
const noexcept;
345 int compareIgnoreCase (
const String& other)
const noexcept;
355 int compareNatural (
StringRef other,
bool isCaseSensitive =
false)
const noexcept;
361 bool startsWith (
StringRef text)
const noexcept;
367 bool startsWithChar (juce_wchar character)
const noexcept;
373 bool startsWithIgnoreCase (
StringRef text)
const noexcept;
379 bool endsWith (
StringRef text)
const noexcept;
385 bool endsWithChar (juce_wchar character)
const noexcept;
391 bool endsWithIgnoreCase (
StringRef text)
const noexcept;
397 bool contains (
StringRef text)
const noexcept;
402 bool containsChar (juce_wchar character)
const noexcept;
407 bool containsIgnoreCase (
StringRef text)
const noexcept;
415 bool containsWholeWord (
StringRef wordToLookFor)
const noexcept;
423 bool containsWholeWordIgnoreCase (
StringRef wordToLookFor)
const noexcept;
432 int indexOfWholeWord (
StringRef wordToLookFor)
const noexcept;
441 int indexOfWholeWordIgnoreCase (
StringRef wordToLookFor)
const noexcept;
449 bool containsAnyOf (
StringRef charactersItMightContain)
const noexcept;
458 bool containsOnly (
StringRef charactersItMightContain)
const noexcept;
467 bool containsNonWhitespaceChars()
const noexcept;
476 bool matchesWildcard (
StringRef wildcard,
bool ignoreCase)
const noexcept;
486 int indexOfChar (juce_wchar characterToLookFor)
const noexcept;
495 int indexOfChar (
int startIndex, juce_wchar characterToLookFor)
const noexcept;
509 int indexOfAnyOf (
StringRef charactersToLookFor,
511 bool ignoreCase =
false)
const noexcept;
518 int indexOf (
StringRef textToLookFor)
const noexcept;
527 int indexOf (
int startIndex,
StringRef textToLookFor)
const noexcept;
534 int indexOfIgnoreCase (
StringRef textToLookFor)
const noexcept;
543 int indexOfIgnoreCase (
int startIndex,
StringRef textToLookFor)
const noexcept;
549 int lastIndexOfChar (juce_wchar character)
const noexcept;
556 int lastIndexOf (
StringRef textToLookFor)
const noexcept;
563 int lastIndexOfIgnoreCase (
StringRef textToLookFor)
const noexcept;
577 int lastIndexOfAnyOf (
StringRef charactersToLookFor,
578 bool ignoreCase =
false)
const noexcept;
595 juce_wchar operator[] (
int index)
const noexcept;
600 juce_wchar getLastCharacter()
const noexcept;
613 String substring (
int startIndex,
int endIndex)
const;
623 String substring (
int startIndex)
const;
634 String dropLastCharacters (
int numberToDrop)
const;
643 String getLastCharacters (
int numCharacters)
const;
662 bool includeSubStringInResult,
663 bool ignoreCase)
const;
674 bool includeSubStringInResult,
675 bool ignoreCase)
const;
691 bool includeSubStringInResult,
692 bool ignoreCase)
const;
702 bool includeSubStringInResult,
703 bool ignoreCase)
const;
733 String toUpperCase()
const;
736 String toLowerCase()
const;
754 String replaceSection (
int startIndex,
755 int numCharactersToReplace,
767 bool ignoreCase =
false)
const;
778 bool ignoreCase =
false)
const;
781 String replaceCharacter (juce_wchar characterToReplace,
782 juce_wchar characterToInsertInstead)
const;
795 StringRef charactersToInsertInstead)
const;
824 String initialSectionContainingOnly (
StringRef permittedCharacters)
const;
832 String initialSectionNotContaining (
StringRef charactersToStopAt)
const;
841 bool isQuotedString()
const;
866 String quoted (juce_wchar quoteCharacter =
'"')
const;
876 int numberOfTimesToRepeat);
881 String paddedLeft (juce_wchar padCharacter,
int minimumLength)
const;
886 String paddedRight (juce_wchar padCharacter,
int minimumLength)
const;
896 static String createStringFromData (
const void* data,
int size);
909 template <
typename... Args>
918 explicit String (
int decimalInteger);
923 explicit String (
unsigned int decimalInteger);
928 explicit String (
short decimalInteger);
933 explicit String (
unsigned short decimalInteger);
938 explicit String (int64 largeIntegerValue);
943 explicit String (uint64 largeIntegerValue);
948 explicit String (
long decimalInteger);
953 explicit String (
unsigned long decimalInteger);
959 explicit String (
float floatValue);
965 explicit String (
double doubleValue);
977 String (
float floatValue,
int numberOfDecimalPlaces,
bool useScientificNotation =
false);
988 String (
double doubleValue,
int numberOfDecimalPlaces,
bool useScientificNotation =
false);
993 explicit String (
bool) =
delete;
1001 int getIntValue()
const noexcept;
1006 int64 getLargeIntValue()
const noexcept;
1017 int getTrailingIntValue()
const noexcept;
1024 float getFloatValue()
const noexcept;
1031 double getDoubleValue()
const noexcept;
1042 int getHexValue32()
const noexcept;
1053 int64 getHexValue64()
const noexcept;
1056 template <
typename IntegerType>
1068 static String toHexString (
const void* data,
int size,
int groupSize = 1);
1075 template <
typename DecimalType>
1078 jassert (numberOfSignificantFigures > 0);
1082 if (numberOfSignificantFigures > 1)
1086 for (
int i = 2; i < numberOfSignificantFigures; ++i)
1095 auto numDigitsBeforePoint = (int) std::ceil (std::log10 (number < 0 ? -number : number));
1097 #if JUCE_PROJUCER_LIVE_BUILD 1098 auto doubleNumber = (double) number;
1099 constexpr
int bufferSize = 311;
1100 char buffer[bufferSize];
1101 auto* ptr = &(buffer[0]);
1102 auto*
const safeEnd = ptr + (bufferSize - 1);
1103 auto numSigFigsParsed = 0;
1105 auto writeToBuffer = [safeEnd] (
char* destination,
char data)
1107 *destination++ = data;
1109 if (destination == safeEnd)
1111 *destination =
'\0';
1118 auto truncateOrRound = [numberOfSignificantFigures] (
double fractional,
int sigFigsParsed)
1120 return (sigFigsParsed == numberOfSignificantFigures - 1) ? (int) std::round (fractional)
1124 if (doubleNumber < 0)
1130 if (numDigitsBeforePoint > 0)
1132 doubleNumber /= std::pow (10.0, numDigitsBeforePoint);
1134 while (numDigitsBeforePoint-- > 0)
1136 if (numSigFigsParsed == numberOfSignificantFigures)
1138 if (writeToBuffer (ptr++,
'0'))
1145 auto digit = truncateOrRound (doubleNumber, numSigFigsParsed);
1147 if (writeToBuffer (ptr++, (
char) (
'0' + digit)))
1151 doubleNumber -= digit;
1154 if (numSigFigsParsed == numberOfSignificantFigures)
1165 if (writeToBuffer (ptr++,
'.'))
1168 while (numSigFigsParsed < numberOfSignificantFigures)
1171 auto digit = truncateOrRound (doubleNumber, numSigFigsParsed);
1173 if (writeToBuffer (ptr++, (
char) (
'0' + digit)))
1176 if (numSigFigsParsed != 0 || digit != 0)
1179 doubleNumber -= digit;
1185 auto shift = numberOfSignificantFigures - numDigitsBeforePoint;
1186 auto factor = std::pow (10.0, shift);
1187 auto rounded = std::round (number * factor) / factor;
1189 std::stringstream ss;
1190 ss << std::fixed << std::setprecision (std::max (shift, 0)) << rounded;
1228 const char* toRawUTF8()
const;
1265 const wchar_t* toWideCharPointer()
const;
1268 std::string toStdString()
const;
1274 static String fromUTF8 (
const char* utf8buffer,
int bufferSizeBytes = -1);
1280 size_t getNumBytesAsUTF8()
const noexcept;
1298 size_t copyToUTF8 (CharPointer_UTF8::CharType* destBuffer,
size_t maxBufferSizeBytes)
const noexcept;
1315 size_t copyToUTF16 (CharPointer_UTF16::CharType* destBuffer,
size_t maxBufferSizeBytes)
const noexcept;
1332 size_t copyToUTF32 (CharPointer_UTF32::CharType* destBuffer,
size_t maxBufferSizeBytes)
const noexcept;
1349 void preallocateBytes (
size_t numBytesNeeded);
1354 void swapWith (
String& other) noexcept;
1357 #if JUCE_MAC || JUCE_IOS || DOXYGEN 1359 static String fromCFString (CFStringRef cfString);
1365 CFStringRef toCFString()
const;
1369 String convertToPrecomposedUnicode()
const;
1375 int getReferenceCount()
const noexcept;
1386 JUCE_DEPRECATED_STATIC (
static const String empty;)
1393 struct PreallocationBytes
1395 explicit PreallocationBytes (
size_t) noexcept;
1399 explicit String (
const PreallocationBytes&);
1400 size_t getByteOffsetOfEnd()
const noexcept;
1406 operator bool()
const noexcept {
return false; }
1409 static String formattedRaw (
const char*, ...);
1411 static String createHex (uint8);
1412 static String createHex (uint16);
1413 static String createHex (uint32);
1414 static String createHex (uint64);
1416 template <
typename Type>
1429 #if ! JUCE_NATIVE_WCHAR_IS_UTF32 1446 #if ! JUCE_NATIVE_WCHAR_IS_UTF32 1456 #if ! JUCE_NATIVE_WCHAR_IS_UTF32 1494 String& JUCE_CALLTYPE operator<< (
String&,
bool) =
delete;
1499 JUCE_API bool JUCE_CALLTYPE operator== (
const String& string1,
const String& string2) noexcept;
1501 JUCE_API bool JUCE_CALLTYPE operator== (
const String& string1,
const char* string2) noexcept;
1503 JUCE_API bool JUCE_CALLTYPE operator== (
const String& string1,
const wchar_t* string2) noexcept;
1512 JUCE_API bool JUCE_CALLTYPE operator!= (
const String& string1,
const String& string2) noexcept;
1514 JUCE_API bool JUCE_CALLTYPE operator!= (
const String& string1,
const char* string2) noexcept;
1516 JUCE_API bool JUCE_CALLTYPE operator!= (
const String& string1,
const wchar_t* string2) noexcept;
1528 template <
class traits>
1529 std::basic_ostream <char, traits>& JUCE_CALLTYPE operator<< (std::basic_ostream <char, traits>& stream,
const String& stringToWrite)
1531 return stream << stringToWrite.toRawUTF8();
1537 template <
class traits>
1538 std::basic_ostream <wchar_t, traits>& JUCE_CALLTYPE operator<< (std::basic_ostream <wchar_t, traits>& stream,
const String& stringToWrite)
1540 return stream << stringToWrite.toWideCharPointer();
1554 template <>
struct hash<juce::
String>
1556 size_t operator() (
const juce::String& s)
const noexcept {
return s.
hash(); }
Wraps a pointer to a null-terminated ASCII character string, and provides various methods to operate ...
#define JUCE_API
This macro is added to all JUCE public class declarations.
These templates are designed to take an integer type, and return an unsigned int version with the sam...
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 isNotEmpty() const noexcept
Returns true if the string contains at least one character.
A simple class for holding temporary references to a string literal or String.
void appendCharPointer(CharPointer textToAppend, size_t maxCharsToTake)
Appends a string to the end of this one.
CharPointerType getCharPointer() const noexcept
Returns the character pointer currently being used to store this string.
void appendCharPointer(CharPointer textToAppend)
Appends a string to the end of this one.
Wraps a pointer to a null-terminated UTF-32 character string, and provides various methods to operate...
bool isEmpty() const noexcept
Returns true if this pointer is pointing to a null character.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
The base class for streams that write data to some kind of destination.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
static String formatted(const String &formatStr, Args... args)
Creates a String from a printf-style parameter list.
Wraps a pointer to a null-terminated UTF-16 character string, and provides various methods to operate...
void appendCharPointer(CharPointer startOfTextToAppend, CharPointer endOfTextToAppend)
Appends a string to the end of this one.
size_t hash() const noexcept
Generates a probably-unique hashcode from this string.
CharType * getAddress() const noexcept
Returns the address that this pointer is pointing to.
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...