mirror of
https://github.com/akuker/RASCSI.git
synced 2025-01-10 17:30:47 +00:00
Improved string to integer conversion
This commit is contained in:
parent
ee98e68d1e
commit
da764200af
@ -255,6 +255,10 @@ void Reset()
|
|||||||
|
|
||||||
bool GetAsInt(const string& value, int& result)
|
bool GetAsInt(const string& value, int& result)
|
||||||
{
|
{
|
||||||
|
if (value.find_first_not_of("0123456789") != string::npos) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = std::stoul(value);
|
result = std::stoul(value);
|
||||||
}
|
}
|
||||||
@ -1106,6 +1110,7 @@ bool ParseArgument(int argc, char* argv[], int& port)
|
|||||||
case 'b': {
|
case 'b': {
|
||||||
if (!GetAsInt(optarg, block_size)) {
|
if (!GetAsInt(optarg, block_size)) {
|
||||||
cerr << "Invalid block size " << optarg << endl;
|
cerr << "Invalid block size " << optarg << endl;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user