LLVM 20.0.0git
Public Member Functions | Static Public Member Functions | List of all members
llvm::StringLiteral Class Reference

A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs with the length computed at compile time. More...

#include "llvm/ADT/StringRef.h"

Inheritance diagram for llvm::StringLiteral:
Inheritance graph
[legend]

Public Member Functions

template<size_t N>
constexpr StringLiteral (const char(&Str)[N])
 
- Public Member Functions inherited from llvm::StringRef
 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.
 
iterator begin () const
 
iterator end () const
 
const unsigned charbytes_begin () const
 
const unsigned charbytes_end () const
 
iterator_range< const unsigned char * > bytes () const
 
constexpr 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_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.
 
constexpr operator std::string_view () const
 
bool starts_with (StringRef Prefix) const
 Check if this string starts with the given Prefix.
 
bool starts_with (char Prefix) const
 
bool starts_with_insensitive (StringRef Prefix) const
 Check if this string starts with the given Prefix, ignoring case.
 
bool ends_with (StringRef Suffix) const
 Check if this string ends with the given Suffix.
 
bool ends_with (char Suffix) const
 
bool ends_with_insensitive (StringRef Suffix) const
 Check if this string ends with the given Suffix, ignoring case.
 
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 consumeInteger (unsigned Radix, APInt &Result)
 Parse the current string as an integer of the specified Radix.
 
bool getAsDouble (double &Result, bool AllowInexact=true) const
 Parse the current string as an IEEE double-precision floating point value.
 
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 Member Functions

template<size_t N>
static constexpr StringLiteral withInnerNUL (const char(&Str)[N])
 

Additional Inherited Members

- Public Types inherited from llvm::StringRef
using iterator = const char *
 
using const_iterator = const char *
 
using size_type = size_t
 
- Static Public Attributes inherited from llvm::StringRef
static constexpr size_t npos = ~size_t(0)
 

Detailed Description

A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs with the length computed at compile time.

In order to avoid the invocation of a global constructor, StringLiteral should only be used in a constexpr context, as such:

constexpr StringLiteral S("test");

Definition at line 838 of file StringRef.h.

Constructor & Destructor Documentation

◆ StringLiteral()

template<size_t N>
constexpr llvm::StringLiteral::StringLiteral ( const char(&)  Str[N])
inlineconstexpr

Definition at line 845 of file StringRef.h.

Member Function Documentation

◆ withInnerNUL()

template<size_t N>
static constexpr StringLiteral llvm::StringLiteral::withInnerNUL ( const char(&)  Str[N])
inlinestaticconstexpr

Definition at line 858 of file StringRef.h.

References N.


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