LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Static Public Attributes | List of all members
llvm::StringRef Class Reference

#include <StringRef.h>

Collaboration diagram for llvm::StringRef:
Collaboration graph
[legend]

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. More...
 
 StringRef (const char *Str)
 Construct a string ref from a cstring. More...
 
 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...
 
Iterators
iterator begin () const
 
iterator end () const
 
String Operations
const char * data () const
 
bool empty () const
 empty - Check if the string is empty. More...
 
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...
 
bool equals (StringRef RHS) const
 
bool equals_lower (StringRef RHS) const
 equals_lower - Check for string equality, ignoring case. More...
 
int compare (StringRef RHS) const
 
int compare_lower (StringRef RHS) const
 compare_lower - Compare two strings, ignoring case. More...
 
int compare_numeric (StringRef RHS) const
 compare_numeric - Compare strings, handle embedded 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...
 
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...
 
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. More...
 
bool startswith_lower (StringRef Prefix) const
 Check if this string starts with the given Prefix, ignoring case. More...
 
bool endswith (StringRef Suffix) const
 Check if this string ends with the given Suffix. More...
 
bool endswith_lower (StringRef Suffix) const
 Check if this string ends with the given Suffix, ignoring case. More...
 
String Searching
size_t find (char C, size_t From=0) const
 
size_t find (StringRef Str, size_t From=0) const
 
size_t rfind (char C, size_t From=npos) const
 
size_t rfind (StringRef Str) const
 
size_t find_first_of (char C, size_t From=0) const
 
size_t find_first_of (StringRef Chars, size_t From=0) const
 
size_t find_first_not_of (char C, size_t From=0) const
 
size_t find_first_not_of (StringRef Chars, size_t From=0) const
 
size_t find_last_of (char C, size_t From=npos) const
 
size_t find_last_of (StringRef Chars, size_t From=npos) const
 
size_t find_last_not_of (char C, size_t From=npos) const
 
size_t find_last_not_of (StringRef Chars, size_t From=npos) const
 
Helpful Algorithms
size_t count (char C) const
 Return the number of occurrences of C in the string. More...
 
size_t count (StringRef Str) const
 
template<typename T >
enable_if_c
< std::numeric_limits< T >
::is_signed, bool >::type 
getAsInteger (unsigned Radix, T &Result) const
 
template<typename T >
enable_if_c
<!std::numeric_limits< T >
::is_signed, bool >::type 
getAsInteger (unsigned Radix, T &Result) const
 
bool getAsInteger (unsigned Radix, APInt &Result) const
 
Substring Operations
StringRef substr (size_t Start, size_t N=npos) const
 
StringRef drop_front (size_t N=1) const
 
StringRef drop_back (size_t N=1) const
 
StringRef slice (size_t Start, size_t End) const
 
std::pair< StringRef, StringRefsplit (char Separator) const
 
std::pair< StringRef, StringRefsplit (StringRef Separator) const
 
void split (SmallVectorImpl< StringRef > &A, StringRef Separator, int MaxSplit=-1, bool KeepEmpty=true) const
 
std::pair< StringRef, StringRefrsplit (char Separator) const
 
StringRef ltrim (StringRef Chars=" \t\n\v\f\r") const
 
StringRef rtrim (StringRef Chars=" \t\n\v\f\r") const
 
StringRef trim (StringRef Chars=" \t\n\v\f\r") 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 41 of file StringRef.h.

Member Typedef Documentation

typedef const char* llvm::StringRef::const_iterator

Definition at line 44 of file StringRef.h.

typedef const char* llvm::StringRef::iterator

Definition at line 43 of file StringRef.h.

Definition at line 46 of file StringRef.h.

Constructor & Destructor Documentation

llvm::StringRef::StringRef ( )
inline

Construct an empty string ref.

Definition at line 73 of file StringRef.h.

Referenced by rsplit(), slice(), split(), and substr().

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

Construct a string ref from a cstring.

Definition at line 76 of file StringRef.h.

References llvm::LibFunc::strlen.

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

Construct a string ref from a pointer and length.

Definition at line 83 of file StringRef.h.

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

Construct a string ref from an std::string.

Definition at line 90 of file StringRef.h.

Member Function Documentation

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

back - Get the last character in the string.

Definition at line 122 of file StringRef.h.

References empty().

Referenced by llvm::ConstantDataSequential::isCString(), parsePhysicalReg(), llvm::yaml::Output::scalarString(), and StripSpaces().

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

Definition at line 97 of file StringRef.h.

