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);
992 explicit String (
bool) =
delete;
999 int getIntValue()
const noexcept;
1004 int64 getLargeIntValue()
const noexcept;
1015 int getTrailingIntValue()
const noexcept;
1022 float getFloatValue()
const noexcept;
1029 double getDoubleValue()
const noexcept;
1040 int getHexValue32()
const noexcept;
1051 int64 getHexValue64()
const noexcept;
1054 template <
typename IntegerType>
1066 static String toHexString (
const void* data,
int size,
int groupSize = 1);
1073 template <
typename DecimalType>
1076 jassert (numberOfSignificantFigures > 0);
1080 if (numberOfSignificantFigures > 1)
1084 for (
int i = 2; i < numberOfSignificantFigures; ++i)
1093 auto numDigitsBeforePoint = (int) std::ceil (std::log10 (number < 0 ? -number : number));
1095 #if JUCE_PROJUCER_LIVE_BUILD 1096 auto doubleNumber = (double) number;
1097 constexpr
int bufferSize = 311;
1098 char buffer[bufferSize];
1099 auto* ptr = &(buffer[0]);
1100 auto*
const safeEnd = ptr + (bufferSize - 1);
1101 auto numSigFigsParsed = 0;
1103 auto writeToBuffer = [safeEnd] (
char* destination,
char data)
1105 *destination++ = data;
1107 if (destination == safeEnd)
1109 *destination =
'\0';
1116 auto truncateOrRound = [numberOfSignificantFigures] (
double fractional,
int sigFigsParsed)
1118 return (sigFigsParsed == numberOfSignificantFigures - 1) ? (int) std::round (fractional)
1122 if (doubleNumber < 0)
1128 if (numDigitsBeforePoint > 0)
1130 doubleNumber /= std::pow (10.0, numDigitsBeforePoint);
1132 while (numDigitsBeforePoint-- > 0)
1134 if (numSigFigsParsed == numberOfSignificantFigures)
1136 if (writeToBuffer (ptr++,
'0'))
1143 auto digit = truncateOrRound (doubleNumber, numSigFigsParsed);
1145 if (writeToBuffer (ptr++, (
char) (
'0' + digit)))
1149 doubleNumber -= digit;
1152 if (numSigFigsParsed == numberOfSignificantFigures)
1163 if (writeToBuffer (ptr++,
'.'))
1166 while (numSigFigsParsed < numberOfSignificantFigures)
1169 auto digit = truncateOrRound (doubleNumber, numSigFigsParsed);
1171 if (writeToBuffer (ptr++, (
char) (
'0' + digit)))
1174 if (numSigFigsParsed != 0 || digit != 0)
1177 doubleNumber -= digit;
1183 auto shift = numberOfSignificantFigures - numDigitsBeforePoint;
1184 auto factor = std::pow (10.0, shift);
1185 auto rounded = std::round (number * factor) / factor;
1187 std::stringstream ss;
1188 ss << std::fixed << std::setprecision (std::max (shift, 0)) << rounded;
1226 const char* toRawUTF8()
const;
1263 const wchar_t* toWideCharPointer()
const;
1266 std::string toStdString()
const;
1272 static String fromUTF8 (
const char* utf8buffer,
int bufferSizeBytes = -1);
1278 size_t getNumBytesAsUTF8()
const noexcept;
1296 size_t copyToUTF8 (CharPointer_UTF8::CharType* destBuffer,
size_t maxBufferSizeBytes)
const noexcept;
1313 size_t copyToUTF16 (CharPointer_UTF16::CharType* destBuffer,
size_t maxBufferSizeBytes)
const noexcept;
1330 size_t copyToUTF32 (CharPointer_UTF32::CharType* destBuffer,
size_t maxBufferSizeBytes)
const noexcept;
1347 void preallocateBytes (
size_t numBytesNeeded);
1352 void swapWith (
String& other) noexcept;
1355 #if JUCE_MAC || JUCE_IOS || DOXYGEN 1357 static String fromCFString (CFStringRef cfString);
1363 CFStringRef toCFString()
const;
1367 String convertToPrecomposedUnicode()
const;
1373 int getReferenceCount()
const noexcept;
1384 JUCE_DEPRECATED_STATIC (
static const String empty;)
1391 struct PreallocationBytes
1393 explicit PreallocationBytes (
size_t) noexcept;
1397 explicit String (
const PreallocationBytes&);
1398 size_t getByteOffsetOfEnd()
const noexcept;
1404 operator bool()
const noexcept {
return false; }
1407 static String formattedRaw (
const char*, ...);
1409 static String createHex (uint8);
1410 static String createHex (uint16);
1411 static String createHex (uint32);
1412 static String createHex (uint64);
1414 template <
typename Type>
1427 #if ! JUCE_NATIVE_WCHAR_IS_UTF32 1444 #if ! JUCE_NATIVE_WCHAR_IS_UTF32 1454 #if ! JUCE_NATIVE_WCHAR_IS_UTF32 1491 String& JUCE_CALLTYPE operator<< (
String&,
bool) =
delete;
1495 JUCE_API bool JUCE_CALLTYPE operator== (
const String& string1,
const String& string2) noexcept;
1497 JUCE_API bool JUCE_CALLTYPE operator== (
const String& string1,
const char* string2) noexcept;
1499 JUCE_API bool JUCE_CALLTYPE operator== (
const String& string1,
const wchar_t* string2) noexcept;
1508 JUCE_API bool JUCE_CALLTYPE operator!= (
const String& string1,
const String& string2) noexcept;
1510 JUCE_API bool JUCE_CALLTYPE operator!= (
const String& string1,
const char* string2) noexcept;
1512 JUCE_API bool JUCE_CALLTYPE operator!= (
const String& string1,
const wchar_t* string2) noexcept;
1525 JUCE_API bool JUCE_CALLTYPE operator>= (
const String& string1,
const String& string2) noexcept;
1527 JUCE_API bool JUCE_CALLTYPE operator<= (
const String& string1,
const String& string2) noexcept;
1533 template <
class traits>
1534 std::basic_ostream <char, traits>& JUCE_CALLTYPE operator<< (std::basic_ostream <char, traits>& stream,
const String& stringToWrite)
1536 return stream << stringToWrite.toRawUTF8();
1542 template <
class traits>
1543 std::basic_ostream <wchar_t, traits>& JUCE_CALLTYPE operator<< (std::basic_ostream <wchar_t, traits>& stream,
const String& stringToWrite)
1545 return stream << stringToWrite.toWideCharPointer();
1559 template <>
struct hash<juce::
String>
1561 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 ...