LMMS
Loading...
Searching...
No Matches
juce::pnglibNamespace::water::String Class Reference

Classes

struct  PreallocationBytes

Public Member Functions

 String () noexcept
 String (const String &other) noexcept
 String (const char *text)
 String (const char *text, size_t maxChars)
 String (const CharPointer_UTF8 text)
 String (const CharPointer_UTF8 text, size_t maxChars)
 String (const CharPointer_UTF8 start, const CharPointer_UTF8 end)
 String (const std::string &)
 String (StringRef)
 ~String () noexcept
int hashCode () const noexcept
int64 hashCode64 () const noexcept
size_t hash () const noexcept
int length () const noexcept
Stringoperator= (const String &other) noexcept
Stringoperator+= (const String &stringToAppend)
Stringoperator+= (const char *textToAppend)
Stringoperator+= (StringRef textToAppend)
Stringoperator+= (int numberToAppend)
Stringoperator+= (long numberToAppend)
Stringoperator+= (int64 numberToAppend)
Stringoperator+= (uint64 numberToAppend)
Stringoperator+= (char characterToAppend)
Stringoperator+= (water_uchar characterToAppend)
void append (const String &textToAppend, size_t maxCharsToTake)
void appendCharPointer (const CharPointer_UTF8 startOfTextToAppend, const CharPointer_UTF8 endOfTextToAppend)
template<class CharPointer>
void appendCharPointer (const CharPointer startOfTextToAppend, const CharPointer endOfTextToAppend)
void appendCharPointer (const CharPointer_UTF8 textToAppend)
template<class CharPointer>
void appendCharPointer (const CharPointer textToAppend, size_t maxCharsToTake)
template<class CharPointer>
void appendCharPointer (const CharPointer textToAppend)
bool isEmpty () const noexcept
bool isNotEmpty () const noexcept
void clear () noexcept
bool equalsIgnoreCase (const String &other) const noexcept
bool equalsIgnoreCase (StringRef other) const noexcept
bool equalsIgnoreCase (const char *other) const noexcept
int compare (const String &other) const noexcept
int compare (const char *other) const noexcept
int compareIgnoreCase (const String &other) const noexcept
int compareNatural (StringRef other, bool isCaseSensitive=false) const noexcept
bool startsWith (StringRef text) const noexcept
bool startsWithChar (water_uchar character) const noexcept
bool startsWithIgnoreCase (StringRef text) const noexcept
bool endsWith (StringRef text) const noexcept
bool endsWithChar (water_uchar character) const noexcept
bool endsWithIgnoreCase (StringRef text) const noexcept
bool contains (StringRef text) const noexcept
bool containsChar (water_uchar character) const noexcept
bool containsIgnoreCase (StringRef text) const noexcept
bool containsWholeWord (StringRef wordToLookFor) const noexcept
bool containsWholeWordIgnoreCase (StringRef wordToLookFor) const noexcept
int indexOfWholeWord (StringRef wordToLookFor) const noexcept
int indexOfWholeWordIgnoreCase (StringRef wordToLookFor) const noexcept
bool containsAnyOf (StringRef charactersItMightContain) const noexcept
bool containsOnly (StringRef charactersItMightContain) const noexcept
bool containsNonWhitespaceChars () const noexcept
bool matchesWildcard (StringRef wildcard, bool ignoreCase) const noexcept
int indexOfChar (water_uchar characterToLookFor) const noexcept
int indexOfChar (int startIndex, water_uchar characterToLookFor) const noexcept
int indexOfAnyOf (StringRef charactersToLookFor, int startIndex=0, bool ignoreCase=false) const noexcept
int indexOf (StringRef textToLookFor) const noexcept
int indexOf (int startIndex, StringRef textToLookFor) const noexcept
int indexOfIgnoreCase (StringRef textToLookFor) const noexcept
int indexOfIgnoreCase (int startIndex, StringRef textToLookFor) const noexcept
int lastIndexOfChar (water_uchar character) const noexcept
int lastIndexOf (StringRef textToLookFor) const noexcept
int lastIndexOfIgnoreCase (StringRef textToLookFor) const noexcept
int lastIndexOfAnyOf (StringRef charactersToLookFor, bool ignoreCase=false) const noexcept
water_uchar operator[] (int index) const noexcept
water_uchar getLastCharacter () const noexcept
String substring (int startIndex, int endIndex) const
String substring (int startIndex) const
String dropLastCharacters (int numberToDrop) const
String getLastCharacters (int numCharacters) const
String fromFirstOccurrenceOf (StringRef substringToStartFrom, bool includeSubStringInResult, bool ignoreCase) const
String fromLastOccurrenceOf (StringRef substringToFind, bool includeSubStringInResult, bool ignoreCase) const
String upToFirstOccurrenceOf (StringRef substringToEndWith, bool includeSubStringInResult, bool ignoreCase) const
String upToLastOccurrenceOf (StringRef substringToFind, bool includeSubStringInResult, bool ignoreCase) const
String trim () const
String trimStart () const
String trimEnd () const
String trimCharactersAtStart (StringRef charactersToTrim) const
String trimCharactersAtEnd (StringRef charactersToTrim) const
String toUpperCase () const
String toLowerCase () const
String replaceSection (int startIndex, int numCharactersToReplace, StringRef stringToInsert) const
String replace (StringRef stringToReplace, StringRef stringToInsertInstead, bool ignoreCase=false) const
String replaceCharacter (water_uchar characterToReplace, water_uchar characterToInsertInstead) const
String replaceCharacters (StringRef charactersToReplace, StringRef charactersToInsertInstead) const
String retainCharacters (StringRef charactersToRetain) const
String removeCharacters (StringRef charactersToRemove) const
String initialSectionContainingOnly (StringRef permittedCharacters) const
String initialSectionNotContaining (StringRef charactersToStopAt) const
bool isQuotedString () const
String unquoted () const
String quoted (water_uchar quoteCharacter='"') const
String paddedLeft (water_uchar padCharacter, int minimumLength) const
String paddedRight (water_uchar padCharacter, int minimumLength) const
 String (int decimalInteger)
 String (unsigned int decimalInteger)
 String (short decimalInteger)
 String (unsigned short decimalInteger)
 String (int64 largeIntegerValue)
 String (uint64 largeIntegerValue)
 String (long decimalInteger)
 String (unsigned long decimalInteger)
 String (float floatValue)
 String (double doubleValue)
 String (float floatValue, int numberOfDecimalPlaces)
 String (double doubleValue, int numberOfDecimalPlaces)
