LLVM 17.0.0git
llvm::StringRef Class Reference

StringRef - Represent a constant reference to a string, i.e. More...

#include "llvm/ADT/StringRef.h"

Inheritance diagram for llvm::StringRef:
[legend]
Collaboration diagram for llvm::StringRef:
[legend]

## Public Types

using iterator = const char *

using const_iterator = const char *

using size_type = size_t

## Public Member Functions

Constructors
StringRef ()=default
Construct an empty string ref.

StringRef (std::nullptr_t)=delete
Disable conversion from nullptr.

constexpr StringRef (const char *Str)
Construct a string ref from a cstring.

constexpr StringRef (const char *data, size_t length)
Construct a string ref from a pointer and length.

StringRef (const std::string &Str)
Construct a string ref from an std::string.

constexpr StringRef (std::string_view Str)
Construct a string ref from an std::string_view.

Iterators
iterator begin () const

iterator end () const

const unsigned charbytes_begin () const

const unsigned charbytes_end () const

iterator_range< const unsigned char * > bytes () const

String Operations
const chardata () const
data - Get a pointer to the start of the string (which may not be null terminated).

constexpr bool empty () const
empty - Check if the string is empty.

constexpr size_t size () const
size - Get the string size.

char front () const
front - Get the first character in the string.

char back () const
back - Get the last character in the string.

template<typename Allocator >
StringRef copy (Allocator &A) const

