1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 08:31:16 +02:00

* Templatise getIntArg / string2Int.

This commit is contained in:
Eelco Dolstra 2009-11-24 12:26:25 +00:00
parent 8022015552
commit 9b8fda796b
5 changed files with 25 additions and 40 deletions

View file

@ -1055,22 +1055,6 @@ string int2String(int n)
}
bool string2Int(const string & s, int & n)
{
std::istringstream str(s);
str >> n;
return str && str.get() == EOF;
}
bool string2Int(const string & s, long long & n)
{
std::istringstream str(s);
str >> n;
return str && str.get() == EOF;
}
bool hasSuffix(const string & s, const string & suffix)
{
return s.size() >= suffix.size() && string(s, s.size() - suffix.size()) == suffix;

View file

@ -295,9 +295,14 @@ bool statusOk(int status);
/* Parse a string into an integer. */
template<class N> bool string2Int(const string & s, N & n)
{
std::istringstream str(s);
str >> n;
return str && str.get() == EOF;
}
string int2String(int n);
bool string2Int(const string & s, int & n);
bool string2Int(const string & s, long long & n);
/* Return true iff `s' ends in `suffix'. */