Referenced by llvm::SmallString< 256 >::append(), llvm::sys::path::append(), llvm::SmallString< 256 >::assign(), llvm::MDString::begin(), llvm::object::Archive::begin_symbols(), llvm::APFloat::convertFromString(), llvm::ConvertUTF8toWide(), llvm::sys::fs::createTemporaryFile(), decodeUTF8(), llvm::MCObjectStreamer::EmitBytes(), llvm::TargetLoweringObjectFileELF::emitPersonalityValue(), llvm::object::Archive::end_symbols(), llvm::yaml::escape(), fixupSubprogramName(), llvm::UnOpInit::Fold(), llvm::APInt::getBitsNeeded(), llvm::object::Archive::Symbol::getName(), llvm::Mangler::getNameWithPrefix(), llvm::StringToOffsetTable::GetOrAddStringOffset(), llvm::StringMap< std::pair< llvm::Type *, llvm::SMLoc > >::GetOrCreateValue(), llvm::object::MachOObjectFile::getRelocationTypeName(), llvm::object::COFFObjectFile::getRelocationTypeName(), llvm::object::ELFFile< ELFT >::getRelocationTypeName(), llvm::object::ELFObjectFile< ELFT >::getRelocationValueString(), llvm::object::COFFObjectFile::getRelocationValueString(), llvm::ConstantDataArray::getString(), llvm::AsmPrinter::GetSymbolWithGlobalValueBase(), llvm::yaml::ScalarNode::getValue(), llvm::hash_value(), llvm::Timer::init(), llvm::StringPool::intern(), isAllZeros(), isValidName(), llvm::RuntimeDyldImpl::loadObject(), llvm::object::MachOUniversalBinary::MachOUniversalBinary(), llvm::sys::fs::make_absolute(), llvm::object::MachOUniversalBinary::ObjectForArch::ObjectForArch(), llvm::SmallString< 256 >::operator+=(), llvm::object::Archive::Child::operator<(), llvm::object::Archive::Child::operator==(), llvm::sys::path::const_iterator::operator==(), llvm::opt::OptTable::OptTable(), llvm::DWARFDebugLoc::parse(), llvm::InlineAsm::ConstraintInfo::Parse(), llvm::InlineAsm::ParseConstraints(), parseDouble(), parsePhysicalReg(), printName(), llvm::sys::path::replace_extension(), llvm::yaml::ScalarNode::ScalarNode(), llvm::TargetLoweringObjectFileELF::SelectSectionForGlobal(), llvm::EngineBuilder::setMArch(), llvm::EngineBuilder::setMCPU(), llvm::Value::setName(), llvm::TimerGroup::setName(), SimplifyCondBranchToCondBranch(), llvm::Regex::sub(), WriteAttributeGroupTable(), and WriteModuleMetadataStore().

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.

Definition at line 141 of file StringRef.h.

Referenced by llvm::SmallString< 256 >::compare(), llvm::operator<(), llvm::operator<=(), llvm::operator>(), llvm::operator>=(), and SortSymbolPair().

int StringRef::compare_lower ( StringRef  RHS) const

compare_lower - Compare two strings, ignoring case.

compare_lower - Compare strings, ignoring case.

Definition at line 53 of file StringRef.cpp.

References ascii_strncasecmp().

Referenced by llvm::SmallString< 256 >::compare_lower(), and equals_lower().

int StringRef::compare_numeric ( StringRef  RHS) const

compare_numeric - Compare strings, handle embedded numbers.

compare_numeric - Compare two strings, treating sequences of digits as numbers.

Definition at line 74 of file StringRef.cpp.

References ascii_isdigit(), and I.

Referenced by llvm::SmallString< 256 >::compare_numeric().

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

Return the number of occurrences of C in the string.

Definition at line 316 of file StringRef.h.

Referenced by llvm::SmallString< 256 >::count(), and llvm::InlineAsm::ConstraintInfo::Parse().

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.

Definition at line 304 of file StringRef.cpp.

References equals(), N, size(), and substr().

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

