Remove std::string alias (for real this time)

Also use std::string_view in a few more places.
This commit is contained in:
Eelco Dolstra
2022-02-25 16:13:02 +01:00
parent 14b38d0887
commit df552ff53e
110 changed files with 773 additions and 681 deletions
+33 -33
View File
@@ -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;