diff options
Diffstat (limited to 'src/nix')
-rw-r--r-- | src/nix/daemon.cc | 16 | ||||
-rw-r--r-- | src/nix/hash.cc | 2 | ||||
-rw-r--r-- | src/nix/prefetch.cc | 14 | ||||
-rw-r--r-- | src/nix/repl.cc | 66 | ||||
-rw-r--r-- | src/nix/why-depends.cc | 4 |
5 files changed, 51 insertions, 51 deletions
diff --git a/src/nix/daemon.cc b/src/nix/daemon.cc index 6a40a0bd3..940923d3b 100644 --- a/src/nix/daemon.cc +++ b/src/nix/daemon.cc @@ -76,7 +76,7 @@ static void setSigChldAction(bool autoReap) } -bool matchUser(const string & user, const string & group, const Strings & users) +bool matchUser(const std::string & user, const std::string & group, const Strings & users) { if (find(users.begin(), users.end(), "*") != users.end()) return true; @@ -85,12 +85,12 @@ bool matchUser(const string & user, const string & group, const Strings & users) return true; for (auto & i : users) - if (string(i, 0, 1) == "@") { - if (group == string(i, 1)) return true; + if (i.substr(0, 1) == "@") { + if (group == i.substr(1)) return true; struct group * gr = getgrnam(i.c_str() + 1); if (!gr) continue; for (char * * mem = gr->gr_mem; *mem; mem++) - if (user == string(*mem)) return true; + if (user == std::string(*mem)) return true; } return false; @@ -198,10 +198,10 @@ static void daemonLoop() PeerInfo peer = getPeerInfo(remote.get()); struct passwd * pw = peer.uidKnown ? getpwuid(peer.uid) : 0; - string user = pw ? pw->pw_name : std::to_string(peer.uid); + std::string user = pw ? pw->pw_name : std::to_string(peer.uid); struct group * gr = peer.gidKnown ? getgrgid(peer.gid) : 0; - string group = gr ? gr->gr_name : std::to_string(peer.gid); + std::string group = gr ? gr->gr_name : std::to_string(peer.gid); Strings trustedUsers = settings.trustedUsers; Strings allowedUsers = settings.allowedUsers; @@ -212,7 +212,7 @@ static void daemonLoop() if ((!trusted && !matchUser(user, group, allowedUsers)) || group == settings.buildUsersGroup) throw Error("user '%1%' is not allowed to connect to the Nix daemon", user); - printInfo(format((string) "accepted connection from pid %1%, user %2%" + (trusted ? " (trusted)" : "")) + printInfo(format((std::string) "accepted connection from pid %1%, user %2%" + (trusted ? " (trusted)" : "")) % (peer.pidKnown ? std::to_string(peer.pid) : "<unknown>") % (peer.uidKnown ? user : "<unknown>")); @@ -234,7 +234,7 @@ static void daemonLoop() // For debugging, stuff the pid into argv[1]. if (peer.pidKnown && savedArgv[1]) { - string processName = std::to_string(peer.pid); + auto processName = std::to_string(peer.pid); strncpy(savedArgv[1], processName.c_str(), strlen(savedArgv[1])); } diff --git a/src/nix/hash.cc b/src/nix/hash.cc index 4535e4ab0..60d9593a7 100644 --- a/src/nix/hash.cc +++ b/src/nix/hash.cc @@ -177,7 +177,7 @@ static int compatNixHash(int argc, char * * argv) else if (*arg == "--base32") base32 = true; else if (*arg == "--truncate") truncate = true; else if (*arg == "--type") { - string s = getArg(*arg, arg, end); + std::string s = getArg(*arg, arg, end); ht = parseHashType(s); } else if (*arg == "--to-base16") op = opTo16; diff --git a/src/nix/prefetch.cc b/src/nix/prefetch.cc index 094d2a519..f2dd44ba4 100644 --- a/src/nix/prefetch.cc +++ b/src/nix/prefetch.cc @@ -16,7 +16,7 @@ using namespace nix; /* If ‘url’ starts with ‘mirror://’, then resolve it using the list of mirrors defined in Nixpkgs. */ -string resolveMirrorUrl(EvalState & state, string url) +std::string resolveMirrorUrl(EvalState & state, const std::string & url) { if (url.substr(0, 9) != "mirror://") return url; @@ -38,8 +38,8 @@ string resolveMirrorUrl(EvalState & state, string url) if (mirrorList->value->listSize() < 1) throw Error("mirror URL '%s' did not expand to anything", url); - string mirror(state.forceString(*mirrorList->value->listElems()[0])); - return mirror + (hasSuffix(mirror, "/") ? "" : "/") + string(s, p + 1); + std::string mirror(state.forceString(*mirrorList->value->listElems()[0])); + return mirror + (hasSuffix(mirror, "/") ? "" : "/") + s.substr(p + 1); } std::tuple<StorePath, Hash> prefetchFile( @@ -128,10 +128,10 @@ static int main_nix_prefetch_url(int argc, char * * argv) { { HashType ht = htSHA256; - std::vector<string> args; + std::vector<std::string> args; bool printPath = getEnv("PRINT_PATH") == "1"; bool fromExpr = false; - string attrPath; + std::string attrPath; bool unpack = false; bool executable = false; std::optional<std::string> name; @@ -147,7 +147,7 @@ static int main_nix_prefetch_url(int argc, char * * argv) else if (*arg == "--version") printVersion("nix-prefetch-url"); else if (*arg == "--type") { - string s = getArg(*arg, arg, end); + auto s = getArg(*arg, arg, end); ht = parseHashType(s); } else if (*arg == "--print-path") @@ -186,7 +186,7 @@ static int main_nix_prefetch_url(int argc, char * * argv) /* If -A is given, get the URL from the specified Nix expression. */ - string url; + std::string url; if (!fromExpr) { if (args.empty()) throw UsageError("you must specify a URL"); diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 575eb0c4c..731337004 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -45,7 +45,7 @@ struct NixRepl : gc #endif { - string curDir; + std::string curDir; std::unique_ptr<EvalState> state; Bindings * autoArgs; @@ -62,18 +62,18 @@ struct NixRepl NixRepl(const Strings & searchPath, nix::ref<Store> store); ~NixRepl(); void mainLoop(const std::vector<std::string> & files); - StringSet completePrefix(string prefix); - bool getLine(string & input, const std::string &prompt); + StringSet completePrefix(const std::string & prefix); + bool getLine(std::string & input, const std::string &prompt); StorePath getDerivationPath(Value & v); - bool processLine(string line); + bool processLine(std::string line); void loadFile(const Path & path); void loadFlake(const std::string & flakeRef); void initEnv(); void reloadFiles(); void addAttrsToScope(Value & attrs); void addVarToScope(const Symbol & name, Value & v); - Expr * parseString(string s); - void evalString(string s, Value & v); + Expr * parseString(std::string s); + void evalString(std::string s, Value & v); typedef std::set<Value *> ValuesSeen; std::ostream & printValue(std::ostream & str, Value & v, unsigned int maxDepth); @@ -81,11 +81,11 @@ struct NixRepl }; -string removeWhitespace(string s) +std::string removeWhitespace(std::string s) { s = chomp(s); size_t n = s.find_first_not_of(" \n\r\t"); - if (n != string::npos) s = string(s, n); + if (n != std::string::npos) s = std::string(s, n); return s; } @@ -104,7 +104,7 @@ NixRepl::~NixRepl() write_history(historyFile.c_str()); } -string runNix(Path program, const Strings & args, +std::string runNix(Path program, const Strings & args, const std::optional<std::string> & input = {}) { auto subprocessEnv = getEnv(); @@ -198,7 +198,7 @@ namespace { void NixRepl::mainLoop(const std::vector<std::string> & files) { - string error = ANSI_RED "error:" ANSI_NORMAL " "; + std::string error = ANSI_RED "error:" ANSI_NORMAL " "; notice("Welcome to Nix " + nixVersion + ". Type :? for help.\n"); for (auto & i : files) @@ -252,7 +252,7 @@ void NixRepl::mainLoop(const std::vector<std::string> & files) } -bool NixRepl::getLine(string & input, const std::string &prompt) +bool NixRepl::getLine(std::string & input, const std::string & prompt) { struct sigaction act, old; sigset_t savedSignalMask, set; @@ -297,7 +297,7 @@ bool NixRepl::getLine(string & input, const std::string &prompt) } -StringSet NixRepl::completePrefix(string prefix) +StringSet NixRepl::completePrefix(const std::string & prefix) { StringSet completions; @@ -313,7 +313,7 @@ StringSet NixRepl::completePrefix(string prefix) size_t slash, dot; - if ((slash = cur.rfind('/')) != string::npos) { + if ((slash = cur.rfind('/')) != std::string::npos) { try { auto dir = std::string(cur, 0, slash); auto prefix2 = std::string(cur, slash + 1); @@ -323,11 +323,11 @@ StringSet NixRepl::completePrefix(string prefix) } } catch (Error &) { } - } else if ((dot = cur.rfind('.')) == string::npos) { + } else if ((dot = cur.rfind('.')) == std::string::npos) { /* This is a variable name; look it up in the current scope. */ StringSet::iterator i = varNames.lower_bound(cur); while (i != varNames.end()) { - if (string(*i, 0, cur.size()) != cur) break; + if (i->substr(0, cur.size()) != cur) break; completions.insert(prev + *i); i++; } @@ -336,8 +336,8 @@ StringSet NixRepl::completePrefix(string prefix) /* This is an expression that should evaluate to an attribute set. Evaluate it to get the names of the attributes. */ - string expr(cur, 0, dot); - string cur2 = string(cur, dot + 1); + auto expr = cur.substr(0, dot); + auto cur2 = cur.substr(dot + 1); Expr * e = parseString(expr); Value v; @@ -345,8 +345,8 @@ StringSet NixRepl::completePrefix(string prefix) state->forceAttrs(v, noPos); for (auto & i : *v.attrs) { - string name = i.name; - if (string(name, 0, cur2.size()) != cur2) continue; + std::string name = i.name; + if (name.substr(0, cur2.size()) != cur2) continue; completions.insert(prev + expr + "." + name); } @@ -365,7 +365,7 @@ StringSet NixRepl::completePrefix(string prefix) } -bool isVarName(const string & s) +static bool isVarName(std::string_view s) { if (s.size() == 0) return false; char c = s[0]; @@ -394,18 +394,18 @@ StorePath NixRepl::getDerivationPath(Value & v) { } -bool NixRepl::processLine(string line) +bool NixRepl::processLine(std::string line) { if (line == "") return true; _isInterrupted = false; - string command, arg; + std::string command, arg; if (line[0] == ':') { size_t p = line.find_first_of(" \n\r\t"); - command = string(line, 0, p); - if (p != string::npos) arg = removeWhitespace(string(line, p)); + command = line.substr(0, p); + if (p != std::string::npos) arg = removeWhitespace(line.substr(p)); } else { arg = line; } @@ -590,13 +590,13 @@ bool NixRepl::processLine(string line) else { size_t p = line.find('='); - string name; - if (p != string::npos && + std::string name; + if (p != std::string::npos && p < line.size() && line[p + 1] != '=' && - isVarName(name = removeWhitespace(string(line, 0, p)))) + isVarName(name = removeWhitespace(line.substr(0, p)))) { - Expr * e = parseString(string(line, p + 1)); + Expr * e = parseString(line.substr(p + 1)); Value & v(*state->allocValue()); v.mkThunk(env, e); addVarToScope(state->symbols.create(name), v); @@ -683,7 +683,7 @@ void NixRepl::addAttrsToScope(Value & attrs) for (auto & i : *attrs.attrs) { staticEnv.vars.emplace_back(i.name, displ); env->values[displ++] = i.value; - varNames.insert((string) i.name); + varNames.insert((std::string) i.name); } staticEnv.sort(); staticEnv.deduplicate(); @@ -700,18 +700,18 @@ void NixRepl::addVarToScope(const Symbol & name, Value & v) staticEnv.vars.emplace_back(name, displ); staticEnv.sort(); env->values[displ++] = &v; - varNames.insert((string) name); + varNames.insert((std::string) name); } -Expr * NixRepl::parseString(string s) +Expr * NixRepl::parseString(std::string s) { Expr * e = state->parseExprFromString(std::move(s), curDir, staticEnv); return e; } -void NixRepl::evalString(string s, Value & v) +void NixRepl::evalString(std::string s, Value & v) { Expr * e = parseString(s); e->eval(*state, *env, v); @@ -787,7 +787,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m else if (maxDepth > 0) { str << "{ "; - typedef std::map<string, Value *> Sorted; + typedef std::map<std::string, Value *> Sorted; Sorted sorted; for (auto & i : *v.attrs) sorted[i.name] = i.value; diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index 657df30d7..cc05deda0 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -157,11 +157,11 @@ struct CmdWhyDepends : SourceExprCommand closure (i.e., that have a non-infinite distance to 'dependency'). Print every edge on a path between `package` and `dependency`. */ - std::function<void(Node &, const string &, const string &)> printNode; + std::function<void(Node &, const std::string &, const std::string &)> printNode; struct BailOut { }; - printNode = [&](Node & node, const string & firstPad, const string & tailPad) { + printNode = [&](Node & node, const std::string & firstPad, const std::string & tailPad) { auto pathS = store->printStorePath(node.path); assert(node.dist != inf); |