return -1;
}
}
+}
+
+namespace {
/* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
-static std::vector<int>* explodesRadical(std::string radicals)
+std::vector<int>* explodesRadical(std::string radicals)
{
std::vector<int>* exploded = new std::vector<int>();
return exploded;
}
-namespace {
class unit_scale : public std::unordered_map<std::string, double> {
public:
using std::unordered_map<std::string, double>::unordered_map;
}
}
}
-}
/* Note: field `unit' for the last element of parameter `units' should be nullptr. */
-static double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
- std::string name, const char* error_msg, const char* default_unit)
+double surf_parse_get_value_with_unit(const char* string, const unit_scale& units, const char* entity_kind,
+ std::string name, const char* error_msg, const char* default_unit)
{
char* ptr;
errno = 0;
surf_parse_error(std::string("unknown unit: ") + ptr);
return res * u->second;
}
+}
+
+extern "C" {
double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
{
- static const unit_scale units{{"w", 7 * 24 * 60 * 60},
- {"d", 24 * 60 * 60},
- {"h", 60 * 60},
- {"m", 60},
- {"s", 1.0},
- {"ms", 1e-3},
- {"us", 1e-6},
- {"ns", 1e-9},
- {"ps", 1e-12}};
+ static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
+ std::make_pair("d", 24 * 60 * 60),
+ std::make_pair("h", 60 * 60),
+ std::make_pair("m", 60),
+ std::make_pair("s", 1.0),
+ std::make_pair("ms", 1e-3),
+ std::make_pair("us", 1e-6),
+ std::make_pair("ns", 1e-9),
+ std::make_pair("ps", 1e-12)};
return surf_parse_get_value_with_unit(string, units, entity_kind, name,
"Append 's' to your time to get seconds", "s");
}