int getIntValue () const noexcept
int64 getLargeIntValue () const noexcept
int getTrailingIntValue () const noexcept
float getFloatValue () const noexcept
double getDoubleValue () const noexcept
int getHexValue32 () const noexcept
int64 getHexValue64 () const noexcept
CharPointer_UTF8 getCharPointer () const noexcept
CharPointer_UTF8 toUTF8 () const
const char * toRawUTF8 () const
std::string toStdString () const
size_t getNumBytesAsUTF8 () const noexcept
size_t copyToUTF8 (CharPointer_UTF8::CharType *destBuffer, size_t maxBufferSizeBytes) const noexcept
void preallocateBytes (size_t numBytesNeeded)
void swapWith (String &other) noexcept
int getReferenceCount () const noexcept

Static Public Member Functions

static String charToString (water_uchar character)
static String repeatedString (StringRef stringToRepeat, int numberOfTimesToRepeat)
static String createStringFromData (const void *data, int size)
static String formatted (const String formatString,...)
static String toHexString (int number)
static String toHexString (int64 number)
static String toHexString (short number)
static String toHexString (const void *data, int size, int groupSize=1)
static String fromUTF8 (const char *utf8buffer, int bufferSizeBytes=-1)

Private Member Functions

 String (const PreallocationBytes &)
size_t getByteOffsetOfEnd () const noexcept

Private Attributes

CharPointer_UTF8 text

Detailed Description

The Water String class!

Using a reference-counted internal representation, these strings are fast and efficient, and there are methods to do just about any operation you'll ever dream of.

See also
StringArray, StringPairArray

Constructor & Destructor Documentation

◆ String() [1/22]

juce::pnglibNamespace::water::String::String ( )
noexcept

Creates an empty string.

See also
empty

◆ String() [2/22]

juce::pnglibNamespace::water::String::String ( const String & other)
noexcept

Creates a copy of another string.

◆ String() [3/22]

juce::pnglibNamespace::water::String::String ( const char * text)

Creates a string from a zero-terminated ascii text string.

The string passed-in must not contain any characters with a value above 127, because these can't be converted to unicode without knowing the original encoding that was used to create the string. If you attempt to pass-in values above 127, you'll get an assertion.

To create strings with extended characters from UTF-8, you should explicitly call String (CharPointer_UTF8 ("my utf8 string..")). It's highly recommended that you use UTF-8 with escape characters in your source code to represent extended characters, because there's no other way to represent unicode strings in a way that isn't dependent on the compiler, source code editor and platform.

◆ String() [4/22]

juce::pnglibNamespace::water::String::String ( const char * text,
size_t maxChars )

Creates a string from a string of 8-bit ascii characters.

The string passed-in must not contain any characters with a value above 127, because these can't be converted to unicode without knowing the original encoding that was used to create the string. If you attempt to pass-in values above 127, you'll get an assertion.

To create strings with extended characters from UTF-8, you should explicitly call String (CharPointer_UTF8 ("my utf8 string..")). It's highly recommended that you use UTF-8 with escape characters in your source code to represent extended characters, because there's no other way to represent unicode strings in a way that isn't dependent on the compiler, source code editor and platform.

This will use up to the first maxChars characters of the string (or less if the string is actually shorter).

◆ String() [5/22]

juce::pnglibNamespace::water::String::String ( const CharPointer_UTF8 text)

Creates a string from a UTF-8 character string

◆ String() [6/22]

juce::pnglibNamespace::water::String::String ( const CharPointer_UTF8 text,
size_t maxChars )

Creates a string from a UTF-8 character string

◆ String() [7/22]

juce::pnglibNamespace::water::String::String ( const CharPointer_UTF8 start,
const CharPointer_UTF8 end )

Creates a string from a UTF-8 character string

◆ String() [8/22]

juce::pnglibNamespace::water::String::String ( const std::string & )

Creates a string from a UTF-8 encoded std::string.

◆ String() [9/22]

juce::pnglibNamespace::water::String::String ( StringRef )

Creates a string from a StringRef

◆ ~String()

juce::pnglibNamespace::water::String::~String ( )
noexcept

Destructor.

◆ String() [10/22]

juce::pnglibNamespace::water::String::String ( int decimalInteger)
explicit

Creates a string containing this signed 32-bit integer as a decimal number.

See also
getIntValue, getFloatValue, getDoubleValue, toHexString

◆ String() [11/22]

juce::pnglibNamespace::water::String::String ( unsigned int decimalInteger)
explicit

Creates a string containing this unsigned 32-bit integer as a decimal number.

See also
getIntValue, getFloatValue, getDoubleValue, toHexString

◆ String() [12/22]

juce::pnglibNamespace::water::String::String ( short decimalInteger)
explicit

Creates a string containing this signed 16-bit integer as a decimal number.

See also
getIntValue, getFloatValue, getDoubleValue, toHexString

◆ String() [13/22]

juce::pnglibNamespace::water::String::String ( unsigned short decimalInteger)
explicit

Creates a string containing this unsigned 16-bit integer as a decimal number.

See also
getIntValue, getFloatValue, getDoubleValue, toHexString

◆ String() [14/22]

juce::pnglibNamespace::water::String::String ( int64 largeIntegerValue)
explicit

Creates a string containing this signed 64-bit integer as a decimal number.

See also
getLargeIntValue, getFloatValue, getDoubleValue, toHexString

◆ String() [15/22]

juce::pnglibNamespace::water::String::String ( uint64 largeIntegerValue)
explicit

Creates a string containing this unsigned 64-bit integer as a decimal number.

See also
getLargeIntValue, getFloatValue, getDoubleValue, toHexString

◆ String() [16/22]

juce::pnglibNamespace::water::String::String ( long decimalInteger)
explicit

Creates a string containing this signed long integer as a decimal number.

See also
getIntValue, getFloatValue, getDoubleValue, toHexString

