diff --git a/src/Algos.cc b/src/Algos.cc index 11ddca5c0..1c0df8027 100644 --- a/src/Algos.cc +++ b/src/Algos.cc @@ -8,11 +8,12 @@ #include #include #include +#include #include #include std::string -toUpper(const StringRef str) noexcept { +toUpper(const std::string_view str) noexcept { std::string res; for (const unsigned char c : str) { res += static_cast(std::toupper(c)); @@ -21,7 +22,7 @@ toUpper(const StringRef str) noexcept { } std::string -toMacroName(const StringRef name) noexcept { +toMacroName(const std::string_view name) noexcept { std::string macroName; for (const unsigned char c : name) { if (std::isalpha(c)) { @@ -36,7 +37,7 @@ toMacroName(const StringRef name) noexcept { } int -execCmd(const StringRef cmd) noexcept { +execCmd(const std::string_view cmd) noexcept { logger::debug("Running `", cmd, '`'); const int status = std::system(cmd.data()); const int exitCode = status >> 8; @@ -44,7 +45,7 @@ execCmd(const StringRef cmd) noexcept { } static std::pair -getCmdOutputImpl(const StringRef cmd) { +getCmdOutputImpl(const std::string_view cmd) { constexpr usize bufferSize = 128; std::array buffer{}; std::string output; @@ -67,7 +68,7 @@ getCmdOutputImpl(const StringRef cmd) { } std::string -getCmdOutput(const StringRef cmd, const usize retry) { +getCmdOutput(const std::string_view cmd, const usize retry) { logger::debug("Running `", cmd, '`'); int exitCode = EXIT_SUCCESS; @@ -87,7 +88,7 @@ getCmdOutput(const StringRef cmd, const usize retry) { } bool -commandExists(const StringRef cmd) noexcept { +commandExists(const std::string_view cmd) noexcept { std::string checkCmd = "command -v "; checkCmd += cmd; checkCmd += " >/dev/null 2>&1"; @@ -96,7 +97,7 @@ commandExists(const StringRef cmd) noexcept { // ref: https://wandbox.org/permlink/zRjT41alOHdwcf00 static usize -levDistance(const StringRef lhs, const StringRef rhs) { +levDistance(const std::string_view lhs, const std::string_view rhs) { const usize lhsSize = lhs.size(); const usize rhsSize = rhs.size(); @@ -132,18 +133,22 @@ levDistance(const StringRef lhs, const StringRef rhs) { } static bool -equalsInsensitive(const StringRef lhs, const StringRef rhs) noexcept { +equalsInsensitive( + const std::string_view lhs, const std::string_view rhs +) noexcept { return std::equal( lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), [](char lhs, char rhs) { return std::tolower(lhs) == std::tolower(rhs); } ); } -Option -findSimilarStr(const StringRef lhs, std::span candidates) { +Option +findSimilarStr( + const std::string_view lhs, std::span candidates +) { // We need to check if `Candidates` has the exact case-insensitive string // because the Levenshtein distance match does not care about it. - for (const StringRef str : candidates) { + for (const std::string_view str : candidates) { if (equalsInsensitive(lhs, str)) { return str; } @@ -155,8 +160,8 @@ findSimilarStr(const StringRef lhs, std::span candidates) { const usize length = lhs.size(); const usize maxDist = length < 3 ? length - 1 : length / 3; - Option> similarStr = None; - for (const StringRef str : candidates) { + Option> similarStr = None; + for (const std::string_view str : candidates) { const usize curDist = levDistance(lhs, str); if (curDist <= maxDist) { // The first similar string found || More similar string found @@ -192,9 +197,9 @@ testLevDistance() { void testLevDistance2() { - constexpr StringRef str1 = "\nMäry häd ä little lämb\n\nLittle lämb\n"; - constexpr StringRef str2 = "\nMary häd ä little lämb\n\nLittle lämb\n"; - constexpr StringRef str3 = "Mary häd ä little lämb\n\nLittle lämb\n"; + constexpr std::string_view str1 = "\nMäry häd ä little lämb\n\nLittle lämb\n"; + constexpr std::string_view str2 = "\nMary häd ä little lämb\n\nLittle lämb\n"; + constexpr std::string_view str3 = "Mary häd ä little lämb\n\nLittle lämb\n"; assertEq(levDistance(str1, str2), 2UL); assertEq(levDistance(str2, str1), 2UL); @@ -221,9 +226,9 @@ testLevDistance2() { void testFindSimilarStr() { - constexpr Arr candidates{ - "if", "ifdef", "ifndef", "elif", "else", "endif", "elifdef", "elifndef" - }; + constexpr Arr candidates{ "if", "ifdef", "ifndef", + "elif", "else", "endif", + "elifdef", "elifndef" }; assertEq(findSimilarStr("id", candidates), "if"sv); assertEq(findSimilarStr("ifd", candidates), "if"sv); @@ -245,11 +250,11 @@ testFindSimilarStr() { void testFindSimilarStr2() { - constexpr Arr candidates{ "aaab", "aaabc" }; + constexpr Arr candidates{ "aaab", "aaabc" }; assertEq(findSimilarStr("aaaa", candidates), "aaab"sv); assertEq(findSimilarStr("1111111111", candidates), None); - constexpr Arr candidateS2{ "AAAA" }; + constexpr Arr candidateS2{ "AAAA" }; assertEq(findSimilarStr("aaaa", candidateS2), "AAAA"sv); pass(); diff --git a/src/Algos.hpp b/src/Algos.hpp index baae825dc..bdba75ab7 100644 --- a/src/Algos.hpp +++ b/src/Algos.hpp @@ -11,14 +11,15 @@ #include #include #include +#include #include -std::string toUpper(StringRef str) noexcept; -std::string toMacroName(StringRef name) noexcept; +std::string toUpper(std::string_view str) noexcept; +std::string toMacroName(std::string_view name) noexcept; -int execCmd(StringRef cmd) noexcept; -std::string getCmdOutput(StringRef cmd, usize retry = 3); -bool commandExists(StringRef cmd) noexcept; +int execCmd(std::string_view cmd) noexcept; +std::string getCmdOutput(std::string_view cmd, usize retry = 3); +bool commandExists(std::string_view cmd) noexcept; template Vec @@ -83,5 +84,6 @@ topoSort( /// /// \returns a similar string if exists. If no similar string exists, /// returns None. -Option -findSimilarStr(StringRef lhs, std::span candidates); +Option findSimilarStr( + std::string_view lhs, std::span candidates +); diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index 6076c1a08..408d72c73 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -23,13 +23,14 @@ #include #include #include +#include #include #include #include #include -static constinit const StringRef TEST_OUT_DIR = "tests"; -static constinit const StringRef PATH_FROM_OUT_DIR = "../../"; +static constinit const std::string_view TEST_OUT_DIR = "tests"; +static constinit const std::string_view PATH_FROM_OUT_DIR = "../../"; // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) static std::string OUT_DIR; @@ -57,7 +58,7 @@ getOutDir() { } static Vec -listSourceFilePaths(const StringRef directory) { +listSourceFilePaths(const std::string_view directory) { Vec sourceFilePaths; for (const auto& entry : fs::recursive_directory_iterator(directory)) { if (!SOURCE_FILE_EXTS.contains(entry.path().extension())) { @@ -183,11 +184,11 @@ struct BuildConfig { void emitVariable(std::ostream& os, const std::string& varName) const; void emitMakefile(std::ostream& os) const; - void emitCompdb(StringRef baseDir, std::ostream& os) const; + void emitCompdb(std::string_view baseDir, std::ostream& os) const; }; static void -emitDep(std::ostream& os, usize& offset, const StringRef dep) { +emitDep(std::ostream& os, usize& offset, const std::string_view dep) { constexpr usize maxLineLen = 80; if (offset + dep.size() + 2 > maxLineLen) { // 2 for space and \. // \ for line continuation. \ is the 80th character. @@ -200,7 +201,7 @@ emitDep(std::ostream& os, usize& offset, const StringRef dep) { static void emitTarget( - std::ostream& os, const StringRef target, + std::ostream& os, const std::string_view target, const HashSet& dependsOn, const Option& sourceFile = None, const Vec& commands = {} @@ -213,12 +214,12 @@ emitTarget( if (sourceFile.has_value()) { emitDep(os, offset, sourceFile.value()); } - for (const StringRef dep : dependsOn) { + for (const std::string_view dep : dependsOn) { emitDep(os, offset, dep); } os << '\n'; - for (const StringRef cmd : commands) { + for (const std::string_view cmd : commands) { os << '\t'; if (!cmd.starts_with('@')) { os << "$(Q)"; @@ -286,7 +287,8 @@ BuildConfig::emitMakefile(std::ostream& os) const { } void -BuildConfig::emitCompdb(const StringRef baseDir, std::ostream& os) const { +BuildConfig::emitCompdb(const std::string_view baseDir, std::ostream& os) + const { const fs::path baseDirPath = fs::canonical(baseDir); const std::string indent1(2, ' '); const std::string indent2(4, ' '); @@ -299,7 +301,7 @@ BuildConfig::emitCompdb(const StringRef baseDir, std::ostream& os) const { } bool isCompileTarget = false; - for (const StringRef cmd : targetInfo.commands) { + for (const std::string_view cmd : targetInfo.commands) { if (!cmd.starts_with("$(CXX)") && !cmd.starts_with("@$(CXX)")) { continue; } @@ -392,7 +394,7 @@ parseMMOutput(const std::string& mmOutput, std::string& target) { } static bool -isUpToDate(const StringRef makefilePath) { +isUpToDate(const std::string_view makefilePath) { if (!fs::exists(makefilePath)) { return false; } @@ -443,7 +445,7 @@ containsTestCode(const std::string& sourceFile) { } static std::string -printfCmd(const StringRef header, const StringRef body) { +printfCmd(const std::string_view header, const std::string_view body) { std::ostringstream oss; logger::info(oss, header, body); std::string msg = oss.str(); @@ -513,7 +515,7 @@ mapHeaderToObj(const fs::path& headerPath, const fs::path& buildOutDir) { // depending header files for the source file. static void collectBinDepObjs( // NOLINT(misc-no-recursion) - HashSet& deps, const StringRef sourceFileName, + HashSet& deps, const std::string_view sourceFileName, const HashSet& objTargetDeps, const HashSet& buildObjTargets, const BuildConfig& config ) { @@ -565,7 +567,7 @@ installDeps() { } static void -addDefine(const StringRef name, const StringRef value) { +addDefine(const std::string_view name, const std::string_view value) { DEFINES += fmt::format(" -D{}='\"{}\"'", name, value); } @@ -586,7 +588,7 @@ setVariables(BuildConfig& config, const bool isDebug) { if (profile.lto) { CXXFLAGS += " -flto"; } - for (const StringRef flag : profile.cxxflags) { + for (const std::string_view flag : profile.cxxflags) { CXXFLAGS += ' '; CXXFLAGS += flag; } diff --git a/src/Cli.cc b/src/Cli.cc index 356ded98a..001bb1e47 100644 --- a/src/Cli.cc +++ b/src/Cli.cc @@ -12,9 +12,10 @@ #include #include #include +#include #include -static constinit const StringRef PADDING = " "; +static constinit const std::string_view PADDING = " "; static void setOffset(const usize offset) noexcept { @@ -23,13 +24,14 @@ setOffset(const usize offset) noexcept { } static void -printHeader(const StringRef header) noexcept { +printHeader(const std::string_view header) noexcept { std::cout << bold(green(header)) << '\n'; } static void printUsage( - const StringRef name, const StringRef cmd, const StringRef usage + const std::string_view name, const std::string_view cmd, + const std::string_view usage ) noexcept { std::cout << bold(green("Usage: ")) << bold(cyan(name)) << ' '; if (!cmd.empty()) { @@ -43,7 +45,9 @@ printUsage( } void -addOptCandidates(Vec& candidates, const Vec& opts) noexcept { +addOptCandidates( + Vec& candidates, const Vec& opts +) noexcept { for (const auto& opt : opts) { candidates.push_back(opt.name); if (!opt.shortName.empty()) { @@ -167,7 +171,7 @@ Subcmd::addOpt(Opt opt) noexcept { return *this; } Subcmd& -Subcmd::setMainFn(std::function)> mainFn +Subcmd::setMainFn(std::function)> mainFn ) noexcept { this->mainFn = std::move(mainFn); return *this; @@ -193,8 +197,8 @@ Subcmd::getUsage() const noexcept { } [[nodiscard]] int -Subcmd::noSuchArg(StringRef arg) const { - Vec candidates; +Subcmd::noSuchArg(std::string_view arg) const { + Vec candidates; if (globalOpts.has_value()) { addOptCandidates(candidates, globalOpts.value()); } @@ -214,7 +218,7 @@ Subcmd::noSuchArg(StringRef arg) const { } [[nodiscard]] int -Subcmd::missingArgumentForOpt(const StringRef arg) { +Subcmd::missingArgumentForOpt(const std::string_view arg) { logger::error("Missing argument for `", arg, "`"); return EXIT_FAILURE; } @@ -310,13 +314,13 @@ Cli::addOpt(Opt opt) noexcept { } bool -Cli::hasSubcmd(StringRef subcmd) const noexcept { +Cli::hasSubcmd(std::string_view subcmd) const noexcept { return subcmds.contains(subcmd); } [[nodiscard]] int -Cli::noSuchArg(StringRef arg) const { - Vec candidates; +Cli::noSuchArg(std::string_view arg) const { + Vec candidates; for (const auto& cmd : subcmds) { candidates.push_back(cmd.second.name); if (!cmd.second.shortName.empty()) { @@ -339,12 +343,14 @@ Cli::noSuchArg(StringRef arg) const { } [[nodiscard]] int -Cli::exec(const StringRef subcmd, const std::span args) const { +Cli::exec( + const std::string_view subcmd, const std::span args +) const { return subcmds.at(subcmd).mainFn(args); } void -Cli::printSubcmdHelp(const StringRef subcmd) const noexcept { +Cli::printSubcmdHelp(const std::string_view subcmd) const noexcept { subcmds.at(subcmd).printHelp(); } @@ -441,7 +447,7 @@ Cli::printCmdHelp() const noexcept { } [[nodiscard]] int -Cli::printHelp(const std::span args) const noexcept { +Cli::printHelp(const std::span args) const noexcept { // Parse args for (auto itr = args.begin(); itr != args.end(); ++itr) { if (const auto res = handleGlobalOpts(itr, args.end(), "help")) { diff --git a/src/Cli.hpp b/src/Cli.hpp index 4c4995228..dfe6935df 100644 --- a/src/Cli.hpp +++ b/src/Cli.hpp @@ -8,6 +8,7 @@ #include #include #include +#include class Opt; class Arg; @@ -21,8 +22,8 @@ template class CliBase { protected: // NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes) - StringRef name; - StringRef desc; + std::string_view name; + std::string_view desc; // NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes) public: @@ -33,8 +34,9 @@ class CliBase { constexpr CliBase& operator=(const CliBase&) noexcept = default; constexpr CliBase& operator=(CliBase&&) noexcept = default; - constexpr explicit CliBase(const StringRef name) noexcept : name(name) {} - constexpr Derived& setDesc(const StringRef desc) noexcept { + constexpr explicit CliBase(const std::string_view name) noexcept + : name(name) {} + constexpr Derived& setDesc(const std::string_view desc) noexcept { this->desc = desc; return static_cast(*this); } @@ -44,12 +46,12 @@ template class ShortAndHidden { protected: // NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes) - StringRef shortName; + std::string_view shortName; bool isHidden = false; // NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes) public: - constexpr Derived& setShort(const StringRef shortName) noexcept { + constexpr Derived& setShort(const std::string_view shortName) noexcept { this->shortName = shortName; return static_cast(*this); } @@ -63,26 +65,27 @@ class Opt : public CliBase, public ShortAndHidden { friend class Subcmd; friend class Cli; - StringRef placeholder; - StringRef defaultVal; + std::string_view placeholder; + std::string_view defaultVal; bool isGlobal = false; public: using CliBase::CliBase; - friend void - addOptCandidates(Vec& candidates, const Vec& opts) noexcept; + friend void addOptCandidates( + Vec& candidates, const Vec& opts + ) noexcept; friend usize calcOptMaxShortSize(const Vec& opts) noexcept; friend usize calcOptMaxOffset(const Vec& opts, usize maxShortSize) noexcept; friend void printOpts(const Vec& opts, usize maxShortSize, usize maxOffset) noexcept; - constexpr Opt& setPlaceholder(const StringRef placeholder) noexcept { + constexpr Opt& setPlaceholder(const std::string_view placeholder) noexcept { this->placeholder = placeholder; return *this; } - constexpr Opt& setDefault(const StringRef defaultVal) noexcept { + constexpr Opt& setDefault(const std::string_view defaultVal) noexcept { this->defaultVal = defaultVal; return *this; } @@ -136,11 +139,11 @@ class Arg : public CliBase { class Subcmd : public CliBase, public ShortAndHidden { friend class Cli; - StringRef cmdName; + std::string_view cmdName; Option> globalOpts = None; Vec localOpts; Arg arg; - std::function)> mainFn; + std::function)> mainFn; public: using CliBase::CliBase; @@ -151,16 +154,16 @@ class Subcmd : public CliBase, public ShortAndHidden { } Subcmd& addOpt(Opt opt) noexcept; - Subcmd& setMainFn(std::function)> mainFn + Subcmd& setMainFn(std::function)> mainFn ) noexcept; - [[nodiscard]] int noSuchArg(StringRef arg) const; - [[nodiscard]] static int missingArgumentForOpt(StringRef arg); + [[nodiscard]] int noSuchArg(std::string_view arg) const; + [[nodiscard]] static int missingArgumentForOpt(std::string_view arg); private: constexpr bool hasShort() const noexcept { return !shortName.empty(); } - constexpr Subcmd& setCmdName(StringRef cmdName) noexcept { + constexpr Subcmd& setCmdName(std::string_view cmdName) noexcept { this->cmdName = cmdName; return *this; } @@ -177,7 +180,7 @@ class Subcmd : public CliBase, public ShortAndHidden { }; class Cli : public CliBase { - HashMap subcmds; + HashMap subcmds; Vec globalOpts; Vec localOpts; @@ -186,13 +189,14 @@ class Cli : public CliBase { Cli& addSubcmd(const Subcmd& subcmd) noexcept; Cli& addOpt(Opt opt) noexcept; - bool hasSubcmd(StringRef subcmd) const noexcept; + bool hasSubcmd(std::string_view subcmd) const noexcept; - [[nodiscard]] int noSuchArg(StringRef arg) const; + [[nodiscard]] int noSuchArg(std::string_view arg) const; [[nodiscard]] int - exec(StringRef subcmd, std::span args) const; - void printSubcmdHelp(StringRef subcmd) const noexcept; - [[nodiscard]] int printHelp(std::span args) const noexcept; + exec(std::string_view subcmd, std::span args) const; + void printSubcmdHelp(std::string_view subcmd) const noexcept; + [[nodiscard]] int printHelp(std::span args + ) const noexcept; usize calcMaxOffset(usize maxShortSize) const noexcept; void printAllSubcmds(bool showHidden, usize maxOffset = 0) const noexcept; @@ -204,7 +208,7 @@ class Cli : public CliBase { // TODO: result-like types make more sense. [[nodiscard]] static inline Option handleGlobalOpts( std::forward_iterator auto& itr, const std::forward_iterator auto end, - StringRef subcmd = "" + std::string_view subcmd = "" ) { if (*itr == "-h"sv || *itr == "--help"sv) { if (!subcmd.empty()) { diff --git a/src/Cmd/Add.cc b/src/Cmd/Add.cc index efac2b8e3..c7cee2f76 100644 --- a/src/Cmd/Add.cc +++ b/src/Cmd/Add.cc @@ -9,9 +9,10 @@ #include #include #include +#include #include -static int addMain(std::span args); +static int addMain(std::span args); const Subcmd ADD_CMD = Subcmd{ "add" } @@ -37,8 +38,8 @@ const Subcmd ADD_CMD = static Option handleNextArg( - std::span::iterator& itr, - const std::span::iterator& end, std::string& arg + std::span::iterator& itr, + const std::span::iterator& end, std::string& arg ) { ++itr; if (itr == end) { @@ -49,7 +50,9 @@ handleNextArg( } static void -handleDependency(HashSet& newDeps, const StringRef dep) { +handleDependency( + HashSet& newDeps, const std::string_view dep +) { if (newDeps.contains(dep)) { logger::warn("The dependency `", dep, "` is already in the poac.toml"); return; @@ -58,7 +61,7 @@ handleDependency(HashSet& newDeps, const StringRef dep) { } static std::string -getDependencyGitUrl(const StringRef dep) { +getDependencyGitUrl(const std::string_view dep) { if (dep.find("://") == std::string::npos) { // check if atleast in "user/repo" format if (dep.find('/') == std::string::npos) { @@ -72,7 +75,7 @@ getDependencyGitUrl(const StringRef dep) { } static std::string -getDependencyName(const StringRef dep) { +getDependencyName(const std::string_view dep) { std::string name; if (dep.find("://") == std::string::npos) { name = dep.substr(dep.find_last_of('/') + 1); @@ -92,7 +95,7 @@ getDependencyName(const StringRef dep) { static int addDependencyToManifest( - const HashSet& newDeps, bool isSystemDependency, + const HashSet& newDeps, bool isSystemDependency, std::string& version, std::string& tag, std::string& rev, std::string& branch ) { @@ -146,13 +149,13 @@ addDependencyToManifest( } static int -addMain(const std::span args) { +addMain(const std::span args) { if (args.empty()) { logger::error("No dependencies to add"); return EXIT_FAILURE; } - HashSet newDeps = {}; + HashSet newDeps = {}; bool isSystemDependency = false; std::string version; // Only used with system-dependencies @@ -163,7 +166,7 @@ addMain(const std::span args) { // clang-format off HashMap< - StringRef, + std::string_view, std::function(decltype(args)::iterator&, decltype(args)::iterator)> > handlers = { diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index 54e0f1346..f90e12125 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -10,8 +10,9 @@ #include #include #include +#include -static int buildMain(std::span args); +static int buildMain(std::span args); const Subcmd BUILD_CMD = Subcmd{ "build" } @@ -45,7 +46,7 @@ buildImpl(std::string& outDir, const bool isDebug) { } static int -buildMain(const std::span args) { +buildMain(const std::span args) { // Parse args bool isDebug = true; bool buildCompdb = false; diff --git a/src/Cmd/Clean.cc b/src/Cmd/Clean.cc index 002f64ea1..dc2e335fa 100644 --- a/src/Cmd/Clean.cc +++ b/src/Cmd/Clean.cc @@ -6,8 +6,9 @@ #include #include #include +#include -static int cleanMain(std::span args) noexcept; +static int cleanMain(std::span args) noexcept; const Subcmd CLEAN_CMD = // Subcmd{ "clean" } @@ -19,7 +20,7 @@ const Subcmd CLEAN_CMD = // .setMainFn(cleanMain); static int -cleanMain(const std::span args) noexcept { +cleanMain(const std::span args) noexcept { fs::path outDir = "poac-out"; // TODO: share across sources // Parse args diff --git a/src/Cmd/Fmt.cc b/src/Cmd/Fmt.cc index a24d99918..276470db8 100644 --- a/src/Cmd/Fmt.cc +++ b/src/Cmd/Fmt.cc @@ -13,8 +13,9 @@ #include #include #include +#include -static int fmtMain(std::span args); +static int fmtMain(std::span args); const Subcmd FMT_CMD = Subcmd{ "fmt" } @@ -63,7 +64,7 @@ collectFormatTargetFiles( } static int -fmtMain(const std::span args) { +fmtMain(const std::span args) { bool isCheck = false; // Parse args for (auto itr = args.begin(); itr != args.end(); ++itr) { @@ -88,7 +89,7 @@ fmtMain(const std::span args) { return EXIT_FAILURE; } - const StringRef packageName = getPackageName(); + const std::string_view packageName = getPackageName(); std::string clangFormatArgs = "--style=file --fallback-style=LLVM -Werror"; if (isVerbose()) { clangFormatArgs += " --verbose"; diff --git a/src/Cmd/Help.cc b/src/Cmd/Help.cc index dc0565697..04ad1a06c 100644 --- a/src/Cmd/Help.cc +++ b/src/Cmd/Help.cc @@ -1,11 +1,11 @@ #include "Help.hpp" #include "../Cli.hpp" -#include "../Rustify.hpp" #include +#include -static int helpMain(std::span args) noexcept; +static int helpMain(std::span args) noexcept; const Subcmd HELP_CMD = // Subcmd{ "help" } @@ -14,6 +14,6 @@ const Subcmd HELP_CMD = // .setMainFn(helpMain); static int -helpMain(const std::span args) noexcept { +helpMain(const std::span args) noexcept { return getCli().printHelp(args); } diff --git a/src/Cmd/Init.cc b/src/Cmd/Init.cc index 42d36f87c..e014ce215 100644 --- a/src/Cmd/Init.cc +++ b/src/Cmd/Init.cc @@ -10,8 +10,9 @@ #include #include #include +#include -static int initMain(std::span args); +static int initMain(std::span args); const Subcmd INIT_CMD = Subcmd{ "init" } @@ -21,7 +22,7 @@ const Subcmd INIT_CMD = .setMainFn(initMain); static int -initMain(const std::span args) { +initMain(const std::span args) { // Parse args bool isBin = true; for (auto itr = args.begin(); itr != args.end(); ++itr) { diff --git a/src/Cmd/Lint.cc b/src/Cmd/Lint.cc index fb1c0cfe8..edf90cb15 100644 --- a/src/Cmd/Lint.cc +++ b/src/Cmd/Lint.cc @@ -10,8 +10,9 @@ #include #include #include +#include -static int lintMain(std::span args); +static int lintMain(std::span args); const Subcmd LINT_CMD = Subcmd{ "lint" } @@ -24,7 +25,7 @@ struct LintArgs { }; static int -lint(const StringRef name, const StringRef cpplintArgs) { +lint(const std::string_view name, const std::string_view cpplintArgs) { logger::info("Linting", name); std::string cpplintCmd = "cpplint"; @@ -52,7 +53,7 @@ lint(const StringRef name, const StringRef cpplintArgs) { } static int -lintMain(const std::span args) { +lintMain(const std::span args) { LintArgs lintArgs; for (auto itr = args.begin(); itr != args.end(); ++itr) { if (const auto res = Cli::handleGlobalOpts(itr, args.end(), "lint")) { @@ -82,7 +83,7 @@ lintMain(const std::span args) { } std::string cpplintArgs = lintArgs.excludes; - const StringRef packageName = getPackageName(); + const std::string_view packageName = getPackageName(); if (fs::exists("CPPLINT.cfg")) { logger::debug("Using CPPLINT.cfg for lint ..."); return lint(packageName, cpplintArgs); @@ -98,7 +99,7 @@ lintMain(const std::span args) { if (!cpplintFilters.empty()) { logger::debug("Using Poac manifest file for lint ..."); cpplintArgs += " --filter="; - for (const StringRef filter : cpplintFilters) { + for (const std::string_view filter : cpplintFilters) { cpplintArgs += filter; cpplintArgs += ','; } diff --git a/src/Cmd/New.cc b/src/Cmd/New.cc index b94745416..71bfd7833 100644 --- a/src/Cmd/New.cc +++ b/src/Cmd/New.cc @@ -16,8 +16,9 @@ #include #include #include +#include -static int newMain(std::span args); +static int newMain(std::span args); const Subcmd NEW_CMD = // Subcmd{ "new" } @@ -27,7 +28,7 @@ const Subcmd NEW_CMD = // .setArg(Arg{ "name" }) .setMainFn(newMain); -static constexpr StringRef MAIN_CC = +static constexpr std::string_view MAIN_CC = "#include \n\n" "int main() {\n" " std::cout << \"Hello, world!\" << std::endl;\n" @@ -47,7 +48,7 @@ getAuthor() noexcept { } std::string -createPoacToml(const StringRef projectName) noexcept { +createPoacToml(const std::string_view projectName) noexcept { std::string poacToml = "[package]\n" "name = \""; @@ -64,7 +65,7 @@ createPoacToml(const StringRef projectName) noexcept { } static std::string -getHeader(const StringRef projectName) noexcept { +getHeader(const std::string_view projectName) noexcept { const std::string projectNameUpper = toMacroName(projectName); std::string header = "#ifndef " + projectNameUpper + "_HPP\n" "#define " + projectNameUpper + "_HPP\n\n" @@ -78,7 +79,9 @@ getHeader(const StringRef projectName) noexcept { } static void -writeToFile(std::ofstream& ofs, const fs::path& fpath, const StringRef text) { +writeToFile( + std::ofstream& ofs, const fs::path& fpath, const std::string_view text +) { ofs.open(fpath); if (ofs.is_open()) { ofs << text; @@ -92,7 +95,7 @@ writeToFile(std::ofstream& ofs, const fs::path& fpath, const StringRef text) { } static void -createTemplateFiles(const bool isBin, const StringRef projectName) { +createTemplateFiles(const bool isBin, const std::string_view projectName) { std::ofstream ofs; if (isBin) { @@ -122,7 +125,7 @@ createTemplateFiles(const bool isBin, const StringRef projectName) { } static int -newMain(const std::span args) { +newMain(const std::span args) { // Parse args bool isBin = true; std::string packageName; diff --git a/src/Cmd/New.hpp b/src/Cmd/New.hpp index 3a039fd9a..a509e50ea 100644 --- a/src/Cmd/New.hpp +++ b/src/Cmd/New.hpp @@ -1,9 +1,9 @@ #pragma once #include "../Cli.hpp" -#include "../Rustify.hpp" #include +#include extern const Subcmd NEW_CMD; -std::string createPoacToml(StringRef projectName) noexcept; +std::string createPoacToml(std::string_view projectName) noexcept; diff --git a/src/Cmd/Run.cc b/src/Cmd/Run.cc index a843d571c..832ff739c 100644 --- a/src/Cmd/Run.cc +++ b/src/Cmd/Run.cc @@ -13,8 +13,9 @@ #include #include #include +#include -static int runMain(std::span args); +static int runMain(std::span args); const Subcmd RUN_CMD = Subcmd{ "run" } @@ -30,7 +31,7 @@ const Subcmd RUN_CMD = .setMainFn(runMain); static int -runMain(const std::span args) { +runMain(const std::span args) { // Parse args bool isDebug = true; auto itr = args.begin(); diff --git a/src/Cmd/Search.cc b/src/Cmd/Search.cc index 973d1d241..2a4fc93c0 100644 --- a/src/Cmd/Search.cc +++ b/src/Cmd/Search.cc @@ -11,8 +11,9 @@ #include #include #include +#include -static int searchMain(std::span args); +static int searchMain(std::span args); const Subcmd SEARCH_CMD = Subcmd{ "search" } @@ -94,7 +95,7 @@ printTable(const nlohmann::json& packages) { } static int -searchMain(const std::span args) { +searchMain(const std::span args) { SearchArgs searchArgs; for (auto itr = args.begin(); itr != args.end(); ++itr) { if (const auto res = Cli::handleGlobalOpts(itr, args.end(), "search")) { diff --git a/src/Cmd/Test.cc b/src/Cmd/Test.cc index 98faa7a83..2d35d3a68 100644 --- a/src/Cmd/Test.cc +++ b/src/Cmd/Test.cc @@ -12,8 +12,9 @@ #include #include #include +#include -static int testMain(std::span args); +static int testMain(std::span args); const Subcmd TEST_CMD = // Subcmd{ "test" } @@ -25,7 +26,7 @@ const Subcmd TEST_CMD = // .setMainFn(testMain); static int -testMain(const std::span args) { +testMain(const std::span args) { // Parse args bool isDebug = true; for (auto itr = args.begin(); itr != args.end(); ++itr) { diff --git a/src/Cmd/Tidy.cc b/src/Cmd/Tidy.cc index 3dc56a29b..8372158c3 100644 --- a/src/Cmd/Tidy.cc +++ b/src/Cmd/Tidy.cc @@ -12,8 +12,9 @@ #include #include #include +#include -static int tidyMain(std::span args); +static int tidyMain(std::span args); const Subcmd TIDY_CMD = Subcmd{ "tidy" } @@ -23,7 +24,7 @@ const Subcmd TIDY_CMD = .setMainFn(tidyMain); static int -tidyImpl(const StringRef makeCmd) { +tidyImpl(const std::string_view makeCmd) { const auto start = std::chrono::steady_clock::now(); const int exitCode = execCmd(makeCmd); @@ -38,7 +39,7 @@ tidyImpl(const StringRef makeCmd) { } static int -tidyMain(const std::span args) { +tidyMain(const std::span args) { // Parse args bool fix = false; for (auto itr = args.begin(); itr != args.end(); ++itr) { diff --git a/src/Cmd/Version.cc b/src/Cmd/Version.cc index 022d048d4..dd34c4aa8 100644 --- a/src/Cmd/Version.cc +++ b/src/Cmd/Version.cc @@ -9,6 +9,7 @@ #include #include #include +#include #ifndef POAC_PKG_VERSION # error "POAC_PKG_VERSION is not defined" @@ -28,24 +29,24 @@ const Subcmd VERSION_CMD = // .setDesc("Show version information") .setMainFn(versionMain); -static consteval StringRef -checkAvailability(const StringRef str) noexcept { +static consteval std::string_view +checkAvailability(const std::string_view str) noexcept { return str.empty() ? "unavailable" : str; } -static constinit const StringRef COMMIT_SHORT_HASH = +static constinit const std::string_view COMMIT_SHORT_HASH = checkAvailability(POAC_COMMIT_SHORT_HASH); -static constinit const StringRef COMMIT_HASH = +static constinit const std::string_view COMMIT_HASH = checkAvailability(POAC_COMMIT_HASH); -static constinit const StringRef COMMIT_DATE = +static constinit const std::string_view COMMIT_DATE = checkAvailability(POAC_COMMIT_DATE); static consteval char -firstMonthChar(const StringRef month) noexcept { +firstMonthChar(const std::string_view month) noexcept { return (month[0] == 'O' || month[0] == 'N' || month[0] == 'D') ? '1' : '0'; } static consteval char -secondMonthChar(const StringRef month) noexcept { +secondMonthChar(const std::string_view month) noexcept { if (month[0] == 'J') { if (month[1] == 'a') { // Jan @@ -113,7 +114,7 @@ static constinit const char COMPILE_DATE[] = { }; int -versionMain(const std::span args) noexcept { +versionMain(const std::span args) noexcept { // Parse args for (auto itr = args.begin(); itr != args.end(); ++itr) { if (const auto res = Cli::handleGlobalOpts(itr, args.end(), "version")) { diff --git a/src/Cmd/Version.hpp b/src/Cmd/Version.hpp index c98e91b21..c896aeb7d 100644 --- a/src/Cmd/Version.hpp +++ b/src/Cmd/Version.hpp @@ -1,9 +1,9 @@ #pragma once #include "../Cli.hpp" -#include "../Rustify.hpp" #include +#include extern const Subcmd VERSION_CMD; -int versionMain(std::span args) noexcept; +int versionMain(std::span args) noexcept; diff --git a/src/Git2/Config.cc b/src/Git2/Config.cc index c255ecafe..d337544a3 100644 --- a/src/Git2/Config.cc +++ b/src/Git2/Config.cc @@ -1,9 +1,9 @@ #include "Config.hpp" -#include "../Rustify.hpp" #include "Exception.hpp" #include +#include namespace git2 { @@ -24,7 +24,7 @@ Config::openDefault() { } std::string -Config::getString(const StringRef name) { +Config::getString(const std::string_view name) { git_buf ret = { nullptr, 0, 0 }; git2Throw(git_config_get_string_buf(&ret, this->raw, name.data())); return { ret.ptr, ret.size }; diff --git a/src/Git2/Config.hpp b/src/Git2/Config.hpp index 1dc2b6c1c..d288dbf97 100644 --- a/src/Git2/Config.hpp +++ b/src/Git2/Config.hpp @@ -1,10 +1,10 @@ #pragma once -#include "../Rustify.hpp" #include "Global.hpp" #include #include +#include namespace git2 { @@ -27,7 +27,7 @@ struct Config : public GlobalState { Config& openDefault(); /// Get the value of a string config variable as an owned string. - std::string getString(StringRef name); + std::string getString(std::string_view name); }; } // end namespace git2 diff --git a/src/Git2/Describe.cc b/src/Git2/Describe.cc index 790356730..4bfd79aba 100644 --- a/src/Git2/Describe.cc +++ b/src/Git2/Describe.cc @@ -1,11 +1,11 @@ #include "Describe.hpp" -#include "../Rustify.hpp" #include "Exception.hpp" #include "Repository.hpp" #include #include +#include namespace git2 { @@ -52,7 +52,7 @@ DescribeOptions::showCommitOidAsFallback(const bool show) { } DescribeOptions& -DescribeOptions::pattern(const StringRef pattern) { +DescribeOptions::pattern(const std::string_view pattern) { this->raw.pattern = pattern.data(); return *this; } @@ -82,7 +82,7 @@ DescribeFormatOptions::alwaysUseLongFormat(const bool long_f) { } DescribeFormatOptions& -DescribeFormatOptions::dirtySuffix(const StringRef suffix) { +DescribeFormatOptions::dirtySuffix(const std::string_view suffix) { this->raw.dirty_suffix = suffix.data(); return *this; } diff --git a/src/Git2/Describe.hpp b/src/Git2/Describe.hpp index 5892db16b..c64c6f1cd 100644 --- a/src/Git2/Describe.hpp +++ b/src/Git2/Describe.hpp @@ -1,11 +1,11 @@ #pragma once -#include "../Rustify.hpp" #include "Global.hpp" #include "Repository.hpp" #include #include +#include namespace git2 { @@ -41,7 +41,7 @@ struct DescribeOptions : public GlobalState { /// back to showing the full id of the commit. DescribeOptions& showCommitOidAsFallback(bool show); - DescribeOptions& pattern(StringRef pattern); + DescribeOptions& pattern(std::string_view pattern); }; struct DescribeFormatOptions : public GlobalState { @@ -67,7 +67,7 @@ struct DescribeFormatOptions : public GlobalState { /// If the workdir is dirty and this is set, this string will be appended to /// the description string. - DescribeFormatOptions& dirtySuffix(StringRef suffix); + DescribeFormatOptions& dirtySuffix(std::string_view suffix); }; struct Describe : public GlobalState { diff --git a/src/Git2/Oid.cc b/src/Git2/Oid.cc index 9d0a459d3..48e6c9a8e 100644 --- a/src/Git2/Oid.cc +++ b/src/Git2/Oid.cc @@ -1,12 +1,12 @@ #include "Oid.hpp" -#include "../Rustify.hpp" #include "Exception.hpp" #include #include #include #include +#include namespace git2 { @@ -17,7 +17,7 @@ Oid::Oid(git_oid* oid) : oid(*oid), raw(oid) {} // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) Oid::Oid(const git_oid* oid) : Oid(const_cast(oid)) {} -Oid::Oid(const StringRef str) { +Oid::Oid(const std::string_view str) { git2Throw(git_oid_fromstrn(raw, str.data(), str.size())); } diff --git a/src/Git2/Oid.hpp b/src/Git2/Oid.hpp index f34f27859..1dbe28dce 100644 --- a/src/Git2/Oid.hpp +++ b/src/Git2/Oid.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace git2 { @@ -23,7 +24,7 @@ struct Oid : public GlobalState { explicit Oid(const git_oid* oid); /// Parse a hex-formatted object id into an oid structure. - explicit Oid(StringRef str); + explicit Oid(std::string_view str); // Since Oid would not be constructed by itself, the destructor is not // responsible for freeing the raw pointer. diff --git a/src/Git2/Repository.cc b/src/Git2/Repository.cc index 8f0982553..1e74b0027 100644 --- a/src/Git2/Repository.cc +++ b/src/Git2/Repository.cc @@ -1,6 +1,5 @@ #include "Repository.hpp" -#include "../Rustify.hpp" #include "Config.hpp" #include "Exception.hpp" #include "Oid.hpp" @@ -8,6 +7,7 @@ #include #include #include +#include namespace git2 { @@ -16,29 +16,29 @@ Repository::~Repository() { } Repository& -Repository::open(const StringRef path) { +Repository::open(const std::string_view path) { git2Throw(git_repository_open(&this->raw, path.data())); return *this; } Repository& -Repository::openBare(const StringRef path) { +Repository::openBare(const std::string_view path) { git2Throw(git_repository_open_bare(&this->raw, path.data())); return *this; } Repository& -Repository::init(const StringRef path) { +Repository::init(const std::string_view path) { git2Throw(git_repository_init(&this->raw, path.data(), false)); return *this; } Repository& -Repository::initBare(const StringRef path) { +Repository::initBare(const std::string_view path) { git2Throw(git_repository_init(&this->raw, path.data(), true)); return *this; } bool -Repository::isIgnored(const StringRef path) const { +Repository::isIgnored(const std::string_view path) const { int ignored = 0; git2Throw(git_ignore_path_is_ignored(&ignored, this->raw, path.data())); return static_cast(ignored); @@ -46,14 +46,15 @@ Repository::isIgnored(const StringRef path) const { Repository& Repository::clone( - const StringRef url, const StringRef path, const git_clone_options* opts + const std::string_view url, const std::string_view path, + const git_clone_options* opts ) { git2Throw(git_clone(&this->raw, url.data(), path.data(), opts)); return *this; } Object -Repository::revparseSingle(const StringRef spec) const { +Repository::revparseSingle(const std::string_view spec) const { git_object* obj = nullptr; git2Throw(git_revparse_single(&obj, this->raw, spec.data())); return git2::Object(obj); @@ -75,7 +76,7 @@ Repository::checkoutHead(bool force) { } Oid -Repository::refNameToId(const StringRef refname) const { +Repository::refNameToId(const std::string_view refname) const { git_oid oid; git2Throw(git_reference_name_to_id(&oid, this->raw, refname.data())); return Oid(oid); diff --git a/src/Git2/Repository.hpp b/src/Git2/Repository.hpp index 4c937c458..c32f95af6 100644 --- a/src/Git2/Repository.hpp +++ b/src/Git2/Repository.hpp @@ -1,6 +1,5 @@ #pragma once -#include "../Rustify.hpp" #include "Config.hpp" #include "Global.hpp" #include "Object.hpp" @@ -8,6 +7,7 @@ #include #include +#include namespace git2 { @@ -25,32 +25,34 @@ struct Repository : public GlobalState { /// Attempt to open an already-existing repository at `path`. /// /// The path can point to either a normal or bare repository. - Repository& open(StringRef path); + Repository& open(std::string_view path); /// Attempt to open an already-existing bare repository at `path`. /// /// The path can point to only a bare repository. - Repository& openBare(StringRef path); + Repository& openBare(std::string_view path); /// Creates a new repository in the specified folder. /// /// This by default will create any necessary directories to create the /// repository, and it will read any user-specified templates when creating /// the repository. This behavior can be configured through `init_opts`. - Repository& init(StringRef path); + Repository& init(std::string_view path); /// Creates a new `--bare` repository in the specified folder. /// /// The folder must exist prior to invoking this function. - Repository& initBare(StringRef path); + Repository& initBare(std::string_view path); /// Check if path is ignored by the ignore rules. - bool isIgnored(StringRef path) const; + bool isIgnored(std::string_view path) const; /// Clone a remote repository. - Repository& - clone(StringRef url, StringRef path, const git_clone_options* opts = nullptr); + Repository& clone( + std::string_view url, std::string_view path, + const git_clone_options* opts = nullptr + ); /// Find a single object, as specified by a revision string. - Object revparseSingle(StringRef spec) const; + Object revparseSingle(std::string_view spec) const; /// Make the repository HEAD directly point to the Commit. Repository& setHeadDetached(const Oid& oid); @@ -59,7 +61,7 @@ struct Repository : public GlobalState { Repository& checkoutHead(bool force = false); /// Lookup a reference by name and resolve immediately to OID. - Oid refNameToId(StringRef refname) const; + Oid refNameToId(std::string_view refname) const; /// Get the configuration file for this repository. /// diff --git a/src/Git2/Revwalk.cc b/src/Git2/Revwalk.cc index 12ab6713b..10019db30 100644 --- a/src/Git2/Revwalk.cc +++ b/src/Git2/Revwalk.cc @@ -1,10 +1,10 @@ #include "Revwalk.hpp" -#include "../Rustify.hpp" #include "Exception.hpp" #include "Repository.hpp" #include +#include namespace git2 { @@ -46,19 +46,19 @@ Revwalk::pushHead() { } Revwalk& -Revwalk::pushGlob(const StringRef glob) { +Revwalk::pushGlob(const std::string_view glob) { git2Throw(git_revwalk_push_glob(this->raw, glob.data())); return *this; } Revwalk& -Revwalk::pushRange(const StringRef range) { +Revwalk::pushRange(const std::string_view range) { git2Throw(git_revwalk_push_range(this->raw, range.data())); return *this; } Revwalk& -Revwalk::pushRef(const StringRef reference) { +Revwalk::pushRef(const std::string_view reference) { git2Throw(git_revwalk_push_ref(this->raw, reference.data())); return *this; } @@ -76,13 +76,13 @@ Revwalk::hideHead() { } Revwalk& -Revwalk::hideGlob(const StringRef glob) { +Revwalk::hideGlob(const std::string_view glob) { git2Throw(git_revwalk_hide_glob(this->raw, glob.data())); return *this; } Revwalk& -Revwalk::hideRef(const StringRef reference) { +Revwalk::hideRef(const std::string_view reference) { git2Throw(git_revwalk_hide_ref(this->raw, reference.data())); return *this; } diff --git a/src/Git2/Revwalk.hpp b/src/Git2/Revwalk.hpp index ebf01e517..585274711 100644 --- a/src/Git2/Revwalk.hpp +++ b/src/Git2/Revwalk.hpp @@ -1,11 +1,11 @@ #pragma once -#include "../Rustify.hpp" #include "Global.hpp" #include "Oid.hpp" #include "Repository.hpp" #include +#include namespace git2 { @@ -59,19 +59,19 @@ struct Revwalk : public GlobalState { /// /// Any references matching this glob which do not point to a committish /// will be ignored. - Revwalk& pushGlob(StringRef glob); + Revwalk& pushGlob(std::string_view glob); /// Push and hide the respective endpoints of the given range. /// /// The range should be of the form `..` where each /// `` is in the form accepted by `revparse_single`. The left-hand /// commit will be hidden and the right-hand commit pushed. - Revwalk& pushRange(StringRef range); + Revwalk& pushRange(std::string_view range); /// Push the OID pointed to by a reference /// /// The reference must point to a committish. - Revwalk& pushRef(StringRef reference); + Revwalk& pushRef(std::string_view reference); /// Mark a commit as not of interest to this revwalk. Revwalk& hide(const Oid& oid); @@ -91,12 +91,12 @@ struct Revwalk : public GlobalState { /// /// Any references matching this glob which do not point to a committish /// will be ignored. - Revwalk& hideGlob(StringRef glob); + Revwalk& hideGlob(std::string_view glob); /// Hide the OID pointed to by a reference. /// /// The reference must point to a committish. - Revwalk& hideRef(StringRef reference); + Revwalk& hideRef(std::string_view reference); }; } // end namespace git2 diff --git a/src/Logger.hpp b/src/Logger.hpp index cd6c7fa17..0c16c6a4b 100644 --- a/src/Logger.hpp +++ b/src/Logger.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -26,8 +27,8 @@ template concept MaybeWriter = Writer || Display; template -concept HeadProcessor = std::is_nothrow_invocable_v - && Display>; +concept HeadProcessor = std::is_nothrow_invocable_v + && Display>; class Logger { Level level = Level::Info; @@ -56,22 +57,22 @@ class Logger { static void error(MaybeWriter auto&&... msgs) noexcept { logln( Level::Error, - [](const StringRef head) noexcept { return bold(red(head)); }, + [](const std::string_view head) noexcept { return bold(red(head)); }, "Error: ", std::forward(msgs)... ); } static void warn(MaybeWriter auto&&... msgs) noexcept { logln( Level::Warn, - [](const StringRef head) noexcept { return bold(yellow(head)); }, + [](const std::string_view head) noexcept { return bold(yellow(head)); }, "Warning: ", std::forward(msgs)... ); } static void info(MaybeWriter auto&&... msgs) noexcept { logln( Level::Info, - [](const StringRef head) noexcept { - const StringRef fmtStr = shouldColor() ? "{:>21} " : "{:>12} "; + [](const std::string_view head) noexcept { + const std::string_view fmtStr = shouldColor() ? "{:>21} " : "{:>12} "; return fmt::format(fmt::runtime(fmtStr), bold(green(head))); }, std::forward(msgs)... @@ -90,7 +91,7 @@ class Logger { private: static void debuglike( - Level level, const StringRef lvlStr, const StringRef func, + Level level, const std::string_view lvlStr, const std::string_view func, Writer auto&& writer, Display auto&&... msgs ) noexcept { // Swap func and writer, since for logln, writer should appear first for @@ -101,12 +102,12 @@ class Logger { ); } static void debuglike( - Level level, const StringRef lvlStr, MaybeWriter auto&& maybeWriter, - Display auto&&... msgs + Level level, const std::string_view lvlStr, + MaybeWriter auto&& maybeWriter, Display auto&&... msgs ) noexcept { logln( level, - [lvlStr](const StringRef func) noexcept { + [lvlStr](const std::string_view func) noexcept { return fmt::format( "{}Poac {} {}{} ", gray("["), lvlStr, func, gray("]") ); diff --git a/src/Manifest.cc b/src/Manifest.cc index c65df83f7..122ec4534 100644 --- a/src/Manifest.cc +++ b/src/Manifest.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #define TOML11_NO_ERROR_PREFIX @@ -190,7 +191,7 @@ getManifestPath() { // Returns an error message if the package name is invalid. Option // TODO: result-like types make more sense. -validatePackageName(const StringRef name) noexcept { +validatePackageName(const std::string_view name) noexcept { // Empty if (name.empty()) { return "must not be empty"; @@ -220,7 +221,7 @@ validatePackageName(const StringRef name) noexcept { } // Using C++ keywords - const HashSet keywords = { + const HashSet keywords = { #include "Keywords.def" }; if (keywords.contains(name)) { @@ -264,7 +265,7 @@ getPackageVersion() { } static void -validateCxxflag(const StringRef cxxflag) { +validateCxxflag(const std::string_view cxxflag) { // cxxflag must start with `-` if (cxxflag.empty() || cxxflag[0] != '-') { throw PoacError("cxxflag must start with `-`"); @@ -406,7 +407,7 @@ static const HashSet ALLOWED_CHARS = { }; static void -validateDepName(const StringRef name) { +validateDepName(const std::string_view name) { if (name.empty()) { throw PoacError("dependency name is empty"); } diff --git a/src/Manifest.hpp b/src/Manifest.hpp index 0520541aa..aad4517bf 100644 --- a/src/Manifest.hpp +++ b/src/Manifest.hpp @@ -5,6 +5,7 @@ #include #include +#include struct DepMetadata { std::string includes; // -Isomething @@ -53,7 +54,7 @@ struct Edition { }; const fs::path& getManifestPath(); -Option validatePackageName(StringRef name) noexcept; +Option validatePackageName(std::string_view name) noexcept; const std::string& getPackageName(); const Edition& getPackageEdition(); const Version& getPackageVersion(); diff --git a/src/Rustify/Aliases.hpp b/src/Rustify/Aliases.hpp index 5848af661..f51df2127 100644 --- a/src/Rustify/Aliases.hpp +++ b/src/Rustify/Aliases.hpp @@ -33,8 +33,6 @@ using f32 = float; using f64 = double; // NOLINTEND(readability-identifier-naming) -using StringRef = std::string_view; - template using Arr = std::array; template @@ -102,13 +100,13 @@ struct source_location { ) noexcept { return { file, line, func }; } - constexpr StringRef file_name() const noexcept { + constexpr std::string_view file_name() const noexcept { return file_; } constexpr int line() const noexcept { return line_; } - constexpr StringRef function_name() const noexcept { + constexpr std::string_view function_name() const noexcept { return func_; } @@ -121,7 +119,8 @@ struct source_location { [[noreturn]] inline void panic( - const StringRef msg, const source_location& loc = source_location::current() + const std::string_view msg, + const source_location& loc = source_location::current() ) noexcept { std::cerr << "panicked at '" << msg << "', " << loc.file_name() << ':' << loc.line() << '\n'; diff --git a/src/Rustify/Tests.hpp b/src/Rustify/Tests.hpp index ee240cd7f..c47750d1c 100644 --- a/src/Rustify/Tests.hpp +++ b/src/Rustify/Tests.hpp @@ -7,15 +7,16 @@ #include #include #include +#include #include #include #include namespace tests { -inline constinit const StringRef GREEN = "\033[32m"; -inline constinit const StringRef RED = "\033[31m"; -inline constinit const StringRef RESET = "\033[0m"; +inline constinit const std::string_view GREEN = "\033[32m"; +inline constinit const std::string_view RED = "\033[31m"; +inline constinit const std::string_view RESET = "\033[0m"; inline constinit const usize SRC_REL_PATH_LEN = 6; // `../../` @@ -29,8 +30,8 @@ inline constinit const usize SRC_REL_PATH_LEN = 6; // `../../` // We first should remove `../../` if it exists, then remove the first // directory name since it can be either `src` or `tests`. Finally, we remove // the file extension, which is basically any of C++ source file extensions. -inline constexpr StringRef -modName(StringRef file) noexcept { +inline constexpr std::string_view +modName(std::string_view file) noexcept { if (file.empty()) { return file; } @@ -40,13 +41,13 @@ modName(StringRef file) noexcept { } usize start = file.find_first_of('/'); - if (start == StringRef::npos) { + if (start == std::string_view::npos) { return file; } ++start; const usize end = file.find_last_of('.'); - if (end == StringRef::npos) { + if (end == std::string_view::npos) { return file; } @@ -74,7 +75,7 @@ error(const source_location& loc, Display auto&&... msgs) noexcept { inline void assertTrue( - const bool cond, const StringRef msg = "", + const bool cond, const std::string_view msg = "", const source_location& loc = source_location::current() ) noexcept { if (cond) { @@ -90,7 +91,7 @@ assertTrue( inline void assertFalse( - const bool cond, const StringRef msg = "", + const bool cond, const std::string_view msg = "", const source_location& loc = source_location::current() ) noexcept { if (!cond) { @@ -108,7 +109,7 @@ template requires(Eq && Display && Display) inline void assertEq( - Lhs&& lhs, Rhs&& rhs, const StringRef msg = "", + Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", const source_location& loc = source_location::current() ) noexcept { if (lhs == rhs) { @@ -130,7 +131,7 @@ template requires(Ne && Display && Display) inline void assertNe( - Lhs&& lhs, Rhs&& rhs, const StringRef msg = "", + Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", const source_location& loc = source_location::current() ) noexcept { if (lhs != rhs) { @@ -152,7 +153,7 @@ template requires(Lt && Display && Display) inline void assertLt( - Lhs&& lhs, Rhs&& rhs, const StringRef msg = "", + Lhs&& lhs, Rhs&& rhs, const std::string_view msg = "", const source_location& loc = source_location::current() ) noexcept { if (lhs < rhs) { @@ -174,7 +175,7 @@ template requires(std::is_invocable_v) inline void assertException( - Fn&& func, const StringRef msg, + Fn&& func, const std::string_view msg, const source_location& loc = source_location::current() ) noexcept { try { diff --git a/src/Semver.cc b/src/Semver.cc index 7ac2cdcde..2766ac6fe 100644 --- a/src/Semver.cc +++ b/src/Semver.cc @@ -7,6 +7,7 @@ #include #include #include +#include std::ostream& operator<<(std::ostream& os, const VersionToken& tok) noexcept { @@ -15,7 +16,7 @@ operator<<(std::ostream& os, const VersionToken& tok) noexcept { os << std::get(tok.value); break; case VersionToken::Ident: - os << std::get(tok.value); + os << std::get(tok.value); break; case VersionToken::Dot: os << '.'; @@ -54,7 +55,8 @@ operator==(const VersionToken& lhs, const VersionToken& rhs) noexcept { case VersionToken::Num: return std::get(lhs.value) == std::get(rhs.value); case VersionToken::Ident: - return std::get(lhs.value) == std::get(rhs.value); + return std::get(lhs.value) + == std::get(rhs.value); case VersionToken::Dot: case VersionToken::Hyphen: case VersionToken::Plus: @@ -267,7 +269,7 @@ VersionLexer::consumeIdent() noexcept { step(); ++len; } - return { VersionToken::Ident, StringRef(s.data() + pos - len, len) }; + return { VersionToken::Ident, std::string_view(s.data() + pos - len, len) }; } VersionToken @@ -354,7 +356,8 @@ VersionLexer::peek() { struct SemverParseError : public SemverError { SemverParseError( - const VersionLexer& lexer, const VersionToken& tok, const StringRef msg + const VersionLexer& lexer, const VersionToken& tok, + const std::string_view msg ) : SemverError( lexer.s, '\n', std::string(lexer.pos, ' '), carets(tok), msg @@ -461,19 +464,19 @@ VersionParser::parseIdent() { } Prerelease -Prerelease::parse(const StringRef str) { +Prerelease::parse(const std::string_view str) { VersionParser parser(str); return parser.parsePre(); } BuildMetadata -BuildMetadata::parse(const StringRef str) { +BuildMetadata::parse(const std::string_view str) { VersionParser parser(str); return parser.parseBuild(); } Version -Version::parse(const StringRef str) { +Version::parse(const std::string_view str) { VersionParser parser(str); return parser.parse(); } diff --git a/src/Semver.hpp b/src/Semver.hpp index 6e57799e0..1a2399c99 100644 --- a/src/Semver.hpp +++ b/src/Semver.hpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -35,10 +36,11 @@ struct VersionToken { using enum Kind; Kind kind; - std::variant value; + std::variant value; constexpr VersionToken( - Kind kind, const std::variant& value + Kind kind, + const std::variant& value ) noexcept : kind(kind), value(value) {} constexpr explicit VersionToken(Kind kind) noexcept @@ -51,7 +53,7 @@ struct VersionToken { struct Prerelease { Vec ident; - static Prerelease parse(StringRef str); + static Prerelease parse(std::string_view str); bool empty() const noexcept; std::string toString() const noexcept; }; @@ -65,7 +67,7 @@ bool operator>=(const Prerelease& lhs, const Prerelease& rhs) noexcept; struct BuildMetadata { Vec ident; - static BuildMetadata parse(StringRef str); + static BuildMetadata parse(std::string_view str); bool empty() const noexcept; std::string toString() const noexcept; }; @@ -77,7 +79,7 @@ struct Version { Prerelease pre; BuildMetadata build; - static Version parse(StringRef str); + static Version parse(std::string_view str); std::string toString() const noexcept; }; std::ostream& operator<<(std::ostream& os, const Version& ver) noexcept; @@ -89,10 +91,11 @@ bool operator<=(const Version& lhs, const Version& rhs) noexcept; bool operator>=(const Version& lhs, const Version& rhs) noexcept; struct VersionLexer { - StringRef s; + std::string_view s; usize pos{ 0 }; - constexpr explicit VersionLexer(const StringRef str) noexcept : s(str) {} + constexpr explicit VersionLexer(const std::string_view str) noexcept + : s(str) {} constexpr bool isEof() const noexcept { return pos >= s.size(); @@ -110,7 +113,8 @@ struct VersionLexer { struct VersionParser { VersionLexer lexer; - constexpr explicit VersionParser(const StringRef str) noexcept : lexer(str) {} + constexpr explicit VersionParser(const std::string_view str) noexcept + : lexer(str) {} Version parse(); u64 parseNum(); diff --git a/src/TermColor.cc b/src/TermColor.cc index 89180e55e..bba8a0fc1 100644 --- a/src/TermColor.cc +++ b/src/TermColor.cc @@ -5,6 +5,7 @@ #include #include +#include static bool isTerm() noexcept { @@ -12,7 +13,7 @@ isTerm() noexcept { } static ColorMode -getColorMode(const StringRef str) noexcept { +getColorMode(const std::string_view str) noexcept { if (str == "always") { return ColorMode::Always; } else if (str == "auto") { @@ -74,7 +75,7 @@ setColorMode(const ColorMode mode) noexcept { } void -setColorMode(const StringRef str) noexcept { +setColorMode(const std::string_view str) noexcept { setColorMode(getColorMode(str)); } @@ -84,7 +85,7 @@ shouldColor() noexcept { } static std::string -colorize(const StringRef str, const StringRef code) noexcept { +colorize(const std::string_view str, const std::string_view code) noexcept { if (!shouldColor()) { return std::string(str); } @@ -115,35 +116,35 @@ colorize(const StringRef str, const StringRef code) noexcept { } std::string -gray(const StringRef str) noexcept { +gray(const std::string_view str) noexcept { return colorize(str, "30"); } std::string -red(const StringRef str) noexcept { +red(const std::string_view str) noexcept { return colorize(str, "31"); } std::string -green(const StringRef str) noexcept { +green(const std::string_view str) noexcept { return colorize(str, "32"); } std::string -yellow(const StringRef str) noexcept { +yellow(const std::string_view str) noexcept { return colorize(str, "33"); } std::string -blue(const StringRef str) noexcept { +blue(const std::string_view str) noexcept { return colorize(str, "34"); } std::string -magenta(const StringRef str) noexcept { +magenta(const std::string_view str) noexcept { return colorize(str, "35"); } std::string -cyan(const StringRef str) noexcept { +cyan(const std::string_view str) noexcept { return colorize(str, "36"); } std::string -bold(const StringRef str) noexcept { +bold(const std::string_view str) noexcept { return colorize(str, "1"); } diff --git a/src/TermColor.hpp b/src/TermColor.hpp index cbeacce12..83bc80ffe 100644 --- a/src/TermColor.hpp +++ b/src/TermColor.hpp @@ -1,8 +1,7 @@ #pragma once -#include "Rustify.hpp" - #include +#include enum class ColorMode { Always, @@ -11,15 +10,15 @@ enum class ColorMode { }; void setColorMode(ColorMode mode) noexcept; -void setColorMode(StringRef str) noexcept; +void setColorMode(std::string_view str) noexcept; bool shouldColor() noexcept; -std::string gray(StringRef str) noexcept; -std::string red(StringRef str) noexcept; -std::string green(StringRef str) noexcept; -std::string yellow(StringRef str) noexcept; -std::string blue(StringRef str) noexcept; -std::string magenta(StringRef str) noexcept; -std::string cyan(StringRef str) noexcept; +std::string gray(std::string_view str) noexcept; +std::string red(std::string_view str) noexcept; +std::string green(std::string_view str) noexcept; +std::string yellow(std::string_view str) noexcept; +std::string blue(std::string_view str) noexcept; +std::string magenta(std::string_view str) noexcept; +std::string cyan(std::string_view str) noexcept; -std::string bold(StringRef str) noexcept; +std::string bold(std::string_view str) noexcept; diff --git a/src/VersionReq.cc b/src/VersionReq.cc index 88ea6f134..1fcaf47ab 100644 --- a/src/VersionReq.cc +++ b/src/VersionReq.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -67,10 +68,10 @@ struct ComparatorToken { }; struct ComparatorLexer { - StringRef s; + std::string_view s; usize pos{ 0 }; - explicit ComparatorLexer(const StringRef str) noexcept : s(str) {} + explicit ComparatorLexer(const std::string_view str) noexcept : s(str) {} bool isEof() const noexcept { return pos >= s.size(); @@ -157,7 +158,7 @@ struct ComparatorLexer { struct ComparatorParser { ComparatorLexer lexer; - explicit ComparatorParser(const StringRef str) noexcept : lexer(str) {} + explicit ComparatorParser(const std::string_view str) noexcept : lexer(str) {} Comparator parse() { Comparator result; @@ -207,7 +208,7 @@ struct ComparatorParser { }; Comparator -Comparator::parse(const StringRef str) { +Comparator::parse(const std::string_view str) { ComparatorParser parser(str); return parser.parse(); } @@ -462,10 +463,10 @@ isCompStart(const char c) noexcept { } struct VersionReqLexer { - StringRef s; + std::string_view s; usize pos{ 0 }; - explicit VersionReqLexer(const StringRef str) noexcept : s(str) {} + explicit VersionReqLexer(const std::string_view str) noexcept : s(str) {} bool isEof() const noexcept { return pos >= s.size(); @@ -504,7 +505,7 @@ struct VersionReqLexer { struct VersionReqParser { VersionReqLexer lexer; - explicit VersionReqParser(const StringRef str) noexcept : lexer(str) {} + explicit VersionReqParser(const std::string_view str) noexcept : lexer(str) {} VersionReq parse() { VersionReq result; @@ -589,7 +590,7 @@ struct VersionReqParser { }; VersionReq -VersionReq::parse(const StringRef str) { +VersionReq::parse(const std::string_view str) { VersionReqParser parser(str); return parser.parse(); } @@ -823,7 +824,7 @@ VersionReq::toString() const noexcept { } std::string -VersionReq::toPkgConfigString(const StringRef name) const noexcept { +VersionReq::toPkgConfigString(const std::string_view name) const noexcept { // For pkg-config, canonicalization is necessary. const VersionReq req = canonicalize(); @@ -903,20 +904,20 @@ namespace tests { inline void assertMatchAll( - const VersionReq& req, const std::span versions, + const VersionReq& req, const std::span versions, const source_location& loc = source_location::current() ) { - for (const StringRef ver : versions) { + for (const std::string_view ver : versions) { assertTrue(req.satisfiedBy(Version::parse(ver)), "", loc); } } inline void assertMatchNone( - const VersionReq& req, const std::span versions, + const VersionReq& req, const std::span versions, const source_location& loc = source_location::current() ) { - for (const StringRef ver : versions) { + for (const std::string_view ver : versions) { assertFalse(req.satisfiedBy(Version::parse(ver)), "", loc); } } diff --git a/src/VersionReq.hpp b/src/VersionReq.hpp index f18d42f1b..6e2d61291 100644 --- a/src/VersionReq.hpp +++ b/src/VersionReq.hpp @@ -19,6 +19,7 @@ #include #include +#include struct OptVersion { u64 major{}; @@ -75,7 +76,7 @@ struct Comparator { Option patch; Prerelease pre; - static Comparator parse(StringRef str); + static Comparator parse(std::string_view str); void from(const OptVersion& ver) noexcept; std::string toString() const noexcept; std::string toPkgConfigString() const noexcept; @@ -87,10 +88,10 @@ struct VersionReq { Comparator left; Option right; - static VersionReq parse(StringRef str); + static VersionReq parse(std::string_view str); bool satisfiedBy(const Version& ver) const noexcept; std::string toString() const noexcept; - std::string toPkgConfigString(StringRef name) const noexcept; + std::string toPkgConfigString(std::string_view name) const noexcept; VersionReq canonicalize() const noexcept; bool canSimplify() const noexcept; }; diff --git a/src/main.cc b/src/main.cc index aa722a559..776ba8909 100644 --- a/src/main.cc +++ b/src/main.cc @@ -7,6 +7,7 @@ #include #include #include +#include const Cli& getCli() noexcept { @@ -76,7 +77,7 @@ main(int argc, char* argv[]) { // Local options else if (*itr == "-V"sv || *itr == "--version"sv) { - const Vec remArgs(itr + 1, args.end()); + const Vec remArgs(itr + 1, args.end()); return versionMain(remArgs); } else if (*itr == "--list"sv) { getCli().printAllSubcmds(true); @@ -86,7 +87,7 @@ main(int argc, char* argv[]) { // Subcommands else if (getCli().hasSubcmd(*itr)) { try { - const Vec remArgs(itr + 1, args.end()); + const Vec remArgs(itr + 1, args.end()); const int exitCode = getCli().exec(*itr, remArgs); if (exitCode != EXIT_SUCCESS) { logger::error( diff --git a/srcOld/Cfg.hpp b/srcOld/Cfg.hpp index dda14f8cf..d7b7ab228 100644 --- a/srcOld/Cfg.hpp +++ b/srcOld/Cfg.hpp @@ -5,6 +5,7 @@ module; #include #include #include +#include #include #include @@ -147,7 +148,7 @@ struct Token { }; Kind kind; - using StringType = StringRef; + using StringType = std::string_view; std::variant value; explicit Token(Kind k) @@ -189,7 +190,7 @@ struct Token { }; constexpr auto -to_kind(StringRef kind) -> Token::Kind { +to_kind(std::string_view kind) -> Token::Kind { if (kind == "(") { return Token::LeftParen; } else if (kind == ")") { @@ -268,13 +269,13 @@ operator<<(std::ostream& os, const Token& token) -> std::ostream& { } struct Lexer { - using ValueType = StringRef::value_type; + using ValueType = std::string_view::value_type; using SizeType = usize; - StringRef str; + std::string_view str; SizeType index{ 0 }; - explicit Lexer(StringRef str) : str(str) {} + explicit Lexer(std::string_view str) : str(str) {} inline auto next() -> Option { const auto [diff, token] = tokenize(this->index); @@ -294,8 +295,9 @@ struct Lexer { ) const -> std::pair> { return { this->diff_step(index_), token }; } - [[nodiscard]] inline auto generate_token(SizeType index_, StringRef kind) - const -> std::pair> { + [[nodiscard]] inline auto generate_token( + SizeType index_, std::string_view kind + ) const -> std::pair> { return generate_token(index_, Token{ to_kind(kind) }); } @@ -323,7 +325,7 @@ struct Lexer { [[nodiscard]] auto ident(SizeType index_) const -> std::pair; - static auto to_ident(StringRef s) noexcept -> Option; + static auto to_ident(std::string_view s) noexcept -> Option; }; auto @@ -397,7 +399,7 @@ Lexer::string(SizeType index_) const -> std::pair { throw cfg::StringError(std::string(this->str) + "\n" + msg); } } - const StringRef s = this->str.substr(start, index_ - start); + const std::string_view s = this->str.substr(start, index_ - start); this->step(index_); return { this->diff_step(index_), Token{ Token::std::string, s } }; } @@ -416,7 +418,7 @@ Lexer::ident(SizeType index_) const -> std::pair { this->step(index_); } - const StringRef s = this->str.substr(start, index_ - start); + const std::string_view s = this->str.substr(start, index_ - start); if (const auto ident = to_ident(s)) { return { this->diff_step(index_), Token{ Token::Ident, ident.value() } }; } else { @@ -430,7 +432,7 @@ Lexer::ident(SizeType index_) const -> std::pair { } auto -Lexer::to_ident(StringRef s) noexcept -> Option { +Lexer::to_ident(std::string_view s) noexcept -> Option { if (s == "cfg") { return Token::ident::cfg; } else if (s == "not") { @@ -483,9 +485,9 @@ struct Cfg { Ident key; Op op; - StringRef value; + std::string_view value; - Cfg(Token::ident key, Op op, StringRef value) + Cfg(Token::ident key, Op op, std::string_view value) : key(from_token_ident(key)), op(op), value(value) {} Cfg() = delete; @@ -700,7 +702,7 @@ CfgExpr::match(const Cfg& c) -> bool { struct Parser { Lexer lexer; - explicit Parser(StringRef str) : lexer(str) {} + explicit Parser(std::string_view str) : lexer(str) {} auto expr() -> CfgExpr; @@ -872,7 +874,7 @@ Parser::eat_right_paren() { } inline auto -parse(StringRef s) -> CfgExpr { +parse(std::string_view s) -> CfgExpr { return Parser(s).expr(); } diff --git a/srcOld/Config.hpp b/srcOld/Config.hpp index e283c9857..b6e525a72 100644 --- a/srcOld/Config.hpp +++ b/srcOld/Config.hpp @@ -40,7 +40,7 @@ inline const fs::path src_dir(cwd / "src"); inline const fs::path include_dir(cwd / "include"); inline const fs::path tests_dir(cwd / "tests"); inline const fs::path main_cpp_file(src_dir / "main.cpp"); -inline constexpr StringRef POAC_OUT = "poac-out"; +inline constexpr std::string_view POAC_OUT = "poac-out"; inline const fs::path out_dir(cwd / POAC_OUT); inline const fs::path conan_deps_dir(out_dir / ".conan"); diff --git a/srcOld/Lockfile.hpp b/srcOld/Lockfile.hpp index bba888ed1..02eb72660 100644 --- a/srcOld/Lockfile.hpp +++ b/srcOld/Lockfile.hpp @@ -22,8 +22,8 @@ import poac.util.rustify; export namespace poac::data::lockfile { -inline constexpr StringRef LOCKFILE_NAME = "poac.lock"; -inline constexpr StringRef LOCKFILE_HEADER = +inline constexpr std::string_view LOCKFILE_NAME = "poac.lock"; +inline constexpr std::string_view LOCKFILE_HEADER = " This file is automatically generated by Poac.\n" "# It is not intended for manual editing."; diff --git a/srcOld/Resolver.hpp b/srcOld/Resolver.hpp index 26101116f..f255b4d8d 100644 --- a/srcOld/Resolver.hpp +++ b/srcOld/Resolver.hpp @@ -57,7 +57,7 @@ get_extracted_path(const resolve::Package& package) -> fs::path { /// Rename unknown extracted directory to easily access when building. [[nodiscard]] auto rename_extracted_directory( - const resolve::Package& package, StringRef extracted_directory_name + const resolve::Package& package, std::string_view extracted_directory_name ) -> Result { const fs::path temporarily_extracted_path = config::default_registry_dir / extracted_directory_name; @@ -78,7 +78,7 @@ get_archive_path(const resolve::Package& package) -> fs::path { } inline auto -convert_to_download_link(StringRef repository) -> std::string { +convert_to_download_link(std::string_view repository) -> std::string { // repository should be like => // https://github.com/boostorg/winapi/tree/boost-1.66.0 // convert it to => @@ -98,10 +98,10 @@ convert_to_download_link(StringRef repository) -> std::string { // So, find the end of `tree/`. const usize end = repository.find('/', start); // Retrieve both sides: `https://github.com/tree/tree/` - const StringRef left = repository.substr(0, start); + const std::string_view left = repository.substr(0, start); // `/tree/v0.1.0`: this side is just a tag. // Mostly, we do not include `tree`, but we can. - StringRef right = repository.substr(end); + std::string_view right = repository.substr(end); return format("{}archive{}.tar.gz", left, right); } diff --git a/srcOld/Resolver/Resolve.hpp b/srcOld/Resolver/Resolve.hpp index 560a1cc28..4b3ec4c2a 100644 --- a/srcOld/Resolver/Resolve.hpp +++ b/srcOld/Resolver/Resolve.hpp @@ -214,7 +214,9 @@ get_versions_satisfy_interval(const Package& package const semver::Interval i(package.dep_info.version_rq); const Vec satisfied_versions = Try(util::net::api::versions(package.name)) - | boost::adaptors::filtered([&i](StringRef s) { return i.satisfies(s); }) + | boost::adaptors::filtered([&i](std::string_view s) { + return i.satisfies(s); + }) | util::meta::CONTAINERIZED; if (satisfied_versions.empty()) {