当前位置: 首页>>代码示例>>C++>>正文


C++ StringRef::rfind方法代码示例

本文整理汇总了C++中StringRef::rfind方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::rfind方法的具体用法?C++ StringRef::rfind怎么用?C++ StringRef::rfind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringRef的用法示例。


在下文中一共展示了StringRef::rfind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ParseProgName

static void ParseProgName(SmallVectorImpl<const char *> &ArgVector,
                          std::set<std::string> &SavedStrings) {
  // Try to infer frontend type and default target from the program name by
  // comparing it against DriverSuffixes in order.

  // If there is a match, the function tries to identify a target as prefix.
  // E.g. "x86_64-linux-clang" as interpreted as suffix "clang" with target
  // prefix "x86_64-linux". If such a target prefix is found, is gets added via
  // -target as implicit first argument.

  std::string ProgName =llvm::sys::path::stem(ArgVector[0]);
#ifdef LLVM_ON_WIN32
  // Transform to lowercase for case insensitive file systems.
  ProgName = StringRef(ProgName).lower();
#endif

  StringRef ProgNameRef = ProgName;
  const DriverSuffix *DS = FindDriverSuffix(ProgNameRef);

  if (!DS) {
    // Try again after stripping any trailing version number:
    // clang++3.5 -> clang++
    ProgNameRef = ProgNameRef.rtrim("0123456789.");
    DS = FindDriverSuffix(ProgNameRef);
  }

  if (!DS) {
    // Try again after stripping trailing -component.
    // clang++-tot -> clang++
    ProgNameRef = ProgNameRef.slice(0, ProgNameRef.rfind('-'));
    DS = FindDriverSuffix(ProgNameRef);
  }

  if (DS) {
    if (const char *Flag = DS->ModeFlag) {
      // Add Flag to the arguments.
      auto it = ArgVector.begin();
      if (it != ArgVector.end())
        ++it;
      ArgVector.insert(it, Flag);
    }

    StringRef::size_type LastComponent = ProgNameRef.rfind(
        '-', ProgNameRef.size() - strlen(DS->Suffix));
    if (LastComponent == StringRef::npos)
      return;

    // Infer target from the prefix.
    StringRef Prefix = ProgNameRef.slice(0, LastComponent);
    std::string IgnoredError;
    if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
      auto it = ArgVector.begin();
      if (it != ArgVector.end())
        ++it;
      const char *arr[] = { "-target", GetStableCStr(SavedStrings, Prefix) };
      ArgVector.insert(it, std::begin(arr), std::end(arr));
    }
  }
}
开发者ID:cpbennett,项目名称:freebsd,代码行数:59,代码来源:driver.cpp

示例2: ParseHead

/// \brief Parse \p Input as function head.
///
/// Parse one line of \p Input, and update function name in \p FName,
/// function's total sample count in \p NumSamples, function's entry
/// count in \p NumHeadSamples.
///
/// \returns true if parsing is successful.
static bool ParseHead(const StringRef &Input, StringRef &FName,
                      unsigned &NumSamples, unsigned &NumHeadSamples) {
  if (Input[0] == ' ')
    return false;
  size_t n2 = Input.rfind(':');
  size_t n1 = Input.rfind(':', n2 - 1);
  FName = Input.substr(0, n1);
  if (Input.substr(n1 + 1, n2 - n1 - 1).getAsInteger(10, NumSamples))
    return false;
  if (Input.substr(n2 + 1).getAsInteger(10, NumHeadSamples))
    return false;
  return true;
}
开发者ID:rafaelgasperetti,项目名称:llvm,代码行数:20,代码来源:SampleProfReader.cpp

示例3: insertArgsFromProgramName

