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

Public Member Functions

 StringRef (const char *stringLiteral) noexcept
 StringRef (CharPointer_UTF8 stringLiteral) noexcept
 StringRef (const String &string) noexcept
 StringRef () noexcept
 operator const char * () const noexcept
 operator CharPointer_UTF8 () const noexcept
bool isEmpty () const noexcept
bool isNotEmpty () const noexcept
int length () const noexcept
char operator[] (int index) const noexcept
bool operator== (const String &s) const noexcept
bool operator!= (const String &s) const noexcept
bool operator== (StringRef s) const noexcept
bool operator!= (StringRef s) const noexcept

Public Attributes

CharPointer_UTF8 text

Detailed Description

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.

void myStringFunction1 (const String&);
void myStringFunction2 (StringRef);
myStringFunction1 ("abc"); // Implicitly allocates a temporary String object.
myStringFunction2 ("abc"); // Much faster, as no local allocations are needed.
Definition juce_PNGLoader.cpp:48
StringRef(const char *stringLiteral) noexcept

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.

See also
String

Constructor & Destructor Documentation

◆ StringRef() [1/4]

juce::pnglibNamespace::water::StringRef::StringRef ( const char * stringLiteral)
noexcept

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 not be null!

◆ StringRef() [2/4]

juce::pnglibNamespace::water::StringRef::StringRef ( CharPointer_UTF8 stringLiteral)
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.

◆ StringRef() [3/4]

juce::pnglibNamespace::water::StringRef::StringRef ( const String & string)
noexcept

Creates a StringRef from a String. The StringRef object does NOT take ownership or copy the data from the String, so you must ensure that the String is not modified or deleted during the lifetime of the StringRef.

◆ StringRef() [4/4]

juce::pnglibNamespace::water::StringRef::StringRef ( )
noexcept

Creates a StringRef pointer to an empty string.

Member Function Documentation

◆ isEmpty()

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

Returns true if the string is empty.

◆ isNotEmpty()

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

Returns true if the string is not empty.

◆ length()

int juce::pnglibNamespace::water::StringRef::length ( ) const
inlinenoexcept

Returns the number of characters in the string.

◆ operator CharPointer_UTF8()

juce::pnglibNamespace::water::StringRef::operator CharPointer_UTF8 ( ) const
inlinenoexcept

Returns a pointer to the underlying string data as a char pointer object.

◆ operator const char *()

juce::pnglibNamespace::water::StringRef::operator const char * ( ) const
inlinenoexcept

Returns a raw pointer to the underlying string data.

◆ operator!=() [1/2]

bool juce::pnglibNamespace::water::StringRef::operator!= ( const String & s) const
inlinenoexcept

Compares this StringRef with a String.

◆ operator!=() [2/2]

bool juce::pnglibNamespace::water::StringRef::operator!= ( StringRef s) const
inlinenoexcept

Case-sensitive comparison of two StringRefs.

◆ operator==() [1/2]

bool juce::pnglibNamespace::water::StringRef::operator== ( const String & s) const
inlinenoexcept

Compares this StringRef with a String.

◆ operator==() [2/2]

bool juce::pnglibNamespace::water::StringRef::operator== ( StringRef s) const
inlinenoexcept

Case-sensitive comparison of two StringRefs.

◆ operator[]()

char juce::pnglibNamespace::water::StringRef::operator[] ( int index) const
inlinenoexcept

Retrieves a character by index.

Member Data Documentation

◆ text

CharPointer_UTF8 juce::pnglibNamespace::water::StringRef::text

The text that is referenced.


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