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


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

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


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

示例1: skipSpace

// Split S into linker script tokens.
std::vector<StringRef> ScriptParserBase::tokenize(StringRef S) {
  std::vector<StringRef> Ret;
  for (;;) {
    S = skipSpace(S);
    if (S.empty())
      return Ret;

    // Quoted token
    if (S.startswith("\"")) {
      size_t E = S.find("\"", 1);
      if (E == StringRef::npos) {
        error("unclosed quote");
        return {};
      }
      Ret.push_back(S.substr(1, E - 1));
      S = S.substr(E + 1);
      continue;
    }

    // Unquoted token
    size_t Pos = S.find_first_not_of(
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
        "0123456789_.$/\\~=+[]*?-:!<>");
    // A character that cannot start a word (which is usually a
    // punctuation) forms a single character token.
    if (Pos == 0)
      Pos = 1;
    Ret.push_back(S.substr(0, Pos));
    S = S.substr(Pos);
  }
}
开发者ID:jy0u,项目名称:lld,代码行数:32,代码来源:ScriptParser.cpp

示例2: 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

示例3: make_pair

/// \brief Attempt to read the lock file with the given name, if it exists.
///
/// \param LockFileName The name of the lock file to read.
///
/// \returns The process ID of the process that owns this lock file
Optional<std::pair<std::string, int> >
LockFileManager::readLockFile(StringRef LockFileName) {
  // Check whether the lock file exists. If not, clearly there's nothing
  // to read, so we just return.
  if (!sys::fs::exists(LockFileName))
    return None;

  // Read the owning host and PID out of the lock file. If it appears that the
  // owning process is dead, the lock file is invalid.
  OwningPtr<MemoryBuffer> MB;
  if (MemoryBuffer::getFile(LockFileName, MB))
    return None;

  StringRef Hostname;
  StringRef PIDStr;
  std::tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " ");
  PIDStr = PIDStr.substr(PIDStr.find_first_not_of(" "));
  int PID;
  if (!PIDStr.getAsInteger(10, PID))
    return std::make_pair(std::string(Hostname), PID);

  // Delete the lock file. It's invalid anyway.
  sys::fs::remove(LockFileName);
  return None;
}
开发者ID:rui314,项目名称:llvm,代码行数:30,代码来源:LockFileManager.cpp

示例4: scalarString

void Output::scalarString(StringRef &S) {
    const char ScalarSafeChars[] = "abcdefghijklmnopqrstuvwxyz"
                                   "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-/^., \t";

    this->newLineCheck();
    if (S.empty()) {
        // Print '' for the empty string because leaving the field empty is not
        // allowed.
        this->outputUpToEndOfLine("''");
        return;
    }
    if (S.find_first_not_of(ScalarSafeChars) == StringRef::npos &&
            !isspace(S.front()) && !isspace(S.back())) {
        // If the string consists only of safe characters, print it out without
        // quotes.
        this->outputUpToEndOfLine(S);
        return;
    }
    unsigned i = 0;
    unsigned j = 0;
    unsigned End = S.size();
    output("'"); // Starting single quote.
    const char *Base = S.data();
    while (j < End) {
        // Escape a single quote by doubling it.
        if (S[j] == '\'') {
            output(StringRef(&Base[i], j - i + 1));
            output("'");
            i = j + 1;
        }
        ++j;
    }
    output(StringRef(&Base[i], j - i));
    this->outputUpToEndOfLine("'"); // Ending single quote.
}
开发者ID:hangyiwu,项目名称:root-cern,代码行数:35,代码来源:YAMLTraits.cpp

示例5: findDecoratedSymbol

// Find decorated symbol, namely /[email protected][0-9]+/ or /\[email protected]@.+/.
bool findDecoratedSymbol(PECOFFLinkingContext *ctx, ResolvableSymbols *syms,
                         std::string sym, std::string &res) {
  const std::set<std::string> &defined = syms->defined();
  // Search for /[email protected][0-9]+/
  {
    std::string s = sym + '@';
    auto it = defined.lower_bound(s);
    for (auto e = defined.end(); it != e; ++it) {
      if (!StringRef(*it).startswith(s))
        break;
      if (it->size() == s.size())
        continue;
      StringRef suffix = StringRef(*it).substr(s.size());
      if (suffix.find_first_not_of("0123456789") != StringRef::npos)
        continue;
      res = *it;
      return true;
    }
  }
  // Search for /\[email protected]@.+/
  {
    std::string s = "?" + ctx->undecorateSymbol(sym).str() + "@@";
    auto it = defined.lower_bound(s);
    if (it != defined.end() && StringRef(*it).startswith(s)) {
      res = *it;
      return true;
    }
  }
  return false;
}
开发者ID:chee-z,项目名称:lld,代码行数:31,代码来源:LinkerGeneratedSymbolFile.cpp

示例6: getToken