static void insertArgsFromProgramName(StringRef ProgName,
                                      const DriverSuffix *DS,
                                      SmallVectorImpl<const char *> &ArgVector,
                                      std::set<std::string> &SavedStrings) {
  if (!DS)
    return;

  if (const char *Flag = DS->ModeFlag) {
    // Add Flag to the arguments.
    auto it = ArgVector.begin();
    if (it != ArgVector.end())
      ++it;
    ArgVector.insert(it, Flag);
  }

  StringRef::size_type LastComponent = ProgName.rfind(
      '-', ProgName.size() - strlen(DS->Suffix));
  if (LastComponent == StringRef::npos)
    return;

  // Infer target from the prefix.
  StringRef Prefix = ProgName.slice(0, LastComponent);
  std::string IgnoredError;
  if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
    auto it = ArgVector.begin();
    if (it != ArgVector.end())
      ++it;
    const char *arr[] = { "-target", GetStableCStr(SavedStrings, Prefix) };
    ArgVector.insert(it, std::begin(arr), std::end(arr));
  }
}
开发者ID:meta-cpp,项目名称:clang,代码行数:31,代码来源:driver.cpp

示例4: ConstantExpr

BOZConstantExpr::BOZConstantExpr(ASTContext &C, SMLoc Loc, StringRef Data)
  : ConstantExpr(BOZConstant, C.IntegerTy, Loc) {
  unsigned Radix = 0;
  switch (Data[0]) {
  case 'B':
    Kind = Binary;
    Radix = 2;
    break;
  case 'O':
    Kind = Octal;
    Radix = 8;
    break;
  case 'Z': case 'X':
    Kind = Hexadecimal;
    Radix = 16;
    break;
  }

  size_t LastQuote = Data.rfind(Data[1]);
  assert(LastQuote == StringRef::npos && "Invalid BOZ constant!");
  llvm::StringRef NumStr = Data.slice(2, LastQuote);
  APInt Val;
  NumStr.getAsInteger(Radix, Val);
  Num.setValue(C, Val);
}
开发者ID:isanbard,项目名称:flang,代码行数:25,代码来源:Expr.cpp

示例5: ActOnImportSpec

void MinimalAction::ActOnImportSpec(SourceLocation PathLoc, StringRef ImportPath,
                                    IdentifierInfo *LocalName,
                                    bool IsLocal) {
  if (IsLocal)
    // FIXME: This should insert all exported symbols in ImportPath into the
    // current file's file scope.
    return;

  TypeNameInfoTable &TNIT = *getTable(TypeNameInfoTablePtr);

  if (LocalName) {
    // FIXME: This should insert all exported symbols in ImportPath into
    // LocalName's scope.
    TNIT.AddEntry(Action::IIT_Package, LocalName);
    TUScope->AddDecl(DeclPtrTy::make(LocalName));
    return;
  }

  // FIXME: The right thing to do here is to load the package file pointed to
  // by ImportPath and get the `package` identifier used therein. As an
  // approximation, just grab the last path component off ImportPath.
  ImportPath = ImportPath.slice(1, ImportPath.size() - 1);  // Strip ""
  size_t SlashPos = ImportPath.rfind('/');
  if (SlashPos != StringRef::npos)
    ImportPath = ImportPath.substr(SlashPos + 1);

  TNIT.AddEntry(Action::IIT_Package, &Idents.get(ImportPath));
  TUScope->AddDecl(DeclPtrTy::make(&Idents.get(ImportPath)));
}
开发者ID:nico,项目名称:gong,代码行数:29,代码来源:MinimalAction.cpp

示例6: getCommentSplit