Referenced by llvm::FoldingSetNodeID::AddString(), llvm::StringSwitch< T, R >::Case(), llvm::sys::unicode::columnWidthUTF8(), llvm::zlib::compress(), llvm::ConvertUTF8toWide(), CopyStringRef(), llvm::zlib::crc32(), llvm::dumpBlock(), edit_distance(), llvm::RuntimeDyldImpl::emitCommonSymbols(), llvm::RuntimeDyldImpl::emitSection(), llvm::StringSwitch< T, R >::EndsWith(), llvm::cl::Option::error(), llvm::DWARFFormValue::extractValue(), llvm::object::Archive::Child::getBuffer(), llvm::DataExtractor::getCStr(), llvm::MCContext::GetDwarfFile(), llvm::AsmToken::getEndLoc(), llvm::MemoryBuffer::getFile(), llvm::getInst(), llvm::AsmToken::getLoc(), llvm::MemoryBuffer::getMemBufferCopy(), llvm::opt::ArgList::GetOrMakeJoinedArgString(), llvm::object::getPtr(), llvm::ConstantDataVector::getSplatValue(), llvm::MCMachOObjectDisassembler::getStaticExitFunctions(), llvm::MCMachOObjectDisassembler::getStaticInitFunctions(), llvm::ConstantDataArray::getString(), llvm::object::MachOObjectFile::getSymbolName(), llvm::DataExtractor::getU16(), llvm::DataExtractor::getU32(), llvm::DataExtractor::getU64(), llvm::DataExtractor::getU8(), llvm::sys::fs::identify_magic(), llvm::ExecutionEngine::InitializeMemory(), LLVMGetSectionContents(), LLVMGetSectionName(), LLVMGetStructName(), LLVMGetSymbolName(), llvm::RuntimeDyldImpl::loadObject(), llvm::Regex::match(), llvm::sys::path::native(), llvm::raw_ostream::operator<<(), llvm::opt::OptTable::ParseOneArg(), llvm::RuntimeDyldMachO::processRelocationRef(), llvm::RuntimeDyldELF::processRelocationRef(), ProvideOption(), llvm::StringRefMemoryObject::readBytes(), llvm::GCOVBuffer::readInt(), llvm::LessRecordRegister::RecordParts::RecordParts(), llvm::Regex::Regex(), replaceSubString(), llvm::report_fatal_error(), llvm::RuntimeDyldImpl::resolveExternalSymbols(), RewriteIntelBracExpression(), llvm::yaml::Output::scalarString(), split(), llvm::StringSwitch< T, R >::StartsWith(), llvm::zlib::uncompress(), and llvm::MD5::update().

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

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

Definition at line 406 of file StringRef.h.

References N, size(), and substr().

Referenced by llvm::ConstantDataSequential::isCString(), and rtrim().

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

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

Definition at line 399 of file StringRef.h.

References N, size(), and substr().

Referenced by ltrim().

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

Determine the edit distance between this string and another string.

Parameters
Otherthe string to compare this string against.
AllowReplacementswhether to allow character replacements (change one character into another) as a single operation, rather than as two operations (an insertion and a removal).
MaxEditDistanceIf 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.

Definition at line 105 of file StringRef.cpp.

References llvm::ComputeEditDistance(), data(), and size().

Referenced by LookupNearestOption().

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

empty - Check if the string is empty.

Definition at line 110 of file StringRef.h.

