bool operator()(const Multilib &M) const override { std::string Error; if (!R.isValid(Error)) { llvm::errs() << Error; assert(false); return false; } return R.match(M.gccSuffix()); }
static void onIf(Analyser* analyser, SourceLocation where, SourceRange source) { llvm::SmallVector<llvm::StringRef, 7> matches; llvm::StringRef guard; if (ndef.match(analyser->get_source(source), &matches)) { guard = matches[1]; } analyser->attachment<ExternalGuards>().d_conditions.push( std::make_pair(guard, where)); }
BreakableToken::Split BreakableComment::getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, llvm::Regex &CommentPragmasRegex) const { // Don't break lines matching the comment pragmas regex. if (CommentPragmasRegex.match(Content[LineIndex])) return Split(StringRef::npos, 0); return getCommentSplit(Content[LineIndex].substr(TailOffset), getContentStartColumn(LineIndex, TailOffset), ColumnLimit, Style.TabWidth, Encoding); }
static std::string getInclude(llvm::StringRef source) { llvm::SmallVector<llvm::StringRef, 7> matches; if (next_include_before_if.match(source, &matches)) { if (matches[3].size()) { return matches[3]; } if (matches[5].size()) { return matches[5]; } } return std::string(); }
static std::string fixupWithCase(StringRef Name, IdentifierNamingCheck::CaseType Case) { static llvm::Regex Splitter( "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)"); SmallVector<StringRef, 8> Substrs; Name.split(Substrs, "_", -1, false); SmallVector<StringRef, 8> Words; for (auto Substr : Substrs) { while (!Substr.empty()) { SmallVector<StringRef, 8> Groups; if (!Splitter.match(Substr, &Groups)) break; if (Groups[2].size() > 0) { Words.push_back(Groups[1]); Substr = Substr.substr(Groups[0].size()); } else if (Groups[3].size() > 0) { Words.push_back(Groups[3]); Substr = Substr.substr(Groups[0].size() - Groups[4].size()); } else if (Groups[5].size() > 0) { Words.push_back(Groups[5]); Substr = Substr.substr(Groups[0].size() - Groups[6].size()); } } } if (Words.empty()) return Name; std::string Fixup; switch (Case) { case IdentifierNamingCheck::CT_AnyCase: Fixup += Name; break; case IdentifierNamingCheck::CT_LowerCase: for (auto const &Word : Words) { if (&Word != &Words.front()) Fixup += "_"; Fixup += Word.lower(); } break; case IdentifierNamingCheck::CT_UpperCase: for (auto const &Word : Words) { if (&Word != &Words.front()) Fixup += "_"; Fixup += Word.upper(); } break; case IdentifierNamingCheck::CT_CamelCase: for (auto const &Word : Words) { Fixup += Word.substr(0, 1).upper(); Fixup += Word.substr(1).lower(); } break; case IdentifierNamingCheck::CT_CamelBack: for (auto const &Word : Words) { if (&Word == &Words.front()) { Fixup += Word.lower(); } else { Fixup += Word.substr(0, 1).upper(); Fixup += Word.substr(1).lower(); } } break; case IdentifierNamingCheck::CT_CamelSnakeCase: for (auto const &Word : Words) { if (&Word != &Words.front()) Fixup += "_"; Fixup += Word.substr(0, 1).upper(); Fixup += Word.substr(1).lower(); } break; case IdentifierNamingCheck::CT_CamelSnakeBack: for (auto const &Word : Words) { if (&Word != &Words.front()) { Fixup += "_"; Fixup += Word.substr(0, 1).upper(); } else { Fixup += Word.substr(0, 1).lower(); } Fixup += Word.substr(1).lower(); } break; } return Fixup; }