29 #ifndef JUCE_STRING_H_INCLUDED
30 #define JUCE_STRING_H_INCLUDED
55 #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
90 String (
const char* text,
size_t maxChars);
95 String (
const wchar_t* text);
100 String (
const wchar_t* text,
size_t maxChars);
137 String (
const std::string&);
166 #if (JUCE_STRING_UTF_TYPE == 32)
168 #elif (JUCE_STRING_UTF_TYPE == 16)
170 #elif (DOXYGEN || JUCE_STRING_UTF_TYPE == 8)
173 #error "You must set the value of JUCE_STRING_UTF_TYPE to be either 8, 16, or 32!"
195 #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
202 String& operator+= (
const char* textToAppend);
204 String& operator+= (
const wchar_t* textToAppend);
206 String& operator+= (
int numberToAppend);
210 String& operator+= (
char characterToAppend);
212 String& operator+= (
wchar_t characterToAppend);
213 #if ! JUCE_NATIVE_WCHAR_IS_UTF32
223 void append (
const String& textToAppend,
size_t maxCharsToTake);
230 void appendCharPointer (
const CharPointerType startOfTextToAppend,
231 const CharPointerType endOfTextToAppend);
238 template <
class CharPo
inter>
240 const CharPointer endOfTextToAppend)
242 jassert (startOfTextToAppend.getAddress() !=
nullptr && endOfTextToAppend.getAddress() !=
nullptr);
244 size_t extraBytesNeeded = 0, numChars = 1;
246 for (CharPointer t (startOfTextToAppend); t != endOfTextToAppend && ! t.isEmpty(); ++numChars)
247 extraBytesNeeded += CharPointerType::getBytesRequiredFor (t.getAndAdvance());
249 if (extraBytesNeeded > 0)
251 const size_t byteOffsetOfNull = getByteOffsetOfEnd();
253 preallocateBytes (byteOffsetOfNull + extraBytesNeeded);
255 .writeWithCharLimit (startOfTextToAppend, (
int) numChars);
260 void appendCharPointer (
const CharPointerType textToAppend);
267 template <
class CharPo
inter>
270 if (textToAppend.getAddress() !=
nullptr)
272 size_t extraBytesNeeded = 0, numChars = 1;
274 for (CharPointer t (textToAppend); numChars <= maxCharsToTake && ! t.isEmpty(); ++numChars)
275 extraBytesNeeded += CharPointerType::getBytesRequiredFor (t.getAndAdvance());
277 if (extraBytesNeeded > 0)
279 const size_t byteOffsetOfNull = getByteOffsetOfEnd();
281 preallocateBytes (byteOffsetOfNull + extraBytesNeeded);
283 .writeWithCharLimit (textToAppend, (
int) numChars);
289 template <
class CharPo
inter>
292 appendCharPointer (textToAppend, std::numeric_limits<size_t>::max());
320 bool equalsIgnoreCase (const
wchar_t* other) const
noexcept;
323 bool equalsIgnoreCase (const
char* other) const
noexcept;
335 int compare (const
char* other) const
noexcept;
341 int compare (const
wchar_t* other) const
noexcept;
469 bool containsNonWhitespaceChars() const
noexcept;
511 int indexOfAnyOf (
StringRef charactersToLookFor,
513 bool ignoreCase = false) const
noexcept;
579 int lastIndexOfAnyOf (
StringRef charactersToLookFor,
580 bool ignoreCase = false) const
noexcept;
615 String substring (
int startIndex,
int endIndex) const;
625 String substring (
int startIndex) const;
636 String dropLastCharacters (
int numberToDrop) const;
645 String getLastCharacters (
int numCharacters) const;
664 bool includeSubStringInResult,
665 bool ignoreCase) const;
676 bool includeSubStringInResult,
677 bool ignoreCase) const;
693 bool includeSubStringInResult,
694 bool ignoreCase) const;
704 bool includeSubStringInResult,
705 bool ignoreCase) const;
735 String toUpperCase() const;
738 String toLowerCase() const;
756 String replaceSection (
int startIndex,
757 int numCharactersToReplace,
769 bool ignoreCase = false) const;
786 StringRef charactersToInsertInstead) const;
815 String initialSectionContainingOnly (
StringRef permittedCharacters) const;
823 String initialSectionNotContaining (
StringRef charactersToStopAt) const;
832 bool isQuotedString() const;
867 int numberOfTimesToRepeat);
887 static
String createStringFromData (const
void* data,
int size);
900 static
String formatted (const
String formatString, ... );
908 explicit
String (
int decimalInteger);
913 explicit
String (
unsigned int decimalInteger);
918 explicit
String (
short decimalInteger);
923 explicit
String (
unsigned short decimalInteger);
939 explicit
String (
float floatValue);
945 explicit
String (
double doubleValue);
954 String (
float floatValue,
int numberOfDecimalPlaces);
963 String (
double doubleValue,
int numberOfDecimalPlaces);
986 int getTrailingIntValue() const
noexcept;
993 float getFloatValue() const
noexcept;
1000 double getDoubleValue() const
noexcept;
1011 int getHexValue32() const
noexcept;
1025 static
String toHexString (
int number);
1031 static
String toHexString (
short number);
1042 static
String toHexString (const
void* data,
int size,
int groupSize = 1);
1051 inline CharPointerType getCharPointer() const
noexcept {
return text; }
1077 const char* toRawUTF8()
const;
1114 const wchar_t* toWideCharPointer()
const;
1117 std::string toStdString()
const;
1123 static String fromUTF8 (
const char* utf8buffer,
int bufferSizeBytes = -1);
1129 size_t getNumBytesAsUTF8() const
noexcept;
1198 void preallocateBytes (
size_t numBytesNeeded);
1206 #if JUCE_MAC || JUCE_IOS || DOXYGEN
1208 static String fromCFString (CFStringRef cfString);
1214 CFStringRef toCFString()
const;
1218 String convertToPrecomposedUnicode()
const;
1224 int getReferenceCount() const
noexcept;
1228 CharPointerType text;
1231 struct PreallocationBytes
1233 explicit PreallocationBytes (
size_t)
noexcept;
1237 explicit String (
const PreallocationBytes&);
1238 size_t getByteOffsetOfEnd() const
noexcept;
1244 operator
bool() const
noexcept {
return false; }
1256 #if ! JUCE_NATIVE_WCHAR_IS_UTF32
1271 #if ! JUCE_NATIVE_WCHAR_IS_UTF32
1281 #if ! JUCE_NATIVE_WCHAR_IS_UTF32
1348 template <
class traits>
1351 return stream << stringToWrite.
toRawUTF8();
1357 template <
class traits>
1370 #endif // JUCE_STRING_H_INCLUDED