diff options
author | Max Kellermann <max@duempel.org> | 2014-01-21 22:52:12 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-21 22:52:12 +0100 |
commit | 411527a240bfed9439f94fbfdccf382beeb80151 (patch) | |
tree | 3774486771efb6d0acaec2913b5559244592dbb5 | |
parent | 7777057d35ceccb39c24b9b64705697dc9a7c4ce (diff) | |
download | mpd-411527a240bfed9439f94fbfdccf382beeb80151.tar.gz mpd-411527a240bfed9439f94fbfdccf382beeb80151.tar.xz mpd-411527a240bfed9439f94fbfdccf382beeb80151.zip |
db/upnp: don't use stringToTokens() in ParseDuration()
Reduce bloat.
Diffstat (limited to '')
-rw-r--r-- | src/db/upnp/Directory.cxx | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx index ce0a86fda..2fa69e4bb 100644 --- a/src/db/upnp/Directory.cxx +++ b/src/db/upnp/Directory.cxx @@ -24,6 +24,7 @@ #include "Tags.hxx" #include "tag/TagBuilder.hxx" #include "tag/TagTable.hxx" +#include "util/NumberParser.hxx" #include <algorithm> #include <string> @@ -45,12 +46,27 @@ ParseItemClass(const char *name) gcc_pure static int -ParseDuration(const std::string &duration) +ParseDuration(const char *duration) { - const auto v = stringToTokens(duration, ":"); - if (v.size() != 3) + char *endptr; + + unsigned result = ParseUnsigned(duration, &endptr); + if (endptr == duration || *endptr != ':') + return 0; + + result *= 60; + duration = endptr + 1; + result += ParseUnsigned(duration, &endptr); + if (endptr == duration || *endptr != ':') return 0; - return atoi(v[0].c_str())*3600 + atoi(v[1].c_str())*60 + atoi(v[2].c_str()); + + result *= 60; + duration = endptr + 1; + result += ParseUnsigned(duration, &endptr); + if (endptr == duration || *endptr != 0) + return 0; + + return result; } /** |