diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-05-15 18:40:50 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-05-15 18:40:50 +0900 |
| commit | bafbbe7c1d5ea39e67e233f9c32975fda7843874 (patch) | |
| tree | f89e784f062e108935662c52f66eb559f6de61db /src/util.cc | |
| parent | 6976ffed9e96ccc70f161aa5a38abddaf9d9befe (diff) | |
Allow subsecond value in ns cookie.txt file's expiry time field
Diffstat (limited to 'src/util.cc')
| -rw-r--r-- | src/util.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc index a2590235..3c9c19b1 100644 --- a/src/util.cc +++ b/src/util.cc @@ -596,6 +596,33 @@ bool parseLLIntNoThrow(int64_t& res, const std::string& s, int base) } } +bool parseDoubleNoThrow(double& res, const std::string& s) +{ + if (s.empty()) { + return false; + } + + errno = 0; + char* endptr; + auto d = strtod(s.c_str(), &endptr); + + if (errno == ERANGE) { + return false; + } + + if (endptr != s.c_str() + s.size()) { + for (auto i = std::begin(s) + (endptr - s.c_str()); i != std::end(s); ++i) { + if (!isspace(*i)) { + return false; + } + } + } + + res = d; + + return true; +} + SegList<int> parseIntSegments(const std::string& src) { SegList<int> sgl; |
