LLVM API Documentation

Public Types | Public Member Functions | Static Public Attributes
llvm::StringRef Class Reference

#include <StringRef.h>

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

List of all members.

Public Types

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

Public Member Functions

iterator begin () const
iterator end () const
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.
template<typename Allocator >
StringRef copy (Allocator &A) const
bool equals (StringRef RHS) const
bool equals_lower (StringRef RHS) const
 equals_lower - Check for string equality, ignoring case.
int compare (StringRef RHS) const
int compare_lower (StringRef RHS) const
 compare_lower - Compare two strings, ignoring case.
int compare_numeric (StringRef RHS) const
 compare_numeric - Compare strings, handle embedded numbers.
unsigned edit_distance (StringRef Other, bool AllowReplacements=true, unsigned MaxEditDistance=0) const
 Determine the edit distance between this string and another string.
std::string str () const
 str - Get the contents as an std::string.
char operator[] (size_t Index) const
 operator std::string () const
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.
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
size_t count (char C) const
 Return the number of occurrences of C in the string.
size_t count (StringRef Str) const
template<typename T >
std::enable_if
< std::numeric_limits< T >
::is_signed, bool >::type 
getAsInteger (unsigned Radix, T &Result) const
template<typename T >
std::enable_if
<!std::numeric_limits< T >
::is_signed, bool >::type 
getAsInteger (unsigned Radix, T &Result) const
bool getAsInteger (unsigned Radix, APInt &Result) const
std::string lower () const
std::string upper () const
 Convert the given ASCII string to uppercase.
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
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.

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


Member Typedef Documentation

Definition at line 43 of file StringRef.h.

Definition at line 42 of file StringRef.h.

Definition at line 45 of file StringRef.h.


Constructor & Destructor Documentation

Construct an empty string ref.

Definition at line 66 of file StringRef.h.

Referenced by drop_back(), and split().

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

Construct a string ref from a cstring.

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

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

Construct a string ref from an std::string.

Definition at line 83 of file StringRef.h.


Member Function Documentation

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

back - Get the last character in the string.

Definition at line 111 of file StringRef.h.

Referenced by llvm::ConstantDataSequential::isCString(), llvm::yaml::needsQuotes(), and parsePhysicalReg().

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

Definition at line 88 of file StringRef.h.

Referenced by llvm::sys::path::append(), llvm::SmallString< 256 >::assign(), llvm::MDString::begin(), llvm::APFloat::convertFromString(), llvm::ConvertUTF8toWide(), llvm::sys::fs::createTemporaryFile(), decodeUTF8(), llvm::MCObjectStreamer::EmitBytes(), llvm::TargetLoweringObjectFileELF::emitPersonalityValue(), llvm::yaml::escape(), fixupSubprogramName(), llvm::APInt::getBitsNeeded(), llvm::MemoryBufferRef::getBufferStart(), llvm::object::Archive::Symbol::getName(), llvm::StringToOffsetTable::GetOrAddStringOffset(), llvm::object::MachOObjectFile::getRelocationTypeName(), llvm::object::ELFFile< ELFT >::getRelocationTypeName(), llvm::object::COFFObjectFile::getRelocationTypeName(), llvm::object::ELFObjectFile< ELFT >::getRelocationValueString(), llvm::object::COFFObjectFile::getRelocationValueString(), llvm::ConstantDataArray::getString(), llvm::TargetLoweringObjectFile::getSymbolWithGlobalValueBase(), llvm::yaml::ScalarNode::getValue(), llvm::hash_value(), llvm::Timer::init(), isAllZeros(), isValidName(), llvm::LLLexer::LLLexer(), llvm::object::MachOUniversalBinary::MachOUniversalBinary(), llvm::sys::fs::make_absolute(), mangleCoveragePath(), llvm::object::MachOUniversalBinary::ObjectForArch::ObjectForArch(), llvm::object::Archive::Child::operator<(), llvm::sys::path::const_iterator::operator==(), llvm::object::Archive::Child::operator==(), llvm::sys::path::reverse_iterator::operator==(), llvm::opt::OptTable::OptTable(), llvm::DWARFDebugLoc::parse(), llvm::DWARFDebugLocDWO::parse(), llvm::InlineAsm::ConstraintInfo::Parse(), llvm::InlineAsm::ParseConstraints(), parseDouble(), parsePhysicalReg(), prependCompressionHeader(), printName(), llvm::sys::path::replace_extension(), llvm::yaml::ScalarNode::ScalarNode(), llvm::AsmLexer::setBuffer(), llvm::EngineBuilder::setMArch(), llvm::EngineBuilder::setMCPU(), llvm::TimerGroup::setName(), SimplifyCondBranchToCondBranch(), llvm::Regex::sub(), llvm::object::Archive::symbol_begin(), llvm::object::Archive::symbol_end(), llvm::TGLexer::TGLexer(), 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 137 of file StringRef.h.

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

