LLVM  16.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]
Collaboration diagram for llvm::StringLiteral:
Collaboration 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. More...
 
 StringRef (std::nullptr_t)=delete
 Disable conversion from nullptr. More...
 
constexpr StringRef (const char *Str)
 Construct a string ref from a cstring. More...
 
constexpr StringRef (const char *data, size_t length)
 Construct a string ref from a pointer and length. More...
 
 StringRef (const std::string &Str)
 Construct a string ref from an std::string. More...
 
constexpr StringRef (std::string_view Str)
 Construct a string ref from an std::string_view. More...
 
iterator begin () const
 
iterator end () const
 
const unsigned char * bytes_begin () const
 
const unsigned char * bytes_end () const
 
iterator_range< const unsigned char * > bytes () const
 
const char * data () const
 data - Get a pointer to the start of the string (which may not be null terminated). More...
 
constexpr bool empty () const
 empty - Check if the string is empty. More...
 
constexpr size_t size () const
 size - Get the string size. More...
 
char front () const
 front - Get the first character in the string. More...
 
char back () const
 back - Get the last character in the string. More...
 
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. More...
 
bool equals_insensitive (StringRef RHS) const
 Check for string equality, ignoring case. More...
 
int compare (StringRef RHS) const
 compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less than, equal to, or greater than the RHS. More...
 
int compare_insensitive (StringRef RHS) const
 Compare two strings, ignoring case. More...
 
int compare_numeric (StringRef RHS) const
 compare_numeric - Compare two strings, treating sequences of digits as numbers. More...
 
unsigned edit_distance (StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
 Determine the edit distance between this string and another string. More...
 
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. More...
 
std::string lower () const
 
std::string upper () const
 Convert the given ASCII string to uppercase. More...
 
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. More...
 
 operator std::string_view () const
 
bool starts_with (StringRef Prefix) const
 Check if this string starts with the given Prefix. More...
 
bool startswith (StringRef Prefix) const
 
bool starts_with_insensitive (StringRef Prefix) const
 Check if this string starts with the given Prefix, ignoring case. More...
 
bool startswith_insensitive (StringRef Prefix) const
 
bool ends_with (StringRef Suffix) const
 Check if this string ends with the given Suffix. More...
 
bool endswith (StringRef Suffix) const
 
bool ends_with_insensitive (StringRef Suffix) const
 Check if this string ends with the given Suffix, ignoring case. More...
 
bool endswith_insensitive (StringRef Suffix) const
 
size_t find (char C, size_t From=0) const
 Search for the first character C in the string. More...
 
size_t find_insensitive (char C, size_t From=0) const
 Search for the first character C in the string, ignoring case. More...
 
size_t find_if (function_ref< bool(char)> F, size_t From=0) const
 Search for the first character satisfying the predicate F. More...
 
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. More...
 
size_t find (StringRef Str, size_t From=0) const
 Search for the first string Str in the string. More...
 
size_t find_insensitive (StringRef Str, size_t From=0) const
 Search for the first string Str in the string, ignoring case. More...
 
size_t rfind (char C, size_t From=npos) const
 Search for the last character C in the string. More...
 
size_t rfind_insensitive (char C, size_t From=npos) const
 Search for the last character C in the string, ignoring case. More...
 
size_t rfind (StringRef Str) const
 Search for the last string Str in the string. More...
 
size_t rfind_insensitive (StringRef Str) const
 Search for the last string Str in the string, ignoring case. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
bool contains (StringRef Other) const
 Return true if the given string is a substring of *this, and false otherwise. More...
 
bool contains (char C) const
 Return true if the given character is contained in *this, and false otherwise. More...
 
bool contains_insensitive (StringRef Other) const
 Return true if the given string is a substring of *this, and false otherwise. More...
 
bool contains_insensitive (char C) const
 Return true if the given character is contained in *this, and false otherwise. More...
 
size_t count (char C) const
 Return the number of occurrences of C in the string. More...
 
size_t count (StringRef Str) const
 Return the number of non-overlapped occurrences of Str in the string. More...
 
template<typename T >
bool getAsInteger (unsigned Radix, T &Result) const
 Parse the current string as an integer of the specified radix. More...
 
template<typename T >
bool consumeInteger (unsigned Radix, T &Result)
 Parse the current string as an integer of the specified radix. More...
 
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. More...
 
bool getAsDouble (double &Result, bool AllowInexact=true) const
 Parse the current string as an IEEE double-precision floating point value. More...
 
constexpr StringRef substr (size_t Start, size_t N=npos) const
 Return a reference to the substring from [Start, Start + N). More...
 
StringRef take_front (size_t N=1) const
 Return a StringRef equal to 'this' but with only the first N elements remaining. More...
 
StringRef take_back (size_t N=1) const
 Return a StringRef equal to 'this' but with only the last N elements remaining. More...
 
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. More...
 
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. More...
 
StringRef drop_front (size_t N=1) const
 Return a StringRef equal to 'this' but with the first N elements dropped. More...
 
StringRef drop_back (size_t N=1) const
 Return a StringRef equal to 'this' but with the last N elements dropped. More...
 
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. More...
 
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. More...
 
bool consume_front (StringRef Prefix)
 Returns true if this StringRef has the given prefix and removes that prefix. More...
 
bool consume_front_insensitive (StringRef Prefix)
 Returns true if this StringRef has the given prefix, ignoring case, and removes that prefix. More...
 
bool consume_back (StringRef Suffix)
 Returns true if this StringRef has the given suffix and removes that suffix. More...
 
bool consume_back_insensitive (StringRef Suffix)
 Returns true if this StringRef has the given suffix, ignoring case, and removes that suffix. More...
 
StringRef slice (size_t Start, size_t End) const
 Return a reference to the substring from [Start, End). More...
 
std::pair< StringRef, StringRefsplit (char Separator) const
 Split into two substrings around the first occurrence of a separator character. More...
 
std::pair< StringRef, StringRefsplit (StringRef Separator) const
 Split into two substrings around the first occurrence of a separator string. More...
 
std::pair< StringRef, StringRefrsplit (StringRef Separator) const
 Split into two substrings around the last occurrence of a separator string. More...
 
void split (SmallVectorImpl< StringRef > &A, StringRef Separator, int MaxSplit=-1, bool KeepEmpty=true) const
 Split into substrings around the occurrences of a separator string. More...
 
void split (SmallVectorImpl< StringRef > &A, char Separator, int MaxSplit=-1, bool KeepEmpty=true) const
 Split into substrings around the occurrences of a separator character. More...
 
std::pair< StringRef, StringRefrsplit (char Separator) const
 Split into two substrings around the last occurrence of a separator character. More...
 
StringRef ltrim (char Char) const
 Return string with consecutive Char characters starting from the the left removed. More...
 
StringRef ltrim (StringRef Chars=" \t\n\v\f\r") const
 Return string with consecutive characters in Chars starting from the left removed. More...
 
StringRef rtrim (char Char) const
 Return string with consecutive Char characters starting from the right removed. More...
 
StringRef rtrim (StringRef Chars=" \t\n\v\f\r") const
 Return string with consecutive characters in Chars starting from the right removed. More...
 
StringRef trim (char Char) const
 Return string with consecutive Char characters starting from the left and right removed. More...
 
StringRef trim (StringRef Chars=" \t\n\v\f\r") const
 Return string with consecutive characters in Chars starting from the left and right removed. More...
 
StringRef detectEOL () const
 Detect the line ending style of the string. More...
 

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 846 of file StringRef.h.

Constructor & Destructor Documentation

◆ StringLiteral()

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

Definition at line 853 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 866 of file StringRef.h.

References N.


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