BreakableToken::Split getCommentSplit(StringRef Text,
                                      unsigned ContentStartColumn,
                                      unsigned ColumnLimit) {
  if (ColumnLimit <= ContentStartColumn + 1)
    return BreakableToken::Split(StringRef::npos, 0);

  unsigned MaxSplit = ColumnLimit - ContentStartColumn + 1;
  StringRef::size_type SpaceOffset = Text.rfind(' ', MaxSplit);
  if (SpaceOffset == StringRef::npos ||
      // Don't break at leading whitespace.
      Text.find_last_not_of(' ', SpaceOffset) == StringRef::npos) {
    // Make sure that we don't break at leading whitespace that
    // reaches past MaxSplit.
    StringRef::size_type FirstNonWhitespace = Text.find_first_not_of(" ");
    if (FirstNonWhitespace == StringRef::npos)
      // If the comment is only whitespace, we cannot split.
      return BreakableToken::Split(StringRef::npos, 0);
    SpaceOffset =
        Text.find(' ', std::max<unsigned>(MaxSplit, FirstNonWhitespace));
  }
  if (SpaceOffset != StringRef::npos && SpaceOffset != 0) {
    StringRef BeforeCut = Text.substr(0, SpaceOffset).rtrim();
    StringRef AfterCut = Text.substr(SpaceOffset).ltrim();
    return BreakableToken::Split(BeforeCut.size(),
                                 AfterCut.begin() - BeforeCut.end());
  }
  return BreakableToken::Split(StringRef::npos, 0);
}
开发者ID:acgessler,项目名称:clang,代码行数:28,代码来源:BreakableToken.cpp

示例7: offsetToPosition

/// Turn an offset in Code into a [line, column] pair.
Position clangd::offsetToPosition(StringRef Code, size_t Offset) {
  StringRef JustBefore = Code.substr(0, Offset);
  // FIXME: \r\n
  // FIXME: UTF-8
  int Lines = JustBefore.count('\n');
  int Cols = JustBefore.size() - JustBefore.rfind('\n') - 1;
  return {Lines, Cols};
}
开发者ID:prazek,项目名称:clang-extra,代码行数:9,代码来源:ClangdServer.cpp

示例8: findPrimaryDefn

bool Module::findPrimaryDefn() {
  StringRef primaryName = qname_;
  size_t dot = primaryName.rfind('.');
  if (dot != primaryName.npos) {
    primaryName = primaryName.substr(dot + 1, primaryName.npos);
  }

  return IterableScope::lookupMember(primaryName, primaryDefs_, false);
}
开发者ID:afrog33k,项目名称:tart,代码行数:9,代码来源:Module.cpp

示例9: getLine

// Returns a whole line containing the current token.
StringRef ScriptParserBase::getLine() {
  StringRef S = getCurrentMB().getBuffer();
  StringRef Tok = Tokens[Pos - 1];

  size_t Pos = S.rfind('\n', Tok.data() - S.data());
  if (Pos != StringRef::npos)
    S = S.substr(Pos + 1);
  return S.substr(0, S.find_first_of("\r\n"));
}
开发者ID:mulichao,项目名称:freebsd,代码行数:10,代码来源:ScriptParser.cpp

示例10: getPriority