compare_lower - Compare two strings, ignoring case.

compare_lower - Compare strings, ignoring case.

Definition at line 52 of file StringRef.cpp.

References ascii_strncasecmp().

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

compare_numeric - Compare strings, handle embedded numbers.

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

Definition at line 73 of file StringRef.cpp.

References ascii_isdigit(), and I.

template<typename Allocator >
StringRef llvm::StringRef::copy ( Allocator &  A) const [inline]

Definition at line 117 of file StringRef.h.

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

Return the number of occurrences of C in the string.

Definition at line 302 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 303 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 96 of file StringRef.h.

Referenced by llvm::SourceMgr::AddIncludeFile(), llvm::FoldingSetNodeID::AddString(), llvm::StringSwitch< T, R >::Case(), llvm::sys::unicode::columnWidthUTF8(), llvm::ConvertUTF8toWide(), CopyStringRef(), llvm::StringMapEntry< Comdat >::Create(), llvm::X86Operand::CreateToken(), decodeTestingFormat(), llvm::dumpBlock(), edit_distance(), llvm::RuntimeDyldImpl::emitCommonSymbols(), llvm::RuntimeDyldImpl::emitSection(), llvm::StringSwitch< T, R >::EndsWith(), llvm::cl::Option::error(), ExecGraphViewer(), llvm::DWARFFormValue::extractValue(), llvm::object::Archive::Child::getBuffer(), llvm::DataExtractor::getCStr(), llvm::AsmToken::getEndLoc(), llvm::MemoryBuffer::getFile(), llvm::object::MachOObjectFile::getIndirectName(), llvm::getInst(), llvm::AsmToken::getLoc(), llvm::MemoryBuffer::getMemBufferCopy(), llvm::opt::ArgList::GetOrMakeJoinedArgString(), getPtr(), llvm::RuntimeDyldMachO::getRelocationValueRef(), llvm::ConstantDataVector::getSplatValue(), 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(), LLVMGetAsString(), LLVMGetSectionContents(), LLVMGetSectionName(), LLVMGetStructName(), LLVMGetSymbolName(), llvm::RuntimeDyldImpl::loadObject(), llvm::Regex::match(), llvm::sys::path::native(), llvm::raw_ostream::operator<<(), llvm::cl::ParseCommandLineOptions(), llvm::opt::OptTable::ParseOneArg(), llvm::RuntimeDyldELF::processRelocationRef(), ProvideOption(), llvm::StringRefMemoryObject::readBytes(), readCoverageMappingData(), llvm::GCOVBuffer::readInt(), llvm::RawInstrProfReader< IntPtrT >::readNextRecord(), llvm::LessRecordRegister::RecordParts::RecordParts(), llvm::Regex::Regex(), replaceSubString(), llvm::report_fatal_error(), llvm::RuntimeDyldImpl::resolveExternalSymbols(), RewriteIntelBracExpression(), llvm::yaml::Output::scalarString(), llvm::X86Operand::setTokenValue(), split(), llvm::StringSwitch< T, R >::StartsWith(), 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 388 of file StringRef.h.

References N, and StringRef().

Referenced by llvm::ConstantDataSequential::isCString().

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

Referenced by CompressDebugSection(), llvm::yaml::isNumber(), llvm::yaml::isNumeric(), and MatchCoprocessorOperandName().

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 104 of file StringRef.cpp.

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

Referenced by LookupNearestOption().

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