bool equals (StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering of inequal strings isn't needed.

bool equals_insensitive (StringRef RHS) const
Check for string equality, ignoring case.

int compare (StringRef RHS) const
compare - Compare two strings; the result is negative, zero, or positive if this string is lexicographically less than, equal to, or greater than the RHS.

int compare_insensitive (StringRef RHS) const
Compare two strings, ignoring case.

int compare_numeric (StringRef RHS) const
compare_numeric - Compare two strings, treating sequences of digits as numbers.

unsigned edit_distance (StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
Determine the edit distance between this string and another string.

unsigned edit_distance_insensitive (StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const

std::string str () const
str - Get the contents as an std::string.

std::string lower () const

std::string upper () const
Convert the given ASCII string to uppercase.

char operator[] (size_t Index) const

template<typename T >
std::enable_if_t< std::is_same< T, std::string >::value, StringRef > & operator= (T &&Str)=delete
Disallow accidental assignment from a temporary std::string.

Type Conversions
operator std::string_view () const

String Predicates
bool starts_with (StringRef Prefix) const
Check if this string starts with the given Prefix.

bool startswith (StringRef Prefix) const

bool starts_with_insensitive (StringRef Prefix) const
Check if this string starts with the given Prefix, ignoring case.

bool startswith_insensitive (StringRef Prefix) const

bool ends_with (StringRef Suffix) const
Check if this string ends with the given Suffix.

bool endswith (StringRef Suffix) const

bool ends_with_insensitive (StringRef Suffix) const
Check if this string ends with the given Suffix, ignoring case.

bool endswith_insensitive (StringRef Suffix) const

String Searching
size_t find (char C, size_t From=0) const
Search for the first character C in the string.

size_t find_insensitive (char C, size_t From=0) const
Search for the first character C in the string, ignoring case.

size_t find_if (function_ref< bool(char)> F, size_t From=0) const
Search for the first character satisfying the predicate F.

size_t find_if_not (function_ref< bool(char)> F, size_t From=0) const
Search for the first character not satisfying the predicate F.

size_t find (StringRef Str, size_t From=0) const
Search for the first string Str in the string.

size_t find_insensitive (StringRef Str, size_t From=0) const
Search for the first string Str in the string, ignoring case.

size_t rfind (char C, size_t From=npos) const
Search for the last character C in the string.

size_t rfind_insensitive (char C, size_t From=npos) const
Search for the last character C in the string, ignoring case.

size_t rfind (StringRef Str) const
Search for the last string Str in the string.

size_t rfind_insensitive (StringRef Str) const
Search for the last string Str in the string, ignoring case.

size_t find_first_of (char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.

size_t find_first_of (StringRef Chars, size_t From=0) const
Find the first character in the string that is in Chars, or npos if not found.

size_t find_first_not_of (char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.

size_t find_first_not_of (StringRef Chars, size_t From=0) const
Find the first character in the string that is not in the string Chars, or npos if not found.

size_t find_last_of (char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.

size_t find_last_of (StringRef Chars, size_t From=npos) const
Find the last character in the string that is in C, or npos if not found.

size_t find_last_not_of (char C, size_t From=npos) const
Find the last character in the string that is not C, or npos if not found.

size_t find_last_not_of (StringRef Chars, size_t From=npos) const
Find the last character in the string that is not in Chars, or npos if not found.

bool contains (StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.

bool contains (char C) const
Return true if the given character is contained in *this, and false otherwise.

bool contains_insensitive (StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.

bool contains_insensitive (char C) const
Return true if the given character is contained in *this, and false otherwise.

size_t count (char C) const
Return the number of occurrences of C in the string.

size_t count (StringRef Str) const
Return the number of non-overlapped occurrences of Str in the string.

template<typename T >
bool getAsInteger (unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.

template<typename T >
bool consumeInteger (unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.

bool getAsInteger (unsigned Radix, APInt &Result) const
Parse the current string as an integer of the specified Radix, or of an autosensed radix if the Radix given is 0.

bool getAsDouble (double &Result, bool AllowInexact=true) const
Parse the current string as an IEEE double-precision floating point value.

Substring Operations
constexpr StringRef substr (size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).

StringRef take_front (size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.

StringRef take_back (size_t N=1) const
Return a StringRef equal to 'this' but with only the last N elements remaining.

StringRef take_while (function_ref< bool(char)> F) const
Return the longest prefix of 'this' such that every character in the prefix satisfies the given predicate.

StringRef take_until (function_ref< bool(char)> F) const
Return the longest prefix of 'this' such that no character in the prefix satisfies the given predicate.

StringRef drop_front (size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.

StringRef drop_back (size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.

StringRef drop_while (function_ref< bool(char)> F) const
Return a StringRef equal to 'this', but with all characters satisfying the given predicate dropped from the beginning of the string.

StringRef drop_until (function_ref< bool(char)> F) const
Return a StringRef equal to 'this', but with all characters not satisfying the given predicate dropped from the beginning of the string.

bool consume_front (StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.

bool consume_front_insensitive (StringRef Prefix)
Returns true if this StringRef has the given prefix, ignoring case, and removes that prefix.

bool consume_back (StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.

bool consume_back_insensitive (StringRef Suffix)
Returns true if this StringRef has the given suffix, ignoring case, and removes that suffix.

StringRef slice (size_t Start, size_t End) const
Return a reference to the substring from [Start, End).

std::pair< StringRef, StringRefsplit (char Separator) const
Split into two substrings around the first occurrence of a separator character.

std::pair< StringRef, StringRefsplit (StringRef Separator) const
Split into two substrings around the first occurrence of a separator string.

std::pair< StringRef, StringRefrsplit (StringRef Separator) const
Split into two substrings around the last occurrence of a separator string.

void split (SmallVectorImpl< StringRef > &A, StringRef Separator, int MaxSplit=-1, bool KeepEmpty=true) const
Split into substrings around the occurrences of a separator string.

void split (SmallVectorImpl< StringRef > &A, char Separator, int MaxSplit=-1, bool KeepEmpty=true) const
Split into substrings around the occurrences of a separator character.

std::pair< StringRef, StringRefrsplit (char Separator) const
Split into two substrings around the last occurrence of a separator character.

StringRef ltrim (char Char) const
Return string with consecutive Char characters starting from the the left removed.

StringRef ltrim (StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left removed.

StringRef rtrim (char Char) const
Return string with consecutive Char characters starting from the right removed.

StringRef rtrim (StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the right removed.

StringRef trim (char Char) const
Return string with consecutive Char characters starting from the left and right removed.

StringRef trim (StringRef Chars=" \t\n\v\f\r") const
Return string with consecutive characters in Chars starting from the left and right removed.

StringRef detectEOL () const
Detect the line ending style of the string.

## Static Public Attributes

static constexpr size_t npos = ~size_t(0)

## Detailed Description

StringRef - Represent a constant reference to a string, i.e.

a character array and a length, which need not be null terminated.

This class does not own the string data, it is expected to be used in situations where the character data resides in some other buffer, whose lifetime extends past that of the StringRef. For this reason, it is not in general safe to store a StringRef.

Definition at line 50 of file StringRef.h.

## ◆ const_iterator

 using llvm::StringRef::const_iterator = const char *

Definition at line 55 of file StringRef.h.

## ◆ iterator

 using llvm::StringRef::iterator = const char *

Definition at line 54 of file StringRef.h.

## ◆ size_type

 using llvm::StringRef::size_type = size_t

Definition at line 56 of file StringRef.h.

## ◆ StringRef() [1/6]

 llvm::StringRef::StringRef ( )
default

Construct an empty string ref.

## ◆ StringRef() [2/6]

 llvm::StringRef::StringRef ( std::nullptr_t )
delete

Disable conversion from nullptr.

This prevents things like if (S == nullptr)

## ◆ StringRef() [3/6]

 constexpr llvm::StringRef::StringRef ( const char * Str )
inlineconstexpr

Construct a string ref from a cstring.

Definition at line 84 of file StringRef.h.

References llvm::Length.

## ◆ StringRef() [4/6]

 constexpr llvm::StringRef::StringRef ( const char * data, size_t length )
inlineconstexpr

Construct a string ref from a pointer and length.

Definition at line 96 of file StringRef.h.

References llvm::Length.

## ◆ StringRef() [5/6]

 llvm::StringRef::StringRef ( const std::string & Str )
inline

Construct a string ref from an std::string.

Definition at line 100 of file StringRef.h.

References llvm::Length.

## ◆ StringRef() [6/6]

 constexpr llvm::StringRef::StringRef ( std::string_view Str )
inlineconstexpr

Construct a string ref from an std::string_view.

Definition at line 104 of file StringRef.h.

References llvm::Length, and llvm::size().

## ◆ back()

 char llvm::StringRef::back ( ) const
inline

back - Get the last character in the string.

Definition at line 146 of file StringRef.h.

References assert(), Data, and llvm::Length.

## ◆ bytes()

 iterator_range< const unsigned char * > llvm::StringRef::bytes ( ) const
inline

Definition at line 121 of file StringRef.h.

References llvm::make_range().

Referenced by llvm::djbHash().

## ◆ bytes_begin()

 const unsigned char * llvm::StringRef::bytes_begin ( ) const
inline

## ◆ bytes_end()

 const unsigned char * llvm::StringRef::bytes_end ( ) const
inline

Definition at line 118 of file StringRef.h.

## ◆ compare()

 int llvm::StringRef::compare ( StringRef RHS ) const
inline

compare - Compare two strings; the result is negative, zero, or positive if this string is lexicographically less than, equal to, or greater than the RHS.

Definition at line 177 of file StringRef.h.

References Data, llvm::Length, and RHS.

## ◆ compare_insensitive()

 int StringRef::compare_insensitive ( StringRef RHS ) const

Compare two strings, ignoring case.

Definition at line 37 of file StringRef.cpp.

References ascii_strncasecmp(), and RHS.

## ◆ compare_numeric()

 int StringRef::compare_numeric ( StringRef RHS ) const

compare_numeric - Compare two strings, treating sequences of digits as numbers.

compare_numeric - Compare strings, handle embedded numbers.

Definition at line 61 of file StringRef.cpp.

References E, I, isDigit(), and RHS.

## ◆ consume_back()

 bool llvm::StringRef::consume_back ( StringRef Suffix )
inline

Returns true if this StringRef has the given suffix and removes that suffix.

Definition at line 642 of file StringRef.h.

References size(), llvm::size(), and substr().

Referenced by llvm::VFABI::tryDemangleForVFABI().

## ◆ consume_back_insensitive()

 bool llvm::StringRef::consume_back_insensitive ( StringRef Suffix )
inline

Returns true if this StringRef has the given suffix, ignoring case, and removes that suffix.

Definition at line 652 of file StringRef.h.

References size(), llvm::size(), and substr().

## ◆ consume_front()

 bool llvm::StringRef::consume_front ( StringRef Prefix )
inline

Returns true if this StringRef has the given prefix and removes that prefix.

Definition at line 622 of file StringRef.h.

References substr().

## ◆ consume_front_insensitive()

 bool llvm::StringRef::consume_front_insensitive ( StringRef Prefix )
inline

Returns true if this StringRef has the given prefix, ignoring case, and removes that prefix.

Definition at line 632 of file StringRef.h.

References substr().

## ◆ consumeInteger()

template<typename T >
 bool llvm::StringRef::consumeInteger ( unsigned Radix, T & Result )
inline

Parse the current string as an integer of the specified radix.

If Radix is specified as zero, this does radix autosensing using extended C rules: 0 is octal, 0x is hex, 0b is binary.

If the string does not begin with a number of the specified radix, this returns true to signify the error. The string is considered erroneous if empty or if it overflows T. The portion of the string representing the discovered numeric value is removed from the beginning of the string.

Definition at line 497 of file StringRef.h.

References llvm::consumeSignedInteger(), and llvm::consumeUnsignedInteger().

## ◆ contains() [1/2]

 bool llvm::StringRef::contains ( char C ) const
inline

Return true if the given character is contained in *this, and false otherwise.

Definition at line 428 of file StringRef.h.

References C.

## ◆ contains() [2/2]

 bool llvm::StringRef::contains ( StringRef Other ) const
inline

Return true if the given string is a substring of *this, and false otherwise.

Definition at line 422 of file StringRef.h.

References llvm::find(), and Other.

## ◆ contains_insensitive() [1/2]

 bool llvm::StringRef::contains_insensitive ( char C ) const
inline

Return true if the given character is contained in *this, and false otherwise.

Definition at line 440 of file StringRef.h.

References C.

## ◆ contains_insensitive() [2/2]

 bool llvm::StringRef::contains_insensitive ( StringRef Other ) const
inline

Return true if the given string is a substring of *this, and false otherwise.

Definition at line 434 of file StringRef.h.

References Other.

## ◆ copy()

template<typename Allocator >
 StringRef llvm::StringRef::copy ( Allocator & A ) const
inline

Definition at line 153 of file StringRef.h.

References A, and llvm::Length.

Referenced by llvm::yaml::Document::parseBlockNode().

## ◆ count() [1/2]

 size_t llvm::StringRef::count ( char C ) const
inline

Return the number of occurrences of C in the string.

Definition at line 449 of file StringRef.h.

References C, Data, I, and llvm::Length.

## ◆ count() [2/2]

 size_t StringRef::count ( StringRef Str ) const

Return the number of non-overlapped occurrences of Str in the string.

count - Return the number of non-overlapped occurrences of

• Str in the string.

Definition at line 371 of file StringRef.cpp.

References find(), N, and npos.

## ◆ detectEOL()

 StringRef llvm::StringRef::detectEOL ( ) const
inline

Detect the line ending style of the string.

If the string contains a line ending, return the line ending character sequence that is detected. Otherwise return '
' for unix line endings.

Returns
- The line ending character sequence.

Definition at line 818 of file StringRef.h.

References Data, llvm::find(), and llvm::Length.

## ◆ drop_back()

 StringRef llvm::StringRef::drop_back ( size_t N = 1 ) const
inline

Return a StringRef equal to 'this' but with the last N elements dropped.

Definition at line 603 of file StringRef.h.

References assert(), N, llvm::size(), and substr().

## ◆ drop_front()

 StringRef llvm::StringRef::drop_front ( size_t N = 1 ) const
inline

## ◆ drop_until()

 StringRef llvm::StringRef::drop_until ( function_ref< bool(char)> F ) const
inline

Return a StringRef equal to 'this', but with all characters not satisfying the given predicate dropped from the beginning of the string.

Definition at line 616 of file StringRef.h.

References F, llvm::find_if(), and substr().

## ◆ drop_while()

 StringRef llvm::StringRef::drop_while ( function_ref< bool(char)> F ) const
inline

Return a StringRef equal to 'this', but with all characters satisfying the given predicate dropped from the beginning of the string.

Definition at line 610 of file StringRef.h.

References F, llvm::find_if_not(), and substr().

## ◆ edit_distance()

 unsigned StringRef::edit_distance ( llvm::StringRef Other, bool AllowReplacements = true, unsigned MaxEditDistance = 0 ) const

Determine the edit distance between this string and another string.

Parameters
 Other the string to compare this string against. AllowReplacements whether to allow character replacements (change one character into another) as a single operation, rather than as two operations (an insertion and a removal). MaxEditDistance If non-zero, the maximum edit distance that this routine is allowed to compute. If the edit distance will exceed that maximum, returns MaxEditDistance+1.
Returns
the minimum number of character insertions, removals, or (if AllowReplacements is true) replacements needed to transform one of the given strings into the other. If zero, the strings are identical.

Definition at line 92 of file StringRef.cpp.

References llvm::ComputeEditDistance(), data(), llvm::Other, and size().

Referenced by llvm::opt::OptTable::findNearest(), and LookupNearestOption().

## ◆ edit_distance_insensitive()

 unsigned llvm::StringRef::edit_distance_insensitive ( StringRef Other, bool AllowReplacements = true, unsigned MaxEditDistance = 0 ) const

Definition at line 100 of file StringRef.cpp.

References llvm::ComputeMappedEditDistance(), data(), llvm::Other, and size().

## ◆ ends_with()

 bool llvm::StringRef::ends_with ( StringRef Suffix ) const
inline

Check if this string ends with the given Suffix.

Definition at line 272 of file StringRef.h.

References llvm::Length.

## ◆ ends_with_insensitive()

 bool StringRef::ends_with_insensitive ( StringRef Suffix ) const

Check if this string ends with the given Suffix, ignoring case.

Definition at line 50 of file StringRef.cpp.

References ascii_strncasecmp(), and end().

## ◆ endswith()

 bool llvm::StringRef::endswith ( StringRef Suffix ) const
inline

## ◆ endswith_insensitive()

 bool llvm::StringRef::endswith_insensitive ( StringRef Suffix ) const
inline

Definition at line 283 of file StringRef.h.

## ◆ equals()

 bool llvm::StringRef::equals ( StringRef RHS ) const
inline

equals - Check for string equality, this is more efficient than compare() when the relative ordering of inequal strings isn't needed.

Definition at line 164 of file StringRef.h.

References Data, llvm::Length, and RHS.

## ◆ equals_insensitive()

 bool llvm::StringRef::equals_insensitive ( StringRef RHS ) const
inline

Check for string equality, ignoring case.

Definition at line 170 of file StringRef.h.

References llvm::Length, and RHS.

## ◆ find() [1/2]

 size_t llvm::StringRef::find ( char C, size_t From = 0 ) const
inline

Search for the first character C in the string.

Returns
The index of the first occurrence of C, or npos if not found.

Definition at line 295 of file StringRef.h.

References C, and From.

## ◆ find() [2/2]

 size_t StringRef::find ( StringRef Str, size_t From = 0 ) const

Search for the first string Str in the string.

find - Search for the first string

Returns
The index of the first occurrence of Str, or npos if not found.
• Str in the string.
Returns
- The index of the first occurrence of

Definition at line 130 of file StringRef.cpp.

References From, llvm::Last, LLVM_UNLIKELY, N, npos, Ptr, and Size.

## ◆ find_first_not_of() [1/2]

 StringRef::size_type StringRef::find_first_not_of ( char C, size_t From = 0 ) const

Find the first character in the string that is not C or npos if not found.

find_first_not_of - Find the first character in the string that is not

Definition at line 251 of file StringRef.cpp.

References llvm::CallingConv::C, and From.

## ◆ find_first_not_of() [2/2]

 StringRef::size_type StringRef::find_first_not_of ( StringRef Chars, size_t From = 0 ) const

Find the first character in the string that is not in the string Chars, or npos if not found.

find_first_not_of - Find the first character in the string that is not in the string

Complexity: O(size() + Chars.size())

Note: O(size() + Chars.size())

Definition at line 259 of file StringRef.cpp.

References llvm::CallingConv::C, From, and npos.

## ◆ find_first_of() [1/2]

 size_t llvm::StringRef::find_first_of ( char C, size_t From = 0 ) const
inline

Find the first character in the string that is C, or npos if not found.

Same as find.

Definition at line 375 of file StringRef.h.

References C, llvm::find(), and From.

## ◆ find_first_of() [2/2]

 StringRef::size_type StringRef::find_first_of ( StringRef Chars, size_t From = 0 ) const

Find the first character in the string that is in Chars, or npos if not found.

find_first_of - Find the first character in the string that is in

Complexity: O(size() + Chars.size())

Note: O(size() + Chars.size())

Definition at line 237 of file StringRef.cpp.

References llvm::CallingConv::C, From, and npos.

## ◆ find_if()

 size_t llvm::StringRef::find_if ( function_ref< bool(char)> F, size_t From = 0 ) const
inline

Search for the first character satisfying the predicate F.

Returns
The index of the first character satisfying F starting from From, or npos if not found.

Definition at line 309 of file StringRef.h.

References drop_front(), empty(), F, From, front(), size(), and llvm::size().

Referenced by find_insensitive().

## ◆ find_if_not()

 size_t llvm::StringRef::find_if_not ( function_ref< bool(char)> F, size_t From = 0 ) const
inline

Search for the first character not satisfying the predicate F.

Returns
The index of the first character not satisfying F starting from From, or npos if not found.

Definition at line 324 of file StringRef.h.

References F, llvm::find_if(), and From.

## ◆ find_insensitive() [1/2]

 size_t StringRef::find_insensitive ( char C, size_t From = 0 ) const

Search for the first character C in the string, ignoring case.

Returns
The index of the first occurrence of C, or npos if not found.

Definition at line 55 of file StringRef.cpp.

References llvm::CallingConv::C, D, find_if(), and From.

Referenced by llvm::Pattern::match().

## ◆ find_insensitive() [2/2]

 size_t StringRef::find_insensitive ( StringRef Str, size_t From = 0 ) const

Search for the first string Str in the string, ignoring case.

Returns
The index of the first occurrence of Str, or npos if not found.

Definition at line 191 of file StringRef.cpp.

References From, npos, and substr().

## ◆ find_last_not_of() [1/2]

 StringRef::size_type StringRef::find_last_not_of ( char C, size_t From = npos ) const

Find the last character in the string that is not C, or npos if not found.

find_last_not_of - Find the last character in the string that is not

Definition at line 289 of file StringRef.cpp.

References llvm::CallingConv::C, From, and npos.

## ◆ find_last_not_of() [2/2]

 StringRef::size_type StringRef::find_last_not_of ( StringRef Chars, size_t From = npos ) const

Find the last character in the string that is not in Chars, or npos if not found.

find_last_not_of - Find the last character in the string that is not in

Complexity: O(size() + Chars.size())

Note: O(size() + Chars.size())

Definition at line 300 of file StringRef.cpp.

References llvm::CallingConv::C, From, and npos.

## ◆ find_last_of() [1/2]

 size_t llvm::StringRef::find_last_of ( char C, size_t From = npos ) const
inline

Find the last character in the string that is C, or npos if not found.

Definition at line 398 of file StringRef.h.

References C, and From.

## ◆ find_last_of() [2/2]

 StringRef::size_type StringRef::find_last_of ( StringRef Chars, size_t From = npos ) const

Find the last character in the string that is in C, or npos if not found.

find_last_of - Find the last character in the string that is in

Complexity: O(size() + Chars.size())

Note: O(size() + Chars.size())

Definition at line 275 of file StringRef.cpp.

References llvm::CallingConv::C, From, and npos.

## ◆ front()

 char llvm::StringRef::front ( ) const
inline

front - Get the first character in the string.

Definition at line 140 of file StringRef.h.

References assert(), and Data.

## ◆ getAsDouble()

 bool StringRef::getAsDouble ( double & Result, bool AllowInexact = true ) const

Parse the current string as an IEEE double-precision floating point value.

The string must be a well-formed double.

If AllowInexact is false, the function will fail if the string cannot be represented exactly. Otherwise, the function only fails in case of an overflow or underflow, or an invalid floating point representation.

Definition at line 587 of file StringRef.cpp.

## ◆ getAsInteger() [1/2]

 bool StringRef::getAsInteger ( unsigned Radix, APInt & Result ) const

Parse the current string as an integer of the specified Radix, or of an autosensed radix if the Radix given is 0.

The current value in Result is discarded, and the storage is changed to be wide enough to store the parsed integer.

Returns
true if the string does not solely consist of a valid non-empty number in the appropriate base.

APInt::fromString is superficially similar but assumes the string is well-formed in the given radix.

Definition at line 512 of file StringRef.cpp.

## ◆ getAsInteger() [2/2]

template<typename T >
 bool llvm::StringRef::getAsInteger ( unsigned Radix, T & Result ) const
inline

Parse the current string as an integer of the specified radix.

If Radix is specified as zero, this does radix autosensing using extended C rules: 0 is octal, 0x is hex, 0b is binary.

If the string is invalid or if only a subset of the string is valid, this returns true to signify the error. The string is considered erroneous if empty or if it overflows T.

Definition at line 468 of file StringRef.h.

References llvm::getAsSignedInteger(), and llvm::getAsUnsignedInteger().

## ◆ ltrim() [1/2]

 StringRef llvm::StringRef::ltrim ( char Char ) const
inline

Return string with consecutive Char characters starting from the the left removed.

Definition at line 778 of file StringRef.h.

References llvm::Length.

## ◆ ltrim() [2/2]

 StringRef llvm::StringRef::ltrim ( StringRef Chars = " \t\n\v\f\r" ) const
inline

Return string with consecutive characters in Chars starting from the left removed.

Definition at line 784 of file StringRef.h.

References llvm::Length.

## ◆ operator std::string_view()

 llvm::StringRef::operator std::string_view ( ) const
inline

Definition at line 248 of file StringRef.h.

References llvm::size().

## ◆ operator=()

template<typename T >
 std::enable_if_t< std::is_same< T, std::string >::value, StringRef > & llvm::StringRef::operator= ( T && Str )
delete

Disallow accidental assignment from a temporary std::string.

The declaration here is extra complicated so that stringRef = {} and stringRef = "abc" continue to select the move assignment operator.

## ◆ operator[]()

 char llvm::StringRef::operator[] ( size_t Index ) const
inline

Definition at line 231 of file StringRef.h.

References assert(), Data, Index, and llvm::Length.

## ◆ rfind() [1/2]

 size_t llvm::StringRef::rfind ( char C, size_t From = npos ) const
inline

Search for the last character C in the string.

Returns
The index of the last occurrence of C, or npos if not found.

Definition at line 345 of file StringRef.h.

References C, Data, From, I, and llvm::Length.

## ◆ rfind() [2/2]

 size_t StringRef::rfind ( StringRef Str ) const

Search for the last string Str in the string.

rfind - Search for the last string

Returns
The index of the last occurrence of Str, or npos if not found.
• Str in the string.
Returns
- The index of the last occurrence of

Definition at line 217 of file StringRef.cpp.

## ◆ rfind_insensitive() [1/2]

 size_t StringRef::rfind_insensitive ( char C, size_t From = npos ) const

Search for the last character C in the string, ignoring case.

Returns
The index of the last occurrence of C, or npos if not found.

Definition at line 202 of file StringRef.cpp.

References llvm::CallingConv::C, From, and npos.

## ◆ rfind_insensitive() [2/2]

 size_t StringRef::rfind_insensitive ( StringRef Str ) const

Search for the last string Str in the string, ignoring case.

Returns
The index of the last occurrence of Str, or npos if not found.

Definition at line 221 of file StringRef.cpp.

References equals_insensitive(), N, npos, and substr().

## ◆ rsplit() [1/2]

 std::pair< StringRef, StringRef > llvm::StringRef::rsplit ( char Separator ) const
inline

Split into two substrings around the last occurrence of a separator character.

If Separator is in the string, then the result is a pair (LHS, RHS) such that (*this == LHS + Separator + RHS) is true and RHS is minimal. If Separator is not in the string, then the result is a pair (LHS, RHS) where (*this == LHS) and (RHS == "").

Parameters
 Separator - The character to split on.
Returns
- The split substrings.

Definition at line 772 of file StringRef.h.

## ◆ rsplit() [2/2]

 std::pair< StringRef, StringRef > llvm::StringRef::rsplit ( StringRef Separator ) const
inline

Split into two substrings around the last occurrence of a separator string.

If Separator is in the string, then the result is a pair (LHS, RHS) such that (*this == LHS + Separator + RHS) is true and RHS is minimal. If Separator is not in the string, then the result is a pair (LHS, RHS) where (*this == LHS) and (RHS == "").

Parameters
 Separator - The string to split on.
Returns
- The split substrings.

Definition at line 720 of file StringRef.h.

References Idx, and size().

## ◆ rtrim() [1/2]

 StringRef llvm::StringRef::rtrim ( char Char ) const
inline

Return string with consecutive Char characters starting from the right removed.

Definition at line 790 of file StringRef.h.

References llvm::Length.

## ◆ rtrim() [2/2]

 StringRef llvm::StringRef::rtrim ( StringRef Chars = " \t\n\v\f\r" ) const
inline

Return string with consecutive characters in Chars starting from the right removed.

Definition at line 796 of file StringRef.h.

References llvm::Length.

## ◆ slice()

 StringRef llvm::StringRef::slice ( size_t Start, size_t End ) const
inline

Return a reference to the substring from [Start, End).

Parameters
 Start The index of the starting character in the substring; if the index is npos or greater than the length of the string then the empty substring will be returned. End The index following the last character to include in the substring. If this is npos or exceeds the number of characters remaining in the string, the string suffix (starting with Start) will be returned. If this is less than Start, an empty string will be returned.

Definition at line 671 of file StringRef.h.

References Data, and llvm::Length.

## ◆ split() [1/4]

 std::pair< StringRef, StringRef > llvm::StringRef::split ( char Separator ) const
inline

Split into two substrings around the first occurrence of a separator character.

If Separator is in the string, then the result is a pair (LHS, RHS) such that (*this == LHS + Separator + RHS) is true and RHS is maximal. If Separator is not in the string, then the result is a pair (LHS, RHS) where (*this == LHS) and (RHS == "").

Parameters
 Separator The character to split on.
Returns
The split substrings.

Definition at line 687 of file StringRef.h.

References split().

## ◆ split() [2/4]

 void StringRef::split ( SmallVectorImpl< StringRef > & A, char Separator, int MaxSplit = -1, bool KeepEmpty = true ) const

Split into substrings around the occurrences of a separator character.

Each substring is stored in A. If MaxSplit is >= 0, at most MaxSplit splits are done and consequently <= MaxSplit + 1 elements are added to A. If KeepEmpty is false, empty strings are not added to A. They still count when considering MaxSplit An useful invariant is that Separator.join(A) == *this if MaxSplit == -1 and KeepEmpty == true

Parameters
 A - Where to put the substrings. Separator - The string to split on. MaxSplit - The maximum number of times the string is split. KeepEmpty - True if empty substring should be added.

Definition at line 339 of file StringRef.cpp.

References A, empty(), find(), Idx, npos, and slice().

## ◆ split() [3/4]

 void StringRef::split ( SmallVectorImpl< StringRef > & A, StringRef Separator, int MaxSplit = -1, bool KeepEmpty = true ) const

Split into substrings around the occurrences of a separator string.

Each substring is stored in A. If MaxSplit is >= 0, at most MaxSplit splits are done and consequently <= MaxSplit + 1 elements are added to A. If KeepEmpty is false, empty strings are not added to A. They still count when considering MaxSplit An useful invariant is that Separator.join(A) == *this if MaxSplit == -1 and KeepEmpty == true

Parameters
 A - Where to put the substrings. Separator - The string to split on. MaxSplit - The maximum number of times the string is split. KeepEmpty - True if empty substring should be added.

Definition at line 312 of file StringRef.cpp.

References A, empty(), find(), Idx, npos, size(), and slice().

## ◆ split() [4/4]

 std::pair< StringRef, StringRef > llvm::StringRef::split ( StringRef Separator ) const
inline

Split into two substrings around the first occurrence of a separator string.

If Separator is in the string, then the result is a pair (LHS, RHS) such that (*this == LHS + Separator + RHS) is true and RHS is maximal. If Separator is not in the string, then the result is a pair (LHS, RHS) where (*this == LHS) and (RHS == "").

Parameters
 Separator - The string to split on.
Returns
- The split substrings.

Definition at line 702 of file StringRef.h.

References llvm::find(), Idx, and size().

## ◆ starts_with()

 bool llvm::StringRef::starts_with ( StringRef Prefix ) const
inline

Check if this string starts with the given Prefix.

Definition at line 257 of file StringRef.h.

References Data, and llvm::Length.

Referenced by llvm::MVT::getVT(), and llvm::RISCV::CPUInfo::is64Bit().

## ◆ starts_with_insensitive()

 bool StringRef::starts_with_insensitive ( StringRef Prefix ) const

Check if this string starts with the given Prefix, ignoring case.

Definition at line 45 of file StringRef.cpp.

References ascii_strncasecmp().

## ◆ startswith_insensitive()

 bool llvm::StringRef::startswith_insensitive ( StringRef Prefix ) const
inline

Definition at line 267 of file StringRef.h.

Referenced by matchOption().

## ◆ substr()

 constexpr StringRef llvm::StringRef::substr ( size_t Start, size_t N = npos ) const
inlineconstexpr

## ◆ take_back()

 StringRef llvm::StringRef::take_back ( size_t N = 1 ) const
inline

Return a StringRef equal to 'this' but with only the last N elements remaining.

If N is greater than the length of the string, the entire string is returned.

Definition at line 576 of file StringRef.h.

References N, and llvm::size().

## ◆ take_front()

 StringRef llvm::StringRef::take_front ( size_t N = 1 ) const
inline

Return a StringRef equal to 'this' but with only the first N elements remaining.

If N is greater than the length of the string, the entire string is returned.

Definition at line 567 of file StringRef.h.

References N, and llvm::size().

## ◆ take_until()

 StringRef llvm::StringRef::take_until ( function_ref< bool(char)> F ) const
inline

Return the longest prefix of 'this' such that no character in the prefix satisfies the given predicate.

Definition at line 590 of file StringRef.h.

References F, llvm::find_if(), and substr().

## ◆ take_while()

 StringRef llvm::StringRef::take_while ( function_ref< bool(char)> F ) const
inline

Return the longest prefix of 'this' such that every character in the prefix satisfies the given predicate.

Definition at line 584 of file StringRef.h.

References F, llvm::find_if_not(), and substr().

## ◆ trim() [1/2]

 StringRef llvm::StringRef::trim ( char Char ) const
inline

Return string with consecutive Char characters starting from the left and right removed.

Definition at line 802 of file StringRef.h.

References rtrim().

## ◆ trim() [2/2]

 StringRef llvm::StringRef::trim ( StringRef Chars = " \t\n\v\f\r" ) const
inline

Return string with consecutive characters in Chars starting from the left and right removed.

Definition at line 808 of file StringRef.h.

References rtrim().

## ◆ upper()

 std::string StringRef::upper ( ) const

Convert the given ASCII string to uppercase.

Definition at line 116 of file StringRef.cpp.

References begin(), end(), and llvm::map_iterator().

## ◆ npos

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