Parses a duration with one of the following suffixes and returns the duration in seconds s - seconds m - minutes h - hours d - days
| 206 | // h - hours |
| 207 | // d - days |
| 208 | Optional<uint64_t> parseDuration(std::string const& str, std::string const& defaultUnit) { |
| 209 | char* endptr; |
| 210 | uint64_t ret = strtoull(str.c_str(), &endptr, 10); |
| 211 | |
| 212 | if (endptr == str.c_str()) { |
| 213 | return Optional<uint64_t>(); |
| 214 | } |
| 215 | |
| 216 | std::string unit; |
| 217 | if (*endptr == '\0') { |
| 218 | if (!defaultUnit.empty()) { |
| 219 | unit = defaultUnit; |
| 220 | } else { |
| 221 | return Optional<uint64_t>(); |
| 222 | } |
| 223 | } else { |
| 224 | unit = endptr; |
| 225 | } |
| 226 | |
| 227 | if (!unit.compare("s")) { |
| 228 | // Nothing to do |
| 229 | } else if (!unit.compare("m")) { |
| 230 | ret *= 60; |
| 231 | } else if (!unit.compare("h")) { |
| 232 | ret *= 60 * 60; |
| 233 | } else if (!unit.compare("d")) { |
| 234 | ret *= 24 * 60 * 60; |
| 235 | } else { |
| 236 | return Optional<uint64_t>(); |
| 237 | } |
| 238 | |
| 239 | return ret; |
| 240 | } |
| 241 | |
| 242 | int vsformat(std::string& outputString, const char* form, va_list args) { |
| 243 | char buf[200]; |
no test coverage detected