empty - Check if the string is empty.

Definition at line 99 of file StringRef.h.

Referenced by llvm::SubtargetFeatures::AddFeature(), llvm::DwarfUnit::applySubprogramAttributes(), llvm::DwarfUnit::applyVariableAttributes(), llvm::ConstantFoldLoadFromConstPtr(), llvm::DwarfUnit::constructTypeDIE(), llvm::APFloat::convertFromString(), llvm::SpecialCaseList::create(), llvm::StructType::create(), llvm::sys::fs::create_directories(), createAArch64MCSubtargetInfo(), llvm::MDBuilder::createAnonymousAARoot(), llvm::ARM_MC::createARMMCSubtargetInfo(), llvm::DIBuilder::createBasicType(), llvm::DIBuilder::createClassType(), llvm::DIBuilder::createCompileUnit(), llvm::DIBuilder::createEnumerationType(), llvm::DIBuilder::createEnumerator(), createFilePathPair(), llvm::DIBuilder::createForwardDecl(), createImportedModule(), llvm::DIBuilder::createReplaceableForwardDecl(), createSparcMCSubtargetInfo(), llvm::DIBuilder::createStructType(), llvm::sys::fs::createTemporaryFile(), llvm::DIBuilder::createUnionType(), llvm::DIBuilder::createUnspecifiedType(), llvm::X86_MC::createX86MCSubtargetInfo(), decodeBase64StringEntry(), llvm::DISubprogram::describes(), EatNumber(), emitComments(), emitDebugValueComment(), EmitGenDwarfAbbrev(), EmitGenDwarfInfo(), llvm::TargetLoweringObjectFileMachO::emitModuleFlags(), llvm::cl::Option::error(), llvm::DWARFFormValue::extractValue(), FoldBlockIntoPredecessor(), llvm::Attribute::get(), llvm::Triple::getARMCPUForArch(), getAsInteger(), llvm::getAsSignedInteger(), llvm::Attribute::getAsString(), llvm::getAsUnsignedInteger(), llvm::APInt::getBitsNeeded(), llvm::MCContext::getCOFFSection(), llvm::DOTGraphTraits< const Function * >::getCompleteNodeLabel(), getELFKindForNamedSection(), llvm::MCContext::getELFSection(), llvm::SubtargetFeatures::getFeatureBits(), llvm::MCDwarfLineTableHeader::getFile(), getFunctionName(), getItineraryLatency(), llvm::TargetLibraryInfo::getLibFunc(), llvm::object::MachOObjectFile::getLibraryShortNameByIndex(), getMemcpyLoadsAndStores(), getMemsetStringVal(), getNameWithPrefixx(), llvm::DwarfCompileUnit::getOrCreateGlobalVariableDIE(), llvm::DwarfUnit::getOrCreateNameSpace(), llvm::MCContext::GetOrCreateSymbol(), llvm::Triple::getOSVersion(), llvm::DwarfUnit::getParentContextString(), llvm::GlobalValue::getRealLinkageName(), llvm::DOTGraphTraits< const Function * >::getSimpleNodeLabel(), llvm::DataExtractor::getSLEB128(), GetSymbolFromOperand(), llvm::TargetLoweringObjectFile::getSymbolWithGlobalValueBase(), llvm::DataExtractor::getULEB128(), llvm::WinEH::getUnwindInfoSection(), 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::GlobalObject::hasSection(), llvm::GlobalValue::hasSection(), llvm::TypePrinting::incorporateTypes(), llvm::MCSubtargetInfo::InitCPUSchedModel(), llvm::NVPTXSubtarget::initializeSubtargetDependencies(), llvm::StringSet< AllocatorTy >::insert(), isEnabled(), isRepeatedByteSequence(), isValidName(), llvm::LoadAndStorePromoter::LoadAndStorePromoter(), LookupNearestOption(), LookupOption(), NameNeedsQuoting(), llvm::yaml::needsQuotes(), llvm::Triple::normalize(), llvm::ARM_MC::ParseARMTriple(), llvm::cl::ParseCommandLineOptions(), llvm::MCSectionMachO::ParseSectionSpecifier(), llvm::TypePrinting::print(), llvm::MCInstPrinter::printAnnotation(), llvm::DIVariable::printExtendedName(), llvm::DIType::printInternal(), PrintLLVMName(), llvm::AssemblyWriter::printNamedMDNode(), llvm::AttributeImpl::Profile(), llvm::GCOVBuffer::readArcTag(), llvm::GCOVBuffer::readBlockTag(), readCoverageMappingData(), llvm::GCOVBuffer::readEdgeTag(), llvm::GCOVBuffer::readFunctionTag(), llvm::GCOVBuffer::readLineTag(), llvm::TextInstrProfReader::readNextRecord(), llvm::GCOVBuffer::readObjectTag(), llvm::GCOVBuffer::readProgramTag(), llvm::LessRecordRegister::RecordParts::RecordParts(), llvm::yaml::Output::scalarString(), llvm::FastISel::selectInstruction(), selectMipsCPU(), llvm::EngineBuilder::selectTarget(), llvm::Module::setDataLayout(), llvm::Value::setName(), llvm::StructType::setName(), split(), StripTypeNames(), llvm::Regex::sub(), llvm::InlineAsm::Verify(), WriteAttributeGroupTable(), and WriteTypeTable().

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

