OpenShot Library | libopenshot-audio 0.2.0
|
A simple class for holding temporary references to a string literal or String. More...
#include <juce_StringRef.h>
Public Member Functions | |
StringRef (const char *stringLiteral) noexcept | |
Creates a StringRef from a raw string literal. | |
StringRef (String::CharPointerType stringLiteral) noexcept | |
Creates a StringRef from a raw char pointer. | |
StringRef (const String &string) noexcept | |
Creates a StringRef from a String. | |
StringRef (const std::string &string) | |
Creates a StringRef from a String. | |
StringRef () noexcept | |
Creates a StringRef pointer to an empty string. | |
operator const String::CharPointerType::CharType * () const noexcept | |
Returns a raw pointer to the underlying string data. | |
operator String::CharPointerType () const noexcept | |
Returns a pointer to the underlying string data as a char pointer object. | |
bool | isEmpty () const noexcept |
Returns true if the string is empty. | |
bool | isNotEmpty () const noexcept |
Returns true if the string is not empty. | |
int | length () const noexcept |
Returns the number of characters in the string. | |
juce_wchar | operator[] (int index) const noexcept |
Retrieves a character by index. | |
bool | operator== (const String &s) const noexcept |
Compares this StringRef with a String. | |
bool | operator!= (const String &s) const noexcept |
Compares this StringRef with a String. | |
bool | operator== (StringRef s) const noexcept |
Case-sensitive comparison of two StringRefs. | |
bool | operator!= (StringRef s) const noexcept |
Case-sensitive comparison of two StringRefs. | |
Public Attributes | |
String::CharPointerType | text |
The text that is referenced. | |
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.
Definition at line 65 of file juce_StringRef.h.
Creates a StringRef from a raw string literal.
The StringRef object does NOT take ownership or copy this data, so you must ensure that the data does not change during the lifetime of the StringRef. Note that this pointer cannot be null!
Definition at line 2149 of file juce_String.cpp.
References juce::CharPointer_ASCII::isValidString().
|
noexcept |
Creates a StringRef from a raw char pointer.
The StringRef object does NOT take ownership or copy this data, so you must ensure that the data does not change during the lifetime of the StringRef.
Definition at line 2180 of file juce_String.cpp.
juce::StringRef::StringRef | ( | const std::string & | string | ) |
|
noexcept |
Creates a StringRef pointer to an empty string.
Definition at line 2145 of file juce_String.cpp.
|
inlinenoexcept |
Returns a raw pointer to the underlying string data.
Definition at line 100 of file juce_StringRef.h.
|
inlinenoexcept |
Returns a pointer to the underlying string data as a char pointer object.
Definition at line 102 of file juce_StringRef.h.
|
inlinenoexcept |
Returns true if the string is empty.
Definition at line 105 of file juce_StringRef.h.
References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::isEmpty().
|
inlinenoexcept |
Returns true if the string is not empty.
Definition at line 107 of file juce_StringRef.h.
References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::isEmpty().
Referenced by juce::StringArray::addTokens().
|
inlinenoexcept |
Returns the number of characters in the string.
Definition at line 109 of file juce_StringRef.h.
|
inlinenoexcept |
Retrieves a character by index.
Definition at line 112 of file juce_StringRef.h.
Compares this StringRef with a String.
Definition at line 115 of file juce_StringRef.h.
Compares this StringRef with a String.
Definition at line 117 of file juce_StringRef.h.
Case-sensitive comparison of two StringRefs.
Definition at line 120 of file juce_StringRef.h.
Case-sensitive comparison of two StringRefs.
Definition at line 122 of file juce_StringRef.h.
String::CharPointerType juce::StringRef::text |
The text that is referenced.
Definition at line 126 of file juce_StringRef.h.
Referenced by juce::StringArray::addTokens(), juce::JSON::fromString(), juce::File::isAbsolutePath(), juce::BigInteger::parseString(), and juce::MidiMessage::textMetaEvent().