Member Typedef Documentation

This is the character encoding type used internally to store the string.

By setting the value of JUCE_STRING_UTF_TYPE to 8, 16, or 32, you can change the internal storage format of the String class. UTF-8 uses the least space (if your strings contain few extended characters), but call operator[] involves iterating the string to find the required index. UTF-32 provides instant random access to its characters, but uses 4 bytes per character to store them. UTF-16 uses more space than UTF-8 and is also slow to index, but is the native wchar_t format used in Windows.

It doesn't matter too much which format you pick, because the toUTF8(), toUTF16() and toUTF32() methods let you access the string's content in any of the other formats.

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::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::String

(

const wchar_t *

text

)

Creates a string from a whcar_t character string.

Depending on the platform, this may be treated as either UTF-32 or UTF-16.

String::String

(

const wchar_t *

text,

size_t

maxChars

)

Creates a string from a whcar_t character string.

Depending on the platform, this may be treated as either UTF-32 or UTF-16.

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.

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.

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).

bool 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.

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).

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. And bear in mind that internally, depending on the platform, it may be using wchar_t or char character types, so that even string literals can't be safely used as parameters if you're writing portable code.

int String::getIntValue

(

)

const

noexcept

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

the 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).

maxBufferSizeBytes

the 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.

the 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).

maxBufferSizeBytes

the 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.

the 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).

maxBufferSizeBytes

the 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.

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

numBytesNeeded

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