本文整理汇总了C++中StringRef::drop_front方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::drop_front方法的具体用法?C++ StringRef::drop_front怎么用?C++ StringRef::drop_front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRef
的用法示例。
在下文中一共展示了StringRef::drop_front方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
std::unique_ptr<Directive> Directive::create(bool RegexKind,
SourceLocation DirectiveLoc,
SourceLocation DiagnosticLoc,
bool MatchAnyLine, StringRef Text,
unsigned Min, unsigned Max) {
if (!RegexKind)
return llvm::make_unique<StandardDirective>(DirectiveLoc, DiagnosticLoc,
MatchAnyLine, Text, Min, Max);
// Parse the directive into a regular expression.
std::string RegexStr;
StringRef S = Text;
while (!S.empty()) {
if (S.startswith("{{")) {
S = S.drop_front(2);
size_t RegexMatchLength = S.find("}}");
assert(RegexMatchLength != StringRef::npos);
// Append the regex, enclosed in parentheses.
RegexStr += "(";
RegexStr.append(S.data(), RegexMatchLength);
RegexStr += ")";
S = S.drop_front(RegexMatchLength + 2);
} else {
size_t VerbatimMatchLength = S.find("{{");
if (VerbatimMatchLength == StringRef::npos)
VerbatimMatchLength = S.size();
// Escape and append the fixed string.
RegexStr += llvm::Regex::escape(S.substr(0, VerbatimMatchLength));
S = S.drop_front(VerbatimMatchLength);
}
}
return llvm::make_unique<RegexDirective>(
DirectiveLoc, DiagnosticLoc, MatchAnyLine, Text, Min, Max, RegexStr);
}
示例2: make_error_code
ErrorOr<StringRef> ELFLinkingContext::searchLibrary(StringRef libName) const {
bool hasColonPrefix = libName[0] == ':';
SmallString<128> path;
for (StringRef dir : _inputSearchPaths) {
// Search for dynamic library
if (!_isStaticExecutable) {
buildSearchPath(path, dir, _sysrootPath);
llvm::sys::path::append(path, hasColonPrefix
? libName.drop_front()
: Twine("lib", libName) + ".so");
if (exists(path.str()))
return path.str().copy(_allocator);
}
// Search for static libraries too
buildSearchPath(path, dir, _sysrootPath);
llvm::sys::path::append(path, hasColonPrefix
? libName.drop_front()
: Twine("lib", libName) + ".a");
if (exists(path.str()))
return path.str().copy(_allocator);
}
if (hasColonPrefix && exists(libName.drop_front()))
return libName.drop_front();
return make_error_code(llvm::errc::no_such_file_or_directory);
}
示例3: assert
Optional<ReplacementItem>
formatv_object_base::parseReplacementItem(StringRef Spec) {
StringRef RepString = Spec.trim("{}");
// If the replacement sequence does not start with a non-negative integer,
// this is an error.
char Pad = ' ';
std::size_t Align = 0;
AlignStyle Where = AlignStyle::Right;
StringRef Options;
size_t Index = 0;
RepString = RepString.trim();
if (RepString.consumeInteger(0, Index)) {
assert(false && "Invalid replacement sequence index!");
return ReplacementItem{};
}
RepString = RepString.trim();
if (!RepString.empty() && RepString.front() == ',') {
RepString = RepString.drop_front();
if (!consumeFieldLayout(RepString, Where, Align, Pad))
assert(false && "Invalid replacement field layout specification!");
}
RepString = RepString.trim();
if (!RepString.empty() && RepString.front() == ':') {
Options = RepString.drop_front().trim();
RepString = StringRef();
}
RepString = RepString.trim();
if (!RepString.empty()) {
assert(false && "Unexpected characters found in replacement string!");
}
return ReplacementItem{Spec, Index, Align, Where, Pad, Options};
}
示例4: consumeFieldLayout
bool formatv_object_base::consumeFieldLayout(StringRef &Spec, AlignStyle &Where,
size_t &Align, char &Pad) {
Where = AlignStyle::Right;
Align = 0;
Pad = ' ';
if (Spec.empty())
return true;
if (Spec.size() > 1) {
// A maximum of 2 characters at the beginning can be used for something
// other
// than the width.
// If Spec[1] is a loc char, then Spec[0] is a pad char and Spec[2:...]
// contains the width.
// Otherwise, if Spec[0] is a loc char, then Spec[1:...] contains the width.
// Otherwise, Spec[0:...] contains the width.
if (auto Loc = translateLocChar(Spec[1])) {
Pad = Spec[0];
Where = *Loc;
Spec = Spec.drop_front(2);
} else if (auto Loc = translateLocChar(Spec[0])) {
Where = *Loc;
Spec = Spec.drop_front(1);
}
}
bool Failed = Spec.consumeInteger(0, Align);
return !Failed;
}
示例5: make_pair
std::pair<ReplacementItem, StringRef>
formatv_object_base::splitLiteralAndReplacement(StringRef Fmt) {
std::size_t From = 0;
while (From < Fmt.size() && From != StringRef::npos) {
std::size_t BO = Fmt.find_first_of('{', From);
// Everything up until the first brace is a literal.
if (BO != 0)
return std::make_pair(ReplacementItem{Fmt.substr(0, BO)}, Fmt.substr(BO));
StringRef Braces =
Fmt.drop_front(BO).take_while([](char C) { return C == '{'; });
// If there is more than one brace, then some of them are escaped. Treat
// these as replacements.
if (Braces.size() > 1) {
size_t NumEscapedBraces = Braces.size() / 2;
StringRef Middle = Fmt.substr(BO, NumEscapedBraces);
StringRef Right = Fmt.drop_front(BO + NumEscapedBraces * 2);
return std::make_pair(ReplacementItem{Middle}, Right);
}
// An unterminated open brace is undefined. We treat the rest of the string
// as a literal replacement, but we assert to indicate that this is
// undefined and that we consider it an error.
std::size_t BC = Fmt.find_first_of('}', BO);
if (BC == StringRef::npos) {
assert(
false &&
"Unterminated brace sequence. Escape with {{ for a literal brace.");
return std::make_pair(ReplacementItem{Fmt}, StringRef());
}
// Even if there is a closing brace, if there is another open brace before
// this closing brace, treat this portion as literal, and try again with the
// next one.
std::size_t BO2 = Fmt.find_first_of('{', BO + 1);
if (BO2 < BC)
return std::make_pair(ReplacementItem{Fmt.substr(0, BO2)},
Fmt.substr(BO2));
StringRef Spec = Fmt.slice(BO + 1, BC);
StringRef Right = Fmt.substr(BC + 1);
auto RI = parseReplacementItem(Spec);
if (RI.hasValue())
return std::make_pair(*RI, Right);
// If there was an error parsing the replacement item, treat it as an
// invalid replacement spec, and just continue.
From = BC + 1;
}
return std::make_pair(ReplacementItem{Fmt}, StringRef());
}
示例6: consumeSignedInteger
bool llvm::consumeSignedInteger(StringRef &Str, unsigned Radix,
long long &Result) {
unsigned long long ULLVal;
// Handle positive strings first.
if (Str.empty() || Str.front() != '-') {
if (consumeUnsignedInteger(Str, Radix, ULLVal) ||
// Check for value so large it overflows a signed value.
(long long)ULLVal < 0)
return true;
Result = ULLVal;
return false;
}
// Get the positive part of the value.
StringRef Str2 = Str.drop_front(1);
if (consumeUnsignedInteger(Str2, Radix, ULLVal) ||
// Reject values so large they'd overflow as negative signed, but allow
// "-0". This negates the unsigned so that the negative isn't undefined
// on signed overflow.
(long long)-ULLVal > 0)
return true;
Str = Str2;
Result = -ULLVal;
return false;
}
示例7: printSymbolVersionDefinition
void printSymbolVersionDefinition(const typename ELFT::Shdr &Shdr,
ArrayRef<uint8_t> Contents,
StringRef StrTab) {
outs() << "Version definitions:\n";
const uint8_t *Buf = Contents.data();
uint32_t VerdefIndex = 1;
// sh_info contains the number of entries in the SHT_GNU_verdef section. To
// make the index column have consistent width, we should insert blank spaces
// according to sh_info.
uint16_t VerdefIndexWidth = std::to_string(Shdr.sh_info).size();
while (Buf) {
auto *Verdef = reinterpret_cast<const typename ELFT::Verdef *>(Buf);
outs() << format_decimal(VerdefIndex++, VerdefIndexWidth) << " "
<< format("0x%02" PRIx16 " ", (uint16_t)Verdef->vd_flags)
<< format("0x%08" PRIx32 " ", (uint32_t)Verdef->vd_hash);
const uint8_t *BufAux = Buf + Verdef->vd_aux;
uint16_t VerdauxIndex = 0;
while (BufAux) {
auto *Verdaux = reinterpret_cast<const typename ELFT::Verdaux *>(BufAux);
if (VerdauxIndex)
outs() << std::string(VerdefIndexWidth + 17, ' ');
outs() << StringRef(StrTab.drop_front(Verdaux->vda_name).data()) << '\n';
BufAux = Verdaux->vda_next ? BufAux + Verdaux->vda_next : nullptr;
++VerdauxIndex;
}
Buf = Verdef->vd_next ? Buf + Verdef->vd_next : nullptr;
}
}
示例8: matchesStyle
static bool matchesStyle(StringRef Name,
IdentifierNamingCheck::NamingStyle Style) {
static llvm::Regex Matchers[] = {
llvm::Regex("^.*$"),
llvm::Regex("^[a-z][a-z0-9_]*$"),
llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
llvm::Regex("^[A-Z][A-Z0-9_]*$"),
llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
};
bool Matches = true;
if (Name.startswith(Style.Prefix))
Name = Name.drop_front(Style.Prefix.size());
else
Matches = false;
if (Name.endswith(Style.Suffix))
Name = Name.drop_back(Style.Suffix.size());
else
Matches = false;
// Ensure the name doesn't have any extra underscores beyond those specified
// in the prefix and suffix.
if (Name.startswith("_") || Name.endswith("_"))
Matches = false;
if (Style.Case && !Matchers[static_cast<size_t>(*Style.Case)].match(Name))
Matches = false;
return Matches;
}
示例9: OS
void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {
SmallString<128> Directive;
raw_svector_ostream OS(Directive);
StringRef Name = Sym->getName();
const Triple &TT = TM.getTargetTriple();
if (TT.isKnownWindowsMSVCEnvironment())
OS << " /EXPORT:";
else
OS << " -export:";
if ((TT.isWindowsGNUEnvironment() || TT.isWindowsCygwinEnvironment()) &&
(Name[0] == getDataLayout().getGlobalPrefix()))
Name = Name.drop_front();
OS << Name;
if (IsData) {
if (TT.isKnownWindowsMSVCEnvironment())
OS << ",DATA";
else
OS << ",data";
}
OS.flush();
OutStreamer->EmitBytes(Directive);
}
示例10: matchesStyle
static bool matchesStyle(StringRef Name,
IdentifierNamingCheck::NamingStyle Style) {
static llvm::Regex Matchers[] = {
llvm::Regex("^.*$"),
llvm::Regex("^[a-z][a-z0-9_]*$"),
llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
llvm::Regex("^[A-Z][A-Z0-9_]*$"),
llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
};
bool Matches = true;
if (Name.startswith(Style.Prefix))
Name = Name.drop_front(Style.Prefix.size());
else
Matches = false;
if (Name.endswith(Style.Suffix))
Name = Name.drop_back(Style.Suffix.size());
else
Matches = false;
if (!Matchers[static_cast<size_t>(Style.Case)].match(Name))
Matches = false;
return Matches;
}
示例11: OS
void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {
SmallString<128> Directive;
raw_svector_ostream OS(Directive);
StringRef Name = Sym->getName();
if (Subtarget->isTargetKnownWindowsMSVC())
OS << " /EXPORT:";
else
OS << " -export:";
if ((Subtarget->isTargetWindowsGNU() || Subtarget->isTargetWindowsCygwin()) &&
(Name[0] == getDataLayout().getGlobalPrefix()))
Name = Name.drop_front();
OS << Name;
if (IsData) {
if (Subtarget->isTargetKnownWindowsMSVC())
OS << ",DATA";
else
OS << ",data";
}
OS.flush();
OutStreamer.EmitBytes(Directive);
}
示例12: FindCheckType
static Check::CheckType FindCheckType(StringRef Buffer, StringRef Prefix) {
char NextChar = Buffer[Prefix.size()];
// Verify that the : is present after the prefix.
if (NextChar == ':')
return Check::CheckPlain;
if (NextChar != '-')
return Check::CheckNone;
StringRef Rest = Buffer.drop_front(Prefix.size() + 1);
if (Rest.startswith("NEXT:"))
return Check::CheckNext;
if (Rest.startswith("SAME:"))
return Check::CheckSame;
if (Rest.startswith("NOT:"))
return Check::CheckNot;
if (Rest.startswith("DAG:"))
return Check::CheckDAG;
if (Rest.startswith("LABEL:"))
return Check::CheckLabel;
return Check::CheckNone;
}
示例13: inferVar
IAMResult IAMInference::inferVar(const clang::VarDecl *varDecl) {
auto fail = [varDecl]() -> IAMResult {
DEBUG(llvm::dbgs() << "failed to infer variable: ");
DEBUG(varDecl->print(llvm::dbgs()));
DEBUG(llvm::dbgs() << "\n");
++FailInferVar;
return {};
};
// Try to find a type to add this as a static property to
StringRef workingName = varDecl->getName();
if (workingName.empty())
return fail();
// Special pattern: constants of the form "kFooBarBaz", extend "FooBar" with
// property "Baz"
if (*camel_case::getWords(workingName).begin() == "k")
workingName = workingName.drop_front(1);
NameBuffer remainingName;
if (auto effectiveDC = findTypeAndMatch(workingName, remainingName))
return importAsStaticProperty(remainingName, effectiveDC);
return fail();
}
示例14: stripPrefix
static bool stripPrefix(StringRef &string, const char (&data)[N]) {
constexpr size_t prefixLength = N - 1;
if (!string.startswith(StringRef(data, prefixLength)))
return false;
string = string.drop_front(prefixLength);
return true;
}
示例15: FindFirstCandidateMatch
// Try to find the first match in buffer for any prefix. If a valid match is
// found, return that prefix and set its type and location. If there are almost
// matches (e.g. the actual prefix string is found, but is not an actual check
// string), but no valid match, return an empty string and set the position to
// resume searching from. If no partial matches are found, return an empty
// string and the location will be StringRef::npos. If one prefix is a substring
// of another, the maximal match should be found. e.g. if "A" and "AA" are
// prefixes then AA-CHECK: should match the second one.
static StringRef FindFirstCandidateMatch(StringRef &Buffer,
Check::CheckType &CheckTy,
size_t &CheckLoc) {
StringRef FirstPrefix;
size_t FirstLoc = StringRef::npos;
size_t SearchLoc = StringRef::npos;
Check::CheckType FirstTy = Check::CheckNone;
CheckTy = Check::CheckNone;
CheckLoc = StringRef::npos;
for (prefix_iterator I = CheckPrefixes.begin(), E = CheckPrefixes.end();
I != E; ++I) {
StringRef Prefix(*I);
size_t PrefixLoc = Buffer.find(Prefix);
if (PrefixLoc == StringRef::npos)
continue;
// Track where we are searching for invalid prefixes that look almost right.
// We need to only advance to the first partial match on the next attempt
// since a partial match could be a substring of a later, valid prefix.
// Need to skip to the end of the word, otherwise we could end up
// matching a prefix in a substring later.
if (PrefixLoc < SearchLoc)
SearchLoc = SkipWord(Buffer, PrefixLoc);
// We only want to find the first match to avoid skipping some.
if (PrefixLoc > FirstLoc)
continue;
// If one matching check-prefix is a prefix of another, choose the
// longer one.
if (PrefixLoc == FirstLoc && Prefix.size() < FirstPrefix.size())
continue;
StringRef Rest = Buffer.drop_front(PrefixLoc);
// Make sure we have actually found the prefix, and not a word containing
// it. This should also prevent matching the wrong prefix when one is a
// substring of another.
if (PrefixLoc != 0 && IsPartOfWord(Buffer[PrefixLoc - 1]))
FirstTy = Check::CheckNone;
else
FirstTy = FindCheckType(Rest, Prefix);
FirstLoc = PrefixLoc;
FirstPrefix = Prefix;
}
// If the first prefix is invalid, we should continue the search after it.
if (FirstTy == Check::CheckNone) {
CheckLoc = SearchLoc;
return "";
}
CheckTy = FirstTy;
CheckLoc = FirstLoc;
return FirstPrefix;
}