◆ String() [17/22]

juce::pnglibNamespace::water::String::String ( unsigned long decimalInteger)
explicit

Creates a string containing this unsigned long integer as a decimal number.

See also
getIntValue, getFloatValue, getDoubleValue, toHexString

◆ String() [18/22]

juce::pnglibNamespace::water::String::String ( float floatValue)
explicit

Creates a string representing this floating-point number.

Parameters
floatValuethe value to convert to a string
See also
getDoubleValue, getIntValue

◆ String() [19/22]

juce::pnglibNamespace::water::String::String ( double doubleValue)
explicit

Creates a string representing this floating-point number.

Parameters
doubleValuethe value to convert to a string
See also
getFloatValue, getIntValue

◆ String() [20/22]

juce::pnglibNamespace::water::String::String ( float floatValue,
int numberOfDecimalPlaces )

Creates a string representing this floating-point number.

Parameters
floatValuethe value to convert to a string
numberOfDecimalPlacesif this is > 0, it will format the number using that many decimal places, and will not use exponent notation. If 0 or less, it will use exponent notation if necessary.
See also
getDoubleValue, getIntValue

◆ String() [21/22]

juce::pnglibNamespace::water::String::String ( double doubleValue,
int numberOfDecimalPlaces )

Creates a string representing this floating-point number.

Parameters
doubleValuethe value to convert to a string
numberOfDecimalPlacesif this is > 0, it will format the number using that many decimal places, and will not use exponent notation. If 0 or less, it will use exponent notation if necessary.
See also
getFloatValue, getIntValue

◆ String() [22/22]

juce::pnglibNamespace::water::String::String ( const PreallocationBytes & )
explicitprivate

Member Function Documentation

◆ append()

void juce::pnglibNamespace::water::String::append ( const String & textToAppend,
size_t maxCharsToTake )

Appends a string to the end of this one.

Parameters
textToAppendthe string to add
maxCharsToTakethe maximum number of characters to take from the string passed in

◆ appendCharPointer() [1/5]

template<class CharPointer>
void juce::pnglibNamespace::water::String::appendCharPointer ( const CharPointer startOfTextToAppend,
const CharPointer endOfTextToAppend )
inline

Appends a string to the end of this one.

Parameters
startOfTextToAppendthe start of the string to add. This must not be a nullptr
endOfTextToAppendthe end of the string to add. This must not be a nullptr

◆ appendCharPointer() [2/5]

template<class CharPointer>
void juce::pnglibNamespace::water::String::appendCharPointer ( const CharPointer textToAppend)
inline

Appends a string to the end of this one.

◆ appendCharPointer() [3/5]

template<class CharPointer>
void juce::pnglibNamespace::water::String::appendCharPointer ( const CharPointer textToAppend,
size_t maxCharsToTake )
inline

Appends a string to the end of this one.

Parameters
textToAppendthe string to add
maxCharsToTakethe maximum number of characters to take from the string passed in

◆ appendCharPointer() [4/5]

void juce::pnglibNamespace::water::String::appendCharPointer ( const CharPointer_UTF8 startOfTextToAppend,
const CharPointer_UTF8 endOfTextToAppend )

Appends a string to the end of this one.

Parameters
startOfTextToAppendthe start of the string to add. This must not be a nullptr
endOfTextToAppendthe end of the string to add. This must not be a nullptr

◆ appendCharPointer() [5/5]

void juce::pnglibNamespace::water::String::appendCharPointer ( const CharPointer_UTF8 textToAppend)

Appends a string to the end of this one.

◆ charToString()

String juce::pnglibNamespace::water::String::charToString ( water_uchar character)
static

Creates a string from a single character.

◆ clear()

void juce::pnglibNamespace::water::String::clear ( )
noexcept

Resets this string to be empty.

◆ compare() [1/2]

int juce::pnglibNamespace::water::String::compare ( const char * other) const
noexcept

Case-sensitive comparison with another string.

Returns
0 if the two strings are identical; negative if this string comes before the other one alphabetically, or positive if it comes after it.

◆ compare() [2/2]

int juce::pnglibNamespace::water::String::compare ( const String & other) const
noexcept

Case-sensitive comparison with another string.

Returns
0 if the two strings are identical; negative if this string comes before the other one alphabetically, or positive if it comes after it.

◆ compareIgnoreCase()

int juce::pnglibNamespace::water::String::compareIgnoreCase ( const String & other) const
noexcept

Case-insensitive comparison with another string.

Returns
0 if the two strings are identical; negative if this string comes before the other one alphabetically, or positive if it comes after it.

◆ compareNatural()

int juce::pnglibNamespace::water::String::compareNatural ( StringRef other,
bool isCaseSensitive = false ) const
noexcept

Compares two strings, taking into account textual characteristics like numbers and spaces.

This comparison is case-insensitive and can detect words and embedded numbers in the strings, making it good for sorting human-readable lists of things like filenames.

Returns
0 if the two strings are identical; negative if this string comes before the other one alphabetically, or positive if it comes after it.

◆ contains()

bool juce::pnglibNamespace::water::String::contains ( StringRef text) const
noexcept

Tests whether the string contains another substring. If the parameter is an empty string, this will always return true. Uses a case-sensitive comparison.

◆ containsAnyOf()

bool juce::pnglibNamespace::water::String::containsAnyOf ( StringRef charactersItMightContain) const
noexcept

Looks for any of a set of characters in the string. Uses a case-sensitive comparison.

Returns
true if the string contains any of the characters from the string that is passed in.

◆ containsChar()

bool juce::pnglibNamespace::water::String::containsChar ( water_uchar character) const
noexcept

Tests whether the string contains a particular character. Uses a case-sensitive comparison.

◆ containsIgnoreCase()

bool juce::pnglibNamespace::water::String::containsIgnoreCase ( StringRef text) const
noexcept

Tests whether the string contains another substring. Uses a case-insensitive comparison.

◆ containsNonWhitespaceChars()

bool juce::pnglibNamespace::water::String::containsNonWhitespaceChars ( ) const
noexcept

Returns true if this string contains any non-whitespace characters.

This will return false if the string contains only whitespace characters, or if it's empty.

