From efde470a1afa5d67798c45bb452ab37309356bef Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Sun, 21 Jul 2024 01:35:09 -0700 Subject: [PATCH] Remove String alias --- poac.toml | 1 + src/Algos.cc | 19 +-- src/Algos.hpp | 22 ++-- src/BuildConfig.cc | 221 ++++++++++++++++++----------------- src/BuildConfig.hpp | 14 ++- src/Cli.cc | 25 ++-- src/Cli.hpp | 5 +- src/Cmd/Add.cc | 42 +++---- src/Cmd/Build.cc | 9 +- src/Cmd/Build.hpp | 4 +- src/Cmd/Fmt.cc | 17 +-- src/Cmd/Init.cc | 2 +- src/Cmd/Lint.cc | 11 +- src/Cmd/New.cc | 14 +-- src/Cmd/New.hpp | 4 +- src/Cmd/Run.cc | 11 +- src/Cmd/Search.cc | 20 ++-- src/Cmd/Test.cc | 3 +- src/Cmd/Tidy.cc | 4 +- src/Git2/Config.cc | 4 +- src/Git2/Config.hpp | 3 +- src/Git2/Describe.cc | 3 +- src/Git2/Describe.hpp | 3 +- src/Git2/Exception.hpp | 3 +- src/Git2/Oid.cc | 5 +- src/Git2/Oid.hpp | 3 +- src/Git2/Time.cc | 5 +- src/Git2/Time.hpp | 3 +- src/Manifest.cc | 66 +++++------ src/Manifest.hpp | 19 +-- src/Parallelism.hpp | 4 +- src/Rustify/Aliases.hpp | 4 +- src/Rustify/Tests.hpp | 3 +- src/Semver.cc | 30 ++--- src/Semver.hpp | 9 +- src/TermColor.cc | 27 ++--- src/TermColor.hpp | 18 +-- src/VersionReq.cc | 35 +++--- src/VersionReq.hpp | 9 +- srcOld/Archive.hpp | 24 ++-- srcOld/Cfg.hpp | 109 ++++++++--------- srcOld/Lockfile.hpp | 15 +-- srcOld/Resolver.hpp | 19 +-- srcOld/Resolver/Registry.hpp | 8 +- srcOld/Resolver/Resolve.hpp | 23 ++-- srcOld/Resolver/Sat.hpp | 6 +- srcOld/Resolver/Types.hpp | 34 +++--- srcOld/Sha256.hpp | 8 +- testsOld/cfg.cc | 6 +- 49 files changed, 507 insertions(+), 449 deletions(-) diff --git a/poac.toml b/poac.toml index d9dafd2fe..2706397a1 100644 --- a/poac.toml +++ b/poac.toml @@ -37,4 +37,5 @@ filters = [ "-runtime/references", # non-const reference rather than a pointer "-whitespace", "+whitespace/ending_newline", + "-runtime/string", # FIXME: remove this after fixing all the warnings ] diff --git a/src/Algos.cc b/src/Algos.cc index 83f554b3f..11ddca5c0 100644 --- a/src/Algos.cc +++ b/src/Algos.cc @@ -7,21 +7,22 @@ #include #include #include +#include #include #include -String +std::string toUpper(const StringRef str) noexcept { - String res; + std::string res; for (const unsigned char c : str) { res += static_cast(std::toupper(c)); } return res; } -String +std::string toMacroName(const StringRef name) noexcept { - String macroName; + std::string macroName; for (const unsigned char c : name) { if (std::isalpha(c)) { macroName += static_cast(std::toupper(c)); @@ -42,11 +43,11 @@ execCmd(const StringRef cmd) noexcept { return exitCode; } -static std::pair +static std::pair getCmdOutputImpl(const StringRef cmd) { constexpr usize bufferSize = 128; std::array buffer{}; - String output; + std::string output; FILE* pipe = popen(cmd.data(), "r"); if (!pipe) { @@ -65,7 +66,7 @@ getCmdOutputImpl(const StringRef cmd) { return { output, exitCode }; } -String +std::string getCmdOutput(const StringRef cmd, const usize retry) { logger::debug("Running `", cmd, '`'); @@ -87,7 +88,7 @@ getCmdOutput(const StringRef cmd, const usize retry) { bool commandExists(const StringRef cmd) noexcept { - String checkCmd = "command -v "; + std::string checkCmd = "command -v "; checkCmd += cmd; checkCmd += " >/dev/null 2>&1"; return execCmd(checkCmd) == EXIT_SUCCESS; @@ -182,7 +183,7 @@ void testLevDistance() { // Test bytelength agnosticity for (char c = 0; c < std::numeric_limits::max(); ++c) { - const String str(1, c); + const std::string str(1, c); assertEq(levDistance(str, str), 0UL); } diff --git a/src/Algos.hpp b/src/Algos.hpp index 28f01ae52..baae825dc 100644 --- a/src/Algos.hpp +++ b/src/Algos.hpp @@ -10,21 +10,23 @@ #include #include #include +#include #include -String toUpper(StringRef str) noexcept; -String toMacroName(StringRef name) noexcept; +std::string toUpper(StringRef str) noexcept; +std::string toMacroName(StringRef name) noexcept; int execCmd(StringRef cmd) noexcept; -String getCmdOutput(StringRef cmd, usize retry = 3); +std::string getCmdOutput(StringRef cmd, usize retry = 3); bool commandExists(StringRef cmd) noexcept; template -Vec +Vec topoSort( - const HashMap& list, const HashMap>& adjList + const HashMap& list, + const HashMap>& adjList ) { - HashMap inDegree; + HashMap inDegree; for (const auto& var : list) { inDegree[var.first] = 0; } @@ -40,16 +42,16 @@ topoSort( } } - std::queue zeroInDegree; + std::queue zeroInDegree; for (const auto& var : inDegree) { if (var.second == 0) { zeroInDegree.push(var.first); } } - Vec res; + Vec res; while (!zeroInDegree.empty()) { - const String node = zeroInDegree.front(); + const std::string node = zeroInDegree.front(); zeroInDegree.pop(); res.push_back(node); @@ -57,7 +59,7 @@ topoSort( // No dependencies continue; } - for (const String& neighbor : adjList.at(node)) { + for (const std::string& neighbor : adjList.at(node)) { inDegree[neighbor]--; if (inDegree[neighbor] == 0) { zeroInDegree.push(neighbor); diff --git a/src/BuildConfig.cc b/src/BuildConfig.cc index 2dcf60b85..89ad31957 100644 --- a/src/BuildConfig.cc +++ b/src/BuildConfig.cc @@ -32,12 +32,12 @@ static constinit const StringRef TEST_OUT_DIR = "tests"; static constinit const StringRef PATH_FROM_OUT_DIR = "../../"; // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) -static String OUT_DIR; -static String CXX = "clang++"; -static String CXXFLAGS; -static String DEFINES; -static String INCLUDES = " -Iinclude"; -static String LIBS; +static std::string OUT_DIR; +static std::string CXX = "clang++"; +static std::string CXXFLAGS; +static std::string DEFINES; +static std::string INCLUDES = " -Iinclude"; +static std::string LIBS; // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) void @@ -48,7 +48,7 @@ setOutDir(const bool isDebug) { OUT_DIR = "poac-out/release"; } } -String +std::string getOutDir() { if (OUT_DIR.empty()) { throw PoacError("outDir is not set"); @@ -99,7 +99,7 @@ operator<<(std::ostream& os, VarType type) { } struct Variable { - String value; + std::string value; VarType type = VarType::Simple; }; @@ -110,66 +110,66 @@ operator<<(std::ostream& os, const Variable& var) { } struct Target { - Vec commands; - Option sourceFile; - HashSet remDeps; + Vec commands; + Option sourceFile; + HashSet remDeps; }; struct BuildConfig { - String packageName; + std::string packageName; Path buildOutDir; - HashMap variables; - HashMap> varDeps; - HashMap targets; - HashMap> targetDeps; - Option> phony; - Option> all; + HashMap variables; + HashMap> varDeps; + HashMap targets; + HashMap> targetDeps; + Option> phony; + Option> all; BuildConfig() = default; - explicit BuildConfig(const String& packageName) + explicit BuildConfig(const std::string& packageName) : packageName(packageName), buildOutDir(packageName + ".d") {} void defineVar( - const String& name, const Variable& value, - const HashSet& dependsOn = {} + const std::string& name, const Variable& value, + const HashSet& dependsOn = {} ) { variables[name] = value; - for (const String& dep : dependsOn) { + for (const std::string& dep : dependsOn) { // reverse dependency varDeps[dep].push_back(name); } } void defineSimpleVar( - const String& name, const String& value, - const HashSet& dependsOn = {} + const std::string& name, const std::string& value, + const HashSet& dependsOn = {} ) { defineVar(name, { value, VarType::Simple }, dependsOn); } void defineCondVar( - const String& name, const String& value, - const HashSet& dependsOn = {} + const std::string& name, const std::string& value, + const HashSet& dependsOn = {} ) { defineVar(name, { value, VarType::Cond }, dependsOn); } void defineTarget( - const String& name, const Vec& commands, - const HashSet& remDeps = {}, - const Option& sourceFile = None + const std::string& name, const Vec& commands, + const HashSet& remDeps = {}, + const Option& sourceFile = None ) { targets[name] = { commands, sourceFile, remDeps }; if (sourceFile.has_value()) { targetDeps[sourceFile.value()].push_back(name); } - for (const String& dep : remDeps) { + for (const std::string& dep : remDeps) { // reverse dependency targetDeps[dep].push_back(name); } } - void addPhony(const String& target) { + void addPhony(const std::string& target) { if (!phony.has_value()) { phony = { target }; } else { @@ -177,11 +177,11 @@ struct BuildConfig { } } - void setAll(const HashSet& dependsOn) { + void setAll(const HashSet& dependsOn) { all = dependsOn; } - void emitVariable(std::ostream& os, const String& varName) const; + void emitVariable(std::ostream& os, const std::string& varName) const; void emitMakefile(std::ostream& os) const; void emitCompdb(StringRef baseDir, std::ostream& os) const; }; @@ -200,8 +200,10 @@ emitDep(std::ostream& os, usize& offset, const StringRef dep) { static void emitTarget( - std::ostream& os, const StringRef target, const HashSet& dependsOn, - const Option& sourceFile = None, const Vec& commands = {} + std::ostream& os, const StringRef target, + const HashSet& dependsOn, + const Option& sourceFile = None, + const Vec& commands = {} ) { usize offset = 0; @@ -227,15 +229,15 @@ emitTarget( } void -BuildConfig::emitVariable(std::ostream& os, const String& varName) const { +BuildConfig::emitVariable(std::ostream& os, const std::string& varName) const { std::ostringstream oss; // TODO: implement an elegant way to get type size. oss << varName << ' ' << variables.at(varName).type; - const String left = oss.str(); + const std::string left = oss.str(); os << left << ' '; constexpr usize maxLineLen = 80; // TODO: share across sources? usize offset = left.size() + 1; // space - String value; + std::string value; for (const char c : variables.at(varName).value) { if (c == ' ') { // Emit value @@ -259,8 +261,8 @@ BuildConfig::emitVariable(std::ostream& os, const String& varName) const { void BuildConfig::emitMakefile(std::ostream& os) const { - const Vec sortedVars = topoSort(variables, varDeps); - for (const String& varName : sortedVars) { + const Vec sortedVars = topoSort(variables, varDeps); + for (const std::string& varName : sortedVars) { emitVariable(os, varName); } if (!sortedVars.empty() && !targets.empty()) { @@ -273,7 +275,7 @@ BuildConfig::emitMakefile(std::ostream& os) const { if (all.has_value()) { emitTarget(os, "all", all.value()); } - const Vec sortedTargets = topoSort(targets, targetDeps); + const Vec sortedTargets = topoSort(targets, targetDeps); // NOLINTNEXTLINE(modernize-loop-convert) for (auto itr = sortedTargets.rbegin(); itr != sortedTargets.rend(); itr++) { emitTarget( @@ -286,8 +288,8 @@ BuildConfig::emitMakefile(std::ostream& os) const { void BuildConfig::emitCompdb(const StringRef baseDir, std::ostream& os) const { const Path baseDirPath = fs::canonical(baseDir); - const String indent1(2, ' '); - const String indent2(4, ' '); + const std::string indent1(2, ' '); + const std::string indent2(4, ' '); std::ostringstream oss; for (const auto& [target, targetInfo] : targets) { @@ -301,7 +303,7 @@ BuildConfig::emitCompdb(const StringRef baseDir, std::ostream& os) const { if (!cmd.starts_with("$(CXX)") && !cmd.starts_with("@$(CXX)")) { continue; } - if (cmd.find("-c") == String::npos) { + if (cmd.find("-c") == std::string::npos) { // Ignore link commands. continue; } @@ -313,10 +315,10 @@ BuildConfig::emitCompdb(const StringRef baseDir, std::ostream& os) const { // We don't check the Option value because we know the first dependency // always exists for compile targets. - const String file = targetInfo.sourceFile.value(); + const std::string file = targetInfo.sourceFile.value(); // The output is the target. - const String output = target; - String cmd = CXX; + const std::string output = target; + std::string cmd = CXX; cmd += ' '; cmd += CXXFLAGS; cmd += DEFINES; @@ -334,7 +336,7 @@ BuildConfig::emitCompdb(const StringRef baseDir, std::ostream& os) const { oss << indent1 << "},\n"; } - String output = oss.str(); + std::string output = oss.str(); if (!output.empty()) { // Remove the last comma. output.pop_back(); // \n @@ -346,9 +348,9 @@ BuildConfig::emitCompdb(const StringRef baseDir, std::ostream& os) const { os << "]\n"; } -String -runMM(const String& sourceFile, const bool isTest = false) { - String command = "cd "; +std::string +runMM(const std::string& sourceFile, const bool isTest = false) { + std::string command = "cd "; command += getOutDir(); command += " && "; command += CXX; @@ -363,13 +365,13 @@ runMM(const String& sourceFile, const bool isTest = false) { return getCmdOutput(command); } -static HashSet -parseMMOutput(const String& mmOutput, String& target) { +static HashSet +parseMMOutput(const std::string& mmOutput, std::string& target) { std::istringstream iss(mmOutput); std::getline(iss, target, ':'); - String dependency; - HashSet deps; + std::string dependency; + HashSet deps; bool isFirst = true; while (std::getline(iss, dependency, ' ')) { if (!dependency.empty() && dependency.front() != '\\') { @@ -406,13 +408,13 @@ isUpToDate(const StringRef makefilePath) { } static bool -containsTestCode(const String& sourceFile) { +containsTestCode(const std::string& sourceFile) { std::ifstream ifs(sourceFile); - String line; + std::string line; while (std::getline(ifs, line)) { - if (line.find("POAC_TEST") != String::npos) { + if (line.find("POAC_TEST") != std::string::npos) { // TODO: Can't we somehow elegantly make the compiler command sharable? - String command = CXX; + std::string command = CXX; command += " -E "; command += CXXFLAGS; command += DEFINES; @@ -420,10 +422,10 @@ containsTestCode(const String& sourceFile) { command += ' '; command += sourceFile; - const String src = getCmdOutput(command); + const std::string src = getCmdOutput(command); command += " -DPOAC_TEST"; - const String testSrc = getCmdOutput(command); + const std::string testSrc = getCmdOutput(command); // If the source file contains POAC_TEST, by processing the source // file with -E, we can check if the source file contains POAC_TEST @@ -440,15 +442,15 @@ containsTestCode(const String& sourceFile) { return false; } -static String +static std::string printfCmd(const StringRef header, const StringRef body) { std::ostringstream oss; logger::info(oss, header, body); - String msg = oss.str(); + std::string msg = oss.str(); // Replace all occurrences of '\n' with "\\n" to escape newlines size_t pos = 0; - while ((pos = msg.find('\n', pos)) != String::npos) { + while ((pos = msg.find('\n', pos)) != std::string::npos) { msg.replace(pos, 1, "\\n"); pos += 2; // Move past the replacement } @@ -458,10 +460,11 @@ printfCmd(const StringRef header, const StringRef body) { static void defineCompileTarget( - BuildConfig& config, const String& objTarget, const String& sourceFile, - const HashSet& remDeps, const bool isTest = false + BuildConfig& config, const std::string& objTarget, + const std::string& sourceFile, const HashSet& remDeps, + const bool isTest = false ) { - Vec commands(3); + Vec commands(3); commands[0] = "@mkdir -p $(@D)"; commands[1] = printfCmd("Compiling", sourceFile.substr(PATH_FROM_OUT_DIR.size())); @@ -475,9 +478,10 @@ defineCompileTarget( static void defineLinkTarget( - BuildConfig& config, const String& binTarget, const HashSet& deps + BuildConfig& config, const std::string& binTarget, + const HashSet& deps ) { - Vec commands(2); + Vec commands(2); commands[0] = printfCmd("Linking", binTarget); commands[1] = "$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@"; config.defineTarget(binTarget, commands, deps); @@ -486,7 +490,7 @@ defineLinkTarget( // Map a path to header file to the corresponding object file. // // e.g., src/path/to/header.h -> poac.d/path/to/header.o -static String +static std::string mapHeaderToObj(const Path& headerPath, const Path& buildOutDir) { Path objBaseDir = fs::relative(headerPath.parent_path(), PATH_FROM_OUT_DIR / "src"_path); @@ -509,9 +513,9 @@ mapHeaderToObj(const Path& headerPath, const Path& buildOutDir) { // depending header files for the source file. static void collectBinDepObjs( // NOLINT(misc-no-recursion) - HashSet& deps, const StringRef sourceFileName, - const HashSet& objTargetDeps, - const HashSet& buildObjTargets, const BuildConfig& config + HashSet& deps, const StringRef sourceFileName, + const HashSet& objTargetDeps, + const HashSet& buildObjTargets, const BuildConfig& config ) { for (const Path headerPath : objTargetDeps) { if (sourceFileName == headerPath.stem()) { @@ -525,7 +529,8 @@ collectBinDepObjs( // NOLINT(misc-no-recursion) continue; } - const String objTarget = mapHeaderToObj(headerPath, config.buildOutDir); + const std::string objTarget = + mapHeaderToObj(headerPath, config.buildOutDir); if (deps.contains(objTarget)) { // We already added this object file. continue; @@ -587,11 +592,11 @@ setVariables(BuildConfig& config, const bool isDebug) { } config.defineSimpleVar("CXXFLAGS", CXXFLAGS); - const String pkgName = toMacroName(config.packageName); + const std::string pkgName = toMacroName(config.packageName); const Version& pkgVersion = getPackageVersion(); - String commitHash; - String commitShortHash; - String commitDate; + std::string commitHash; + std::string commitShortHash; + std::string commitDate; try { git2::Repository repo{}; repo.open("."); @@ -623,10 +628,10 @@ setVariables(BuildConfig& config, const bool isDebug) { static void processSrc( BuildConfig& config, const Path& sourceFilePath, - HashSet& buildObjTargets, tbb::spin_mutex* mtx = nullptr + HashSet& buildObjTargets, tbb::spin_mutex* mtx = nullptr ) { - String objTarget; // source.o - const HashSet objTargetDeps = + std::string objTarget; // source.o + const HashSet objTargetDeps = parseMMOutput(runMM(sourceFilePath), objTarget); const Path targetBaseDir = fs::relative( @@ -637,7 +642,7 @@ processSrc( buildTargetBaseDir /= targetBaseDir; } - const String buildObjTarget = buildTargetBaseDir / objTarget; + const std::string buildObjTarget = buildTargetBaseDir / objTarget; if (mtx) { mtx->lock(); @@ -649,9 +654,9 @@ processSrc( } } -static HashSet +static HashSet processSources(BuildConfig& config, const Vec& sourceFilePaths) { - HashSet buildObjTargets; + HashSet buildObjTargets; if (isParallel()) { tbb::spin_mutex mtx; @@ -675,16 +680,16 @@ processSources(BuildConfig& config, const Vec& sourceFilePaths) { static void processTestSrc( BuildConfig& config, const Path& sourceFilePath, - const HashSet& buildObjTargets, Vec& testCommands, - HashSet& testTargets, tbb::spin_mutex* mtx = nullptr + const HashSet& buildObjTargets, Vec& testCommands, + HashSet& testTargets, tbb::spin_mutex* mtx = nullptr ) { if (!containsTestCode(sourceFilePath.string().substr(PATH_FROM_OUT_DIR.size()) )) { return; } - String objTarget; // source.o - const HashSet objTargetDeps = + std::string objTarget; // source.o + const HashSet objTargetDeps = parseMMOutput(runMM(sourceFilePath, true /* isTest */), objTarget); const Path targetBaseDir = fs::relative( @@ -695,14 +700,14 @@ processTestSrc( testTargetBaseDir /= targetBaseDir; } - const String testObjTarget = + const std::string testObjTarget = (testTargetBaseDir / "test_").string() + objTarget; - const String testTargetName = sourceFilePath.stem().string(); - const String testTarget = + const std::string testTargetName = sourceFilePath.stem().string(); + const std::string testTarget = (testTargetBaseDir / "test_").string() + testTargetName; // Test binary target. - HashSet testTargetDeps = { testObjTarget }; + HashSet testTargetDeps = { testObjTarget }; collectBinDepObjs( testTargetDeps, sourceFilePath.stem().string(), objTargetDeps, buildObjTargets, config @@ -737,7 +742,7 @@ configureBuild(const bool isDebug) { throw PoacError("src/main.cc not found"); } - const String outDir = getOutDir(); + const std::string outDir = getOutDir(); if (!fs::exists(outDir)) { fs::create_directories(outDir); } @@ -753,7 +758,7 @@ configureBuild(const bool isDebug) { config.addPhony("all"); Vec sourceFilePaths = listSourceFilePaths("src"); - String srcs; + std::string srcs; for (Path& sourceFilePath : sourceFilePaths) { sourceFilePath = PATH_FROM_OUT_DIR / sourceFilePath; srcs += ' ' + sourceFilePath.string(); @@ -761,12 +766,12 @@ configureBuild(const bool isDebug) { config.defineSimpleVar("SRCS", srcs); // Source Pass - const HashSet buildObjTargets = + const HashSet buildObjTargets = processSources(config, sourceFilePaths); // Project binary target. - const String mainObjTarget = config.buildOutDir / "main.o"; - HashSet projTargetDeps = { mainObjTarget }; + const std::string mainObjTarget = config.buildOutDir / "main.o"; + HashSet projTargetDeps = { mainObjTarget }; collectBinDepObjs( projTargetDeps, "", config.targets.at(mainObjTarget).remDeps, // we don't need sourceFile @@ -775,8 +780,8 @@ configureBuild(const bool isDebug) { defineLinkTarget(config, config.packageName, projTargetDeps); // Test Pass - Vec testCommands; - HashSet testTargets; + Vec testCommands; + HashSet testTargets; if (isParallel()) { tbb::spin_mutex mtx; tbb::parallel_for( @@ -821,7 +826,7 @@ configureBuild(const bool isDebug) { } /// @returns the directory where the Makefile is generated. -String +std::string emitMakefile(const bool isDebug) { setOutDir(isDebug); @@ -829,8 +834,8 @@ emitMakefile(const bool isDebug) { // make sure the dependencies are installed. installDeps(); - const String outDir = getOutDir(); - const String makefilePath = outDir + "/Makefile"; + const std::string outDir = getOutDir(); + const std::string makefilePath = outDir + "/Makefile"; if (isUpToDate(makefilePath)) { logger::debug("Makefile is up to date"); return outDir; @@ -844,15 +849,15 @@ emitMakefile(const bool isDebug) { } /// @returns the directory where the compilation database is generated. -String +std::string emitCompdb(const bool isDebug) { setOutDir(isDebug); // compile_commands.json also needs INCLUDES, but not LIBS. installDeps(); - const String outDir = getOutDir(); - const String compdbPath = outDir + "/compile_commands.json"; + const std::string outDir = getOutDir(); + const std::string compdbPath = outDir + "/compile_commands.json"; if (isUpToDate(compdbPath)) { logger::debug("compile_commands.json is up to date"); return outDir; @@ -865,14 +870,14 @@ emitCompdb(const bool isDebug) { return outDir; } -String +std::string modeString(const bool isDebug) { return isDebug ? "debug" : "release"; } -String +std::string getMakeCommand() { - String makeCommand; + std::string makeCommand; if (isVerbose()) { makeCommand = "make"; } else { diff --git a/src/BuildConfig.hpp b/src/BuildConfig.hpp index 17c226779..b84a8fb69 100644 --- a/src/BuildConfig.hpp +++ b/src/BuildConfig.hpp @@ -2,16 +2,18 @@ #include "Rustify.hpp" +#include + // clang-format off -inline const HashSet SOURCE_FILE_EXTS{ +inline const HashSet SOURCE_FILE_EXTS{ ".c", ".c++", ".cc", ".cpp", ".cxx" }; -inline const HashSet HEADER_FILE_EXTS{ +inline const HashSet HEADER_FILE_EXTS{ ".h", ".h++", ".hh", ".hpp", ".hxx" }; // clang-format on -String emitMakefile(bool isDebug); -String emitCompdb(bool isDebug); -String modeString(bool isDebug); -String getMakeCommand(); +std::string emitMakefile(bool isDebug); +std::string emitCompdb(bool isDebug); +std::string modeString(bool isDebug); +std::string getMakeCommand(); diff --git a/src/Cli.cc b/src/Cli.cc index c9abc4361..b2ee93f85 100644 --- a/src/Cli.cc +++ b/src/Cli.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include static constinit const StringRef PADDING = " "; @@ -91,16 +92,16 @@ printOpts( void Opt::print(const usize maxShortSize, usize maxOffset) const noexcept { - String option; + std::string option; if (!shortName.empty()) { option += bold(cyan(shortName)); option += ", "; if (maxShortSize > shortName.size()) { - option += String(maxShortSize - shortName.size(), ' '); + option += std::string(maxShortSize - shortName.size(), ' '); } } else { // This coloring is for the alignment with std::setw later. - option += bold(cyan(String(maxShortSize, ' '))); + option += bold(cyan(std::string(maxShortSize, ' '))); option += " "; // ", " } option += bold(cyan(name)); @@ -120,13 +121,13 @@ Opt::print(const usize maxShortSize, usize maxOffset) const noexcept { std::cout << '\n'; } -String +std::string Arg::getLeft() const noexcept { if (name.empty()) { return ""; } - String left; + std::string left; if (required) { left += '<'; } else { @@ -145,7 +146,7 @@ Arg::getLeft() const noexcept { } void Arg::print(usize maxOffset) const noexcept { - const String left = getLeft(); + const std::string left = getLeft(); if (shouldColor()) { // Color escape sequences are not visible but affect std::setw. constexpr usize colorEscapeSeqLen = 9; @@ -174,9 +175,9 @@ Subcmd::setGlobalOpts(const Vec& globalOpts) noexcept { this->globalOpts = globalOpts; return *this; } -String +std::string Subcmd::getUsage() const noexcept { - String str = bold(green("Usage: ")); + std::string str = bold(green("Usage: ")); str += bold(cyan(cmdName)); str += ' '; str += bold(cyan(name)); @@ -197,7 +198,7 @@ Subcmd::noSuchArg(StringRef arg) const { } addOptCandidates(candidates, localOpts); - String suggestion; + std::string suggestion; if (const auto similar = findSimilarStr(arg, candidates)) { suggestion = bold(cyan(" Tip:")) + " did you mean '" + bold(yellow(similar.value())) + "'?\n\n"; @@ -267,7 +268,7 @@ Subcmd::printHelp() const noexcept { void Subcmd::print(usize maxOffset) const noexcept { - String cmdStr = bold(cyan(name)); + std::string cmdStr = bold(cyan(name)); if (hasShort()) { cmdStr += ", "; cmdStr += bold(cyan(shortName)); @@ -323,7 +324,7 @@ Cli::noSuchArg(StringRef arg) const { addOptCandidates(candidates, globalOpts); addOptCandidates(candidates, localOpts); - String suggestion; + std::string suggestion; if (const auto similar = findSimilarStr(arg, candidates)) { suggestion = bold(cyan(" Tip:")) + " did you mean '" + bold(yellow(similar.value())) + "'?\n\n"; @@ -426,7 +427,7 @@ Cli::printCmdHelp() const noexcept { printHeader("Commands:"); printAllSubcmds(false, maxOffset); - const String dummyDesc = "See all commands with " + bold(cyan("--list")); + const std::string dummyDesc = "See all commands with " + bold(cyan("--list")); Subcmd{ "..." }.setDesc(dummyDesc).print(maxOffset); std::cout diff --git a/src/Cli.hpp b/src/Cli.hpp index aa036b180..f6a3d50e7 100644 --- a/src/Cli.hpp +++ b/src/Cli.hpp @@ -6,6 +6,7 @@ #include #include #include +#include class Opt; class Arg; @@ -127,7 +128,7 @@ class Arg : public CliBase { return name.size(); } - String getLeft() const noexcept; + std::string getLeft() const noexcept; void print(usize maxOffset) const noexcept; }; @@ -163,7 +164,7 @@ class Subcmd : public CliBase, public ShortAndHidden { } Subcmd& setGlobalOpts(const Vec& globalOpts) noexcept; - String getUsage() const noexcept; + std::string getUsage() const noexcept; void printHelp() const noexcept; void print(usize maxOffset) const noexcept; diff --git a/src/Cmd/Add.cc b/src/Cmd/Add.cc index 36442f77b..957f0cabf 100644 --- a/src/Cmd/Add.cc +++ b/src/Cmd/Add.cc @@ -7,6 +7,7 @@ #include #include +#include #include static int addMain(std::span args); @@ -36,13 +37,13 @@ const Subcmd ADD_CMD = static Option handleNextArg( std::span::iterator& itr, - const std::span::iterator& end, String& arg + const std::span::iterator& end, std::string& arg ) { ++itr; if (itr == end) { return Subcmd::missingArgumentForOpt(*--itr); } - arg = String(*itr); + arg = std::string(*itr); return None; } @@ -55,24 +56,24 @@ handleDependency(HashSet& newDeps, const StringRef dep) { newDeps.insert(dep); } -static String +static std::string getDependencyGitUrl(const StringRef dep) { - if (dep.find("://") == String::npos) { + if (dep.find("://") == std::string::npos) { // check if atleast in "user/repo" format - if (dep.find('/') == String::npos) { - logger::error("Invalid dependency: " + String(dep)); + if (dep.find('/') == std::string::npos) { + logger::error("Invalid dependency: " + std::string(dep)); return ""; } - return "https://github.com/" + String(dep) + ".git"; + return "https://github.com/" + std::string(dep) + ".git"; } - return String(dep); + return std::string(dep); } -static String +static std::string getDependencyName(const StringRef dep) { - String name; - if (dep.find("://") == String::npos) { + std::string name; + if (dep.find("://") == std::string::npos) { name = dep.substr(dep.find_last_of('/') + 1); } else { name = dep.substr( @@ -90,8 +91,9 @@ getDependencyName(const StringRef dep) { static int addDependencyToManifest( - const HashSet& newDeps, bool isSystemDependency, String& version, - String& tag, String& rev, String& branch + const HashSet& newDeps, bool isSystemDependency, + std::string& version, std::string& tag, std::string& rev, + std::string& branch ) { toml::value depData = toml::table{}; @@ -121,8 +123,8 @@ addDependencyToManifest( for (const auto& dep : newDeps) { if (!isSystemDependency) { - const String gitUrl = getDependencyGitUrl(dep); - const String depName = getDependencyName(dep); + const std::string gitUrl = getDependencyGitUrl(dep); + const std::string depName = getDependencyName(dep); if (gitUrl.empty() || depName.empty()) { return EXIT_FAILURE; @@ -131,7 +133,7 @@ addDependencyToManifest( deps[depName] = depData; deps[depName]["git"] = gitUrl; } else { - deps[String(dep)] = depData; + deps[std::string(dep)] = depData; } } @@ -152,11 +154,11 @@ addMain(const std::span args) { HashSet newDeps = {}; bool isSystemDependency = false; - String version; // Only used with system-dependencies + std::string version; // Only used with system-dependencies - String tag; - String rev; - String branch; + std::string tag; + std::string rev; + std::string branch; // clang-format off HashMap< diff --git a/src/Cmd/Build.cc b/src/Cmd/Build.cc index 09960ce62..54e0f1346 100644 --- a/src/Cmd/Build.cc +++ b/src/Cmd/Build.cc @@ -9,6 +9,7 @@ #include #include #include +#include static int buildMain(std::span args); @@ -25,11 +26,11 @@ const Subcmd BUILD_CMD = .setMainFn(buildMain); int -buildImpl(String& outDir, const bool isDebug) { +buildImpl(std::string& outDir, const bool isDebug) { const auto start = std::chrono::steady_clock::now(); outDir = emitMakefile(isDebug); - const String makeCommand = getMakeCommand() + " -C " + outDir; + const std::string makeCommand = getMakeCommand() + " -C " + outDir; const int exitCode = execCmd(makeCommand); const auto end = std::chrono::steady_clock::now(); @@ -76,12 +77,12 @@ buildMain(const std::span args) { } if (!buildCompdb) { - String outDir; + std::string outDir; return buildImpl(outDir, isDebug); } // Build compilation database - const String outDir = emitCompdb(isDebug); + const std::string outDir = emitCompdb(isDebug); logger::info("Generated", outDir, "/compile_commands.json"); return EXIT_SUCCESS; } diff --git a/src/Cmd/Build.hpp b/src/Cmd/Build.hpp index 5cc99d608..5d430b15a 100644 --- a/src/Cmd/Build.hpp +++ b/src/Cmd/Build.hpp @@ -3,5 +3,7 @@ #include "../Cli.hpp" #include "../Rustify.hpp" +#include + extern const Subcmd BUILD_CMD; -int buildImpl(String& outDir, bool isDebug); +int buildImpl(std::string& outDir, bool isDebug); diff --git a/src/Cmd/Fmt.cc b/src/Cmd/Fmt.cc index 4353498b9..a4bf37803 100644 --- a/src/Cmd/Fmt.cc +++ b/src/Cmd/Fmt.cc @@ -23,7 +23,9 @@ const Subcmd FMT_CMD = .setMainFn(fmtMain); static void -collectFormatTargetFiles(const Path& manifestDir, String& clangFormatArgs) { +collectFormatTargetFiles( + const Path& manifestDir, std::string& clangFormatArgs +) { // Read git repository if exists git2::Repository repo = git2::Repository(); bool hasGitRepo = false; @@ -38,7 +40,8 @@ collectFormatTargetFiles(const Path& manifestDir, String& clangFormatArgs) { for (auto entry = fs::recursive_directory_iterator(manifestDir); entry != fs::recursive_directory_iterator(); ++entry) { if (entry->is_directory()) { - const String path = fs::relative(entry->path(), manifestDir).string(); + const std::string path = + fs::relative(entry->path(), manifestDir).string(); if (hasGitRepo && repo.isIgnored(path)) { logger::debug("Ignore: ", path); entry.disable_recursion_pending(); @@ -51,7 +54,7 @@ collectFormatTargetFiles(const Path& manifestDir, String& clangFormatArgs) { continue; } - const String ext = path.extension().string(); + const std::string ext = path.extension().string(); if (SOURCE_FILE_EXTS.contains(ext) || HEADER_FILE_EXTS.contains(ext)) { clangFormatArgs += ' ' + path.string(); } @@ -86,7 +89,7 @@ fmtMain(const std::span args) { } const StringRef packageName = getPackageName(); - String clangFormatArgs = "--style=file --fallback-style=LLVM -Werror"; + std::string clangFormatArgs = "--style=file --fallback-style=LLVM -Werror"; if (isVerbose()) { clangFormatArgs += " --verbose"; } @@ -100,8 +103,8 @@ fmtMain(const std::span args) { const Path& manifestDir = getManifestPath().parent_path(); collectFormatTargetFiles(manifestDir, clangFormatArgs); - const String clangFormat = "cd " + manifestDir.string() - + " && ${POAC_FMT:-clang-format} " - + clangFormatArgs; + const std::string clangFormat = "cd " + manifestDir.string() + + " && ${POAC_FMT:-clang-format} " + + clangFormatArgs; return execCmd(clangFormat); } diff --git a/src/Cmd/Init.cc b/src/Cmd/Init.cc index 2c9a8c9b1..42d36f87c 100644 --- a/src/Cmd/Init.cc +++ b/src/Cmd/Init.cc @@ -45,7 +45,7 @@ initMain(const std::span args) { return EXIT_FAILURE; } - const String packageName = fs::current_path().stem().string(); + const std::string packageName = fs::current_path().stem().string(); if (const auto err = validatePackageName(packageName)) { logger::error("package names ", err.value(), ": `", packageName, '`'); return EXIT_FAILURE; diff --git a/src/Cmd/Lint.cc b/src/Cmd/Lint.cc index e79b9b61a..fb1c0cfe8 100644 --- a/src/Cmd/Lint.cc +++ b/src/Cmd/Lint.cc @@ -9,6 +9,7 @@ #include #include #include +#include static int lintMain(std::span args); @@ -19,14 +20,14 @@ const Subcmd LINT_CMD = .setMainFn(lintMain); struct LintArgs { - String excludes; + std::string excludes; }; static int lint(const StringRef name, const StringRef cpplintArgs) { logger::info("Linting", name); - String cpplintCmd = "cpplint"; + std::string cpplintCmd = "cpplint"; cpplintCmd += cpplintArgs; if (!isVerbose()) { cpplintCmd += " --quiet"; @@ -35,7 +36,7 @@ lint(const StringRef name, const StringRef cpplintArgs) { // Read .gitignore if exists if (fs::exists(".gitignore")) { std::ifstream ifs(".gitignore"); - String line; + std::string line; while (std::getline(ifs, line)) { if (line.empty() || line[0] == '#') { continue; @@ -80,7 +81,7 @@ lintMain(const std::span args) { return EXIT_FAILURE; } - String cpplintArgs = lintArgs.excludes; + std::string cpplintArgs = lintArgs.excludes; const StringRef packageName = getPackageName(); if (fs::exists("CPPLINT.cfg")) { logger::debug("Using CPPLINT.cfg for lint ..."); @@ -93,7 +94,7 @@ lintMain(const std::span args) { cpplintArgs += " --root=src"; } - const Vec& cpplintFilters = getLintCpplintFilters(); + const Vec& cpplintFilters = getLintCpplintFilters(); if (!cpplintFilters.empty()) { logger::debug("Using Poac manifest file for lint ..."); cpplintArgs += " --filter="; diff --git a/src/Cmd/New.cc b/src/Cmd/New.cc index e78401a22..2814c24f0 100644 --- a/src/Cmd/New.cc +++ b/src/Cmd/New.cc @@ -33,7 +33,7 @@ static constexpr StringRef MAIN_CC = " std::cout << \"Hello, world!\" << std::endl;\n" "}\n"; -static String +static std::string getAuthor() noexcept { try { git2::Config config = git2::Config(); @@ -46,9 +46,9 @@ getAuthor() noexcept { } } -String +std::string createPoacToml(const StringRef projectName) noexcept { - String poacToml = + std::string poacToml = "[package]\n" "name = \""; poacToml += projectName; @@ -63,10 +63,10 @@ createPoacToml(const StringRef projectName) noexcept { return poacToml; } -static String +static std::string getHeader(const StringRef projectName) noexcept { - const String projectNameUpper = toMacroName(projectName); - String header = "#ifndef " + projectNameUpper + "_HPP\n" + const std::string projectNameUpper = toMacroName(projectName); + std::string header = "#ifndef " + projectNameUpper + "_HPP\n" "#define " + projectNameUpper + "_HPP\n\n" "namespace "; header += projectName; @@ -125,7 +125,7 @@ static int newMain(const std::span args) { // Parse args bool isBin = true; - String packageName; + std::string packageName; for (auto itr = args.begin(); itr != args.end(); ++itr) { if (const auto res = Cli::handleGlobalOpts(itr, args.end(), "new")) { if (res.value() == Cli::CONTINUE) { diff --git a/src/Cmd/New.hpp b/src/Cmd/New.hpp index ce18410b8..3a039fd9a 100644 --- a/src/Cmd/New.hpp +++ b/src/Cmd/New.hpp @@ -3,5 +3,7 @@ #include "../Cli.hpp" #include "../Rustify.hpp" +#include + extern const Subcmd NEW_CMD; -String createPoacToml(StringRef projectName) noexcept; +std::string createPoacToml(StringRef projectName) noexcept; diff --git a/src/Cmd/Run.cc b/src/Cmd/Run.cc index 96015b054..a843d571c 100644 --- a/src/Cmd/Run.cc +++ b/src/Cmd/Run.cc @@ -12,6 +12,7 @@ #include #include +#include static int runMain(std::span args); @@ -54,17 +55,17 @@ runMain(const std::span args) { } } - String runArgs; + std::string runArgs; for (; itr != args.end(); ++itr) { - runArgs += ' ' + String(*itr); + runArgs += ' ' + std::string(*itr); } - String outDir; + std::string outDir; if (buildImpl(outDir, isDebug) != EXIT_SUCCESS) { return EXIT_FAILURE; } - const String& projectName = getPackageName(); - const String command = outDir + "/" + projectName + runArgs; + const std::string& projectName = getPackageName(); + const std::string command = outDir + "/" + projectName + runArgs; return execCmd(command); } diff --git a/src/Cmd/Search.cc b/src/Cmd/Search.cc index 683a73838..973d1d241 100644 --- a/src/Cmd/Search.cc +++ b/src/Cmd/Search.cc @@ -29,13 +29,13 @@ const Subcmd SEARCH_CMD = .setMainFn(searchMain); struct SearchArgs { - String name; + std::string name; usize perPage = 10; usize page = 1; }; static usize -writeCallback(void* contents, usize size, usize nmemb, String* userp) { +writeCallback(void* contents, usize size, usize nmemb, std::string* userp) { userp->append(static_cast(contents), size * nmemb); return size * nmemb; } @@ -50,8 +50,8 @@ searchPackages(const SearchArgs& args) { req["variables"]["limit"] = args.perPage; req["variables"]["offset"] = (args.page - 1) * args.perPage; - const String reqStr = req.dump(); - String resStr; + const std::string reqStr = req.dump(); + std::string resStr; CURL* curl = curl_easy_init(); if (!curl) { @@ -82,11 +82,11 @@ printTable(const nlohmann::json& packages) { std::cout << std::left << std::setw(nameWidth) << "Name" << std::setw(verWidth) << "Version" << "Description" << '\n'; - std::cout << String(tableWidth, '-') << '\n'; + std::cout << std::string(tableWidth, '-') << '\n'; for (const auto& package : packages) { - const String name = package["name"]; - const String version = package["version"]; - const String description = package["description"]; + const std::string name = package["name"]; + const std::string version = package["version"]; + const std::string description = package["description"]; std::cout << std::left << std::setw(nameWidth) << name << std::setw(verWidth) << version << description << '\n'; @@ -105,14 +105,14 @@ searchMain(const std::span args) { } } else if (*itr == "--per-page") { if (itr + 1 < args.end()) { - searchArgs.perPage = std::stoul(String(*++itr)); + searchArgs.perPage = std::stoul(std::string(*++itr)); } else { logger::error("missing argument for `--per-page`"); return EXIT_FAILURE; } } else if (*itr == "--page") { if (itr + 1 < args.end()) { - searchArgs.page = std::stoul(String(*++itr)); + searchArgs.page = std::stoul(std::string(*++itr)); } else { logger::error("missing argument for `--page`"); return EXIT_FAILURE; diff --git a/src/Cmd/Test.cc b/src/Cmd/Test.cc index 1800fe0e3..98faa7a83 100644 --- a/src/Cmd/Test.cc +++ b/src/Cmd/Test.cc @@ -11,6 +11,7 @@ #include #include #include +#include static int testMain(std::span args); @@ -54,7 +55,7 @@ testMain(const std::span args) { const auto start = std::chrono::steady_clock::now(); - const String outDir = emitMakefile(isDebug); + const std::string outDir = emitMakefile(isDebug); const int exitCode = execCmd(getMakeCommand() + " -C " + outDir + " test"); const auto end = std::chrono::steady_clock::now(); diff --git a/src/Cmd/Tidy.cc b/src/Cmd/Tidy.cc index 469ca4836..26d5c0713 100644 --- a/src/Cmd/Tidy.cc +++ b/src/Cmd/Tidy.cc @@ -72,7 +72,7 @@ tidyMain(const std::span args) { const Path outDir = emitMakefile(true /* isDebug */); - String tidyFlags = " POAC_TIDY_FLAGS='"; + std::string tidyFlags = " POAC_TIDY_FLAGS='"; if (!isVerbose()) { tidyFlags += "-quiet"; } @@ -85,7 +85,7 @@ tidyMain(const std::span args) { } tidyFlags += '\''; - String makeCmd = getMakeCommand(); + std::string makeCmd = getMakeCommand(); makeCmd += " -C "; makeCmd += outDir.string(); makeCmd += tidyFlags; diff --git a/src/Git2/Config.cc b/src/Git2/Config.cc index 70fb632a8..c255ecafe 100644 --- a/src/Git2/Config.cc +++ b/src/Git2/Config.cc @@ -3,6 +3,8 @@ #include "../Rustify.hpp" #include "Exception.hpp" +#include + namespace git2 { Config::Config() { @@ -21,7 +23,7 @@ Config::openDefault() { return *this; } -String +std::string Config::getString(const StringRef name) { git_buf ret = { nullptr, 0, 0 }; git2Throw(git_config_get_string_buf(&ret, this->raw, name.data())); diff --git a/src/Git2/Config.hpp b/src/Git2/Config.hpp index 36f496460..1dc2b6c1c 100644 --- a/src/Git2/Config.hpp +++ b/src/Git2/Config.hpp @@ -4,6 +4,7 @@ #include "Global.hpp" #include +#include namespace git2 { @@ -26,7 +27,7 @@ struct Config : public GlobalState { Config& openDefault(); /// Get the value of a string config variable as an owned string. - String getString(StringRef name); + std::string getString(StringRef name); }; } // end namespace git2 diff --git a/src/Git2/Describe.cc b/src/Git2/Describe.cc index e2655cf08..790356730 100644 --- a/src/Git2/Describe.cc +++ b/src/Git2/Describe.cc @@ -5,6 +5,7 @@ #include "Repository.hpp" #include +#include namespace git2 { @@ -96,7 +97,7 @@ Describe::workdir(const Repository& repo, DescribeOptions& opts) { return *this; } -String +std::string Describe::format(const DescribeFormatOptions& opts) const { git_buf ret = { nullptr, 0, 0 }; git2Throw(git_describe_format(&ret, this->raw, &opts.raw)); diff --git a/src/Git2/Describe.hpp b/src/Git2/Describe.hpp index 0e71adcdf..5892db16b 100644 --- a/src/Git2/Describe.hpp +++ b/src/Git2/Describe.hpp @@ -5,6 +5,7 @@ #include "Repository.hpp" #include +#include namespace git2 { @@ -82,7 +83,7 @@ struct Describe : public GlobalState { Describe& workdir(const Repository& repo, DescribeOptions& opts); - String format(const DescribeFormatOptions& opts) const; + std::string format(const DescribeFormatOptions& opts) const; }; } // namespace git2 diff --git a/src/Git2/Exception.hpp b/src/Git2/Exception.hpp index c32783f5f..ac2915035 100644 --- a/src/Git2/Exception.hpp +++ b/src/Git2/Exception.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace git2 { @@ -63,7 +64,7 @@ struct Exception final : public std::exception { Exception& operator=(Exception&&) noexcept = default; private: - String msg = "git2-cpp: "; + std::string msg = "git2-cpp: "; git_error_t cat{ GIT_ERROR_NONE }; }; diff --git a/src/Git2/Oid.cc b/src/Git2/Oid.cc index 35e3a5356..9d0a459d3 100644 --- a/src/Git2/Oid.cc +++ b/src/Git2/Oid.cc @@ -6,6 +6,7 @@ #include #include #include +#include namespace git2 { @@ -33,9 +34,9 @@ Oid::isZero() const { # define GIT_OID_MAX_HEXSIZE GIT_OID_HEXSZ #endif -String +std::string Oid::toString() const { - String buf(static_cast(GIT_OID_MAX_HEXSIZE), '\0'); + std::string buf(static_cast(GIT_OID_MAX_HEXSIZE), '\0'); git_oid_tostr(buf.data(), buf.size() + 1, raw); return buf; } diff --git a/src/Git2/Oid.hpp b/src/Git2/Oid.hpp index edd0bbda8..f34f27859 100644 --- a/src/Git2/Oid.hpp +++ b/src/Git2/Oid.hpp @@ -5,6 +5,7 @@ #include #include +#include namespace git2 { @@ -38,7 +39,7 @@ struct Oid : public GlobalState { bool isZero() const; /// Format a git_oid into a buffer as a hex string. - String toString() const; + std::string toString() const; }; std::ostream& operator<<(std::ostream& os, const Oid& oid); diff --git a/src/Git2/Time.cc b/src/Git2/Time.cc index d8d21869c..89c651904 100644 --- a/src/Git2/Time.cc +++ b/src/Git2/Time.cc @@ -2,16 +2,17 @@ #include #include +#include namespace git2 { -String +std::string Time::toString() const { const auto time2 = static_cast(time); std::tm* time3 = std::localtime(&time2); constexpr usize dateLen = 10; // YYYY-MM-DD - String buffer(dateLen, '\0'); + std::string buffer(dateLen, '\0'); if (std::strftime( buffer.data(), dateLen + 1, // null-terminator "%Y-%m-%d", time3 diff --git a/src/Git2/Time.hpp b/src/Git2/Time.hpp index 1632809c1..33f4eed5f 100644 --- a/src/Git2/Time.hpp +++ b/src/Git2/Time.hpp @@ -3,13 +3,14 @@ #include "../Rustify.hpp" #include +#include namespace git2 { struct Time { git_time_t time; - String toString() const; + std::string toString() const; }; } // namespace git2 diff --git a/src/Manifest.cc b/src/Manifest.cc index 14ea92d48..4bdce1c95 100644 --- a/src/Manifest.cc +++ b/src/Manifest.cc @@ -17,7 +17,7 @@ #define TOML11_NO_ERROR_PREFIX #include -Edition::Edition(const String& str) : str(str) { +Edition::Edition(const std::string& str) : str(str) { if (str == "98") { edition = Cpp98; return; @@ -46,13 +46,13 @@ Edition::Edition(const String& str) : str(str) { throw PoacError("invalid edition: ", str); } -String +std::string Edition::getString() const noexcept { return str; } struct Package { - String name; + std::string name; Edition edition; Version version; }; @@ -62,7 +62,7 @@ namespace toml { template <> struct from { static Edition from_toml(const value& val) { - const String& editionStr = toml::get(val); + const std::string& editionStr = toml::get(val); return Edition(editionStr); } }; @@ -76,13 +76,13 @@ struct into { template <> struct from { static Version from_toml(const value& val) { - const String& versionStr = toml::get(val); + const std::string& versionStr = toml::get(val); return Version::parse(versionStr); } }; template <> struct into { - static String into_toml(const Version& ver) { + static std::string into_toml(const Version& ver) { return ver.toString(); } }; @@ -114,15 +114,15 @@ findManifest() { } struct GitDependency { - String name; - String url; - Option target; + std::string name; + std::string url; + Option target; DepMetadata install() const; }; struct SystemDependency { - String name; + std::string name; VersionReq versionReq; DepMetadata install() const; @@ -162,7 +162,7 @@ struct Manifest { Option debugProfile = None; Option releaseProfile = None; - Option> cpplintFilters = None; + Option> cpplintFilters = None; private: Manifest() noexcept = default; @@ -189,7 +189,7 @@ getManifestPath() { } // Returns an error message if the package name is invalid. -Option // TODO: result-like types make more sense. +Option // TODO: result-like types make more sense. validatePackageName(const StringRef name) noexcept { // Empty if (name.empty()) { @@ -250,7 +250,7 @@ parsePackage() { return manifest.package.value(); } -const String& +const std::string& getPackageName() { return parsePackage().name; } @@ -292,7 +292,7 @@ parseProfile(const toml::table& table) { if (!flag.is_string()) { throw PoacError("[profile.cxxflags] must be an array of strings"); } - const String flagStr = flag.as_string(); + const std::string flagStr = flag.as_string(); validateCxxflag(flagStr); profile.cxxflags.insert(flagStr); } @@ -304,7 +304,7 @@ parseProfile(const toml::table& table) { } static Profile -getProfile(Option profileName) { +getProfile(Option profileName) { Manifest& manifest = Manifest::instance(); if (!manifest.data.value().contains("profile")) { return {}; @@ -368,7 +368,7 @@ getReleaseProfile() { return manifest.releaseProfile.value(); } -const Vec& +const Vec& getLintCpplintFilters() { Manifest& manifest = Manifest::instance(); if (manifest.cpplintFilters.has_value()) { @@ -376,12 +376,12 @@ getLintCpplintFilters() { } const auto& table = toml::get(*manifest.data); - Vec filters; + Vec filters; if (!table.contains("lint")) { filters = {}; } else { - filters = toml::find_or>( - *manifest.data, "lint", "cpplint", "filters", Vec{} + filters = toml::find_or>( + *manifest.data, "lint", "cpplint", "filters", Vec{} ); } manifest.cpplintFilters = filters; @@ -472,17 +472,17 @@ validateDepName(const StringRef name) { } static GitDependency -parseGitDep(const String& name, const toml::table& info) { +parseGitDep(const std::string& name, const toml::table& info) { validateDepName(name); - String gitUrlStr; - Option target = None; + std::string gitUrlStr; + Option target = None; const auto& gitUrl = info.at("git"); if (gitUrl.is_string()) { gitUrlStr = gitUrl.as_string(); // rev, tag, or branch - for (const String key : { "rev", "tag", "branch" }) { + for (const std::string key : { "rev", "tag", "branch" }) { if (info.contains(key)) { const auto& value = info.at(key); if (value.is_string()) { @@ -496,14 +496,14 @@ parseGitDep(const String& name, const toml::table& info) { } static SystemDependency -parseSystemDep(const String& name, const toml::table& info) { +parseSystemDep(const std::string& name, const toml::table& info) { validateDepName(name); const auto& version = info.at("version"); if (!version.is_string()) { throw PoacError("system dependency version must be a string"); } - const String versionReq = version.as_string(); + const std::string versionReq = version.as_string(); return { name, VersionReq::parse(versionReq) }; } @@ -558,7 +558,7 @@ GitDependency::install() const { if (target.has_value()) { // Checkout to target. - const String target = this->target.value(); + const std::string target = this->target.value(); const git2::Object obj = repo.revparseSingle(target); repo.setHeadDetached(obj.id()); repo.checkoutHead(true); @@ -570,7 +570,7 @@ GitDependency::install() const { } const Path includeDir = installDir / "include"; - String includes = "-isystem "; + std::string includes = "-isystem "; if (fs::exists(includeDir) && fs::is_directory(includeDir) && !fs::is_empty(includeDir)) { @@ -585,13 +585,13 @@ GitDependency::install() const { DepMetadata SystemDependency::install() const { - const String pkgConfigVer = versionReq.toPkgConfigString(name); - const String cflagsCmd = "pkg-config --cflags '" + pkgConfigVer + "'"; - const String libsCmd = "pkg-config --libs '" + pkgConfigVer + "'"; + const std::string pkgConfigVer = versionReq.toPkgConfigString(name); + const std::string cflagsCmd = "pkg-config --cflags '" + pkgConfigVer + "'"; + const std::string libsCmd = "pkg-config --libs '" + pkgConfigVer + "'"; - String cflags = getCmdOutput(cflagsCmd); + std::string cflags = getCmdOutput(cflagsCmd); cflags.pop_back(); // remove '\n' - String libs = getCmdOutput(libsCmd); + std::string libs = getCmdOutput(libsCmd); libs.pop_back(); // remove '\n' return { cflags, libs }; @@ -638,7 +638,7 @@ testValidateDepName() { continue; } assertException( - [c]() { validateDepName("1" + String(1, c) + "1"); }, + [c]() { validateDepName("1" + std::string(1, c) + "1"); }, "dependency name must be alphanumeric, `-`, `_`, `/`, `.`, or `+`" ); } diff --git a/src/Manifest.hpp b/src/Manifest.hpp index 85838e546..63f65941c 100644 --- a/src/Manifest.hpp +++ b/src/Manifest.hpp @@ -4,14 +4,15 @@ #include "Semver.hpp" #include +#include struct DepMetadata { - String includes; // -Isomething - String libs; // -Lsomething -lsomething + std::string includes; // -Isomething + std::string libs; // -Lsomething -lsomething }; struct Profile { - HashSet cxxflags; + HashSet cxxflags; bool lto = false; // Merges this profile with another profile. If a field in this profile is @@ -35,13 +36,13 @@ struct Edition { private: Year edition = Year::Cpp20; - String str = "20"; + std::string str = "20"; public: Edition() = default; - explicit Edition(const String& str); + explicit Edition(const std::string& str); - String getString() const noexcept; + std::string getString() const noexcept; inline auto operator<=>(const Edition& otherEdition) const { return edition <=> otherEdition.edition; @@ -52,11 +53,11 @@ struct Edition { }; const Path& getManifestPath(); -Option validatePackageName(StringRef name) noexcept; -const String& getPackageName(); +Option validatePackageName(StringRef name) noexcept; +const std::string& getPackageName(); const Edition& getPackageEdition(); const Version& getPackageVersion(); const Profile& getDebugProfile(); const Profile& getReleaseProfile(); -const Vec& getLintCpplintFilters(); +const Vec& getLintCpplintFilters(); Vec installDependencies(); diff --git a/src/Parallelism.hpp b/src/Parallelism.hpp index 327ef1ba5..bd22a80d3 100644 --- a/src/Parallelism.hpp +++ b/src/Parallelism.hpp @@ -2,8 +2,10 @@ #include "Rustify.hpp" +#include + usize numThreads() noexcept; -inline const String NUM_DEFAULT_THREADS = std::to_string(numThreads()); +inline const std::string NUM_DEFAULT_THREADS = std::to_string(numThreads()); void setParallelism(usize numThreads) noexcept; usize getParallelism() noexcept; diff --git a/src/Rustify/Aliases.hpp b/src/Rustify/Aliases.hpp index 3f8152600..97285a255 100644 --- a/src/Rustify/Aliases.hpp +++ b/src/Rustify/Aliases.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -38,7 +37,6 @@ using f32 = float; using f64 = double; // NOLINTEND(readability-identifier-naming) -using String = std::string; using StringRef = std::string_view; using Path = fs::path; @@ -68,7 +66,7 @@ using Tuple = std::tuple; struct NoneT : protected std::monostate { constexpr bool operator==(const usize rhs) const { - return String::npos == rhs; + return std::string_view::npos == rhs; } // NOLINTNEXTLINE(google-explicit-constructor) diff --git a/src/Rustify/Tests.hpp b/src/Rustify/Tests.hpp index c4af72287..ee240cd7f 100644 --- a/src/Rustify/Tests.hpp +++ b/src/Rustify/Tests.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -180,7 +181,7 @@ assertException( std::forward(func)(); error(loc, "expected exception `", typeid(E).name(), "` not thrown"); } catch (const E& e) { - if (e.what() == String(msg)) { + if (e.what() == std::string(msg)) { return; // OK } diff --git a/src/Semver.cc b/src/Semver.cc index fad8a4483..7ac2cdcde 100644 --- a/src/Semver.cc +++ b/src/Semver.cc @@ -33,7 +33,7 @@ operator<<(std::ostream& os, const VersionToken& tok) noexcept { return os; } -String +std::string VersionToken::toString() const noexcept { std::ostringstream oss; oss << *this; @@ -77,7 +77,7 @@ operator>(const VersionToken& lhs, const VersionToken& rhs) { return rhs < lhs; } -static String +static std::string carets(const VersionToken& tok) noexcept { switch (tok.kind) { case VersionToken::Eof: @@ -85,7 +85,7 @@ carets(const VersionToken& tok) noexcept { return "^"; default: // NOLINTNEXTLINE(modernize-return-braced-init-list) - return String(tok.size(), '^'); + return std::string(tok.size(), '^'); } } @@ -94,9 +94,9 @@ Prerelease::empty() const noexcept { return ident.empty(); } -String +std::string Prerelease::toString() const noexcept { - String str; + std::string str; for (usize i = 0; i < ident.size(); ++i) { if (i > 0) { str += '.'; @@ -149,9 +149,9 @@ BuildMetadata::empty() const noexcept { return ident.empty(); } -String +std::string BuildMetadata::toString() const noexcept { - String str; + std::string str; for (usize i = 0; i < ident.size(); ++i) { if (i > 0) { str += '.'; @@ -181,9 +181,9 @@ operator>(const BuildMetadata& lhs, const BuildMetadata& rhs) noexcept { return rhs < lhs; } -String +std::string Version::toString() const noexcept { - String str = std::to_string(major); + std::string str = std::to_string(major); str += '.' + std::to_string(minor); str += '.' + std::to_string(patch); if (!pre.empty()) { @@ -277,7 +277,7 @@ VersionLexer::consumeNum() { while (pos < s.size() && std::isdigit(s[pos])) { if (len > 0 && value == 0) { throw SemverError( - s, '\n', String(pos - len, ' '), "^ invalid leading zero" + s, '\n', std::string(pos - len, ' '), "^ invalid leading zero" ); } @@ -286,7 +286,7 @@ VersionLexer::consumeNum() { // Check for overflow if (value > (std::numeric_limits::max() - digit) / base) { throw SemverError( - s, '\n', String(pos - len, ' '), String(len, '^'), + s, '\n', std::string(pos - len, ' '), std::string(len, '^'), " number exceeds UINT64_MAX" ); } @@ -356,7 +356,9 @@ struct SemverParseError : public SemverError { SemverParseError( const VersionLexer& lexer, const VersionToken& tok, const StringRef msg ) - : SemverError(lexer.s, '\n', String(lexer.pos, ' '), carets(tok), msg) {} + : SemverError( + lexer.s, '\n', std::string(lexer.pos, ' '), carets(tok), msg + ) {} }; Version @@ -389,7 +391,7 @@ VersionParser::parse() { if (!lexer.isEof()) { throw SemverParseError( lexer, lexer.peek(), - " unexpected character: `" + String(1, lexer.s[lexer.pos]) + '`' + " unexpected character: `" + std::string(1, lexer.s[lexer.pos]) + '`' ); } @@ -726,7 +728,7 @@ testGe() { void testSpecOrder() { - const Vec vers = { + const Vec vers = { "1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-alpha.beta", "1.0.0-beta", "1.0.0-beta.2", "1.0.0-beta.11", "1.0.0-rc.1", "1.0.0", }; diff --git a/src/Semver.hpp b/src/Semver.hpp index 37b6eb616..6e57799e0 100644 --- a/src/Semver.hpp +++ b/src/Semver.hpp @@ -13,6 +13,7 @@ #include "Rustify.hpp" #include +#include #include #include @@ -43,7 +44,7 @@ struct VersionToken { constexpr explicit VersionToken(Kind kind) noexcept : kind(kind), value(std::monostate{}) {} - String toString() const noexcept; + std::string toString() const noexcept; usize size() const noexcept; }; @@ -52,7 +53,7 @@ struct Prerelease { static Prerelease parse(StringRef str); bool empty() const noexcept; - String toString() const noexcept; + std::string toString() const noexcept; }; bool operator==(const Prerelease& lhs, const Prerelease& rhs) noexcept; bool operator!=(const Prerelease& lhs, const Prerelease& rhs) noexcept; @@ -66,7 +67,7 @@ struct BuildMetadata { static BuildMetadata parse(StringRef str); bool empty() const noexcept; - String toString() const noexcept; + std::string toString() const noexcept; }; struct Version { @@ -77,7 +78,7 @@ struct Version { BuildMetadata build; static Version parse(StringRef str); - String toString() const noexcept; + std::string toString() const noexcept; }; std::ostream& operator<<(std::ostream& os, const Version& ver) noexcept; bool operator==(const Version& lhs, const Version& rhs) noexcept; diff --git a/src/TermColor.cc b/src/TermColor.cc index 52211d28a..89180e55e 100644 --- a/src/TermColor.cc +++ b/src/TermColor.cc @@ -4,6 +4,7 @@ #include "Rustify.hpp" #include +#include static bool isTerm() noexcept { @@ -82,18 +83,18 @@ shouldColor() noexcept { return ColorState::instance().shouldColor(); } -static String +static std::string colorize(const StringRef str, const StringRef code) noexcept { if (!shouldColor()) { - return String(str); + return std::string(str); } - String res; + std::string res; if (str.starts_with("\033[")) { const usize end = str.find('m'); - if (end == String::npos) { + if (end == std::string::npos) { // Invalid color escape sequence - return String(str); + return std::string(str); } res = str.substr(0, end); @@ -113,36 +114,36 @@ colorize(const StringRef str, const StringRef code) noexcept { return res; } -String +std::string gray(const StringRef str) noexcept { return colorize(str, "30"); } -String +std::string red(const StringRef str) noexcept { return colorize(str, "31"); } -String +std::string green(const StringRef str) noexcept { return colorize(str, "32"); } -String +std::string yellow(const StringRef str) noexcept { return colorize(str, "33"); } -String +std::string blue(const StringRef str) noexcept { return colorize(str, "34"); } -String +std::string magenta(const StringRef str) noexcept { return colorize(str, "35"); } -String +std::string cyan(const StringRef str) noexcept { return colorize(str, "36"); } -String +std::string bold(const StringRef str) noexcept { return colorize(str, "1"); } diff --git a/src/TermColor.hpp b/src/TermColor.hpp index 2a025aa94..cbeacce12 100644 --- a/src/TermColor.hpp +++ b/src/TermColor.hpp @@ -2,6 +2,8 @@ #include "Rustify.hpp" +#include + enum class ColorMode { Always, Auto, @@ -12,12 +14,12 @@ void setColorMode(ColorMode mode) noexcept; void setColorMode(StringRef str) noexcept; bool shouldColor() noexcept; -String gray(StringRef str) noexcept; -String red(StringRef str) noexcept; -String green(StringRef str) noexcept; -String yellow(StringRef str) noexcept; -String blue(StringRef str) noexcept; -String magenta(StringRef str) noexcept; -String cyan(StringRef str) 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; -String bold(StringRef str) noexcept; +std::string bold(StringRef str) noexcept; diff --git a/src/VersionReq.cc b/src/VersionReq.cc index 08db29b32..88ea6f134 100644 --- a/src/VersionReq.cc +++ b/src/VersionReq.cc @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -23,7 +24,7 @@ struct VersionReqError : public PoacError { ) {} }; -String +std::string toString(const Comparator::Op op) noexcept { switch (op) { case Comparator::Exact: @@ -183,7 +184,7 @@ struct ComparatorParser { break; default: throw ComparatorError( - lexer.s, '\n', String(lexer.pos, ' '), + lexer.s, '\n', std::string(lexer.pos, ' '), "^ expected =, >=, <=, >, <, or version" ); } @@ -195,7 +196,7 @@ struct ComparatorParser { const auto token2 = lexer.next(); if (token2.kind != ComparatorToken::Ver) { throw ComparatorError( - lexer.s, '\n', String(lexer.pos, ' '), "^ expected version" + lexer.s, '\n', std::string(lexer.pos, ' '), "^ expected version" ); } result.from(std::get(token2.value)); @@ -220,7 +221,7 @@ Comparator::from(const OptVersion& ver) noexcept { } void -optVersionString(const Comparator& cmp, String& result) noexcept { +optVersionString(const Comparator& cmp, std::string& result) noexcept { result += std::to_string(cmp.major); if (cmp.minor.has_value()) { result += "."; @@ -238,9 +239,9 @@ optVersionString(const Comparator& cmp, String& result) noexcept { } } -String +std::string Comparator::toString() const noexcept { - String result; + std::string result; if (op.has_value()) { result += ::toString(op.value()); } @@ -248,9 +249,9 @@ Comparator::toString() const noexcept { return result; } -String +std::string Comparator::toPkgConfigString() const noexcept { - String result; + std::string result; if (op.has_value()) { result += ::toString(op.value()); result += ' '; // we just need this space for pkg-config @@ -514,7 +515,7 @@ struct VersionReqParser { lexer.skipWs(); if (!lexer.isEof()) { throw VersionReqError( - lexer.s, '\n', String(lexer.pos, ' '), + lexer.s, '\n', std::string(lexer.pos, ' '), "^ NoOp and Exact cannot chain" ); } @@ -526,7 +527,7 @@ struct VersionReqParser { return result; } else if (token.kind != VersionReqToken::And) { throw VersionReqError( - lexer.s, '\n', String(lexer.pos, ' '), "^ expected `&&`" + lexer.s, '\n', std::string(lexer.pos, ' '), "^ expected `&&`" ); } @@ -534,7 +535,7 @@ struct VersionReqParser { lexer.skipWs(); if (!lexer.isEof()) { throw VersionReqError( - lexer.s, '\n', String(lexer.pos, ' '), "^ expected end of string" + lexer.s, '\n', std::string(lexer.pos, ' '), "^ expected end of string" ); } @@ -546,7 +547,7 @@ struct VersionReqParser { const VersionReqToken token = lexer.next(); if (token.kind != VersionReqToken::Comp) { throw VersionReqError( - lexer.s, '\n', String(lexer.pos, ' '), + lexer.s, '\n', std::string(lexer.pos, ' '), "^ expected =, >=, <=, >, <, or version" ); } @@ -582,7 +583,7 @@ struct VersionReqParser { [[noreturn]] void compExpected() { throw VersionReqError( - lexer.s, '\n', String(lexer.pos, ' '), "^ expected >=, <=, >, or <" + lexer.s, '\n', std::string(lexer.pos, ' '), "^ expected >=, <=, >, or <" ); } }; @@ -811,9 +812,9 @@ VersionReq::canonicalize() const noexcept { return req; } -String +std::string VersionReq::toString() const noexcept { - String result = left.toString(); + std::string result = left.toString(); if (right.has_value()) { result += " && "; result += right->toString(); @@ -821,12 +822,12 @@ VersionReq::toString() const noexcept { return result; } -String +std::string VersionReq::toPkgConfigString(const StringRef name) const noexcept { // For pkg-config, canonicalization is necessary. const VersionReq req = canonicalize(); - String result(name); + std::string result(name); result += ' '; result += req.left.toPkgConfigString(); if (req.right.has_value()) { diff --git a/src/VersionReq.hpp b/src/VersionReq.hpp index ba5480922..f18d42f1b 100644 --- a/src/VersionReq.hpp +++ b/src/VersionReq.hpp @@ -18,6 +18,7 @@ #include "Semver.hpp" #include +#include struct OptVersion { u64 major{}; @@ -76,8 +77,8 @@ struct Comparator { static Comparator parse(StringRef str); void from(const OptVersion& ver) noexcept; - String toString() const noexcept; - String toPkgConfigString() const noexcept; + std::string toString() const noexcept; + std::string toPkgConfigString() const noexcept; bool satisfiedBy(const Version& ver) const noexcept; Comparator canonicalize() const noexcept; }; @@ -88,8 +89,8 @@ struct VersionReq { static VersionReq parse(StringRef str); bool satisfiedBy(const Version& ver) const noexcept; - String toString() const noexcept; - String toPkgConfigString(StringRef name) const noexcept; + std::string toString() const noexcept; + std::string toPkgConfigString(StringRef name) const noexcept; VersionReq canonicalize() const noexcept; bool canSimplify() const noexcept; }; diff --git a/srcOld/Archive.hpp b/srcOld/Archive.hpp index 02dc41ecd..4657f5add 100644 --- a/srcOld/Archive.hpp +++ b/srcOld/Archive.hpp @@ -8,6 +8,7 @@ module; #include // NOLINT(build/include_order) #include // NOLINT(build/include_order) #include +#include // internal #include "result-macros.hpp" @@ -34,7 +35,7 @@ using Writer = std::unique_ptr; [[nodiscard]] auto archive_write_data_block( const Writer& writer, const void* buffer, usize size, i64 offset -) noexcept -> Result { +) noexcept -> Result { const la_ssize_t res = archive_write_data_block(writer.get(), buffer, size, offset); if (res < ARCHIVE_OK) { @@ -45,7 +46,7 @@ archive_write_data_block( [[nodiscard]] auto copy_data(Archive* reader, const Writer& writer) noexcept - -> Result { + -> Result { usize size{}; const void* buff = nullptr; i64 offset{}; @@ -63,7 +64,7 @@ copy_data(Archive* reader, const Writer& writer) noexcept [[nodiscard]] auto archive_write_finish_entry(const Writer& writer -) noexcept -> Result { +) noexcept -> Result { const i32 res = archive_write_finish_entry(writer.get()); if (res < ARCHIVE_OK) { return Err(archive_error_string(writer.get())); @@ -76,7 +77,7 @@ archive_write_finish_entry(const Writer& writer [[nodiscard]] auto archive_write_header( Archive* reader, const Writer& writer, archive_entry* entry -) noexcept -> Result { +) noexcept -> Result { if (archive_write_header(writer.get(), entry) < ARCHIVE_OK) { return Err(archive_error_string(writer.get())); } else if (archive_entry_size(entry) > 0) { @@ -86,8 +87,9 @@ archive_write_header( } auto -set_extract_path(archive_entry* entry, const Path& extract_path) -> String { - String current_file = archive_entry_pathname(entry); +set_extract_path(archive_entry* entry, const Path& extract_path) + -> std::string { + std::string current_file = archive_entry_pathname(entry); const Path full_output_path = extract_path / current_file; log::debug("extracting to `{}`", full_output_path.string()); archive_entry_set_pathname(entry, full_output_path.c_str()); @@ -97,7 +99,7 @@ set_extract_path(archive_entry* entry, const Path& extract_path) -> String { [[nodiscard]] auto archive_read_next_header(Archive* reader, archive_entry** entry) noexcept( !static_cast(ARCHIVE_EOF) // NOLINT(modernize-use-bool-literals) -) -> Result { +) -> Result { const i32 res = ::archive_read_next_header(reader, entry); if (res == ARCHIVE_EOF) { return Ok(ARCHIVE_EOF); @@ -111,9 +113,9 @@ archive_read_next_header(Archive* reader, archive_entry** entry) noexcept( [[nodiscard]] auto extract_impl(Archive* reader, const Writer& writer, const Path& extract_path) - -> Result { + -> Result { archive_entry* entry = nullptr; - String extracted_directory_name; + std::string extracted_directory_name; while (Try(archive::archive_read_next_header(reader, &entry)) != ARCHIVE_EOF ) { if (extracted_directory_name.empty()) { @@ -130,7 +132,7 @@ extract_impl(Archive* reader, const Writer& writer, const Path& extract_path) [[nodiscard]] auto archive_read_open_filename( Archive* reader, const Path& file_path, usize block_size -) noexcept -> Result { +) noexcept -> Result { if (archive_read_open_filename(reader, file_path.c_str(), block_size)) { return Err("Cannot archive_read_open_filename"); } @@ -153,7 +155,7 @@ read_as_targz(Archive* reader) noexcept { export [[nodiscard]] auto extract(const Path& target_file_path, const Path& extract_path) - -> Result { + -> Result { Archive* reader = archive_read_new(); if (!reader) { return Err("Cannot archive_read_new"); diff --git a/srcOld/Cfg.hpp b/srcOld/Cfg.hpp index 7c5351961..dda14f8cf 100644 --- a/srcOld/Cfg.hpp +++ b/srcOld/Cfg.hpp @@ -18,7 +18,7 @@ import poac.util.rustify; export namespace poac::util::cfg { struct Exception : public std::exception { - explicit Exception(String what) : what_(std::move(what)) {} + explicit Exception(std::string what) : what_(std::move(what)) {} explicit Exception(const char* what) : what_(what) {} ~Exception() noexcept override = default; [[nodiscard]] inline auto what() const noexcept -> const char* override { @@ -31,13 +31,13 @@ struct Exception : public std::exception { auto operator=(Exception&&) noexcept -> Exception& = default; private: - String what_; + std::string what_; }; struct StringError : public cfg::Exception { - explicit StringError(const String& what_) + explicit StringError(const std::string& what_) : Exception("missing terminating '\"' character\n" + what_) {} - explicit StringError(const char* what_) : StringError(String(what_)) {} + explicit StringError(const char* what_) : StringError(std::string(what_)) {} ~StringError() noexcept override = default; StringError(const StringError&) = default; @@ -48,11 +48,11 @@ struct StringError : public cfg::Exception { struct IdentError : public cfg::Exception { public: - explicit IdentError(const String& what_) + explicit IdentError(const std::string& what_) : Exception( "cfg expected parenthesis, comma, identifier, or string\n" + what_ ) {} - explicit IdentError(const char* what_) : IdentError(String(what_)) {} + explicit IdentError(const char* what_) : IdentError(std::string(what_)) {} ~IdentError() noexcept override = default; IdentError(const IdentError&) = default; @@ -63,9 +63,10 @@ struct IdentError : public cfg::Exception { struct OperatorError : public cfg::Exception { public: - explicit OperatorError(const String& what_) + explicit OperatorError(const std::string& what_) : Exception("cfg operator error\n" + what_) {} - explicit OperatorError(const char* what_) : OperatorError(String(what_)) {} + explicit OperatorError(const char* what_) + : OperatorError(std::string(what_)) {} ~OperatorError() noexcept override = default; OperatorError(const OperatorError&) = default; @@ -76,7 +77,7 @@ struct OperatorError : public cfg::Exception { struct ExpressionError : public cfg::Exception { public: - explicit ExpressionError(const String& what_) : Exception(what_) {} + explicit ExpressionError(const std::string& what_) : Exception(what_) {} explicit ExpressionError(const char* what_) : Exception(what_) {} ~ExpressionError() noexcept override = default; @@ -88,9 +89,9 @@ struct ExpressionError : public cfg::Exception { struct SyntaxError : public cfg::Exception { public: - explicit SyntaxError(const String& what_) + explicit SyntaxError(const std::string& what_) : Exception("cfg syntax error\n" + what_) {} - explicit SyntaxError(const char* what_) : SyntaxError(String(what_)) {} + explicit SyntaxError(const char* what_) : SyntaxError(std::string(what_)) {} ~SyntaxError() noexcept override = default; SyntaxError(const SyntaxError&) = default; @@ -127,7 +128,7 @@ struct Token { Lt, /// `<=` LtEq, - String, + std::string, Ident, }; @@ -151,13 +152,13 @@ struct Token { explicit Token(Kind k) : kind( - k != Kind::String && k != Kind::Ident + k != Kind::std::string && k != Kind::Ident ? k : throw std::invalid_argument("poac::util::cfg::Token") ) {} Token(Kind k, StringType s) : kind( - k == Kind::String + k == Kind::std::string ? k : throw std::invalid_argument("poac::util::cfg::Token") ), @@ -211,7 +212,7 @@ to_kind(StringRef kind) -> Token::Kind { } auto -to_string(Token::ident ident) -> String { +to_string(Token::ident ident) -> std::string { switch (ident) { case Token::ident::cfg: return "cfg"; @@ -257,7 +258,7 @@ operator<<(std::ostream& os, const Token& token) -> std::ostream& { return (os << "lt: <"); case Token::LtEq: return (os << "lteq: <="); - case Token::String: + case Token::std::string: return (os << "string: " << token.get_str()); case Token::Ident: return (os << "ident: " << to_string(token.get_ident())); @@ -330,9 +331,9 @@ Lexer::analyze_two_phrase(SizeType index_, const char kind) const -> std::pair> { if (this->one(index_) == '=') { this->step(index_); - return generate_token(index_, String{ kind } + '='); + return generate_token(index_, std::string{ kind } + '='); } else { - return generate_token(index_, String{ kind }); + return generate_token(index_, std::string{ kind }); } } @@ -355,7 +356,7 @@ Lexer::tokenize(SizeType index_ [[fallthrough]]; case '=': this->step(index_); - return generate_token(index_, String{ one }); + return generate_token(index_, std::string{ one }); case '>': [[fallthrough]]; case '<': @@ -388,26 +389,26 @@ Lexer::string(SizeType index_) const -> std::pair { while (this->one(index_) != '"') { this->step(index_); if (index_ >= this->str.size()) { - String msg; - msg += String(start - 1, ' '); + std::string msg; + msg += std::string(start - 1, ' '); msg += "^"; - msg += String(this->str.size() - start, '-'); + msg += std::string(this->str.size() - start, '-'); msg += " unterminated string"; - throw cfg::StringError(String(this->str) + "\n" + msg); + throw cfg::StringError(std::string(this->str) + "\n" + msg); } } const StringRef s = this->str.substr(start, index_ - start); this->step(index_); - return { this->diff_step(index_), Token{ Token::String, s } }; + return { this->diff_step(index_), Token{ Token::std::string, s } }; } auto Lexer::ident(SizeType index_) const -> std::pair { if (!is_ident_start(this->one(index_))) { - String msg; - msg += String(index_, ' '); + std::string msg; + msg += std::string(index_, ' '); msg += "^ unexpected character"; - throw cfg::IdentError(String(this->str) + "\n" + msg); + throw cfg::IdentError(std::string(this->str) + "\n" + msg); } const SizeType start = index_; this->step(index_); @@ -419,12 +420,12 @@ Lexer::ident(SizeType index_) const -> std::pair { if (const auto ident = to_ident(s)) { return { this->diff_step(index_), Token{ Token::Ident, ident.value() } }; } else { - String msg; - msg += String(start, ' '); + std::string msg; + msg += std::string(start, ' '); msg += "^"; - msg += String(index_ - start - 1, '-'); + msg += std::string(index_ - start - 1, '-'); msg += " unknown identify"; - throw cfg::IdentError(String(this->str) + "\n" + msg); + throw cfg::IdentError(std::string(this->str) + "\n" + msg); } } @@ -761,9 +762,9 @@ auto Parser::cfg() -> Cfg { const usize index = lexer.index; if (const auto token = lexer.next(); !token.has_value()) { - String msg = String(index + 1, ' '); + std::string msg = std::string(index + 1, ' '); msg += " ^ expected operator, but cfg expression ended"; - throw cfg::SyntaxError(String(lexer.str) + "\n" + msg); + throw cfg::SyntaxError(std::string(lexer.str) + "\n" + msg); } else if (token->kind == Token::Ident) { if (this->r_try(Token::Equals)) { return this->cfg_str(token->get_ident(), Cfg::Op::Equals); @@ -777,23 +778,23 @@ Parser::cfg() -> Cfg { return this->cfg_str(lexer.index, token->get_ident(), Cfg::Op::LtEq); } } - String msg = String(lexer.index + 1, ' '); + std::string msg = std::string(lexer.index + 1, ' '); msg += "^ expected operator"; - throw cfg::SyntaxError(String(lexer.str) + "\n" + msg); + throw cfg::SyntaxError(std::string(lexer.str) + "\n" + msg); } [[noreturn]] void Parser::throw_operator_error(const usize index, Cfg::Op op) const { - String msg; + std::string msg; if (op == Cfg::Op::Gt || op == Cfg::Op::Lt) { - msg += String(index - 1, ' '); + msg += std::string(index - 1, ' '); msg += "^"; } else if (op == Cfg::Op::GtEq || op == Cfg::Op::LtEq) { - msg += String(index - 2, ' '); + msg += std::string(index - 2, ' '); msg += "^-"; } msg += " cannot be specified except os_version"; - throw cfg::OperatorError(String(lexer.str) + "\n" + msg); + throw cfg::OperatorError(std::string(lexer.str) + "\n" + msg); } auto @@ -809,20 +810,20 @@ auto Parser::cfg_str(Token::ident ident, Cfg::Op op) -> Cfg { const usize index = lexer.index; if (const auto t = lexer.next()) { - if (t->kind == Token::String) { + if (t->kind == Token::std::string) { return { ident, op, t->get_str() }; } else { - String msg = String(index + 1, ' '); + std::string msg = std::string(index + 1, ' '); msg += "^"; const i32 range = lexer.index - index - 2; - msg += String(range < 0 ? 0 : range, '-'); + msg += std::string(range < 0 ? 0 : range, '-'); msg += " expected a string"; - throw cfg::SyntaxError(String(lexer.str) + "\n" + msg); + throw cfg::SyntaxError(std::string(lexer.str) + "\n" + msg); } } else { - String msg = String(index, ' '); + std::string msg = std::string(index, ' '); msg += "^ expected a string, but cfg expression ended"; - throw cfg::SyntaxError(String(lexer.str) + "\n" + msg); + throw cfg::SyntaxError(std::string(lexer.str) + "\n" + msg); } } @@ -842,14 +843,14 @@ Parser::eat_left_paren(Token::ident prev) { const usize index = lexer.index; if (const auto token = lexer.next()) { if (token->kind != Token::LeftParen) { - String msg = String(index, ' '); + std::string msg = std::string(index, ' '); msg += "^ excepted '(' after `" + to_string(prev) + "`"; - throw cfg::SyntaxError(String(lexer.str) + "\n" + msg); + throw cfg::SyntaxError(std::string(lexer.str) + "\n" + msg); } } else { - String msg = String(index, ' '); + std::string msg = std::string(index, ' '); msg += "^ expected '(', but cfg expression ended"; - throw cfg::SyntaxError(String(lexer.str) + "\n" + msg); + throw cfg::SyntaxError(std::string(lexer.str) + "\n" + msg); } } void @@ -857,16 +858,16 @@ Parser::eat_right_paren() { const usize index = lexer.index; if (const auto token = lexer.next()) { if (token->kind != Token::RightParen) { - String msg = String(index, ' '); + std::string msg = std::string(index, ' '); msg += "^"; - msg += String(lexer.index - index - 1, '-'); + msg += std::string(lexer.index - index - 1, '-'); msg += " excepted ')'"; - throw cfg::SyntaxError(String(lexer.str) + "\n" + msg); + throw cfg::SyntaxError(std::string(lexer.str) + "\n" + msg); } } else { - String msg = String(index, ' '); + std::string msg = std::string(index, ' '); msg += "^ expected ')', but cfg expression ended"; - throw cfg::SyntaxError(String(lexer.str) + "\n" + msg); + throw cfg::SyntaxError(std::string(lexer.str) + "\n" + msg); } } diff --git a/srcOld/Lockfile.hpp b/srcOld/Lockfile.hpp index d61a6af30..0957e0b85 100644 --- a/srcOld/Lockfile.hpp +++ b/srcOld/Lockfile.hpp @@ -3,6 +3,7 @@ module; // std #include #include +#include #include // external @@ -27,7 +28,7 @@ inline constexpr StringRef LOCKFILE_HEADER = "# It is not intended for manual editing."; using InvalidLockfileVersion = Error<"invalid lockfile version found: {}", i64>; -using FailedToReadLockfile = Error<"failed to read lockfile:\n{}", String>; +using FailedToReadLockfile = Error<"failed to read lockfile:\n{}", std::string>; inline auto poac_lock_last_modified(const Path& base_dir) -> fs::file_time_type { @@ -53,9 +54,9 @@ inline constexpr i64 LOCKFILE_VERSION = 1; // NOLINTNEXTLINE(bugprone-exception-escape) struct Package { - String name; - String version; - Vec dependencies; + std::string name; + std::string version; + Vec dependencies; }; struct Lockfile { @@ -92,11 +93,11 @@ convert_to_lock(const resolver::UniqDeps& deps Package p{ pack.name, pack.dep_info.version_rq, - Vec{}, + Vec{}, }; if (inner_deps.has_value()) { // Extract name from inner dependencies and drop version. - Vec ideps; + Vec ideps; for (const auto& [name, _v] : inner_deps.value()) { static_cast(_v); ideps.emplace_back(name); @@ -107,7 +108,7 @@ convert_to_lock(const resolver::UniqDeps& deps } toml::basic_value lock( - Lockfile{ .package = packages }, { String(LOCKFILE_HEADER) } + Lockfile{ .package = packages }, { std::string(LOCKFILE_HEADER) } ); return Ok(lock); } diff --git a/srcOld/Resolver.hpp b/srcOld/Resolver.hpp index 9cfffeed7..f8b8f9ca4 100644 --- a/srcOld/Resolver.hpp +++ b/srcOld/Resolver.hpp @@ -44,7 +44,7 @@ namespace poac::core::resolver { using namespace std::literals::string_view_literals; inline auto -get_install_name(const resolve::Package& package) -> String { +get_install_name(const resolve::Package& package) -> std::string { return boost::replace_first_copy(package.name, "/", "-") + "-" + package.dep_info.version_rq; } @@ -78,7 +78,7 @@ get_archive_path(const resolve::Package& package) -> Path { } inline auto -convert_to_download_link(StringRef repository) -> String { +convert_to_download_link(StringRef repository) -> std::string { // repository should be like => // https://github.com/boostorg/winapi/tree/boost-1.66.0 // convert it to => @@ -107,7 +107,7 @@ convert_to_download_link(StringRef repository) -> String { [[nodiscard]] inline auto get_download_link(const resolve::Package& package -) -> Result, String> { +) -> Result, std::string> { const auto [repository, sha256sum] = Try(util::net::api::repoinfo(package.name, package.dep_info.version_rq)); return Ok(std::make_pair(convert_to_download_link(repository), sha256sum)); @@ -115,7 +115,7 @@ get_download_link(const resolve::Package& package [[nodiscard]] auto fetch_impl(const resolve::Package& package -) noexcept -> Result> { +) noexcept -> Result> { try { const auto [download_link, sha256sum] = Try(get_download_link(package).map_err(to_anyhow)); @@ -130,7 +130,7 @@ fetch_impl(const resolve::Package& package return Ok(std::make_pair(archive_path, sha256sum)); } catch (const std::exception& e) { - return Result>(Err(e.what())) + return Result>(Err(e.what())) .with_context([&package] { return Err(package.name, package.dep_info.version_rq) .get(); @@ -158,7 +158,8 @@ fetch(const resolve::UniqDeps& deps) -> Result { const auto [installed_path, sha256sum] = Try(fetch_impl(package)); // Check if sha256sum of the downloaded package is the same with one // stored in DB. - if (const String actual_sha256sum = Try(util::sha256::sum(installed_path)); + if (const std::string actual_sha256sum = + Try(util::sha256::sum(installed_path)); sha256sum != actual_sha256sum) { fs::remove(installed_path); return Err( @@ -166,7 +167,7 @@ fetch(const resolve::UniqDeps& deps) -> Result { ); } - const String extracted_directory_name = + const std::string extracted_directory_name = Try(util::archive::extract(installed_path, config::default_registry_dir) .map_err(to_anyhow)); Try(rename_extracted_directory(package, extracted_directory_name)); @@ -303,8 +304,8 @@ get_registries(const toml::value& manifest) -> Result { return Err(name); } } - String index = toml::find(table, "index"); - String type = toml::find(table, "type"); + std::string index = toml::find(table, "index"); + std::string type = toml::find(table, "type"); if (type != "poac" && type != "conan-v1") { return Err(name, type); } diff --git a/srcOld/Resolver/Registry.hpp b/srcOld/Resolver/Registry.hpp index bf54fd84a..dec92a6d4 100644 --- a/srcOld/Resolver/Registry.hpp +++ b/srcOld/Resolver/Registry.hpp @@ -1,5 +1,7 @@ module; +#include + // external #include @@ -12,8 +14,8 @@ export namespace poac::core::resolver::registry { // NOLINTNEXTLINE(bugprone-exception-escape) struct Registry { - String index; - String type; + std::string index; + std::string type; }; inline auto @@ -29,6 +31,6 @@ hash_value(const Registry& r) -> usize { return seed; } -using Registries = HashMap; +using Registries = HashMap; } // namespace poac::core::resolver::registry diff --git a/srcOld/Resolver/Resolve.hpp b/srcOld/Resolver/Resolve.hpp index ec1ae3066..560a1cc28 100644 --- a/srcOld/Resolver/Resolve.hpp +++ b/srcOld/Resolver/Resolve.hpp @@ -40,7 +40,7 @@ get_package(const UniqDeps::value_type& deps } inline auto -to_binary_numbers(const i32& x, const usize& digit) -> String { +to_binary_numbers(const i32& x, const usize& digit) -> std::string { return format("{:0{}b}", x, digit); } @@ -150,7 +150,7 @@ create_cnf(const DupDeps& activated) -> Vec> { [[nodiscard]] auto solve_sat(const DupDeps& activated, const Vec>& clauses) - -> Result, String> { + -> Result, std::string> { // deps.activated.size() == variables const Vec assignments = Try(sat::solve(clauses, activated.size())); UniqDeps resolved_deps{}; @@ -168,7 +168,7 @@ solve_sat(const DupDeps& activated, const Vec>& clauses) [[nodiscard]] auto backtrack_loop(const DupDeps& activated -) -> Result, String> { +) -> Result, std::string> { const Vec> clauses = create_cnf(activated); if (util::verbosity::is_verbose()) { for (const Vec& c : clauses) { @@ -208,11 +208,11 @@ duplicate_loose(const SinglePassRange& rng) -> bool { // name is boost/config, no boost-config [[nodiscard]] auto get_versions_satisfy_interval(const Package& package -) -> Result, String> { +) -> Result, std::string> { // TODO(ken-matsui): (`>1.2 and <=1.3.2` -> NG,`>1.2.0-alpha and <=1.3.2` -> // OK) `2.0.0` specific version or `>=0.1.2 and <3.4.0` version interval const semver::Interval i(package.dep_info.version_rq); - const Vec satisfied_versions = + const Vec satisfied_versions = Try(util::net::api::versions(package.name)) | boost::adaptors::filtered([&i](StringRef s) { return i.satisfies(s); }) | util::meta::CONTAINERIZED; @@ -231,7 +231,7 @@ struct Cache { Package package; /// versions in the interval - Vec versions; + Vec versions; }; inline auto @@ -277,7 +277,7 @@ gather_deps_of_deps( return package == cache.package; }); - const Vec dep_versions = + const Vec dep_versions = found_cache != interval_cache.cend() ? found_cache->versions : get_versions_satisfy_interval(package).unwrap(); @@ -285,7 +285,7 @@ gather_deps_of_deps( // Cache interval and versions pair interval_cache.emplace(Cache{ package, dep_versions }); } - for (const String& dep_version : dep_versions) { + for (const std::string& dep_version : dep_versions) { cur_deps_deps.emplace_back(Package{ package.name, dep_version }); } } @@ -324,7 +324,7 @@ gather_deps( [[nodiscard]] auto gather_all_deps(const UniqDeps& deps -) -> Result, String> { +) -> Result, std::string> { DupDeps duplicate_deps; IntervalCache interval_cache; @@ -348,10 +348,11 @@ gather_all_deps(const UniqDeps& deps // Get versions using interval // FIXME: versions API and deps API are received the almost same responses - const Vec versions = Try(get_versions_satisfy_interval(package)); + const Vec versions = + Try(get_versions_satisfy_interval(package)); // Cache interval and versions pair interval_cache.emplace(Cache{ package, versions }); - for (const String& version : versions) { + for (const std::string& version : versions) { gather_deps( Package{ package.name, { version, package.dep_info.index, package.dep_info.type } }, diff --git a/srcOld/Resolver/Sat.hpp b/srcOld/Resolver/Sat.hpp index f65f5ec40..b2db1bdfd 100644 --- a/srcOld/Resolver/Sat.hpp +++ b/srcOld/Resolver/Sat.hpp @@ -153,7 +153,8 @@ unit_propagate(Vec>& clauses, Vec& literals) -> Status { // recursive DPLL algorithm [[nodiscard]] auto -dpll(Vec>& clauses, Vec& literals) -> Result, String> { +dpll(Vec>& clauses, Vec& literals) + -> Result, std::string> { // NOLINTNEXTLINE(bugprone-branch-clone) if (clauses.empty()) { return Ok(to_assignments(literals)); @@ -200,7 +201,8 @@ dpll(Vec>& clauses, Vec& literals) -> Result, String> { } [[nodiscard]] inline auto -solve(Vec> clauses, const u32& variables) -> Result, String> { +solve(Vec> clauses, const u32& variables) + -> Result, std::string> { // Express the assignment status of the literal value corresponding to index. // a vector that stores the value assigned to each variable, where // -1 - unassigned, 0 - true, 1 - false. diff --git a/srcOld/Resolver/Types.hpp b/srcOld/Resolver/Types.hpp index 99756d81c..c802a6e17 100644 --- a/srcOld/Resolver/Types.hpp +++ b/srcOld/Resolver/Types.hpp @@ -34,13 +34,13 @@ struct DependencyInfo { /// Version Requirement /// /// Sometimes, this is like `1.66.0` or like `>=1.64.0 and <2.0.0`. - String version_rq; + std::string version_rq; /// Registry Index - String index; + std::string index; /// Package type - String type; + std::string type; }; inline auto @@ -61,7 +61,7 @@ hash_value(const DependencyInfo& d) -> usize { // NOLINTNEXTLINE(bugprone-exception-escape) struct Package { /// Package name - String name; + std::string name; DependencyInfo dep_info; }; @@ -95,7 +95,7 @@ template using UniqDeps = std::conditional_t< W::value, HashMap, // - HashMap>; + HashMap>; } // namespace poac::core::resolver::resolve @@ -107,12 +107,14 @@ using FailedToParseConfig = Error<"parsing the value of the `dependencies` key in poac.toml failed">; using FailedToResolveDeps = Error<"failed to resolve dependencies">; using FailedToResolveDepsWithCause = - Error<"failed to resolve dependencies:\n{}", String>; -using FailedToCreateDirs = Error<"failed to create directories:\n{}", String>; -using FailedToRename = - Error<"failed to rename a downloaded package: `{}: {}`", String, String>; + Error<"failed to resolve dependencies:\n{}", std::string>; +using FailedToCreateDirs = + Error<"failed to create directories:\n{}", std::string>; +using FailedToRename = Error< + "failed to rename a downloaded package: `{}: {}`", std::string, + std::string>; using FailedToFetch = - Error<"failed to fetch a package: `{}: {}`", String, String>; + Error<"failed to fetch a package: `{}: {}`", std::string, std::string>; using IncorrectSha256sum = Error< "the sha256sum when published did not match one when downloaded.\n" " published: `{}` != downloaded: `{}\n" @@ -120,15 +122,15 @@ using IncorrectSha256sum = Error< "was removed from this PC. We highly recommend submitting an " "issue on GitHub of the package and stopping using this package:\n" " {}: {}", - String, String, String, String>; + std::string, std::string, std::string, std::string>; using RedefinePredefinedRegistryEntry = Error< "Registry entry named `{}` is predefined and can't be overwritten.\n", - String>; + std::string>; using DuplicateRegistryEntry = - Error<"Registry entry named `{}` is duplicated.\n", String>; + Error<"Registry entry named `{}` is duplicated.\n", std::string>; using UnknownRegistryType = Error< - "Registry entry named `{}` has unknown registry type `{}`.\n", String, - String>; -using Unknown = Error<"unknown error occurred: {}", String>; + "Registry entry named `{}` has unknown registry type `{}`.\n", std::string, + std::string>; +using Unknown = Error<"unknown error occurred: {}", std::string>; } // namespace poac::core::resolver diff --git a/srcOld/Sha256.hpp b/srcOld/Sha256.hpp index d9a2d32fe..1194eccb9 100644 --- a/srcOld/Sha256.hpp +++ b/srcOld/Sha256.hpp @@ -17,7 +17,7 @@ import poac.util.rustify; namespace poac::util::sha256 { -using FailedToReadFile = Error<"Failed to read file: `{}`", String>; +using FailedToReadFile = Error<"Failed to read file: `{}`", std::string>; using FailedToCreateSha256Digest = Error<"Failed to create a sha256 digest">; inline constexpr i32 BUF_SIZE = 32768; @@ -25,8 +25,8 @@ inline constexpr i32 HASH_SIZE = 65; // ref: https://stackoverflow.com/a/2458382 auto -hash_string(const Vec& hash) -> String { - String output; +hash_string(const Vec& hash) -> std::string { + std::string output; for (const unsigned char h : hash) { // ref: https://stackoverflow.com/a/64311447 output += format("{:0>2x}", h); // zero paddings in 2 length @@ -36,7 +36,7 @@ hash_string(const Vec& hash) -> String { // ref: https://stackoverflow.com/a/34289358 export [[nodiscard]] auto -sum(const Path& path) -> Result { +sum(const Path& path) -> Result { std::ifstream file(path, std::ios::binary); if (!file) { return Err(path.string()); diff --git a/testsOld/cfg.cc b/testsOld/cfg.cc index 7cf738f85..2ac79a47a 100644 --- a/testsOld/cfg.cc +++ b/testsOld/cfg.cc @@ -336,7 +336,7 @@ main() -> int { "test struct Token"_test = [] { using poac::util::cfg::Token; - expect(throws([] { Token{ Token::String }; })); + expect(throws([] { Token{ Token::std::string }; })); expect(throws([] { Token{ Token::Ident }; })); expect(throws([] { Token(Token::Comma, "foo"); })); expect(throws([] { @@ -406,7 +406,7 @@ main() -> int { { std::ostringstream output; const std::string s = "foo"; - output << Token{ Token::String, s }; + output << Token{ Token::std::string, s }; expect(eq(output.str(), "string: " + s)); } { @@ -572,7 +572,7 @@ main() -> int { } { std::ostringstream output; - output << Token{ Token::String, "test_string" }; + output << Token{ Token::std::string, "test_string" }; expect(eq(output.str(), "string: test_string"s)); } {