Referenced by llvm::SubtargetFeatures::AddFeature(), llvm::CompileUnit::addGlobalType(), back(), llvm::ConstantFoldLoadFromConstPtr(), llvm::CompileUnit::constructVariableDIE(), llvm::APFloat::convertFromString(), llvm::SpecialCaseList::create(), llvm::StructType::create(), llvm::sys::fs::create_directories(), llvm::ARM_MC::createARMMCSubtargetInfo(), llvm::DIBuilder::createBasicType(), llvm::DIBuilder::createClassType(), llvm::DIBuilder::createCompileUnit(), llvm::DIBuilder::createEnumerationType(), llvm::DIBuilder::createEnumerator(), createFilePathPair(), llvm::DIBuilder::createForwardDecl(), llvm::MCObjectDisassembler::createFunction(), llvm::CompileUnit::createGlobalVariableDIE(), createImportedModule(), createMipsMCSubtargetInfo(), llvm::DIBuilder::createStructType(), llvm::sys::fs::createTemporaryFile(), llvm::DIBuilder::createUnionType(), llvm::DIBuilder::createUnspecifiedType(), llvm::X86_MC::createX86MCSubtargetInfo(), llvm::DISubprogram::describes(), EatNumber(), emitComments(), emitDebugValueComment(), EmitGenDwarfAbbrev(), EmitGenDwarfInfo(), llvm::TargetLoweringObjectFileMachO::emitModuleFlags(), llvm::cl::Option::error(), llvm::DWARFFormValue::extractValue(), FoldBlockIntoPredecessor(), front(), llvm::Attribute::get(), getAsInteger(), llvm::getAsSignedInteger(), llvm::Attribute::getAsString(), llvm::getAsUnsignedInteger(), llvm::APInt::getBitsNeeded(), llvm::DOTGraphTraits< const Function * >::getCompleteNodeLabel(), llvm::MCContext::GetDwarfFile(), getELFKindForNamedSection(), llvm::MCContext::getELFSection(), llvm::Module::getEndianness(), llvm::SubtargetFeatures::getFeatureBits(), getFunctionName(), getItineraryLatency(), llvm::TargetLibraryInfo::getLibFunc(), getMemcpyLoadsAndStores(), getMemsetStringVal(), llvm::Mangler::getNameWithPrefix(), llvm::CompileUnit::getOrCreateNameSpace(), llvm::DwarfDebug::getOrCreateSourceID(), llvm::CompileUnit::getOrCreateSubprogramDIE(), llvm::MCContext::GetOrCreateSymbol(), llvm::CompileUnit::getOrCreateTypeDIE(), llvm::Triple::getOSVersion(), llvm::CompileUnit::getParentContextString(), llvm::Module::getPointerSize(), llvm::GlobalValue::getRealLinkageName(), llvm::DOTGraphTraits< const Function * >::getSimpleNodeLabel(), llvm::DataExtractor::getSLEB128(), llvm::DataExtractor::getULEB128(), llvm::yaml::Node::getVerbatimTag(), llvm::sys::path::has_extension(), llvm::sys::path::has_filename(), llvm::sys::path::has_parent_path(), llvm::sys::path::has_relative_path(), llvm::sys::path::has_root_directory(), llvm::sys::path::has_root_name(), llvm::sys::path::has_root_path(), llvm::sys::path::has_stem(), hasFlag(), llvm::TypePrinting::incorporateTypes(), llvm::MCSubtargetInfo::InitCPUSchedModel(), llvm::StringSet< AllocatorTy >::insert(), isEnabled(), isRepeatedByteSequence(), isValidName(), llvm::LoadAndStorePromoter::LoadAndStorePromoter(), LookupNearestOption(), LookupOption(), NameNeedsQuoting(), llvm::Triple::normalize(), llvm::ARM_MC::ParseARMTriple(), llvm::cl::ParseCommandLineOptions(), ParseMipsTriple(), llvm::MCSectionMachO::ParseSectionSpecifier(), PrependFlag(), llvm::TypePrinting::print(), llvm::FileInfo::print(), llvm::MCInstPrinter::printAnnotation(), llvm::DIVariable::printExtendedName(), llvm::DIType::printInternal(), PrintLLVMName(), llvm::AssemblyWriter::printNamedMDNode(), llvm::RuntimeDyldELF::processRelocationRef(), llvm::AttributeImpl::Profile(), llvm::GCOVBuffer::readArcTag(), llvm::GCOVBuffer::readBlockTag(), llvm::GCOVBuffer::readEdgeTag(), llvm::GCOVBuffer::readFunctionTag(), llvm::GCOVBuffer::readLineTag(), llvm::GCOVBuffer::readObjectTag(), llvm::GCOVBuffer::readProgramTag(), llvm::LessRecordRegister::RecordParts::RecordParts(), llvm::yaml::Output::scalarString(), llvm::EngineBuilder::selectTarget(), llvm::Value::setName(), llvm::StructType::setName(), Split(), split(), StripSpaces(), StripTypeNames(), llvm::Regex::sub(), llvm::MCObjectSymbolizer::tryAddingSymbolicOperand(), llvm::InlineAsm::Verify(), WriteAttributeGroupTable(), WriteTypeTable(), llvm::yaml2mcmodule(), and llvm::yaml::yamlize().

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

Definition at line 99 of file StringRef.h.

Referenced by llvm::SmallString< 256 >::append(), llvm::sys::path::append(), llvm::SmallString< 256 >::assign(), llvm::ConvertUTF8toWide(), decodeUTF8(), llvm::MCObjectStreamer::EmitBytes(), llvm::TargetLoweringObjectFileELF::emitPersonalityValue(), llvm::MDString::end(), endswith(), endswith_lower(), llvm::yaml::escape(), fixupSubprogramName(), llvm::UnOpInit::Fold(), llvm::Mangler::getNameWithPrefix(), llvm::StringToOffsetTable::GetOrAddStringOffset(), llvm::StringMap< std::pair< llvm::Type *, llvm::SMLoc > >::GetOrCreateValue(), llvm::object::MachOObjectFile::getRelocationTypeName(), llvm::object::COFFObjectFile::getRelocationTypeName(), llvm::object::ELFFile< ELFT >::getRelocationTypeName(), llvm::object::ELFObjectFile< ELFT >::getRelocationValueString(), llvm::object::COFFObjectFile::getRelocationValueString(), llvm::ConstantDataArray::getString(), llvm::AsmPrinter::GetSymbolWithGlobalValueBase(), llvm::yaml::ScalarNode::getValue(), llvm::hash_value(), llvm::Timer::init(), llvm::StringPool::intern(), isAllZeros(), isValidName(), llvm::sys::fs::make_absolute(), llvm::SmallString< 256 >::operator+=(), llvm::opt::OptTable::OptTable(), llvm::DWARFDebugLoc::parse(), llvm::InlineAsm::ConstraintInfo::Parse(), llvm::InlineAsm::ParseConstraints(), parseDouble(), parsePhysicalReg(), printName(), llvm::X86AsmPrinter::printSymbolOperand(), llvm::Regex::Regex(), llvm::sys::path::replace_extension(), llvm::yaml::ScalarNode::ScalarNode(), llvm::TargetLoweringObjectFileELF::SelectSectionForGlobal(), llvm::EngineBuilder::setMArch(), llvm::EngineBuilder::setMCPU(), llvm::Value::setName(), llvm::TimerGroup::setName(), llvm::Regex::sub(), llvm::UnrollLoop(), llvm::UnrollRuntimeLoopProlog(), WriteAttributeGroupTable(), and WriteModuleMetadataStore().