It is equivalent to calling "myString.trim().isNotEmpty()".

◆ containsOnly()

bool juce::pnglibNamespace::water::String::containsOnly ( StringRef charactersItMightContain) const
noexcept

Looks for a set of characters in the string. Uses a case-sensitive comparison.

Returns
Returns false if any of the characters in this string do not occur in the parameter string. If this string is empty, the return value will always be true.

◆ containsWholeWord()

bool juce::pnglibNamespace::water::String::containsWholeWord ( StringRef wordToLookFor) const
noexcept

Tests whether the string contains another substring as a distinct word.

Returns
true if the string contains this word, surrounded by non-alphanumeric characters
See also
indexOfWholeWord, containsWholeWordIgnoreCase

◆ containsWholeWordIgnoreCase()

bool juce::pnglibNamespace::water::String::containsWholeWordIgnoreCase ( StringRef wordToLookFor) const
noexcept

Tests whether the string contains another substring as a distinct word.

Returns
true if the string contains this word, surrounded by non-alphanumeric characters
See also
indexOfWholeWordIgnoreCase, containsWholeWord

◆ copyToUTF8()

size_t juce::pnglibNamespace::water::String::copyToUTF8 ( CharPointer_UTF8::CharType * destBuffer,
size_t maxBufferSizeBytes ) const
noexcept

Copies the string to a buffer as UTF-8 characters.

Returns the number of bytes copied to the buffer, including the terminating null character.

To find out how many bytes you need to store this string as UTF-8, you can call CharPointer_UTF8::getBytesRequiredFor (myString.getCharPointer())

Parameters
destBufferthe place to copy it to; if this is a null pointer, the method just returns the number of bytes required (including the terminating null character).
maxBufferSizeBytesthe size of the destination buffer, in bytes. If the string won't fit, it'll put in as many as it can while still allowing for a terminating null char at the end, and will return the number of bytes that were actually used.
See also
CharPointer_UTF8::writeWithDestByteLimit

◆ createStringFromData()

String juce::pnglibNamespace::water::String::createStringFromData ( const void * data,
int size )
static

Creates a string from data in an unknown format.

This looks at some binary data and tries to guess whether it's Unicode or 8-bit characters, then returns a string that represents it correctly.

Should be able to handle Unicode endianness correctly, by looking at the first two bytes.

◆ dropLastCharacters()

String juce::pnglibNamespace::water::String::dropLastCharacters ( int numberToDrop) const

Returns a version of this string with a number of characters removed from the end.

Parameters
numberToDropthe number of characters to drop from the end of the string. If this is greater than the length of the string, an empty string will be returned. If zero or less, the original string will be returned.
See also
substring, fromFirstOccurrenceOf, upToFirstOccurrenceOf, fromLastOccurrenceOf, getLastCharacter

◆ endsWith()

bool juce::pnglibNamespace::water::String::endsWith ( StringRef text) const
noexcept

Tests whether the string ends with another string. If the parameter is an empty string, this will always return true. Uses a case-sensitive comparison.

◆ endsWithChar()

bool juce::pnglibNamespace::water::String::endsWithChar ( water_uchar character) const
noexcept

Tests whether the string ends with a particular character. If the character is 0, this will always return false. Uses a case-sensitive comparison.

◆ endsWithIgnoreCase()

bool juce::pnglibNamespace::water::String::endsWithIgnoreCase ( StringRef text) const
noexcept

Tests whether the string ends with another string. If the parameter is an empty string, this will always return true. Uses a case-insensitive comparison.

◆ equalsIgnoreCase() [1/3]

bool juce::pnglibNamespace::water::String::equalsIgnoreCase ( const char * other) const
noexcept

Case-insensitive comparison with another string.

◆ equalsIgnoreCase() [2/3]

bool juce::pnglibNamespace::water::String::equalsIgnoreCase ( const String & other) const
noexcept

Case-insensitive comparison with another string.

◆ equalsIgnoreCase() [3/3]

bool juce::pnglibNamespace::water::String::equalsIgnoreCase ( StringRef other) const
noexcept

Case-insensitive comparison with another string.

◆ formatted()

String juce::pnglibNamespace::water::String::formatted ( const String formatString,
... )
static

Creates a String from a printf-style parameter list.

I don't like this method. I don't use it myself, and I recommend avoiding it and using the operator<< methods or pretty much anything else instead. It's only provided here because of the popular unrest that was stirred-up when I tried to remove it...

If you're really determined to use it, at least make sure that you never, ever, pass any String objects to it as parameters.

◆ fromFirstOccurrenceOf()

String juce::pnglibNamespace::water::String::fromFirstOccurrenceOf ( StringRef substringToStartFrom,
bool includeSubStringInResult,
bool ignoreCase ) const

Returns a section of the string starting from a given substring.

This will search for the first occurrence of the given substring, and return the section of the string starting from the point where this is found (optionally not including the substring itself).

e.g. for the string "123456", fromFirstOccurrenceOf ("34", true) would return "3456", and fromFirstOccurrenceOf ("34", false) would return "56".

If the substring isn't found, the method will return an empty string.

If ignoreCase is true, the comparison will be case-insensitive.

See also
upToFirstOccurrenceOf, fromLastOccurrenceOf

◆ fromLastOccurrenceOf()

String juce::pnglibNamespace::water::String::fromLastOccurrenceOf ( StringRef substringToFind,
bool includeSubStringInResult,
bool ignoreCase ) const

Returns a section of the string starting from the last occurrence of a given substring.

Similar to fromFirstOccurrenceOf(), but using the last occurrence of the substring, and unlike fromFirstOccurrenceOf(), if the substring isn't found, this method will return the whole of the original string.

See also
fromFirstOccurrenceOf, upToLastOccurrenceOf

◆ fromUTF8()

String juce::pnglibNamespace::water::String::fromUTF8 ( const char * utf8buffer,
int bufferSizeBytes = -1 )
static

Creates a String from a UTF-8 encoded buffer. If the size is < 0, it'll keep reading until it hits a zero.

◆ getByteOffsetOfEnd()

size_t juce::pnglibNamespace::water::String::getByteOffsetOfEnd ( ) const
privatenoexcept

◆ getCharPointer()

