A simple class for holding temporary references to a string literal or String. More...
#include <juce_StringRef.h>
Public Member Functions | |
StringRef () noexcept | |
Creates a StringRef pointer to an empty string. More... | |
StringRef (const char *stringLiteral) noexcept | |
Creates a StringRef from a raw string literal. More... | |
StringRef (const std::string &string) | |
Creates a StringRef from a String. More... | |
StringRef (const String &string) noexcept | |
Creates a StringRef from a String. More... | |
StringRef (String::CharPointerType stringLiteral) noexcept | |
Creates a StringRef from a raw char pointer. More... | |
bool | isEmpty () const noexcept |
Returns true if the string is empty. More... | |
bool | isNotEmpty () const noexcept |
Returns true if the string is not empty. More... | |
int | length () const noexcept |
Returns the number of characters in the string. More... | |
operator const String::CharPointerType::CharType * () const noexcept | |
Returns a raw pointer to the underlying string data. More... | |
operator String::CharPointerType () const noexcept | |
Returns a pointer to the underlying string data as a char pointer object. More... | |
bool | operator!= (const String &s) const noexcept |
Compares this StringRef with a String. More... | |
bool | operator!= (StringRef s) const noexcept |
Case-sensitive comparison of two StringRefs. More... | |
bool | operator< (const String &s) const noexcept |
Compares this StringRef with a String. More... | |
bool | operator<= (const String &s) const noexcept |
Compares this StringRef with a String. More... | |
bool | operator== (const String &s) const noexcept |
Compares this StringRef with a String. More... | |
bool | operator== (StringRef s) const noexcept |
Case-sensitive comparison of two StringRefs. More... | |
bool | operator> (const String &s) const noexcept |
Compares this StringRef with a String. More... | |
bool | operator>= (const String &s) const noexcept |
Compares this StringRef with a String. More... | |
juce_wchar | operator[] (int index) const noexcept |
Retrieves a character by index. More... | |
Public Attributes | |
String::CharPointerType | text |
The text that is referenced. More... | |
A simple class for holding temporary references to a string literal or String.
Unlike a real String object, the StringRef does not allocate any memory or take ownership of the strings you give to it - it simply holds a reference to a string that has been allocated elsewhere. The main purpose of the class is to be used instead of a const String& as the type of function arguments where the caller may pass either a string literal or a String object. This means that when the called uses a string literal, there's no need for an temporary String object to be allocated, and this cuts down overheads substantially.
Because the class is simply a wrapper around a pointer, you should always pass it by value, not by reference.
For examples of it in use, see the XmlElement or StringArray classes.
Bear in mind that there are still many cases where it's better to use an argument which is a const String&. For example if the function stores the string or needs to internally create a String from the argument, then it's better for the original argument to already be a String.
@tags{Core}
|
noexcept |
|
noexcept |
|
noexcept |
juce::StringRef::StringRef | ( | const std::string & | string | ) |
|
noexcept |
Creates a StringRef pointer to an empty string.
|
inlinenoexcept |
Returns true if the string is empty.
References juce::String::isEmpty(), and juce::UnitTestCategories::text.
|
inlinenoexcept |
Returns true if the string is not empty.
References juce::String::isEmpty(), and juce::UnitTestCategories::text.
Referenced by juce::ValueTreePropertyWithDefault::varArrayToDelimitedString().
|
inlinenoexcept |
Returns the number of characters in the string.
References juce::String::length(), and juce::UnitTestCategories::text.
|
inlinenoexcept |
Returns a raw pointer to the underlying string data.
References juce::UnitTestCategories::text.
|
inlinenoexcept |
Returns a pointer to the underlying string data as a char pointer object.
References juce::UnitTestCategories::text.
Compares this StringRef with a String.
References juce::String::compare(), juce::gl::s, and juce::UnitTestCategories::text.
Case-sensitive comparison of two StringRefs.
References juce::String::compare(), juce::gl::s, and juce::UnitTestCategories::text.
Compares this StringRef with a String.
References juce::String::compare(), juce::gl::s, and juce::UnitTestCategories::text.
Compares this StringRef with a String.
References juce::String::compare(), juce::gl::s, and juce::UnitTestCategories::text.
Compares this StringRef with a String.
References juce::String::compare(), juce::gl::s, and juce::UnitTestCategories::text.
Case-sensitive comparison of two StringRefs.
References juce::String::compare(), juce::gl::s, and juce::UnitTestCategories::text.
Compares this StringRef with a String.
References juce::String::compare(), juce::gl::s, and juce::UnitTestCategories::text.
Compares this StringRef with a String.
References juce::String::compare(), juce::gl::s, and juce::UnitTestCategories::text.
|
inlinenoexcept |
Retrieves a character by index.
References juce::gl::index, and juce::UnitTestCategories::text.
String::CharPointerType juce::StringRef::text |
The text that is referenced.
Referenced by juce::Rectangle< int >::fromString(), and juce::operator+().