/// \brief Attempt to read the lock file with the given name, if it exists.
///
/// \param LockFileName The name of the lock file to read.
///
/// \returns The process ID of the process that owns this lock file
Optional<std::pair<std::string, int> >
LockFileManager::readLockFile(StringRef LockFileName) {
  // Read the owning host and PID out of the lock file. If it appears that the
  // owning process is dead, the lock file is invalid.
  std::unique_ptr<MemoryBuffer> MB;
  if (MemoryBuffer::getFile(LockFileName, MB)) {
    sys::fs::remove(LockFileName);
    return None;
  }

  StringRef Hostname;
  StringRef PIDStr;
  std::tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " ");
  PIDStr = PIDStr.substr(PIDStr.find_first_not_of(" "));
  int PID;
  if (!PIDStr.getAsInteger(10, PID)) {
    auto Owner = std::make_pair(std::string(Hostname), PID);
    if (processStillExecuting(Owner.first, Owner.second))
      return Owner;
  }

  // Delete the lock file. It's invalid anyway.
  sys::fs::remove(LockFileName);
  return None;
}
开发者ID:ADonut,项目名称:LLVM-GPGPU,代码行数:30,代码来源:LockFileManager.cpp

示例7: DumpInput

static void DumpInput(const StringRef &Filename) {
  OwningPtr<MemoryBuffer> Buff;

  if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
    errs() << Filename << ": " << ec.message() << "\n";
    return;
  }

  OwningPtr<ObjectFile> Obj(ObjectFile::createObjectFile(Buff.take()));

  StringRef DebugInfoSection;
  StringRef DebugAbbrevSection;
  StringRef DebugLineSection;
  StringRef DebugArangesSection;
  StringRef DebugStringSection;

  error_code ec;
  for (ObjectFile::section_iterator i = Obj->begin_sections(),
                                    e = Obj->end_sections();
                                    i != e; i.increment(ec)) {
    StringRef name;
    i->getName(name);
    StringRef data;
    i->getContents(data);

    if (name.startswith("__DWARF,"))
      name = name.substr(8); // Skip "__DWARF," prefix.
    name = name.substr(name.find_first_not_of("._")); // Skip . and _ prefixes.
    if (name == "debug_info")
      DebugInfoSection = data;
    else if (name == "debug_abbrev")
      DebugAbbrevSection = data;
    else if (name == "debug_line")
      DebugLineSection = data;
    else if (name == "debug_aranges")
      DebugArangesSection = data;
    else if (name == "debug_str")
      DebugStringSection = data;
  }

  OwningPtr<DIContext> dictx(DIContext::getDWARFContext(/*FIXME*/true,
                                                        DebugInfoSection,
                                                        DebugAbbrevSection,
                                                        DebugArangesSection,
                                                        DebugLineSection,
                                                        DebugStringSection));
  if (Address == -1ULL) {
    outs() << Filename
           << ":\tfile format " << Obj->getFileFormatName() << "\n\n";
    // Dump the complete DWARF structure.
    dictx->dump(outs());
  } else {
    // Print line info for the specified address.
    DILineInfo dli = dictx->getLineInfoForAddress(Address);
    outs() << (dli.getFileName() ? dli.getFileName() : "<unknown>") << ':'
           << dli.getLine() << ':' << dli.getColumn() << '\n';
  }
}
开发者ID:lygstate,项目名称:llvm-mirror,代码行数:58,代码来源:llvm-dwarfdump.cpp

示例8:

size_t swift::ide::getOffsetOfTrimmedLine(unsigned LineIndex, StringRef Text) {
  size_t LineOffset = swift::ide::getOffsetOfLine(LineIndex, Text);

  // Skip leading whitespace.
  size_t FirstNonWSOnLine = Text.find_first_not_of(" \t\v\f", LineOffset);
  if (FirstNonWSOnLine != std::string::npos)
    LineOffset = FirstNonWSOnLine;

  return LineOffset;
}
开发者ID:AlexShiLucky,项目名称:swift,代码行数:10,代码来源:Formatting.cpp

示例9: make_pair

/// getToken - This function extracts one token from source, ignoring any
/// leading characters that appear in the Delimiters string, and ending the
/// token at any of the characters that appear in the Delimiters string.  If
/// there are no tokens in the source string, an empty string is returned.
/// The function returns a pair containing the extracted token and the
/// remaining tail string.
std::pair<StringRef, StringRef> llvm::getToken(StringRef Source,
        StringRef Delimiters) {
    // Figure out where the token starts.
    StringRef::size_type Start = Source.find_first_not_of(Delimiters);

    // Find the next occurrence of the delimiter.
    StringRef::size_type End = Source.find_first_of(Delimiters, Start);

    return std::make_pair(Source.slice(Start, End), Source.substr(End));
}
开发者ID:PeterMitrano,项目名称:ntcore,代码行数:16,代码来源:StringExtras.cpp

示例10: notifyInputSectionName

void ELFLinkingContext::notifyInputSectionName(StringRef name) {
    // Save sections names which can be represented as a C identifier.
    if (name.find_first_not_of("0123456789"
                               "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                               "abcdefghijklmnopqrstuvwxyz"
                               "_") == StringRef::npos) {
        std::lock_guard<std::mutex> lock(_cidentMutex);
        _cidentSections.insert(name);
    }
}
开发者ID:lamproae,项目名称:lld,代码行数:10,代码来源:ELFLinkingContext.cpp

