OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
juce::StringRef Class Referencefinal

`#include <juce_StringRef.h>`

## Public Member Functions
| StringRef (const char *stringLiteral) noexcept
| StringRef (String::CharPointerType stringLiteral) noexcept
| StringRef (const String &string) noexcept
| StringRef (const std::string &string)
| StringRef () noexcept
| operator const String::CharPointerType::CharType * () const noexcept
| operator String::CharPointerType () const noexcept
bool | isEmpty () const noexcept
bool | isNotEmpty () const noexcept
int | length () const noexcept
juce_wchar | operator[] (int index) const noexcept
bool | operator== (const String &s) const noexcept
bool | operator!= (const String &s) const noexcept
bool | operator< (const String &s) const noexcept
bool | operator<= (const String &s) 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
String::CharPointerType | text
String | stringCopy

## 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.
juce::StringRef
Definition: juce_StringRef.h:62
juce::String
Definition: juce_String.h:39

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

Definition at line 61 of file juce_StringRef.h.

## Constructor & Destructor Documentation

## ◆ StringRef() [1/5]

juce::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 cannot be null!

Definition at line 2154 of file juce_String.cpp.

## ◆ StringRef() [2/5]

juce::StringRef::StringRef | ( | String::CharPointerType | 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.

Definition at line 2185 of file juce_String.cpp.

## ◆ StringRef() [3/5]

juce::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.

Definition at line 2190 of file juce_String.cpp.

## ◆ StringRef() [4/5]

juce::StringRef::StringRef | ( | const std::string & | string | ) |

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

Definition at line 2191 of file juce_String.cpp.

## ◆ StringRef() [5/5]

juce::StringRef::StringRef | ( |  | ) |
| noexcept

Creates a StringRef pointer to an empty string.

Definition at line 2150 of file juce_String.cpp.

## Member Function Documentation

## ◆ isEmpty()

bool juce::StringRef::isEmpty | ( |  | ) | const
| inline noexcept

Returns true if the string is empty.

Definition at line 101 of file juce_StringRef.h.

Referenced by juce::StringPool::getPooledString(), and juce::File::hasFileExtension().

## ◆ isNotEmpty()

bool juce::StringRef::isNotEmpty | ( |  | ) | const
| inline noexcept

Returns true if the string is not empty.

Definition at line 103 of file juce_StringRef.h.

Referenced by juce::StringArray::addTokens(), juce::PropertySet::removeValue(), and juce::File::withFileExtension().

## ◆ length()

int juce::StringRef::length | ( |  | ) | const
| inline noexcept

Returns the number of characters in the string.

Definition at line 105 of file juce_StringRef.h.

Referenced by juce::String::fromFirstOccurrenceOf(), juce::String::fromLastOccurrenceOf(), juce::File::hasFileExtension(), juce::MemoryBlock::loadFromHexString(), juce::String::replace(), juce::String::replaceCharacters(), juce::String::replaceFirstOccurrenceOf(), juce::String::upToFirstOccurrenceOf(), and juce::String::upToLastOccurrenceOf().

## ◆ operator const String::CharPointerType::CharType *()

juce::StringRef::operator const String::CharPointerType::CharType * | ( |  | ) | const
| inline noexcept

Returns a raw pointer to the underlying string data.

Definition at line 96 of file juce_StringRef.h.

## ◆ operator String::CharPointerType()

juce::StringRef::operator String::CharPointerType | ( |  | ) | const
| inline noexcept

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

Definition at line 98 of file juce_StringRef.h.

## ◆ operator!=() [1/2]

bool juce::StringRef::operator!= | ( | const String & | s | ) | const
| inline noexcept

Compares this StringRef with a String.

Definition at line 113 of file juce_StringRef.h.

## ◆ operator!=() [2/2]

bool juce::StringRef::operator!= | ( | StringRef | s | ) | const
| inline noexcept

Case-sensitive comparison of two StringRefs.

Definition at line 126 of file juce_StringRef.h.

## ◆ operator<()

bool juce::StringRef::operator< | ( | const String & | s | ) | const
| inline noexcept

Compares this StringRef with a String.

Definition at line 115 of file juce_StringRef.h.

## ◆ operator<=()

bool juce::StringRef::operator<= | ( | const String & | s | ) | const
| inline noexcept

Compares this StringRef with a String.

Definition at line 117 of file juce_StringRef.h.

## ◆ operator==() [1/2]

bool juce::StringRef::operator== | ( | const String & | s | ) | const
| inline noexcept

Compares this StringRef with a String.

Definition at line 111 of file juce_StringRef.h.

## ◆ operator==() [2/2]

bool juce::StringRef::operator== | ( | StringRef | s | ) | const
| inline noexcept

Case-sensitive comparison of two StringRefs.

Definition at line 124 of file juce_StringRef.h.

## ◆ operator>()

bool juce::StringRef::operator> | ( | const String & | s | ) | const
| inline noexcept

Compares this StringRef with a String.

Definition at line 119 of file juce_StringRef.h.

## ◆ operator>=()

bool juce::StringRef::operator>= | ( | const String & | s | ) | const
| inline noexcept

Compares this StringRef with a String.

Definition at line 121 of file juce_StringRef.h.

## ◆ operator[]()

juce_wchar juce::StringRef::operator[] | ( | int | index | ) | const
| inline noexcept

Retrieves a character by index.

Definition at line 108 of file juce_StringRef.h.

## Member Data Documentation

## ◆ stringCopy

String juce::StringRef::stringCopy

Definition at line 135 of file juce_StringRef.h.

## ◆ text

String::CharPointerType juce::StringRef::text

The text that is referenced.

Definition at line 130 of file juce_StringRef.h.

Referenced by juce::StringArray::addLines(), juce::StringArray::addTokens(), juce::Base64::convertFromBase64(), juce::JSON::escapeString(), juce::MemoryBlock::fromBase64Encoding(), juce::Time::fromISO8601(), juce::JSON::fromString(), juce::File::getChildFile(), juce::StringPool::getPooledString(), juce::File::hasFileExtension(), juce::String::initialSectionContainingOnly(), juce::String::initialSectionNotContaining(), juce::File::isAbsolutePath(), juce::StringArray::joinIntoString(), juce::MemoryBlock::loadFromHexString(), juce::BigInteger::parseString(), juce::String::removeCharacters(), juce::String::repeatedString(), juce::String::replaceCharacters(), juce::String::replaceSection(), juce::String::retainCharacters(), juce::MidiMessage::textMetaEvent(), juce::String::trimCharactersAtEnd(), juce::String::trimCharactersAtStart(), and juce::File::withFileExtension().

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

- juce_StringRef.h
- juce_String.cpp