Definition at line 90 of file StringRef.h.

Referenced by llvm::sys::path::append(), llvm::SmallString< 256 >::assign(), llvm::ConvertUTF8toWide(), decodeUTF8(), llvm::MCObjectStreamer::EmitBytes(), llvm::TargetLoweringObjectFileELF::emitPersonalityValue(), llvm::MDString::end(), endswith_lower(), llvm::yaml::escape(), fixupSubprogramName(), llvm::MemoryBufferRef::getBufferEnd(), llvm::StringToOffsetTable::GetOrAddStringOffset(), llvm::object::MachOObjectFile::getRelocationTypeName(), llvm::object::ELFFile< ELFT >::getRelocationTypeName(), llvm::object::COFFObjectFile::getRelocationTypeName(), llvm::object::ELFObjectFile< ELFT >::getRelocationValueString(), llvm::object::COFFObjectFile::getRelocationValueString(), llvm::ConstantDataArray::getString(), llvm::TargetLoweringObjectFile::getSymbolWithGlobalValueBase(), llvm::yaml::ScalarNode::getValue(), llvm::hash_value(), llvm::Timer::init(), isAllZeros(), isValidName(), llvm::AsmLexer::LexUntilEndOfLine(), llvm::AsmLexer::LexUntilEndOfStatement(), llvm::sys::fs::make_absolute(), mangleCoveragePath(), llvm::opt::OptTable::OptTable(), llvm::DWARFDebugLoc::parse(), llvm::DWARFDebugLocDWO::parse(), llvm::InlineAsm::ConstraintInfo::Parse(), llvm::InlineAsm::ParseConstraints(), parseDouble(), parsePhysicalReg(), prependCompressionHeader(), printName(), llvm::Regex::Regex(), llvm::sys::path::replace_extension(), llvm::yaml::ScalarNode::ScalarNode(), llvm::EngineBuilder::setMArch(), llvm::EngineBuilder::setMCPU(), llvm::TimerGroup::setName(), llvm::Regex::sub(), WriteAttributeGroupTable(), and WriteModuleMetadataStore().

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

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

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

Referenced by count(), llvm::SmallString< 256 >::equals_lower(), find(), GetUnrollMetadata(), llvm::yaml::isBool(), llvm::yaml::isNull(), llvm::yaml::isNumber(), llvm::yaml::isNumeric(), isPageZeroSegment(), llvm::object::ExportEntry::operator==(), llvm::operator==(), and rfind().

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

equals_lower - Check for string equality, ignoring case.

Definition at line 131 of file StringRef.h.

Referenced by llvm::SmallString< 256 >::compare(), 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 142 of file StringRef.cpp.

References equals(), llvm::LibFunc::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 212 of file StringRef.cpp.

References npos.