bool llvm::StringRef::endswith ( StringRef  Suffix) const
inline
bool StringRef::endswith_lower ( StringRef  Suffix) const

Check if this string ends with the given Suffix, ignoring case.

Definition at line 68 of file StringRef.cpp.

References ascii_strncasecmp(), and end().

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.

Definition at line 129 of file StringRef.h.

Referenced by count(), llvm::SmallString< 256 >::equals(), find(), GenerateARCAnnotation(), GenerateARCBBEntranceAnnotation(), GenerateARCBBTerminatorAnnotation(), llvm::operator==(), and rfind().

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

equals_lower - Check for string equality, ignoring case.

Definition at line 135 of file StringRef.h.

References compare_lower().

Referenced by llvm::SmallString< 256 >::equals_lower(), llvm::X86TargetLowering::getRegForInlineAsmConstraint(), and llvm::StrInStrNoCase().

size_t llvm::StringRef::find ( char  C,
size_t  From = 0 
) const
inline
size_t StringRef::find ( StringRef  Str,
size_t  From = 0 
) const

Search for the first string Str in the string.

Returns
The index of the first occurrence of Str, or npos if not found.

find - Search for the first string

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

Definition at line 143 of file StringRef.cpp.

References equals(), llvm::Intrinsic::memset, N, npos, size(), and substr().

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.

Definition at line 213 of file StringRef.cpp.

References npos.

Referenced by llvm::DWARFContextInMemory::DWARFContextInMemory(), llvm::SmallString< 256 >::find_first_not_of(), llvm::getToken(), ltrim(), printName(), llvm::yaml::Output::scalarString(), and llvm::Regex::sub().

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.

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

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

Definition at line 224 of file StringRef.cpp.

References npos, and size().

size_t llvm::StringRef::find_first_of ( char  C,
size_t  From = 0 
) const
inline
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.

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

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

  • Chars, or npos if not found.

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

Definition at line 199 of file StringRef.cpp.

References npos, and 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.

Definition at line 254 of file StringRef.cpp.

References npos.

Referenced by rtrim().

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.

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

find_last_not_of - Find the last character in the string that is not in

  • Chars, or npos if not found.

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

Definition at line 265 of file StringRef.cpp.

References npos, and 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.

Definition at line 291 of file StringRef.h.

References rfind().

Referenced by llvm::sys::path::extension(), llvm::SmallString< 256 >::find_last_of(), llvm::SourceMgr::getLineAndColumn(), llvm::yaml::Node::getVerbatimTag(), llvm::sys::path::replace_extension(), and llvm::sys::path::stem().

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.

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

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

  • C, or npos if not found.

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

Definition at line 240 of file StringRef.cpp.

References npos, and size().

char llvm::StringRef::front ( ) const
inline
template<typename T >
enable_if_c<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.

Definition at line 337 of file StringRef.h.

References llvm::getAsSignedInteger().

Referenced by llvm::AMDGPUMachineFunction::AMDGPUMachineFunction(), llvm::object::Archive::Child::Child(), EmitGCCInlineAsmStr(), getInt(), llvm::object::Archive::Child::getName(), llvm::yaml::ScalarTraits< MCModuleYAML::Operand >::input(), llvm::MCSectionMachO::ParseSectionSpecifier(), llvm::StackProtector::runOnFunction(), llvm::Regex::sub(), and llvm::object::yaml::BinaryRef::writeAsBinary().

template<typename T >
enable_if_c<!std::numeric_limits<T>::is_signed, bool>::type llvm::StringRef::getAsInteger ( unsigned  Radix,
T Result 
) const
inline

