summaryrefslogtreecommitdiff
path: root/src/bytesizeparser.cc
diff options
context:
space:
mode:
authorGoran Mekić <meka@tilda.center>2017-03-05 11:40:07 +0100
committerGoran Mekić <meka@tilda.center>2017-03-07 11:42:05 +0100
commitfaf80b071b54f2f736df2390171f7b3b939d03c2 (patch)
treed79840f21d52f0717634607a4e929c97f4991286 /src/bytesizeparser.cc
parentbbc7e836f054aea09a1cde23d553a01892ea18c4 (diff)
Test diskstreaming CLI
Diffstat (limited to 'src/bytesizeparser.cc')
-rw-r--r--src/bytesizeparser.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/bytesizeparser.cc b/src/bytesizeparser.cc
index 0bab316..329407d 100644
--- a/src/bytesizeparser.cc
+++ b/src/bytesizeparser.cc
@@ -58,13 +58,18 @@ std::size_t byteSizeParser(const std::string& argument)
std::string suffix;
bool error = false;
+ if(argument.find('-') != std::string::npos)
+ {
+ error = true;
+ }
+
try
{
stream_size = std::stoi(argument, &suffix_index);
}
catch(std::invalid_argument)
{
- std::cerr << "Invalid option for diskstreamsize" << std::endl;
+ std::cerr << "Invalid argument for diskstreamsize" << std::endl;
error = true;
}
catch(std::out_of_range)
@@ -82,17 +87,16 @@ std::size_t byteSizeParser(const std::string& argument)
}
if(!error)
{
- std::size_t suffix_size = suffixToSize(suffix[0]);
- if (suffix_size)
+ std::size_t suffix_size = 1;
+ if(suffix_index <= suffix.length())
{
- stream_size *= suffix_size;
+ suffix_size = suffixToSize(suffix[0]);
+
}
+ stream_size *= suffix_size;
}
if(error)
{
- std::cerr << "Stream size should be in <number>[suffix] format ";
- std::cerr << "where [suffix] is k, M, or G." << std::endl;
- std::cerr << "Example: 10M which is 10 * 1024 * 1024 bytes" << std::endl;
return 0;
}
return stream_size;