Referenced by llvm::DWARFContextInMemory::DWARFContextInMemory(), llvm::SmallString< 256 >::find_first_not_of(), llvm::SmallString< 256 >::find_last_of(), llvm::getToken(), llvm::yaml::isNumber(), llvm::yaml::needsQuotes(), printName(), 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 223 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 198 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 253 of file StringRef.cpp.

References npos.

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 264 of file StringRef.cpp.

References npos, and size().

size_t llvm::StringRef::find_last_of ( char  C,
size_t  From = npos 
) const [inline]
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 239 of file StringRef.cpp.

References npos, and size().

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

front - Get the first character in the string.

Definition at line 105 of file StringRef.h.

Referenced by getAsInteger(), llvm::getAsSignedInteger(), llvm::TargetLibraryInfo::getLibFunc(), llvm::yaml::isNumeric(), llvm::yaml::needsQuotes(), and parsePhysicalReg().

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.

Definition at line 323 of file StringRef.h.

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

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

Definition at line 334 of file StringRef.h.

References llvm::getAsSignedInteger().

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

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

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

Definition at line 191 of file StringRef.h.

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

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

Referenced by llvm::SmallString< 256 >::find_first_of(), llvm::object::MachOObjectFile::guessLibraryShortName(), llvm::SmallString< 256 >::rfind(), and rtrim().

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

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

References npos, and rfind().

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

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

size - Get the string size.

Definition at line 102 of file StringRef.h.

Referenced by llvm::FoldingSetNodeID::AddString(), llvm::StringSwitch< T, R >::Case(), llvm::RuntimeDyldCheckerImpl::checkAllRulesInBuffer(), llvm::sys::locale::columnWidth(), llvm::sys::unicode::columnWidthUTF8(), compareBySuffix(), llvm::ConstantFoldLoadFromConstPtr(), llvm::APFloat::convertFromString(), llvm::ConvertUTF8toWide(), CopyStringRef(), count(), llvm::StringMapEntry< Comdat >::Create(), llvm::X86Operand::CreateToken(), decodeBase64StringEntry(), decodeTestingFormat(), dumpPubSection(), edit_distance(), llvm::object::elf_hash(), llvm::object::ELFFile< ELFT >::ELFFile(), llvm::emitSourceFileHeader(), llvm::sys::path::end(), llvm::StringSwitch< T, R >::EndsWith(), llvm::Regex::escape(), llvm::sys::path::extension(), 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::MemoryBufferRef::getBufferSize(), llvm::object::getElfArchType(), llvm::AsmToken::getEndLoc(), llvm::StringRefMemoryObject::getExtent(), llvm::object::MachOObjectFile::getIndirectName(), GetLazyPtr(), llvm::MDString::getLength(), llvm::object::MachOObjectFile::getLibraryShortNameByIndex(), 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::ConstantDataArray::getString(), llvm::AsmToken::getStringContents(), GetStringLengthH(), llvm::DWARFUnit::getStringOffsetSectionItem(), llvm::object::ELFFile< ELFT >::getSymbolVersion(), getUnicodeEncoding(), llvm::yaml::ScalarNode::getValue(), llvm::object::MachOObjectFile::guessLibraryShortName(), HandlePrefixedOrGroupedOption(), llvm::HashString(), llvm::sys::fs::identify_magic(), llvm::ExecutionEngine::InitializeMemory(), llvm::NVPTXSubtarget::initializeSubtargetDependencies(), isRepeatedByteSequence(), llvm::DataExtractor::isValidOffset(), llvm::join_impl(), LLVMGetAsString(), lower(), llvm::object::MachOUniversalBinary::MachOUniversalBinary(), llvm::MCGenDwarfLabelEntry::Make(), llvm::opt::DerivedArgList::MakeJoinedArg(), llvm::Regex::match(), MatchCoprocessorOperandName(), matchOption(), NameNeedsQuoting(), llvm::object::MachOUniversalBinary::ObjectForArch::ObjectForArch(), llvm::raw_ostream::operator<<(), llvm::DWARFDebugLoc::parse(), llvm::DWARFDebugLocDWO::parse(), parseBackslash(), llvm::cl::ParseCommandLineOptions(), parseSectionFlags(), llvm::MCSectionMachO::ParseSectionSpecifier(), prependCompressionHeader(), llvm::MCSymbol::print(), PrintEscapedString(), PrintHelpOptionList(), printLine(), PrintLLVMName(), llvm::AssemblyWriter::printNamedMDNode(), PrintQuotedString(), printSourceLine(), llvm::RandomNumberGenerator::RandomNumberGenerator(), llvm::sys::path::rbegin(), readCoverageMappingData(), llvm::GCOVBuffer::readInt(), llvm::RawInstrProfReader< IntPtrT >::readNextRecord(), llvm::GCOVBuffer::readString(), llvm::LessRecordRegister::RecordParts::RecordParts(), llvm::sys::path::relative_path(), llvm::sys::path::replace_extension(), replaceSubString(), llvm::report_fatal_error(), RequiresVFPRegListValidation(), llvm::RuntimeDyldImpl::resolveExternalSymbols(), RewriteIntelBracExpression(), rfind(), llvm::yaml::Output::scalarString(), llvm::TargetLoweringObjectFileELF::SelectSectionForGlobal(), llvm::StructType::setName(), llvm::X86Operand::setTokenValue(), slice(), split(), llvm::StringSwitch< T, R >::StartsWith(), llvm::sys::path::stem(), llvm::StrInStrNoCase(), llvm::Regex::sub(), llvm::cl::TokenizeGNUCommandLine(), llvm::cl::TokenizeWindowsCommandLine(), llvm::MD5::update(), UpgradeIntrinsicFunction1(), upper(), llvm::raw_ostream::write_escaped(), 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 403 of file StringRef.h.

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