// If an input string is in the form of "foo.N" where N is a number,
// return N. Otherwise, returns 65536, which is one greater than the
// lowest priority.
int elf::getPriority(StringRef S) {
  size_t Pos = S.rfind('.');
  if (Pos == StringRef::npos)
    return 65536;
  int V;
  if (!to_integer(S.substr(Pos + 1), V, 10))
    return 65536;
  return V;
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:12,代码来源:OutputSections.cpp

示例11: getLine

// Returns the line that the character S[Pos] is in.
static StringRef getLine(StringRef S, size_t Pos) {
  size_t Begin = S.rfind('\n', Pos);
  size_t End = S.find('\n', Pos);
  Begin = (Begin == StringRef::npos) ? 0 : Begin + 1;
  if (End == StringRef::npos)
    End = S.size();
  // rtrim for DOS-style newlines.
  return S.substr(Begin, End - Begin).rtrim();
}
开发者ID:jy0u,项目名称:lld,代码行数:10,代码来源:ScriptParser.cpp

示例12: setQualifiedName

void Module::setQualifiedName(StringRef qual) {
  qname_ = qual;
  size_t dot = qual.rfind('.');
  if (dot == qual.npos) {
    name_ = moduleStrings_.intern(qual);
    packageName_.clear();
  } else {
    name_ = moduleStrings_.intern(qual.substr(dot + 1, qual.npos));
    packageName_ = qual.substr(0, dot);
  }
}
开发者ID:afrog33k,项目名称:tart,代码行数:11,代码来源:Module.cpp

示例13: symbol

Symbol symbol(StringRef QName) {
  Symbol Sym;
  Sym.ID = SymbolID(QName.str());
  size_t Pos = QName.rfind("::");
  if (Pos == StringRef::npos) {
    Sym.Name = QName;
    Sym.Scope = "";
  } else {
    Sym.Name = QName.substr(Pos + 2);
    Sym.Scope = QName.substr(0, Pos + 2);
  }
  return Sym;
}
开发者ID:vmiklos,项目名称:clang-tools-extra,代码行数:13,代码来源:TestIndex.cpp

示例14: getStringSplit

BreakableToken::Split getStringSplit(StringRef Text,
                                     unsigned ContentStartColumn,
                                     unsigned ColumnLimit) {

  if (ColumnLimit <= ContentStartColumn)
    return BreakableToken::Split(StringRef::npos, 0);
  unsigned MaxSplit = ColumnLimit - ContentStartColumn;
  // FIXME: Reduce unit test case.
  if (Text.empty())
    return BreakableToken::Split(StringRef::npos, 0);
  MaxSplit = std::min<unsigned>(MaxSplit, Text.size() - 1);
  StringRef::size_type SpaceOffset = Text.rfind(' ', MaxSplit);
  if (SpaceOffset != StringRef::npos && SpaceOffset != 0)
    return BreakableToken::Split(SpaceOffset + 1, 0);
  StringRef::size_type SlashOffset = Text.rfind('/', MaxSplit);
  if (SlashOffset != StringRef::npos && SlashOffset != 0)
    return BreakableToken::Split(SlashOffset + 1, 0);
  StringRef::size_type SplitPoint = getStartOfCharacter(Text, MaxSplit);
  if (SplitPoint == StringRef::npos || SplitPoint == 0)
    return BreakableToken::Split(StringRef::npos, 0);
  return BreakableToken::Split(SplitPoint, 0);
}
开发者ID:acgessler,项目名称:clang,代码行数:22,代码来源:BreakableToken.cpp

示例15: tryParse

bool ObjCRuntime::tryParse(StringRef input) {
  // Look for the last dash.
  std::size_t dash = input.rfind('-');

  // We permit dashes in the runtime name, and we also permit the
  // version to be omitted, so if we see a dash not followed by a
  // digit then we need to ignore it.
  if (dash != StringRef::npos && dash + 1 != input.size() &&
      (input[dash+1] < '0' || input[dash+1] > '9')) {
    dash = StringRef::npos;
  }

  // Everything prior to that must be a valid string name.
  Kind kind;
  StringRef runtimeName = input.substr(0, dash);
  Version = VersionTuple(0);
  if (runtimeName == "macosx") {
    kind = ObjCRuntime::MacOSX;
  } else if (runtimeName == "macosx-fragile") {
    kind = ObjCRuntime::FragileMacOSX;
  } else if (runtimeName == "ios") {
    kind = ObjCRuntime::iOS;
  } else if (runtimeName == "gnustep") {
    // If no version is specified then default to the most recent one that we
    // know about.
    Version = VersionTuple(1, 6);
    kind = ObjCRuntime::GNUstep;
  } else if (runtimeName == "gcc") {
    kind = ObjCRuntime::GCC;
  } else if (runtimeName == "objfw") {
    kind = ObjCRuntime::ObjFW;
    Version = VersionTuple(0, 8);
  } else if (runtimeName == "host") {
    kind = ObjCRuntime::Host;
  } else {
    return true;
  }
  TheKind = kind;

  if (dash != StringRef::npos) {
    StringRef verString = input.substr(dash + 1);
    if (Version.tryParse(verString))
      return true;
  }

  if (kind == ObjCRuntime::ObjFW && Version > VersionTuple(0, 8))
    Version = VersionTuple(0, 8);

  return false;
}
开发者ID:eerolanguage,项目名称:clang-interpreter-runtime,代码行数:50,代码来源:ObjCRuntime.cpp


注:本文中的StringRef::rfind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。