WPILibC++  unspecified
llvm::StringRef Class Reference

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

#include <StringRef.h>

Public Types

typedef const char * iterator
 
typedef const char * const_iterator
 
typedef size_t size_type
 

Public Member Functions

Constructors
 StringRef ()
 Construct an empty string ref.
 
 StringRef (const char *Str)
 Construct a string ref from a cstring.
 
 StringRef (const char *data, size_t length, bool isNullTerminated=false)
 Construct a string ref from a pointer and length.
 
 StringRef (const std::string &Str)
 Construct a string ref from an std::string.
 
Iterators
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
 
String Operations
const char * data () const
 data - Get a pointer to the start of the string (which may not be null terminated). More...
 
const char * c_str (llvm::SmallVectorImpl< char > &buf) const
 c_str - Get a null terminated pointer to the start of the string If string is not null terminated, use buffer to store new string
 
bool empty () const
 empty - Check if the string is empty.
 
size_t size () const
 size - Get the string size.
 
bool is_null_terminated () const
 is_null_terminated - Get if the string is guaranteed null terminated
 
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. More...
 
bool equals_lower (StringRef RHS) const
 equals_lower - Check for string equality, ignoring case.
 
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_lower (StringRef RHS) const
 compare_lower - Compare two strings, ignoring case. More...
 
int compare_numeric (StringRef RHS) const
 compare_numeric - Compare two strings, treating sequences of digits as numbers. More...
 
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.
 
Operator Overloads
char operator[] (size_t Index) const
 
Type Conversions
 operator std::string () const
 
String Predicates
bool startswith (StringRef Prefix) const
 Check if this string starts with the given Prefix.
 
bool startswith_lower (StringRef Prefix) const
 Check if this string starts with the given Prefix, ignoring case.
 
bool endswith (StringRef Suffix) const
 Check if this string ends with the given Suffix.
 
bool endswith_lower (StringRef Suffix) const
 Check if this string ends with the given Suffix, ignoring case.
 
String Searching
size_t find (char C, size_t From=0) const
 Search for the first character C in the string. More...
 
size_t find (StringRef Str, size_t From=0) const
 Search for the first string Str in the string. More...
 
size_t rfind (char C, size_t From=npos) const
 Search for the last character C in the string. More...
 
size_t rfind (StringRef Str) const
 Search for the last string Str in the string. 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...
 
Helpful Algorithms
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. More...
 
template<typename T >
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger (unsigned Radix, T &Result) const
 Parse the current string as an integer of the specified radix. More...
 
template<typename T >
std::enable_if<!std::numeric_limits< T >::is_signed, bool >::type getAsInteger (unsigned Radix, T &Result) const
 
Substring Operations
StringRef substr (size_t Start, size_t N=npos) const
 Return a reference to the substring from [Start, Start + N). 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 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...
 
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...
 

Static Public Attributes

static const 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.

Member Function Documentation

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

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.

int StringRef::compare_lower ( StringRef  RHS) const

compare_lower - Compare two strings, ignoring case.

compare_lower - Compare strings, ignoring case.

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.

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.
const char* llvm::StringRef::data ( ) const
inline

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

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

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

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

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

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.

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.
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
  • Str, or npos if not found.
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

  • C or npos if not found.
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())

  • Chars, or npos if not found.

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

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.

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())

  • Chars, or npos if not found.

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

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

  • C, or npos if not found.
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())

  • Chars, or npos if not found.

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

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.

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())

  • C, or npos if not found.

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

template<typename T >
std::enable_if<std::numeric_limits<T>::is_signed, bool>::type 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.

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

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

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.

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.
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
  • Str, or npos if not found.
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.
StringRef llvm::StringRef::rtrim ( char  Char) const
inline

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

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.

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

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

Parameters
StartThe 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.
EndThe 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.
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
SeparatorThe character to split on.
Returns
The split substrings.
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.
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.
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.
StringRef llvm::StringRef::substr ( size_t  Start,
size_t  N = npos 
) const
inline

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

Parameters
StartThe 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.
NThe number of characters to included in the substring. If N exceeds the number of characters remaining in the string, the string suffix (starting with Start) will be returned.
StringRef llvm::StringRef::trim ( char  Char) const
inline

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

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.


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