llvm::StringRef Class Reference

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

#include <StringRef.h>

List of all members.

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)
 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
String Operations



const char * data () const
 data - Get a pointer to the start of the string (which may not be null terminated).
bool empty () const
 empty - Check if the string is empty.
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.
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_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
int compare_lower (StringRef RHS) const
 compare_lower - 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)
 Determine the edit distance between this string and another string.
std::string str () const
 str - Get the contents as an std::string.
Operator Overloads



char operator[] (size_t Index) const
Type Conversions



 operator std::string () const
String Predicates



bool startswith (StringRef Prefix) const
 startswith - Check if this string starts with the given
bool endswith (StringRef Suffix) const
 endswith - Check if this string ends with the given
String Searching



size_t find (char C, size_t From=0) const
 find - Search for the first character
size_t find (StringRef Str, size_t From=0) const
 find - Search for the first string
size_t rfind (char C, size_t From=npos) const
 rfind - Search for the last character
size_t rfind (StringRef Str) const
 rfind - Search for the last string
size_type find_first_of (char C, size_t From=0) const
 find_first_of - Find the first character in the string that is
size_type find_first_of (StringRef Chars, size_t From=0) const
 find_first_of - Find the first character in the string that is in
size_type find_first_not_of (char C, size_t From=0) const
 find_first_not_of - Find the first character in the string that is not
size_type find_first_not_of (StringRef Chars, size_t From=0) const
 find_first_not_of - Find the first character in the string that is not in the string
size_type find_last_of (char C, size_t From=npos) const
 find_last_of - Find the last character in the string that is
size_type find_last_of (StringRef Chars, size_t From=npos) const
 find_last_of - Find the last character in the string that is in
Helpful Algorithms



size_t count (char C) const
 count - Return the number of occurrences of
size_t count (StringRef Str) const
 count - Return the number of non-overlapped occurrences of
bool getAsInteger (unsigned Radix, long long &Result) const
 getAsInteger - Parse the current string as an integer of the specified radix.
bool getAsInteger (unsigned Radix, unsigned long long &Result) const
bool getAsInteger (unsigned Radix, int &Result) const
bool getAsInteger (unsigned Radix, unsigned &Result) const
bool getAsInteger (unsigned Radix, APInt &Result) const
 getAsInteger - Parse the current string as an integer of the specified radix, or of an autosensed radix if the radix given is 0.
Substring Operations



StringRef substr (size_t Start, size_t N=npos) const
 substr - Return a reference to the substring from [Start, Start + N).
StringRef slice (size_t Start, size_t End) const
 slice - Return a reference to the substring from [Start, End).
std::pair< StringRef, StringRefsplit (char Separator) const
 split - Split into two substrings around the first occurrence of a separator character.
std::pair< StringRef, StringRefsplit (StringRef Separator) const
 split - Split into two substrings around the first occurrence of a separator string.
void split (SmallVectorImpl< StringRef > &A, StringRef Separator, int MaxSplit=-1, bool KeepEmpty=true) const
 split - Split into substrings around the occurrences of a separator string.
std::pair< StringRef, StringRefrsplit (char Separator) const
 rsplit - Split into two substrings around the last occurrence of a separator character.

Static Public Attributes

static const size_t npos = ~size_t(0)

Static Private Member Functions

static size_t min (size_t a, size_t b)
static size_t max (size_t a, size_t b)
static int compareMemory (const char *Lhs, const char *Rhs, size_t Length)

Private Attributes

const char * Data
 The start of the string, in an external buffer.
size_t Length
 The length of the string.

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 Typedef Documentation

typedef const char* llvm::StringRef::const_iterator
typedef const char* llvm::StringRef::iterator

Constructor & Destructor Documentation

llvm::StringRef::StringRef (  )  [inline]

Construct an empty string ref.

llvm::StringRef::StringRef ( const char *  Str  )  [inline]

Construct a string ref from a cstring.

llvm::StringRef::StringRef ( const char *  data,
size_t  length 
) [inline]

Construct a string ref from a pointer and length.

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

Construct a string ref from an std::string.


Member Function Documentation

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

back - Get the last character in the string.

iterator llvm::StringRef::begin (  )  const [inline]
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.

static int llvm::StringRef::compareMemory ( const char *  Lhs,
const char *  Rhs,
size_t  Length 
) [inline, static, private]
size_t StringRef::count ( StringRef  Str  )  const

count - Return the number of non-overlapped occurrences of

  • Str in the string.
size_t llvm::StringRef::count ( char  C  )  const [inline]

count - Return the number of occurrences of

  • C 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).

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

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.
bool llvm::StringRef::empty (  )  const [inline]

empty - Check if the string is empty.

iterator llvm::StringRef::end (  )  const [inline]
bool llvm::StringRef::endswith ( StringRef  Suffix  )  const [inline]

endswith - Check if this string ends with the given

  • Suffix.
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.

bool llvm::StringRef::equals_lower ( StringRef  RHS  )  const [inline]

equals_lower - Check for string equality, ignoring case.

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

find - Search for the first string

  • Str in the string.
Returns:
- The index of the first occurrence of
  • Str, or npos if not found.
size_t llvm::StringRef::find ( char  C,
size_t  From = 0 
) const [inline]

find - Search for the first character

  • C in the string.
Returns:
- The index of the first occurrence of
  • C, or npos if not found.
StringRef::size_type StringRef::find_first_not_of ( StringRef  Chars,
size_t  From = 0 
) const

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

  • Chars, or npos if not found.

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

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

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_of ( StringRef  Chars,
size_t  From = 0 
) const

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

  • Chars, or npos if not found.

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

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

find_first_of - Find the first character in the string that is

  • C, or npos if not found. Same as find.
StringRef::size_type StringRef::find_last_of ( StringRef  Chars,
size_t  From = npos 
) const

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

  • C, or npos if not found.

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

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

find_last_of - Find the last character in the string that is

  • C, or npos if not found.
char llvm::StringRef::front (  )  const [inline]

front - Get the first character in the string.

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

getAsInteger - 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.

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

getAsInteger - 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.

static size_t llvm::StringRef::max ( size_t  a,
size_t  b 
) [inline, static, private]
static size_t llvm::StringRef::min ( size_t  a,
size_t  b 
) [inline, static, private]
llvm::StringRef::operator std::string (  )  const [inline]
char llvm::StringRef::operator[] ( size_t  Index  )  const [inline]
size_t StringRef::rfind ( StringRef  Str  )  const

rfind - Search for the last string

  • Str in the string.
Returns:
- The index of the last occurrence of
  • Str, or npos if not found.
size_t llvm::StringRef::rfind ( char  C,
size_t  From = npos 
) const [inline]

rfind - Search for the last character

  • C in the string.
Returns:
- The index of the last occurrence of
  • C, or npos if not found.
std::pair<StringRef, StringRef> llvm::StringRef::rsplit ( char  Separator  )  const [inline]

rsplit - 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.
size_t llvm::StringRef::size (  )  const [inline]

size - Get the string size.

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

slice - 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 less than

  • Start, or exceeds the number of characters remaining in the string, the string suffix (starting with
  • Start) will be returned.
void llvm::StringRef::split ( SmallVectorImpl< StringRef > &  A,
StringRef  Separator,
int  MaxSplit = -1,
bool  KeepEmpty = true 
) const

split - 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 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.
std::pair<StringRef, StringRef> llvm::StringRef::split ( StringRef  Separator  )  const [inline]

split - 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.
std::pair<StringRef, StringRef> llvm::StringRef::split ( char  Separator  )  const [inline]

split - 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.
bool llvm::StringRef::startswith ( StringRef  Prefix  )  const [inline]

startswith - Check if this string starts with the given

  • Prefix.
std::string llvm::StringRef::str (  )  const [inline]

str - Get the contents as an std::string.

StringRef llvm::StringRef::substr ( size_t  Start,
size_t  N = npos 
) const [inline]

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

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.
N - The 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.

Member Data Documentation

const char* llvm::StringRef::Data [private]

The start of the string, in an external buffer.

size_t llvm::StringRef::Length [private]

The length of the string.

const size_t StringRef::npos = ~size_t(0) [static]

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

Generated on 2 Nov 2013 for Galois by  doxygen 1.6.1