示例11:

/// Retrieve the section named \a SecName in \a Obj.
///
/// To accommodate for platform discrepancies, the name passed should be
/// (for example) 'debug_info' to match either '__debug_info' or '.debug_info'.
/// This function will strip the initial platform-specific characters.
static Optional<object::SectionRef>
getSectionByName(const object::ObjectFile &Obj, StringRef SecName) {
  for (const object::SectionRef &Section : Obj.sections()) {
    StringRef SectionName;
    Section.getName(SectionName);
    SectionName = SectionName.substr(SectionName.find_first_not_of("._"));
    if (SectionName != SecName)
      continue;
    return Section;
  }
  return None;
}
开发者ID:jaredmcneill,项目名称:netbsd-src,代码行数:17,代码来源:DwarfStreamer.cpp

示例12: measureASCIIArt

static unsigned measureASCIIArt(StringRef S, unsigned NumLeadingSpaces) {
  StringRef Spaces = S.substr(0, NumLeadingSpaces);
  if (Spaces.size() != NumLeadingSpaces)
    return 0;
  if (Spaces.find_first_not_of(' ') != StringRef::npos)
    return 0;

  S = S.drop_front(NumLeadingSpaces);

  if (S.startswith(" * "))
    return NumLeadingSpaces + 3;
  if (S.startswith(" *\n") || S.startswith(" *\n\r"))
    return NumLeadingSpaces + 2;
  return 0;
}
开发者ID:6008,项目名称:swift,代码行数:15,代码来源:LineList.cpp

示例13: getOffsetOfLine

size_t swift::ide::getExpandedIndentForLine(unsigned LineIndex,
                                            CodeFormatOptions Options,
                                            StringRef Text) {
  size_t LineOffset = getOffsetOfLine(LineIndex, Text);

  // Tab-expand all leading whitespace
  size_t FirstNonWSOnLine = Text.find_first_not_of(" \t\v\f", LineOffset);
  size_t Indent = 0;
  while (LineOffset < Text.size() && LineOffset < FirstNonWSOnLine) {
    if (Text[LineOffset++] == '\t')
      Indent += Options.TabWidth;
    else
      Indent += 1;
  }
  return Indent;
}
开发者ID:AlexShiLucky,项目名称:swift,代码行数:16,代码来源:Formatting.cpp

示例14: PrintCheckFailed

static void PrintCheckFailed(const SourceMgr &SM, const CheckString &CheckStr,
                             StringRef Buffer,
                             StringMap<StringRef> &VariableTable) {
  // Otherwise, we have an error, emit an error message.
  SM.PrintMessage(CheckStr.Loc, SourceMgr::DK_Error,
                  "expected string not found in input");

  // Print the "scanning from here" line.  If the current position is at the
  // end of a line, advance to the start of the next line.
  Buffer = Buffer.substr(Buffer.find_first_not_of(" \t\n\r"));

  SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), SourceMgr::DK_Note,
                  "scanning from here");

  // Allow the pattern to print additional information if desired.
  CheckStr.Pat.PrintFailureInfo(SM, Buffer, VariableTable);
}
开发者ID:agheorghiu,项目名称:root,代码行数:17,代码来源:FileCheck.cpp

示例15: tokenize

// Split S into linker script tokens.
void ScriptParserBase::tokenize(MemoryBufferRef MB) {
  std::vector<StringRef> Vec;
  MBs.push_back(MB);
  StringRef S = MB.getBuffer();
  StringRef Begin = S;

  for (;;) {
    S = skipSpace(S);
    if (S.empty())
      break;

    // Quoted token. Note that double-quote characters are parts of a token
    // because, in a glob match context, only unquoted tokens are interpreted
    // as glob patterns. Double-quoted tokens are literal patterns in that
    // context.
    if (S.startswith("\"")) {
      size_t E = S.find("\"", 1);
      if (E == StringRef::npos) {
        StringRef Filename = MB.getBufferIdentifier();
        size_t Lineno = Begin.substr(0, S.data() - Begin.data()).count('\n');
        error(Filename + ":" + Twine(Lineno + 1) + ": unclosed quote");
        return;
      }

      Vec.push_back(S.take_front(E + 1));
      S = S.substr(E + 1);
      continue;
    }

    // Unquoted token. This is more relaxed than tokens in C-like language,
    // so that you can write "file-name.cpp" as one bare token, for example.
    size_t Pos = S.find_first_not_of(
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
        "0123456789_.$/\\~=+[]*?-:!<>^");

    // A character that cannot start a word (which is usually a
    // punctuation) forms a single character token.
    if (Pos == 0)
      Pos = 1;
    Vec.push_back(S.substr(0, Pos));
    S = S.substr(Pos);
  }

  Tokens.insert(Tokens.begin() + Pos, Vec.begin(), Vec.end());
}
开发者ID:mulichao,项目名称:freebsd,代码行数:46,代码来源:ScriptParser.cpp


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