The unified diff between revisions [84c381b3..] and [13704fef..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'src/parsing.cpp'
#
#
# patch "src/parsing.cpp"
# from [da4e1440bbc2184e0a75be183aa78f5be4beb154]
# to [07004ffd721f7f70ccb2f50f0a1f4a7e98c028cb]
#
============================================================
--- src/parsing.cpp da4e1440bbc2184e0a75be183aa78f5be4beb154
+++ src/parsing.cpp 07004ffd721f7f70ccb2f50f0a1f4a7e98c028cb
@@ -55,6 +55,37 @@ std::string to_string(u64bit n, u32bit m
}
/*************************************************
+* Convert a string into a time duration *
+*************************************************/
+u32bit timespec_to_u32bit(const std::string& timespec)
+ {
+ if(timespec == "")
+ return 0;
+
+ const char suffix = timespec[timespec.size()-1];
+ std::string value = timespec.substr(0, timespec.size()-1);
+
+ u32bit scale = 1;
+
+ if(Charset::is_digit(suffix))
+ value += suffix;
+ else if(suffix == 's')
+ scale = 1;
+ else if(suffix == 'm')
+ scale = 60;
+ else if(suffix == 'h')
+ scale = 60 * 60;
+ else if(suffix == 'd')
+ scale = 24 * 60 * 60;
+ else if(suffix == 'y')
+ scale = 365 * 24 * 60 * 60;
+ else
+ throw Decoding_Error("timespec_to_u32bit: Bad input " + timespec);
+
+ return scale * to_u32bit(value);
+ }
+
+/*************************************************
* Parse a SCAN-style algorithm name *
*************************************************/
std::vector<std::string> parse_algorithm_name(const std::string& namex)
@@ -211,34 +242,6 @@ bool x500_name_cmp(const std::string& na
}
/*************************************************
-* Parse and compute an arithmetic expression *
-*************************************************/
-u32bit parse_expr(const std::string& expr)
- {
- const bool have_add = (expr.find('+') != std::string::npos);
- const bool have_mul = (expr.find('*') != std::string::npos);
-
- if(have_add)
- {
- std::vector<std::string> sub_expr = split_on(expr, '+');
- u32bit result = 0;
- for(u32bit j = 0; j != sub_expr.size(); ++j)
- result += parse_expr(sub_expr[j]);
- return result;
- }
- else if(have_mul)
- {
- std::vector<std::string> sub_expr = split_on(expr, '*');
- u32bit result = 1;
- for(u32bit j = 0; j != sub_expr.size(); ++j)
- result *= parse_expr(sub_expr[j]);
- return result;
- }
- else
- return to_u32bit(expr);
- }
-
-/*************************************************
* Convert a decimal-dotted string to binary IP *
*************************************************/
u32bit string_to_ipv4(const std::string& str)