Definition at line 348 of file StringRef.h.

References llvm::getAsUnsignedInteger().

bool StringRef::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. 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.

Definition at line 407 of file StringRef.cpp.

References empty(), front(), GetAutoSenseRadix(), llvm::APInt::getBitWidth(), size(), substr(), and llvm::APInt::zext().

std::string StringRef::lower ( ) const
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.

Definition at line 498 of file StringRef.h.

References drop_front(), and find_first_not_of().

Referenced by llvm::opt::OptTable::ParseOneArg(), and trim().

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

Definition at line 199 of file StringRef.h.

References str().

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

Definition at line 190 of file StringRef.h.

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.

Definition at line 250 of file StringRef.h.

References npos.

Referenced by find_last_of(), llvm::SmallString< 256 >::rfind(), and rsplit().

size_t StringRef::rfind ( StringRef  Str) const

Search for the last string Str in the string.

Returns
The index of the last occurrence of Str, or npos if not found.

rfind - Search for the last string

  • Str in the string.
Returns
- The index of the last occurrence of
  • Str, or npos if not found.

Definition at line 183 of file StringRef.cpp.

References equals(), N, npos, size(), and substr().

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.

Definition at line 489 of file StringRef.h.

References npos, rfind(), slice(), and StringRef().

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.

Definition at line 504 of file StringRef.h.

References drop_back(), and find_last_not_of().

Referenced by llvm::object::Archive::Child::Child(), llvm::object::Archive::Child::getName(), and trim().

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

size - Get the string size.

Definition at line 113 of file StringRef.h.

Referenced by llvm::FoldingSetNodeID::AddString(), llvm::StringSwitch< T, R >::Case(), llvm::sys::locale::columnWidth(), llvm::sys::unicode::columnWidthUTF8(), compareBySuffix(), llvm::zlib::compress(), llvm::ConstantFoldLoadFromConstPtr(), llvm::APFloat::convertFromString(), llvm::ConvertUTF8toWide(), CopyStringRef(), count(), llvm::zlib::crc32(), drop_back(), drop_front(), dumpPubSection(), edit_distance(), llvm::object::elf_hash(), llvm::emitSourceFileHeader(), llvm::sys::path::end(), llvm::StringSwitch< T, R >::EndsWith(), llvm::sys::path::extension(), llvm::DWARFUnit::extractImpl(), find(), find_first_not_of(), find_first_of(), find_last_not_of(), find_last_of(), fixupSubprogramName(), llvm::DWARFUnit::getAddrOffsetSectionItem(), llvm::ConstantDataSequential::getAsCString(), getAsInteger(), llvm::APInt::getBitsNeeded(), llvm::MCContext::GetDwarfFile(), llvm::AsmToken::getEndLoc(), llvm::StringRefMemoryObject::getExtent(), GetLazyPtr(), llvm::MDString::getLength(), llvm::MemoryBuffer::getMemBufferCopy(), getMemsetStringVal(), llvm::object::Archive::Child::getName(), llvm::MemoryBuffer::getNewUninitMemBuffer(), getOptionPred(), llvm::opt::ArgList::GetOrMakeJoinedArgString(), llvm::Triple::getOSVersion(), llvm::object::Archive::Child::getSize(), llvm::MCMachOObjectDisassembler::getStaticExitFunctions(), llvm::MCMachOObjectDisassembler::getStaticInitFunctions(), llvm::ConstantDataArray::getString(), llvm::AsmToken::getStringContents(), GetStringLengthH(), llvm::DWARFUnit::getStringOffsetSectionItem(), llvm::object::ELFFile< ELFT >::getSymbolVersion(), getUnicodeEncoding(), llvm::yaml::ScalarNode::getValue(), HandlePrefixedOrGroupedOption(), llvm::sys::fs::has_magic(), llvm::HashString(), llvm::sys::fs::identify_magic(), llvm::ExecutionEngine::InitializeMemory(), llvm::yaml::ScalarTraits< MCModuleYAML::Operand >::input(), isRepeatedByteSequence(), llvm::DataExtractor::isValidOffset(), llvm::join_impl(), lower(), llvm::object::MachOUniversalBinary::MachOUniversalBinary(), llvm::MCGenDwarfLabelEntry::Make(), llvm::opt::DerivedArgList::MakeJoinedArg(), llvm::Regex::match(), MatchCoprocessorOperandName(), matchOption(), NameNeedsQuoting(), llvm::object::MachOUniversalBinary::ObjectForArch::ObjectForArch(), llvm::sys::path::const_iterator::operator++(), llvm::sys::path::const_iterator::operator--(), llvm::raw_ostream::operator<<(), llvm::DWARFDebugLoc::parse(), llvm::ARM_MC::ParseARMTriple(), parseBackslash(), parseSectionFlags(), llvm::MCSectionMachO::ParseSectionSpecifier(), llvm::MCSymbol::print(), PrintEscapedString(), PrintHelpOptionList(), printLine(), PrintLLVMName(), llvm::AssemblyWriter::printNamedMDNode(), PrintQuotedString(), printSourceLine(), llvm::GCOVBuffer::readInt(), llvm::GCOVBuffer::readString(), llvm::LessRecordRegister::RecordParts::RecordParts(), llvm::sys::path::relative_path(), llvm::sys::path::replace_extension(), replaceSubString(), llvm::report_fatal_error(), llvm::RuntimeDyldImpl::resolveExternalSymbols(), RewriteIntelBracExpression(), rfind(), llvm::sys::path::root_directory(), llvm::sys::path::root_name(), llvm::sys::path::root_path(), llvm::yaml::Output::scalarString(), llvm::StructType::setName(), split(), llvm::StringSwitch< T, R >::StartsWith(), llvm::sys::path::stem(), llvm::StrInStrNoCase(), StripSpaces(), llvm::Regex::sub(), llvm::cl::TokenizeGNUCommandLine(), llvm::cl::TokenizeWindowsCommandLine(), llvm::zlib::uncompress(), llvm::MD5::update(), UpgradeIntrinsicFunction1(), upper(), llvm::raw_ostream::write_escaped(), llvm::MCObjectWriter::WriteBytes(), WriteModuleMetadata(), and WriteStringRecord().

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