CharPointer_UTF8 juce::pnglibNamespace::water::String::getCharPointer ( ) const
inlinenoexcept

Returns the character pointer currently being used to store this string.

Because it returns a reference to the string's internal data, the pointer that is returned must not be stored anywhere, as it can be deleted whenever the string changes.

◆ getDoubleValue()

double juce::pnglibNamespace::water::String::getDoubleValue ( ) const
noexcept

Parses this string as a floating point number.

Returns
the value of the string as a 64-bit floating point value.
See also
getFloatValue

◆ getFloatValue()

float juce::pnglibNamespace::water::String::getFloatValue ( ) const
noexcept

Parses this string as a floating point number.

Returns
the value of the string as a 32-bit floating point value.
See also
getDoubleValue

◆ getHexValue32()

int juce::pnglibNamespace::water::String::getHexValue32 ( ) const
noexcept

Parses the string as a hexadecimal number.

Non-hexadecimal characters in the string are ignored.

If the string contains too many characters, then the lowest significant digits are returned, e.g. "ffff12345678" would produce 0x12345678.

Returns
a 32-bit number which is the value of the string in hex.

◆ getHexValue64()

int64 juce::pnglibNamespace::water::String::getHexValue64 ( ) const
noexcept

Parses the string as a hexadecimal number.

Non-hexadecimal characters in the string are ignored.

If the string contains too many characters, then the lowest significant digits are returned, e.g. "ffff1234567812345678" would produce 0x1234567812345678.

Returns
a 64-bit number which is the value of the string in hex.

◆ getIntValue()

int juce::pnglibNamespace::water::String::getIntValue ( ) const
noexcept

Reads the value of the string as a decimal number (up to 32 bits in size).

Returns
the value of the string as a 32 bit signed base-10 integer.
See also
getTrailingIntValue, getHexValue32, getHexValue64

◆ getLargeIntValue()

int64 juce::pnglibNamespace::water::String::getLargeIntValue ( ) const
noexcept

Reads the value of the string as a decimal number (up to 64 bits in size).

Returns
the value of the string as a 64 bit signed base-10 integer.

◆ getLastCharacter()

water_uchar juce::pnglibNamespace::water::String::getLastCharacter ( ) const
noexcept

Returns the final character of the string. If the string is empty this will return 0.

◆ getLastCharacters()

String juce::pnglibNamespace::water::String::getLastCharacters ( int numCharacters) const

Returns a number of characters from the end of the string.

This returns the last numCharacters characters from the end of the string. If the string is shorter than numCharacters, the whole string is returned.

See also
substring, dropLastCharacters, getLastCharacter

◆ getNumBytesAsUTF8()

size_t juce::pnglibNamespace::water::String::getNumBytesAsUTF8 ( ) const
noexcept

Returns the number of bytes required to represent this string as UTF8. The number returned does NOT include the trailing zero.

See also
toUTF8, copyToUTF8

◆ getReferenceCount()

int juce::pnglibNamespace::water::String::getReferenceCount ( ) const
noexcept

Returns the number of String objects which are currently sharing the same internal data as this one.

◆ getTrailingIntValue()

int juce::pnglibNamespace::water::String::getTrailingIntValue ( ) const
noexcept

Parses a decimal number from the end of the string.

This will look for a value at the end of the string. e.g. for "321 xyz654" it will return 654; for "2 3 4" it'll return 4.

Negative numbers are not handled, so "xyz-5" returns 5.

See also
getIntValue

◆ hash()

size_t juce::pnglibNamespace::water::String::hash ( ) const
noexcept

Generates a probably-unique hashcode from this string.

◆ hashCode()

int juce::pnglibNamespace::water::String::hashCode ( ) const
noexcept

Generates a probably-unique 32-bit hashcode from this string.

◆ hashCode64()

int64 juce::pnglibNamespace::water::String::hashCode64 ( ) const
noexcept

Generates a probably-unique 64-bit hashcode from this string.

◆ indexOf() [1/2]

int juce::pnglibNamespace::water::String::indexOf ( int startIndex,
StringRef textToLookFor ) const
noexcept

Searches for a substring within this string. Uses a case-sensitive comparison.

Parameters
startIndexthe index from which the search should proceed
textToLookForthe string to search for
Returns
the index of the first occurrence of this substring, or -1 if it's not found. If textToLookFor is an empty string, this will always return -1.

◆ indexOf() [2/2]

int juce::pnglibNamespace::water::String::indexOf ( StringRef textToLookFor) const
noexcept

Searches for a substring within this string. Uses a case-sensitive comparison.

Returns
the index of the first occurrence of this substring, or -1 if it's not found. If textToLookFor is an empty string, this will always return 0.

◆ indexOfAnyOf()

int juce::pnglibNamespace::water::String::indexOfAnyOf ( StringRef charactersToLookFor,
int startIndex = 0,
bool ignoreCase = false ) const
noexcept

Returns the index of the first character that matches one of the characters passed-in to this method.

This scans the string, beginning from the startIndex supplied, and if it finds a character that appears in the string charactersToLookFor, it returns its index.

If none of these characters are found, it returns -1.

If ignoreCase is true, the comparison will be case-insensitive.

See also
indexOfChar, lastIndexOfAnyOf

◆ indexOfChar() [1/2]

int juce::pnglibNamespace::water::String::indexOfChar ( int startIndex,
water_uchar characterToLookFor ) const
noexcept

Searches for a character inside this string. Uses a case-sensitive comparison.

Parameters
startIndexthe index from which the search should proceed
characterToLookForthe character to look for
Returns
the index of the first occurrence of the character in this string, or -1 if it's not found.

◆ indexOfChar() [2/2]

int juce::pnglibNamespace::water::String::indexOfChar ( water_uchar characterToLookFor) const
noexcept

Searches for a character inside this string. Uses a case-sensitive comparison.

Returns
the index of the first occurrence of the character in this string, or -1 if it's not found.

◆ indexOfIgnoreCase() [1/2]

int juce::pnglibNamespace::water::String::indexOfIgnoreCase ( int startIndex,
StringRef textToLookFor ) const
noexcept

Searches for a substring within this string. Uses a case-insensitive comparison.

