From df552ff53e68dff8ca360adbdbea214ece1d08ee Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 25 Feb 2022 16:00:00 +0100 Subject: Remove std::string alias (for real this time) Also use std::string_view in a few more places. --- src/nix-env/nix-env.cc | 82 ++++++++++++++++++++++++------------------------- src/nix-env/user-env.cc | 2 +- src/nix-env/user-env.hh | 2 +- 3 files changed, 43 insertions(+), 43 deletions(-) (limited to 'src/nix-env') diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index f83edb6a1..12e08bbe1 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -46,7 +46,7 @@ struct InstallSourceInfo InstallSourceType type; Path nixExprPath; /* for srcNixExprDrvs, srcNixExprs */ Path profile; /* for srcProfile */ - string systemFilter; /* for srcNixExprDrvs */ + std::string systemFilter; /* for srcNixExprDrvs */ Bindings * autoArgs; }; @@ -59,7 +59,7 @@ struct Globals bool dryRun; bool preserveInstalled; bool removeAll; - string forceName; + std::string forceName; bool prebuiltOnly; }; @@ -68,8 +68,8 @@ typedef void (* Operation) (Globals & globals, Strings opFlags, Strings opArgs); -static string needArg(Strings::iterator & i, - Strings & args, const string & arg) +static std::string needArg(Strings::iterator & i, + Strings & args, const std::string & arg) { if (i == args.end()) throw UsageError("'%1%' requires an argument", arg); return *i++; @@ -77,7 +77,7 @@ static string needArg(Strings::iterator & i, static bool parseInstallSourceOptions(Globals & globals, - Strings::iterator & i, Strings & args, const string & arg) + Strings::iterator & i, Strings & args, const std::string & arg) { if (arg == "--from-expression" || arg == "-E") globals.instSource.type = srcNixExprs; @@ -124,9 +124,9 @@ static void getAllExprs(EvalState & state, otherwise the attribute cannot be selected with the `-A' option. Useful if you want to stick a Nix expression directly in ~/.nix-defexpr. */ - string attrName = i; + std::string attrName = i; if (hasSuffix(attrName, ".nix")) - attrName = string(attrName, 0, attrName.size() - 4); + attrName = std::string(attrName, 0, attrName.size() - 4); if (!seen.insert(attrName).second) { printError("warning: name collision in input Nix expressions, skipping '%1%'", path2); continue; @@ -175,8 +175,8 @@ static void loadSourceExpr(EvalState & state, const Path & path, Value & v) static void loadDerivations(EvalState & state, Path nixExprPath, - string systemFilter, Bindings & autoArgs, - const string & pathPrefix, DrvInfos & elems) + std::string systemFilter, Bindings & autoArgs, + const std::string & pathPrefix, DrvInfos & elems) { Value vRoot; loadSourceExpr(state, nixExprPath, vRoot); @@ -343,9 +343,9 @@ static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems, if (selector.hits == 0 && selector.fullName != "*") { const auto prefixHits = searchByPrefix(allElems, selector.name); - + if (prefixHits.empty()) { - throw Error("selector '%1%' matches no derivations", selector.fullName); + throw Error("selector '%1%' matches no derivations", selector.fullName); } else { std::string suggestionMessage = ", maybe you meant:"; for (const auto & drvName : prefixHits) { @@ -360,9 +360,9 @@ static DrvInfos filterBySelector(EvalState & state, const DrvInfos & allElems, } -static bool isPath(const string & s) +static bool isPath(std::string_view s) { - return s.find('/') != string::npos; + return s.find('/') != std::string_view::npos; } @@ -433,8 +433,8 @@ static void queryInstSources(EvalState & state, auto outputs = state.store->queryDerivationOutputMap(path); elem.setOutPath(state.store->printStorePath(outputs.at("out"))); if (name.size() >= drvExtension.size() && - string(name, name.size() - drvExtension.size()) == drvExtension) - name = string(name, 0, name.size() - drvExtension.size()); + std::string(name, name.size() - drvExtension.size()) == drvExtension) + name = name.substr(0, name.size() - drvExtension.size()); } else elem.setOutPath(state.store->printStorePath(path)); @@ -515,7 +515,7 @@ static void installDerivations(Globals & globals, while (true) { - string lockToken = optimisticLockProfile(profile); + auto lockToken = optimisticLockProfile(profile); DrvInfos allElems(newElems); @@ -551,7 +551,7 @@ static void installDerivations(Globals & globals, static void opInstall(Globals & globals, Strings opFlags, Strings opArgs) { for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) { - string arg = *i++; + auto arg = *i++; if (parseInstallSourceOptions(globals, i, opFlags, arg)) ; else if (arg == "--preserve-installed" || arg == "-P") globals.preserveInstalled = true; @@ -578,7 +578,7 @@ static void upgradeDerivations(Globals & globals, name and a higher version number. */ while (true) { - string lockToken = optimisticLockProfile(globals.profile); + auto lockToken = optimisticLockProfile(globals.profile); DrvInfos installedElems = queryInstalled(*globals.state, globals.profile); @@ -606,7 +606,7 @@ static void upgradeDerivations(Globals & globals, take the one with the highest version. Do not upgrade if it would decrease the priority. */ DrvInfos::iterator bestElem = availElems.end(); - string bestVersion; + std::string bestVersion; for (auto j = availElems.begin(); j != availElems.end(); ++j) { if (comparePriorities(*globals.state, i, *j) > 0) continue; @@ -662,7 +662,7 @@ static void opUpgrade(Globals & globals, Strings opFlags, Strings opArgs) { UpgradeType upgradeType = utLt; for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) { - string arg = *i++; + std::string arg = *i++; if (parseInstallSourceOptions(globals, i, opFlags, arg)) ; else if (arg == "--lt") upgradeType = utLt; else if (arg == "--leq") upgradeType = utLeq; @@ -676,7 +676,7 @@ static void opUpgrade(Globals & globals, Strings opFlags, Strings opArgs) static void setMetaFlag(EvalState & state, DrvInfo & drv, - const string & name, const string & value) + const std::string & name, const std::string & value) { auto v = state.allocValue(); v->mkString(value); @@ -692,12 +692,12 @@ static void opSetFlag(Globals & globals, Strings opFlags, Strings opArgs) throw UsageError("not enough arguments to '--set-flag'"); Strings::iterator arg = opArgs.begin(); - string flagName = *arg++; - string flagValue = *arg++; + std::string flagName = *arg++; + std::string flagValue = *arg++; DrvNames selectors = drvNamesFromArgs(Strings(arg, opArgs.end())); while (true) { - string lockToken = optimisticLockProfile(globals.profile); + std::string lockToken = optimisticLockProfile(globals.profile); DrvInfos installedElems = queryInstalled(*globals.state, globals.profile); @@ -728,7 +728,7 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs) if (!store2) throw Error("--set is not supported for this Nix store"); for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) { - string arg = *i++; + std::string arg = *i++; if (parseInstallSourceOptions(globals, i, opFlags, arg)) ; else throw UsageError("unknown flag '%1%'", arg); } @@ -769,7 +769,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors, Path & profile) { while (true) { - string lockToken = optimisticLockProfile(profile); + auto lockToken = optimisticLockProfile(profile); DrvInfos workingElems = queryInstalled(*globals.state, profile); @@ -855,11 +855,11 @@ void printTable(Table & table) Strings::iterator j; size_t column; for (j = i.begin(), column = 0; j != i.end(); ++j, ++column) { - string s = *j; + std::string s = *j; replace(s.begin(), s.end(), '\n', ' '); cout << s; if (column < nrColumns - 1) - cout << string(widths[column] - s.size() + 2, ' '); + cout << std::string(widths[column] - s.size() + 2, ' '); } cout << std::endl; } @@ -876,7 +876,7 @@ void printTable(Table & table) typedef enum { cvLess, cvEqual, cvGreater, cvUnavail } VersionDiff; static VersionDiff compareVersionAgainstSet( - const DrvInfo & elem, const DrvInfos & elems, string & version) + const DrvInfo & elem, const DrvInfos & elems, std::string & version) { DrvName name(elem.queryName()); @@ -958,7 +958,7 @@ static void queryJSON(Globals & globals, std::vector & elems, bool prin static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) { Strings remaining; - string attrPath; + std::string attrPath; bool printStatus = false; bool printName = true; @@ -977,7 +977,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) settings.readOnlyMode = true; /* makes evaluation a bit faster */ for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) { - string arg = *i++; + auto arg = *i++; if (arg == "--status" || arg == "-s") printStatus = true; else if (arg == "--no-name") printName = false; else if (arg == "--system") printSystem = true; @@ -1094,7 +1094,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) attrs["substitutable"] = hasSubs ? "1" : "0"; } else columns.push_back( - (string) (isInstalled ? "I" : "-") + (std::string) (isInstalled ? "I" : "-") + (isValid ? "P" : "-") + (hasSubs ? "S" : "-")); } @@ -1118,7 +1118,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) same named packages in either the set of available elements, or the set of installed elements. !!! This is O(N * M), should be O(N * lg M). */ - string version; + std::string version; VersionDiff diff = compareVersionAgainstSet(i, otherElems, version); char ch; @@ -1136,7 +1136,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) attrs["maxComparedVersion"] = version; } } else { - string column = (string) "" + ch + " " + version; + auto column = (std::string) "" + ch + " " + version; if (diff == cvGreater && tty) column = ANSI_RED + column + ANSI_NORMAL; columns.push_back(column); @@ -1150,7 +1150,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) columns.push_back(i.querySystem()); if (printDrvPath) { - string drvPath = i.queryDrvPath(); + auto drvPath = i.queryDrvPath(); if (xmlOutput) { if (drvPath != "") attrs["drvPath"] = drvPath; } else @@ -1159,7 +1159,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) if (printOutPath && !xmlOutput) { DrvInfo::Outputs outputs = i.queryOutputs(); - string s; + std::string s; for (auto & j : outputs) { if (!s.empty()) s += ';'; if (j.first != "out") { s += j.first; s += "="; } @@ -1169,7 +1169,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs) } if (printDescription) { - string descr = i.queryMetaString("description"); + auto descr = i.queryMetaString("description"); if (xmlOutput) { if (descr != "") attrs["description"] = descr; } else @@ -1331,12 +1331,12 @@ static void opDeleteGenerations(Globals & globals, Strings opFlags, Strings opAr if (opArgs.size() == 1 && opArgs.front() == "old") { deleteOldGenerations(globals.profile, globals.dryRun); - } else if (opArgs.size() == 1 && opArgs.front().find('d') != string::npos) { + } else if (opArgs.size() == 1 && opArgs.front().find('d') != std::string::npos) { deleteGenerationsOlderThan(globals.profile, opArgs.front(), globals.dryRun); - } else if (opArgs.size() == 1 && opArgs.front().find('+') != string::npos) { + } else if (opArgs.size() == 1 && opArgs.front().find('+') != std::string::npos) { if (opArgs.front().size() < 2) throw Error("invalid number of generations '%1%'", opArgs.front()); - string str_max = string(opArgs.front(), 1, opArgs.front().size()); + auto str_max = opArgs.front().substr(1); auto max = string2Int(str_max); if (!max || *max == 0) throw Error("invalid number of generations to keep '%1%'", opArgs.front()); @@ -1366,7 +1366,7 @@ static int main_nix_env(int argc, char * * argv) Strings opFlags, opArgs; Operation op = 0; RepairFlag repair = NoRepair; - string file; + std::string file; Globals globals; diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc index 5842e6501..37e4086cb 100644 --- a/src/nix-env/user-env.cc +++ b/src/nix-env/user-env.cc @@ -32,7 +32,7 @@ DrvInfos queryInstalled(EvalState & state, const Path & userEnv) bool createUserEnv(EvalState & state, DrvInfos & elems, const Path & profile, bool keepDerivations, - const string & lockToken) + const std::string & lockToken) { /* Build the components in the user environment, if they don't exist already. */ diff --git a/src/nix-env/user-env.hh b/src/nix-env/user-env.hh index f188efe9b..10646f713 100644 --- a/src/nix-env/user-env.hh +++ b/src/nix-env/user-env.hh @@ -8,6 +8,6 @@ DrvInfos queryInstalled(EvalState & state, const Path & userEnv); bool createUserEnv(EvalState & state, DrvInfos & elems, const Path & profile, bool keepDerivations, - const string & lockToken); + const std::string & lockToken); } -- cgit v1.2.3