23#if ! defined (DOXYGEN) && (JUCE_MAC || JUCE_IOS)
26 #if __has_attribute(objc_bridge)
27 #define JUCE_CF_BRIDGED_TYPE(T) __attribute__ ((objc_bridge (T)))
29 #define JUCE_CF_BRIDGED_TYPE(T)
32 typedef const struct JUCE_CF_BRIDGED_TYPE(NSString) __CFString * CFStringRef;
34 #undef JUCE_CF_BRIDGED_TYPE
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&);
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!"
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);
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();
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();
290 CharPointerType (addBytesToPointer (text.getAddress(), (
int) byteOffsetOfNull))
291 .writeWithCharLimit (textToAppend, (
int) numChars);
297 template <
class CharPo
inter>
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...); }
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>
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)); }
1370JUCE_API String JUCE_CALLTYPE operator+ (
const char* string1,
const String& string2);
1372JUCE_API String JUCE_CALLTYPE operator+ (
const wchar_t* string1,
const String& string2);
1374JUCE_API String JUCE_CALLTYPE operator+ (
char string1,
const String& string2);
1376JUCE_API String JUCE_CALLTYPE operator+ (
wchar_t string1,
const String& string2);
1377#if ! JUCE_NATIVE_WCHAR_IS_UTF32
1379JUCE_API String JUCE_CALLTYPE operator+ (juce_wchar string1,
const String& string2);
1383JUCE_API String JUCE_CALLTYPE operator+ (String string1,
const String& string2);
1385JUCE_API String JUCE_CALLTYPE operator+ (String string1,
const char* string2);
1387JUCE_API String JUCE_CALLTYPE operator+ (String string1,
const wchar_t* string2);
1389JUCE_API String JUCE_CALLTYPE operator+ (String string1,
const std::string& string2);
1391JUCE_API String JUCE_CALLTYPE operator+ (String string1,
char characterToAppend);
1393JUCE_API String JUCE_CALLTYPE operator+ (String string1,
wchar_t characterToAppend);
1394#if ! JUCE_NATIVE_WCHAR_IS_UTF32
1396JUCE_API String JUCE_CALLTYPE operator+ (String string1, juce_wchar characterToAppend);
1401JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
char characterToAppend);
1403JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
wchar_t characterToAppend);
1404#if ! JUCE_NATIVE_WCHAR_IS_UTF32
1406JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, juce_wchar characterToAppend);
1410JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
const char* string2);
1412JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
const wchar_t* string2);
1414JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
const String& string2);
1416JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, StringRef string2);
1418JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
const std::string& string2);
1421JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, uint8 number);
1423JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
short number);
1425JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
int number);
1427JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
long number);
1429JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
unsigned long number);
1431JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, int64 number);
1433JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, uint64 number);
1435JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
float number);
1437JUCE_API String& JUCE_CALLTYPE operator<< (String& string1,
double number);
1442String& JUCE_CALLTYPE operator<< (String&,
bool) =
delete;
1447JUCE_API
bool JUCE_CALLTYPE operator== (
const String& string1,
const String& string2)
noexcept;
1449JUCE_API
bool JUCE_CALLTYPE operator== (
const String& string1,
const char* string2)
noexcept;
1451JUCE_API
bool JUCE_CALLTYPE operator== (
const String& string1,
const wchar_t* string2)
noexcept;
1453JUCE_API
bool JUCE_CALLTYPE operator== (
const String& string1, CharPointer_UTF8 string2)
noexcept;
1455JUCE_API
bool JUCE_CALLTYPE operator== (
const String& string1, CharPointer_UTF16 string2)
noexcept;
1457JUCE_API
bool JUCE_CALLTYPE operator== (
const String& string1, CharPointer_UTF32 string2)
noexcept;
1460JUCE_API
bool JUCE_CALLTYPE operator!= (
const String& string1,
const String& string2)
noexcept;
1462JUCE_API
bool JUCE_CALLTYPE operator!= (
const String& string1,
const char* string2)
noexcept;
1464JUCE_API
bool JUCE_CALLTYPE operator!= (
const String& string1,
const wchar_t* string2)
noexcept;
1466JUCE_API
bool JUCE_CALLTYPE operator!= (
const String& string1, CharPointer_UTF8 string2)
noexcept;
1468JUCE_API
bool JUCE_CALLTYPE operator!= (
const String& string1, CharPointer_UTF16 string2)
noexcept;
1470JUCE_API
bool JUCE_CALLTYPE operator!= (
const String& string1, CharPointer_UTF32 string2)
noexcept;
1476template <
class traits>
1477std::basic_ostream <char, traits>& JUCE_CALLTYPE operator<< (std::basic_ostream <char, traits>& stream,
const String& stringToWrite)
1479 return stream << stringToWrite.toRawUTF8();
1485template <
class traits>
1486std::basic_ostream <wchar_t, traits>& JUCE_CALLTYPE operator<< (std::basic_ostream <wchar_t, traits>& stream,
const String& stringToWrite)
1488 return stream << stringToWrite.toWideCharPointer();
1492JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream,
const String& stringToWrite);
1495JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, StringRef stringToWrite);
1502 template <>
struct hash<juce::String>
1504 size_t operator() (
const juce::String& s)
const noexcept {
return s.hash(); }
CharPointerType getCharPointer() const noexcept
CharPointerType begin() const
int length() const noexcept
bool isEmpty() const noexcept
void append(const String &textToAppend, size_t maxCharsToTake)
static String toDecimalStringWithSignificantFigures(DecimalType number, int numberOfSignificantFigures)
int64 hashCode64() const noexcept
void appendCharPointer(CharPointer startOfTextToAppend, CharPointer endOfTextToAppend)
void appendCharPointer(CharPointerType startOfTextToAppend, CharPointerType endOfTextToAppend)
void preallocateBytes(size_t numBytesNeeded)
size_t hash() const noexcept
static String formatted(const String &formatStr, Args... args)
CharPointerType end() const
static String toHexString(IntegerType number)
void appendCharPointer(CharPointer textToAppend, size_t maxCharsToTake)
void appendCharPointer(CharPointer textToAppend)
static String charToString(juce_wchar character)
int hashCode() const noexcept
bool isNotEmpty() const noexcept