Parameters
startIndexthe index from which the search should proceed
textToLookForthe string to search for
Returns
the index of the first occurrence of this substring, or -1 if it's not found. If textToLookFor is an empty string, this will always return -1.

◆ indexOfIgnoreCase() [2/2]

int juce::pnglibNamespace::water::String::indexOfIgnoreCase ( StringRef textToLookFor) const
noexcept

Searches for a substring within this string. Uses a case-insensitive comparison.

Returns
the index of the first occurrence of this substring, or -1 if it's not found. If textToLookFor is an empty string, this will always return 0.

◆ indexOfWholeWord()

int juce::pnglibNamespace::water::String::indexOfWholeWord ( StringRef wordToLookFor) const
noexcept

Finds an instance of another substring if it exists as a distinct word.

Returns
if the string contains this word, surrounded by non-alphanumeric characters, then this will return the index of the start of the substring. If it isn't found, then it will return -1
See also
indexOfWholeWordIgnoreCase, containsWholeWord

◆ indexOfWholeWordIgnoreCase()

int juce::pnglibNamespace::water::String::indexOfWholeWordIgnoreCase ( StringRef wordToLookFor) const
noexcept

Finds an instance of another substring if it exists as a distinct word.

Returns
if the string contains this word, surrounded by non-alphanumeric characters, then this will return the index of the start of the substring. If it isn't found, then it will return -1
See also
indexOfWholeWord, containsWholeWordIgnoreCase

◆ initialSectionContainingOnly()

String juce::pnglibNamespace::water::String::initialSectionContainingOnly ( StringRef permittedCharacters) const

Returns a section from the start of the string that only contains a certain set of characters.

This returns the leftmost section of the string, up to (and not including) the first character that doesn't appear in the string passed in.

◆ initialSectionNotContaining()

String juce::pnglibNamespace::water::String::initialSectionNotContaining ( StringRef charactersToStopAt) const

Returns a section from the start of the string that only contains a certain set of characters.

This returns the leftmost section of the string, up to (and not including) the first character that occurs in the string passed in. (If none of the specified characters are found in the string, the return value will just be the original string).

◆ isEmpty()

bool juce::pnglibNamespace::water::String::isEmpty ( ) const
inlinenoexcept

Returns true if the string contains no characters. Note that there's also an isNotEmpty() method to help write readable code.

See also
containsNonWhitespaceChars()

◆ isNotEmpty()

bool juce::pnglibNamespace::water::String::isNotEmpty ( ) const
inlinenoexcept

Returns true if the string contains at least one character. Note that there's also an isEmpty() method to help write readable code.

See also
containsNonWhitespaceChars()

◆ isQuotedString()

bool juce::pnglibNamespace::water::String::isQuotedString ( ) const

Checks whether the string might be in quotation marks.

Returns
true if the string begins with a quote character (either a double or single quote). It is also true if there is whitespace before the quote, but it doesn't check the end of the string.
See also
unquoted, quoted

◆ lastIndexOf()

int juce::pnglibNamespace::water::String::lastIndexOf ( StringRef textToLookFor) const
noexcept

Searches for a substring inside this string (working backwards from the end of the string). Uses a case-sensitive comparison.

Returns
the index of the start of the last occurrence of the substring within this string, or -1 if it's not found. If textToLookFor is an empty string, this will always return -1.

◆ lastIndexOfAnyOf()

int juce::pnglibNamespace::water::String::lastIndexOfAnyOf ( StringRef charactersToLookFor,
bool ignoreCase = false ) const
noexcept

Returns the index of the last character in this string that matches one of the characters passed-in to this method.

This scans the string backwards, starting from its end, and if it finds a character that appears in the string charactersToLookFor, it returns its index.

If none of these characters are found, it returns -1.

If ignoreCase is true, the comparison will be case-insensitive.

See also
lastIndexOf, indexOfAnyOf

◆ lastIndexOfChar()

int juce::pnglibNamespace::water::String::lastIndexOfChar ( water_uchar character) const
noexcept

Searches for a character inside this string (working backwards from the end of the string). Uses a case-sensitive comparison.

Returns
the index of the last occurrence of the character in this string, or -1 if it's not found.

◆ lastIndexOfIgnoreCase()

int juce::pnglibNamespace::water::String::lastIndexOfIgnoreCase ( StringRef textToLookFor) const
noexcept

Searches for a substring inside this string (working backwards from the end of the string). Uses a case-insensitive comparison.

Returns
the index of the start of the last occurrence of the substring within this string, or -1 if it's not found. If textToLookFor is an empty string, this will always return -1.

◆ length()

int juce::pnglibNamespace::water::String::length ( ) const
noexcept

Returns the number of characters in the string.

◆ matchesWildcard()

bool juce::pnglibNamespace::water::String::matchesWildcard ( StringRef wildcard,
bool ignoreCase ) const
noexcept

Returns true if the string matches this simple wildcard expression.

So for example String ("abcdef").matchesWildcard ("*DEF", true) would return true.

This isn't a full-blown regex though! The only wildcard characters supported are "*" and "?". It's mainly intended for filename pattern matching.

◆ operator+=() [1/9]

String & juce::pnglibNamespace::water::String::operator+= ( char characterToAppend)

Appends a character at the end of this string.

◆ operator+=() [2/9]

String & juce::pnglibNamespace::water::String::operator+= ( const char * textToAppend)

Appends another string at the end of this one.

◆ operator+=() [3/9]

String & juce::pnglibNamespace::water::String::operator+= ( const String & stringToAppend)

Appends another string at the end of this one.

◆ operator+=() [4/9]

String & juce::pnglibNamespace::water::String::operator+= ( int numberToAppend)

Appends a decimal number at the end of this string.

◆ operator+=() [5/9]

String & juce::pnglibNamespace::water::String::operator+= ( int64 numberToAppend)

Appends a decimal number at the end of this string.

◆ operator+=() [6/9]

String & juce::pnglibNamespace::water::String::operator+= ( long numberToAppend)

Appends a decimal number at the end of this string.

◆ operator+=() [7/9]

String & juce::pnglibNamespace::water::String::operator+= ( StringRef textToAppend)

Appends another string at the end of this one.

◆ operator+=() [8/9]