Referenced by llvm::SmallString< 256 >::c_str(), llvm::object::ObjectFile::createMachOObjectFile(), llvm::emitSourceFileHeader(), getObjCClassCategory(), getObjCMethodName(), llvm::AsmToken::getStringContents(), llvm::getToken(), llvm::object::MachOObjectFile::guessLibraryShortName(), llvm::GCOVBuffer::readArcTag(), llvm::GCOVBuffer::readBlockTag(), llvm::GCOVBuffer::readEdgeTag(), llvm::GCOVBuffer::readFunctionTag(), llvm::GCOVBuffer::readGCDAFormat(), llvm::GCOVBuffer::readGCNOFormat(), llvm::GCOVBuffer::readGCOVVersion(), llvm::GCOVBuffer::readInt(), llvm::GCOVBuffer::readLineTag(), llvm::GCOVBuffer::readObjectTag(), llvm::GCOVBuffer::readProgramTag(), llvm::GCOVBuffer::readString(), 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 419 of file StringRef.h.

References 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(), printHelpStr(), llvm::GCOVBuffer::readString(), Split(), split(), split(), llvm::Regex::sub(), and GraphSession::TryFindProgram().

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

References find(), npos, 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 276 of file StringRef.cpp.

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

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

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

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

Referenced by llvm::SubtargetFeatures::AddFeature(), llvm::DwarfUnit::addGlobalName(), llvm::Record::addTemplateArg(), cacheAnnotationFromMD(), llvm::ARM_MC::createARMMCSubtargetInfo(), llvm::X86_MC::createX86MCSubtargetInfo(), ExecGraphViewer(), llvm::Attribute::getAsString(), llvm::bfi_detail::getBlockName(), llvm::DOTGraphTraits< const Function * >::getGraphName(), llvm::DOTGraphTraits< const MachineFunction * >::getGraphName(), llvm::MCSectionCOFF::getLabelBeginName(), llvm::MCSectionELF::getLabelBeginName(), llvm::MCSectionCOFF::getLabelEndName(), llvm::MCSectionELF::getLabelEndName(), llvm::DOTGraphTraits< BlockFrequencyInfo * >::getNodeLabel(), llvm::DOTGraphTraits< MachineBlockFrequencyInfo * >::getNodeLabel(), llvm::DOTGraphTraits< const Function * >::getSimpleNodeLabel(), llvm::MipsTargetMachine::getSubtargetImpl(), llvm::Record::getValueAsBitOrUnset(), INITIALIZE_PASS(), llvm::Record::isTemplateArg(), llvm::LockFileManager::LockFileManager(), lookupFunction(), LookupNearestOption(), llvm::opt::DerivedArgList::MakeJoinedArg(), mangleCoveragePath(), llvm::cl::parser< std::string >::parse(), llvm::AArch64InstPrinter::printSystemPStateField(), llvm::Record::removeValue(), llvm::sys::fs::directory_entry::replace_filename(), llvm::DOTGraphTraitsViewer< AnalysisT, IsSimple, GraphT, AnalysisGraphTraitsT >::runOnFunction(), llvm::DOTGraphTraitsPrinter< AnalysisT, IsSimple, GraphT, AnalysisGraphTraitsT >::runOnFunction(), llvm::MCContext::setCompilationDir(), llvm::MCParsedAsmOperand::setConstraint(), startswith(), llvm::Twine::str(), llvm::Regex::sub(), llvm::UpgradeIntrinsicCall(), usedInGlobalVarDef(), 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 374 of file StringRef.h.