References StringRef().

Referenced by llvm::object::ObjectFile::createMachOObjectFile(), llvm::emitSourceFileHeader(), getObjCClassCategory(), getObjCMethodName(), llvm::AsmToken::getStringContents(), llvm::getToken(), llvm::sys::path::const_iterator::operator++(), llvm::sys::path::const_iterator::operator--(), llvm::GCOVBuffer::readArcTag(), llvm::GCOVBuffer::readBlockTag(), llvm::GCOVBuffer::readEdgeTag(), llvm::GCOVBuffer::readFunctionTag(), llvm::GCOVBuffer::readGCOVFormat(), llvm::GCOVBuffer::readInt(), llvm::GCOVBuffer::readLineTag(), llvm::GCOVBuffer::readObjectTag(), llvm::GCOVBuffer::readProgramTag(), llvm::GCOVBuffer::readString(), rsplit(), llvm::SmallString< 256 >::slice(), split(), and llvm::Regex::sub().

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.

Definition at line 437 of file StringRef.h.

References find(), npos, slice(), and StringRef().

Referenced by llvm::Triple::getArchName(), llvm::Triple::getEnvironmentName(), llvm::Triple::getOSAndEnvironmentName(), llvm::Triple::getOSName(), llvm::Triple::getVendorName(), LookupNearestOption(), llvm::Triple::normalize(), llvm::MCSectionMachO::ParseSectionSpecifier(), llvm::FileInfo::print(), printHelpStr(), llvm::GCOVBuffer::readString(), split(), split(), and llvm::Regex::sub().

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.

Definition at line 454 of file StringRef.h.

References find(), npos, size(), slice(), and StringRef().

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

Definition at line 277 of file StringRef.cpp.

References data(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), size(), and split().

bool llvm::StringRef::startswith ( StringRef  Prefix) const
inline
bool StringRef::startswith_lower ( StringRef  Prefix) const

Check if this string starts with the given Prefix, ignoring case.

Definition at line 62 of file StringRef.cpp.

References ascii_strncasecmp().

Referenced by matchOption().

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

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

Definition at line 181 of file StringRef.h.