String & juce::pnglibNamespace::water::String::operator+= ( uint64 numberToAppend)

Appends a decimal number at the end of this string.

◆ operator+=() [9/9]

String & juce::pnglibNamespace::water::String::operator+= ( water_uchar characterToAppend)

Appends a character at the end of this string.

◆ operator=()

String & juce::pnglibNamespace::water::String::operator= ( const String & other)
noexcept

Replaces this string's contents with another string.

◆ operator[]()

water_uchar juce::pnglibNamespace::water::String::operator[] ( int index) const
noexcept

Returns the character at this index in the string. In a release build, no checks are made to see if the index is within a valid range, so be careful! In a debug build, the index is checked and an assertion fires if it's out-of-range.

Also beware that depending on the encoding format that the string is using internally, this method may execute in either O(1) or O(n) time, so be careful when using it in your algorithms. If you're scanning through a string to inspect its characters, you should never use this operator for random access, it's far more efficient to call getCharPointer() to return a pointer, and then to use that to iterate the string.

See also
getCharPointer

◆ paddedLeft()

String juce::pnglibNamespace::water::String::paddedLeft ( water_uchar padCharacter,
int minimumLength ) const

Returns a copy of this string with the specified character repeatedly added to its beginning until the total length is at least the minimum length specified.

◆ paddedRight()

String juce::pnglibNamespace::water::String::paddedRight ( water_uchar padCharacter,
int minimumLength ) const

Returns a copy of this string with the specified character repeatedly added to its end until the total length is at least the minimum length specified.

◆ preallocateBytes()

void juce::pnglibNamespace::water::String::preallocateBytes ( size_t numBytesNeeded)

Increases the string's internally allocated storage.

Although the string's contents won't be affected by this call, it will increase the amount of memory allocated internally for the string to grow into.

If you're about to make a large number of calls to methods such as += or <<, it's more efficient to preallocate enough extra space beforehand, so that these methods won't have to keep resizing the string to append the extra characters.

Parameters
numBytesNeededthe number of bytes to allocate storage for. If this value is less than the currently allocated size, it will have no effect.

◆ quoted()

String juce::pnglibNamespace::water::String::quoted ( water_uchar quoteCharacter = '"') const