Referenced by llvm::RuntimeDyldCheckerImpl::checkAllRulesInBuffer(), llvm::object::Archive::Child::Child(), CommaSeparateAndAddOccurrence(), consumeCompressedDebugSectionHeader(), count(), decodeBase64StringEntry(), decodeTestingFormat(), llvm::DWARFContextInMemory::DWARFContextInMemory(), EatNumber(), emitComments(), llvm::RuntimeDyldCheckerExprEval::evaluate(), llvm::sys::path::extension(), llvm::DWARFFormValue::extractValue(), find(), llvm::SimplifyFortifiedLibCalls::fold(), llvm::Triple::getARMCPUForArch(), llvm::object::MachOUniversalBinary::ObjectForArch::getAsArchive(), llvm::ConstantDataSequential::getAsCString(), getAsInteger(), llvm::object::MachOUniversalBinary::ObjectForArch::getAsObjectFile(), llvm::getAsSignedInteger(), llvm::getAsUnsignedInteger(), GetAutoSenseRadix(), llvm::getConstantStringInfo(), llvm::TargetLoweringObjectFileMachO::getDepLibFromLinkerOpt(), llvm::TargetLoweringObjectFileCOFF::getDepLibFromLinkerOpt(), GetLazyPtr(), llvm::TargetLibraryInfo::getLibFunc(), getMemcpyLoadsAndStores(), llvm::object::Archive::Child::getName(), getNameWithPrefixx(), getOptionPred(), llvm::Triple::getOSVersion(), getPtr(), llvm::GlobalValue::getRealLinkageName(), llvm::object::MachOObjectFile::getSectionContents(), llvm::WinEH::getSectionSuffix(), llvm::object::MachOObjectFile::getStringTableData(), GetSymbolFromOperand(), llvm::object::ELFFile< ELFT >::getSymbolVersion(), llvm::getToken(), llvm::yaml::ScalarNode::getValue(), llvm::yaml::Node::getVerbatimTag(), HandlePrefixedOrGroupedOption(), LookupOption(), llvm::MCGenDwarfLabelEntry::Make(), matchOption(), llvm::sys::path::parent_path(), llvm::DWARFDebugLoc::parse(), llvm::DWARFDebugLocDWO::parse(), llvm::yaml::Document::parseBlockNode(), llvm::cl::ParseCommandLineOptions(), llvm::coverage::RawCoverageReader::readString(), llvm::sys::path::relative_path(), llvm::sys::path::rend(), RequiresVFPRegListValidation(), rfind(), llvm::sys::path::root_path(), llvm::SmallString< 256 >::slice(), slice(), llvm::sys::path::stem(), llvm::StrInStrNoCase(), StripFlag(), llvm::Regex::sub(), 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 492 of file StringRef.h.

Referenced by llvm::RuntimeDyldCheckerImpl::check(), and llvm::RuntimeDyldCheckerExprEval::evaluate().

std::string StringRef::upper ( ) const

Convert the given ASCII string to uppercase.

Definition at line 125 of file StringRef.cpp.

References ascii_toupper(), and size().

Referenced by llvm::AArch64InstPrinter::printMRSSystemRegister(), and llvm::AArch64InstPrinter::printMSRSystemRegister().


Member Data Documentation

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

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