Referenced by llvm::CompileUnit::addGlobalName(), llvm::CompileUnit::addGlobalType(), llvm::Record::addTemplateArg(), cacheAnnotationFromMD(), llvm::ARM_MC::createARMMCSubtargetInfo(), createMipsMCSubtargetInfo(), llvm::X86_MC::createX86MCSubtargetInfo(), ExecGraphViewer(), llvm::object::MachOUniversalBinary::ObjectForArch::getAsObjectFile(), llvm::Attribute::getAsString(), llvm::DOTGraphTraits< const Function * >::getGraphName(), llvm::DOTGraphTraits< const MachineFunction * >::getGraphName(), llvm::MCSectionELF::getLabelBeginName(), llvm::MCSectionCOFF::getLabelBeginName(), llvm::MCSectionELF::getLabelEndName(), llvm::MCSectionCOFF::getLabelEndName(), llvm::DOTGraphTraits< BlockFrequencyInfo * >::getNodeLabel(), llvm::DOTGraphTraits< const Function * >::getSimpleNodeLabel(), llvm::Record::getValueAsBit(), llvm::Record::getValueAsBitOrUnset(), llvm::Record::getValueAsBitsInit(), llvm::Record::getValueAsDag(), llvm::Record::getValueAsDef(), llvm::Record::getValueAsInt(), llvm::Record::getValueAsListInit(), llvm::Record::getValueAsListOfDefs(), llvm::Record::getValueAsListOfInts(), llvm::Record::getValueAsListOfStrings(), llvm::Record::getValueAsString(), llvm::Record::getValueInit(), INITIALIZE_PASS(), llvm::Record::isTemplateArg(), llvm::LockFileManager::LockFileManager(), lookupFunction(), LookupNearestOption(), llvm::opt::DerivedArgList::MakeJoinedArg(), operator std::string(), llvm::cl::parser< std::string >::parse(), llvm::X86AsmPrinter::printSymbolOperand(), llvm::Record::removeValue(), llvm::DOTGraphTraitsViewer< Analysis, Simple >::runOnFunction(), llvm::DOTGraphTraitsPrinter< Analysis, Simple >::runOnFunction(), llvm::MCContext::setCompilationDir(), llvm::MCParsedAsmOperand::setConstraint(), llvm::MCContext::setMainFileName(), llvm::MCAtom::setName(), llvm::Twine::str(), llvm::Regex::sub(), llvm::UpgradeIntrinsicCall(), usedInGlobalVarDef(), llvm::LockFileManager::waitForUnlock(), and llvm::LockFileManager::~LockFileManager().

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.

Definition at line 392 of file StringRef.h.

References N, and StringRef().

Referenced by llvm::object::Archive::Child::Child(), CommaSeparateAndAddOccurence(), consumeCompressedDebugSectionHeader(), count(), drop_back(), drop_front(), llvm::DWARFContextInMemory::DWARFContextInMemory(), EatNumber(), emitComments(), llvm::sys::path::extension(), llvm::DWARFFormValue::extractValue(), find(), llvm::SimplifyFortifiedLibCalls::fold(), llvm::ConstantDataSequential::getAsCString(), getAsInteger(), llvm::object::MachOUniversalBinary::ObjectForArch::getAsObjectFile(), llvm::getAsSignedInteger(), llvm::getAsUnsignedInteger(), GetAutoSenseRadix(), llvm::getConstantStringInfo(), GetLazyPtr(), llvm::TargetLibraryInfo::getLibFunc(), getMemcpyLoadsAndStores(), llvm::object::Archive::Child::getName(), llvm::Mangler::getNameWithPrefix(), getOptionPred(), llvm::Triple::getOSVersion(), llvm::MCJIT::getPointerToFunction(), llvm::object::getPtr(), llvm::GlobalValue::getRealLinkageName(), llvm::object::MachOObjectFile::getSectionContents(), llvm::MCWin64EHUnwindEmitter::GetSectionSuffix(), llvm::object::MachOObjectFile::getStringTableData(), llvm::object::ELFFile< ELFT >::getSymbolVersion(), llvm::getToken(), llvm::yaml::ScalarNode::getValue(), llvm::yaml::Node::getVerbatimTag(), HandlePrefixedOrGroupedOption(), llvm::yaml::ScalarTraits< MCModuleYAML::Operand >::input(), LookupOption(), llvm::MCGenDwarfLabelEntry::Make(), matchOption(), llvm::sys::path::const_iterator::operator++(), llvm::sys::path::const_iterator::operator--(), llvm::sys::path::parent_path(), llvm::DWARFDebugLoc::parse(), llvm::ARM_MC::ParseARMTriple(), llvm::yaml::Document::parseBlockNode(), llvm::cl::ParseCommandLineOptions(), ParseMipsTriple(), llvm::sys::path::relative_path(), rfind(), llvm::sys::path::root_path(), Split(), llvm::sys::path::stem(), llvm::StrInStrNoCase(), StripFlag(), StripSpaces(), llvm::Regex::sub(), llvm::SmallString< 256 >::substr(), llvm::UpgradeIntrinsicCall(), and UpgradeIntrinsicFunction1().

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.

Definition at line 510 of file StringRef.h.

References ltrim(), and rtrim().

std::string StringRef::upper ( ) const

Convert the given ASCII string to uppercase.

Definition at line 126 of file StringRef.cpp.

References ascii_toupper(), and size().

Member Data Documentation

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

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