Adds quotation marks around a string. This will return a copy of the string with a quote at the start and end, (but won't add the quote if there's already one there, so it's safe to call this on strings that may already have quotes around them). Note that this is a const method, and won't alter the string itself.

Parameters
quoteCharacterthe character to add at the start and end
See also
isQuotedString, unquoted

◆ removeCharacters()

String juce::pnglibNamespace::water::String::removeCharacters ( StringRef charactersToRemove) const

Returns a version of this string with a set of characters removed.

This will return a copy of this string, omitting any characters which are found in the string passed-in.

e.g. for "1122334455", removeCharacters ("432") would return "1155"

Note that this is a const method, and won't alter the string itself.

◆ repeatedString()

String juce::pnglibNamespace::water::String::repeatedString ( StringRef stringToRepeat,
int numberOfTimesToRepeat )
static

Creates a string which is a version of a string repeated and joined together.

Parameters
stringToRepeatthe string to repeat
numberOfTimesToRepeathow many times to repeat it

◆ replace()

String juce::pnglibNamespace::water::String::replace ( StringRef stringToReplace,
StringRef stringToInsertInstead,
bool ignoreCase = false ) const

Replaces all occurrences of a substring with another string.

Returns a copy of this string, with any occurrences of stringToReplace swapped for stringToInsertInstead.

Note that this is a const method, and won't alter the string itself.

◆ replaceCharacter()

String juce::pnglibNamespace::water::String::replaceCharacter ( water_uchar characterToReplace,
water_uchar characterToInsertInstead ) const

Returns a string with all occurrences of a character replaced with a different one.

◆ replaceCharacters()

String juce::pnglibNamespace::water::String::replaceCharacters ( StringRef charactersToReplace,
StringRef charactersToInsertInstead ) const

Replaces a set of characters with another set.

Returns a string in which each character from charactersToReplace has been replaced by the character at the equivalent position in newCharacters (so the two strings passed in must be the same length).

e.g. replaceCharacters ("abc", "def") replaces 'a' with 'd', 'b' with 'e', etc.

Note that this is a const method, and won't affect the string itself.

◆ replaceSection()

String juce::pnglibNamespace::water::String::replaceSection ( int startIndex,
int numCharactersToReplace,
StringRef stringToInsert ) const

Replaces a sub-section of the string with another string.

This will return a copy of this string, with a set of characters from startIndex to startIndex + numCharsToReplace removed, and with a new string inserted in their place.

Note that this is a const method, and won't alter the string itself.

Parameters
startIndexthe first character to remove. If this is beyond the bounds of the string, it will be constrained to a valid range.
numCharactersToReplacethe number of characters to remove. If zero or less, no characters will be taken out.
stringToInsertthe new string to insert at startIndex after the characters have been removed.

◆ retainCharacters()

String juce::pnglibNamespace::water::String::retainCharacters ( StringRef charactersToRetain) const

Returns a version of this string that only retains a fixed set of characters.

This will return a copy of this string, omitting any characters which are not found in the string passed-in.

e.g. for "1122334455", retainCharacters ("432") would return "223344"

Note that this is a const method, and won't alter the string itself.

◆ startsWith()

bool juce::pnglibNamespace::water::String::startsWith ( StringRef text) const
noexcept

Tests whether the string begins with another string. If the parameter is an empty string, this will always return true. Uses a case-sensitive comparison.

◆ startsWithChar()

bool juce::pnglibNamespace::water::String::startsWithChar ( water_uchar character) const
noexcept

Tests whether the string begins with a particular character. If the character is 0, this will always return false. Uses a case-sensitive comparison.

◆ startsWithIgnoreCase()

bool juce::pnglibNamespace::water::String::startsWithIgnoreCase ( StringRef text) const
noexcept

Tests whether the string begins with another string. If the parameter is an empty string, this will always return true. Uses a case-insensitive comparison.

◆ substring() [1/2]

String juce::pnglibNamespace::water::String::substring ( int startIndex) const

Returns a section of the string, starting from a given position.

Parameters
startIndexthe first character to include. If this is beyond the end of the string, an empty string is returned. If it is zero or less, the whole string is returned.
Returns
the substring from startIndex up to the end of the string
See also
dropLastCharacters, getLastCharacters, fromFirstOccurrenceOf, upToFirstOccurrenceOf, fromLastOccurrenceOf

◆ substring() [2/2]

String juce::pnglibNamespace::water::String::substring ( int startIndex,
int endIndex ) const

Returns a subsection of the string.

If the range specified is beyond the limits of the string, as much as possible is returned.

Parameters
startIndexthe index of the start of the substring needed
endIndexall characters from startIndex up to (but not including) this index are returned
See also
fromFirstOccurrenceOf, dropLastCharacters, getLastCharacters, upToFirstOccurrenceOf

◆ swapWith()

void juce::pnglibNamespace::water::String::swapWith ( String & other)
noexcept

Swaps the contents of this string with another one. This is a very fast operation, as no allocation or copying needs to be done.

◆ toHexString() [1/4]

String juce::pnglibNamespace::water::String::toHexString ( const void * data,
int size,
int groupSize = 1 )
static

Creates a string containing a hex dump of a block of binary data.

Parameters
datathe binary data to use as input
sizehow many bytes of data to use
groupSizehow many bytes are grouped together before inserting a space into the output. e.g. group size 0 has no spaces, group size 1 looks like: "be a1 c2 ff", group size 2 looks like "bea1 c2ff".

◆ toHexString() [2/4]

String juce::pnglibNamespace::water::String::toHexString ( int number)
static

Creates a string representing this 32-bit value in hexadecimal.

◆ toHexString() [3/4]

String juce::pnglibNamespace::water::String::toHexString ( int64 number)
static

Creates a string representing this 64-bit value in hexadecimal.

◆ toHexString() [4/4]

String juce::pnglibNamespace::water::String::toHexString ( short number)
static

Creates a string representing this 16-bit value in hexadecimal.

◆ toLowerCase()

String juce::pnglibNamespace::water::String::toLowerCase ( ) const

Returns an lower-case version of this string.

◆ toRawUTF8()

const char * juce::pnglibNamespace::water::String::toRawUTF8 ( ) const

Returns a pointer to a UTF-8 version of this string.

Because it returns a reference to the string's internal data, the pointer that is returned must not be stored anywhere, as it can be deleted whenever the string changes.

To find out how many bytes you need to store this string as UTF-8, you can call CharPointer_UTF8::getBytesRequiredFor (myString.getCharPointer())

See also
getCharPointer, toUTF8, toUTF16

◆ toStdString()

std::string juce::pnglibNamespace::water::String::toStdString ( ) const

◆ toUpperCase()

String juce::pnglibNamespace::water::String::toUpperCase ( ) const

Returns an upper-case version of this string.

◆ toUTF8()

CharPointer_UTF8 juce::pnglibNamespace::water::String::toUTF8 ( ) const

Returns a pointer to a UTF-8 version of this string.

Because it returns a reference to the string's internal data, the pointer that is returned must not be stored anywhere, as it can be deleted whenever the string changes.

To find out how many bytes you need to store this string as UTF-8, you can call CharPointer_UTF8::getBytesRequiredFor (myString.getCharPointer())

See also
toRawUTF8, getCharPointer, toUTF16

◆ trim()

String juce::pnglibNamespace::water::String::trim ( ) const

Returns a copy of this string with any whitespace characters removed from the start and end.

◆ trimCharactersAtEnd()

String juce::pnglibNamespace::water::String::trimCharactersAtEnd ( StringRef charactersToTrim) const

Returns a copy of this string, having removed a specified set of characters from its end. Characters are removed from the end of the string until it finds one that is not in the specified set, and then it stops.

Parameters
charactersToTrimthe set of characters to remove.
See also
trim, trimEnd, trimCharactersAtStart

◆ trimCharactersAtStart()

String juce::pnglibNamespace::water::String::trimCharactersAtStart ( StringRef charactersToTrim) const

Returns a copy of this string, having removed a specified set of characters from its start. Characters are removed from the start of the string until it finds one that is not in the specified set, and then it stops.

Parameters
charactersToTrimthe set of characters to remove.
See also
trim, trimStart, trimCharactersAtEnd

◆ trimEnd()

String juce::pnglibNamespace::water::String::trimEnd ( ) const

Returns a copy of this string with any whitespace characters removed from the end.

◆ trimStart()

String juce::pnglibNamespace::water::String::trimStart ( ) const

Returns a copy of this string with any whitespace characters removed from the start.

◆ unquoted()

String juce::pnglibNamespace::water::String::unquoted ( ) const

Removes quotation marks from around the string, (if there are any).

Returns a copy of this string with any quotes removed from its ends. Quotes that aren't at the ends of the string are not affected. If there aren't any quotes, the original string is returned.

Note that this is a const method, and won't alter the string itself.

See also
isQuotedString, quoted

◆ upToFirstOccurrenceOf()

String juce::pnglibNamespace::water::String::upToFirstOccurrenceOf ( StringRef substringToEndWith,
bool includeSubStringInResult,
bool ignoreCase ) const

Returns the start of this string, up to the first occurrence of a substring.

This will search for the first occurrence of a given substring, and then return a copy of the string, up to the position of this substring, optionally including or excluding the substring itself in the result.

e.g. for the string "123456", upTo ("34", false) would return "12", and upTo ("34", true) would return "1234".

If the substring isn't found, this will return the whole of the original string.

See also
upToLastOccurrenceOf, fromFirstOccurrenceOf

◆ upToLastOccurrenceOf()

String juce::pnglibNamespace::water::String::upToLastOccurrenceOf ( StringRef substringToFind,
bool includeSubStringInResult,
bool ignoreCase ) const

Returns the start of this string, up to the last occurrence of a substring.

Similar to upToFirstOccurrenceOf(), but this finds the last occurrence rather than the first. If the substring isn't found, this will return the whole of the original string.

See also
upToFirstOccurrenceOf, fromFirstOccurrenceOf

Member Data Documentation

◆ text

CharPointer_UTF8 juce::pnglibNamespace::water::String::text
private

The documentation for this class was generated from the following file: