Skip to content

Commit

Permalink
int2String() -> std::to_string()
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Oct 29, 2015
1 parent 71039be commit 5c28943
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ string EvalState::coerceToString(const Pos & pos, Value & v, PathSet & context,
shell scripting convenience, just like `null'. */
if (v.type == tBool && v.boolean) return "1";
if (v.type == tBool && !v.boolean) return "";
if (v.type == tInt) return int2String(v.integer);
if (v.type == tInt) return std::to_string(v.integer);
if (v.type == tNull) return "";

if (v.isList()) {
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ void DerivationGoal::startBuilder()
if (passAsFile.find(i.first) == passAsFile.end()) {
env[i.first] = i.second;
} else {
Path p = tmpDir + "/.attr-" + int2String(fileNr++);
Path p = tmpDir + "/.attr-" + std::to_string(fileNr++);
writeFile(p, i.second);
filesToChown.insert(p);
env[i.first + "Path"] = p;
Expand Down Expand Up @@ -2142,7 +2142,7 @@ void DerivationGoal::startBuilder()
CLONE_PARENT are not allowed together. */
child = clone(childEntry, stack + stackSize, flags & ~CLONE_NEWPID, this);
if (child == -1) throw SysError("cloning builder process");
writeFull(builderOut.writeSide, int2String(child) + "\n");
writeFull(builderOut.writeSide, std::to_string(child) + "\n");
_exit(0);
}, options);
if (helper.wait(true) != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/download.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Path downloadFileCached(const string & url, bool unpack)
assert(!storePath.empty());
replaceSymlink(storePath, fileLink);

writeFile(dataFile, url + "\n" + res.etag + "\n" + int2String(time(0)) + "\n");
writeFile(dataFile, url + "\n" + res.etag + "\n" + std::to_string(time(0)) + "\n");
} catch (DownloadError & e) {
if (storePath.empty()) throw;
printMsg(lvlError, format("warning: %1%; using cached result") % e.msg());
Expand Down
2 changes: 1 addition & 1 deletion src/libutil/archive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static void parse(ParseSink & sink, Source & source, const Path & path)
if (i != names.end()) {
printMsg(lvlDebug, format("case collision between ‘%1%’ and ‘%2%’") % i->first % name);
name += caseHackSuffix;
name += int2String(++i->second);
name += std::to_string(++i->second);
} else
names[name] = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libutil/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Nest::~Nest()

static string escVerbosity(Verbosity level)
{
return int2String((int) level);
return std::to_string((int) level);
}


Expand Down
7 changes: 0 additions & 7 deletions src/libutil/util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ template<class N> bool string2Int(const string & s, N & n)
return str && str.get() == EOF;
}

template<class N> string int2String(N n)
{
std::ostringstream str;
str << n;
return str.str();
}


/* Return true iff `s' ends in `suffix'. */
bool hasSuffix(const string & s, const string & suffix);
Expand Down
16 changes: 8 additions & 8 deletions src/nix-daemon/nix-daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ static void performOp(bool trusted, unsigned int clientVersion,
settings.keepGoing = readInt(from) != 0;
settings.set("build-fallback", readInt(from) ? "true" : "false");
verbosity = (Verbosity) readInt(from);
settings.set("build-max-jobs", int2String(readInt(from)));
settings.set("build-max-silent-time", int2String(readInt(from)));
settings.set("build-max-jobs", std::to_string(readInt(from)));
settings.set("build-max-silent-time", std::to_string(readInt(from)));
if (GET_PROTOCOL_MINOR(clientVersion) >= 2)
settings.useBuildHook = readInt(from) != 0;
if (GET_PROTOCOL_MINOR(clientVersion) >= 4) {
Expand All @@ -426,7 +426,7 @@ static void performOp(bool trusted, unsigned int clientVersion,
settings.printBuildTrace = readInt(from) != 0;
}
if (GET_PROTOCOL_MINOR(clientVersion) >= 6)
settings.set("build-cores", int2String(readInt(from)));
settings.set("build-cores", std::to_string(readInt(from)));
if (GET_PROTOCOL_MINOR(clientVersion) >= 10)
settings.set("build-use-substitutes", readInt(from) ? "true" : "false");
if (GET_PROTOCOL_MINOR(clientVersion) >= 12) {
Expand Down Expand Up @@ -720,7 +720,7 @@ static void daemonLoop(char * * argv)

/* Handle socket-based activation by systemd. */
if (getEnv("LISTEN_FDS") != "") {
if (getEnv("LISTEN_PID") != int2String(getpid()) || getEnv("LISTEN_FDS") != "1")
if (getEnv("LISTEN_PID") != std::to_string(getpid()) || getEnv("LISTEN_FDS") != "1")
throw Error("unexpected systemd environment variables");
fdSocket = SD_LISTEN_FDS_START;
}
Expand Down Expand Up @@ -796,10 +796,10 @@ static void daemonLoop(char * * argv)
PeerInfo peer = getPeerInfo(remote);

struct passwd * pw = peer.uidKnown ? getpwuid(peer.uid) : 0;
string user = pw ? pw->pw_name : int2String(peer.uid);
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 : int2String(peer.gid);
string group = gr ? gr->gr_name : std::to_string(peer.gid);

Strings trustedUsers = settings.get("trusted-users", Strings({"root"}));
Strings allowedUsers = settings.get("allowed-users", Strings({"*"}));
Expand All @@ -811,7 +811,7 @@ static void daemonLoop(char * * argv)
throw Error(format("user ‘%1%’ is not allowed to connect to the Nix daemon") % user);

printMsg(lvlInfo, format((string) "accepted connection from pid %1%, user %2%" + (trusted ? " (trusted)" : ""))
% (peer.pidKnown ? int2String(peer.pid) : "<unknown>")
% (peer.pidKnown ? std::to_string(peer.pid) : "<unknown>")
% (peer.uidKnown ? user : "<unknown>"));

/* Fork a child to handle the connection. */
Expand All @@ -832,7 +832,7 @@ static void daemonLoop(char * * argv)

/* For debugging, stuff the pid into argv[1]. */
if (peer.pidKnown && argv[1]) {
string processName = int2String(peer.pid);
string processName = std::to_string(peer.pid);
strncpy(argv[1], processName.c_str(), strlen(argv[1]));
}

Expand Down
2 changes: 1 addition & 1 deletion src/nix-instantiate/nix-instantiate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void processExpr(EvalState & state, const Strings & attrPaths,
printGCWarning();
else {
Path rootName = gcRoot;
if (++rootNr > 1) rootName += "-" + int2String(rootNr);
if (++rootNr > 1) rootName += "-" + std::to_string(rootNr);
drvPath = addPermRoot(*store, drvPath, rootName, indirectRoot);
}
std::cout << format("%1%%2%\n") % drvPath % (outputName != "out" ? "!" + outputName : "");
Expand Down
4 changes: 2 additions & 2 deletions src/nix-store/nix-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static PathSet realisePath(Path path, bool build = true)
printGCWarning();
else {
Path rootName = gcRoot;
if (rootNr > 1) rootName += "-" + int2String(rootNr);
if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
if (i->first != "out") rootName += "-" + i->first;
outPath = addPermRoot(*store, outPath, rootName, indirectRoot);
}
Expand All @@ -98,7 +98,7 @@ static PathSet realisePath(Path path, bool build = true)
else {
Path rootName = gcRoot;
rootNr++;
if (rootNr > 1) rootName += "-" + int2String(rootNr);
if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
path = addPermRoot(*store, path, rootName, indirectRoot);
}
return singleton<PathSet>(path);
Expand Down

0 comments on commit 5c28943

Please sign in to comment.