LLVM API Documentation

llvm::StringRef Class Reference

#include <StringRef.h>

Collaboration diagram for llvm::StringRef:
[legend]

List of all members.

Public Types

typedef const char * iterator

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, unsigned _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
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 (const StringRef &RHS) const
int compare (const StringRef &RHS) const
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 (const StringRef &Prefix) const
 startswith - Check if this string starts with the given
bool endswith (const StringRef &Suffix) const
 endswith - Check if this string ends with the given
String Searching
size_t find (char C) const
size_t find (const StringRef &Str) const
size_t count (char C) const
 count - Return the number of occurrences of
size_t count (const StringRef &Str) const
Substring Operations
StringRef substr (size_t Start, size_t N=npos) const
StringRef slice (size_t Start, size_t End) const
std::pair< StringRef, StringRef > split (char Separator) const

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.

Definition at line 27 of file StringRef.h.


Member Typedef Documentation

typedef const char* llvm::StringRef::iterator

Definition at line 29 of file StringRef.h.


Constructor & Destructor Documentation

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

Construct an empty string ref.

Definition at line 44 of file StringRef.h.

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

Construct a string ref from a cstring.

Definition at line 47 of file StringRef.h.

llvm::StringRef::StringRef ( const char *  _Data,
unsigned  _Length 
) [inline]

Construct a string ref from a pointer and length.

Definition at line 51 of file StringRef.h.

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

Construct a string ref from an std::string.

Definition at line 55 of file StringRef.h.


Member Function Documentation

iterator llvm::StringRef::begin (  )  const [inline]

iterator llvm::StringRef::end (  )  const [inline]

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

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

Definition at line 72 of file StringRef.h.

Referenced by llvm::NamedMDNode::Create(), llvm::AsmToken::getLoc(), llvm::raw_ostream::operator<<(), llvm::MCSectionMachO::ParseSectionSpecifier(), PrintLLVMName(), and llvm::DebugInfoFinder::processModule().

bool llvm::StringRef::empty (  )  const [inline]

size_t llvm::StringRef::size (  )  const [inline]

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

front - Get the first character in the string.

Definition at line 81 of file StringRef.h.

References empty().

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

back - Get the last character in the string.

Definition at line 87 of file StringRef.h.

References empty().

Referenced by StripSpaces().

bool llvm::StringRef::equals ( const 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 94 of file StringRef.h.

References Data, and Length.

Referenced by llvm::operator==().

int llvm::StringRef::compare ( const 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.

Definition at line 101 of file StringRef.h.

References Data, and Length.

Referenced by llvm::operator<(), llvm::operator<=(), llvm::operator>(), and llvm::operator>=().

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

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

Definition at line 113 of file StringRef.h.

Referenced by llvm::Value::getNameStr(), llvm::TypeSymbolTable::getUniqueName(), llvm::Linker::LinkInLibrary(), and operator std::string().

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

Definition at line 119 of file StringRef.h.

llvm::StringRef::operator std::string (  )  const [inline]

Definition at line 128 of file StringRef.h.

References str().

bool llvm::StringRef::startswith ( const StringRef &  Prefix  )  const [inline]

startswith - Check if this string starts with the given

  • Prefix.

Definition at line 137 of file StringRef.h.

References Length.

Referenced by llvm::ConstantFoldCall(), llvm::Triple::getDarwinNumber(), StripDebugInfo(), and StripSymtab().

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

endswith - Check if this string ends with the given

  • Suffix.

Definition at line 142 of file StringRef.h.

References Length.

size_t llvm::StringRef::find ( char  C  )  const [inline]

find - Search for the character

  • C in the string.
Returns:
- The index of the first occurence of
  • C, or npos if not found.

Definition at line 154 of file StringRef.h.

References Data, and Length.

size_t llvm::StringRef::find ( const StringRef &  Str  )  const [inline]

find - Search for the string

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

Definition at line 165 of file StringRef.h.

References equals(), Length, and size().

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

count - Return the number of occurrences of

  • C in the string.

Definition at line 176 of file StringRef.h.

References Data, and Length.

size_t llvm::StringRef::count ( const StringRef &  Str  )  const [inline]

count - Return the number of non-overlapped occurrences of

  • Str in the string.

Definition at line 186 of file StringRef.h.

References equals(), Length, and size().

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.

Definition at line 210 of file StringRef.h.

References Data, and Length.

Referenced by EatNumber(), llvm::Triple::getDarwinNumber(), and StripSpaces().

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.

Definition at line 225 of file StringRef.h.

References Data, and Length.

Referenced by llvm::AsmToken::getStringContents().

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

split - Split into two substrings around the first occurence 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 241 of file StringRef.h.

References Idx.

Referenced by llvm::Triple::getArchName(), llvm::Triple::getEnvironmentName(), llvm::Triple::getOSAndEnvironmentName(), llvm::Triple::getOSName(), llvm::Triple::getVendorName(), and llvm::MCSectionMachO::ParseSectionSpecifier().


Member Data Documentation

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

Definition at line 30 of file StringRef.h.


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