Commit 187cc573 authored by Stefan Roellin's avatar Stefan Roellin

db/upnp/Directory: fix parsing of durations with fractions of seconds

The duration of a song can have fractions of seconds (quote from http://www.upnp.org/schemas/av/didl-lite-v2.xsd): The format of the duration string is: H+:MM:SS[.F+], or H+:MM:SS[.F0/F1] Where: +H one or more digits to indicate elapsed hours, MM exactly 2 digits to indicate minutes (00 to 59), SS exactly 2 digits to indicate seconds (00 to 59), F+ any number of digits (including no digits) to indicate fractions of seconds, F0/F1 a fraction, with F0 and F1 at least one digit long, and F0 < F1. The string may be preceded by an optional + or - sign, and the decimal point itself may be omitted if there are no fractional seconds digits. Until now, a duration with fractions of seconds could not be parsed and resulted in an unknown duration. Only durations in the format "H+:MM:SS" were feasible. This commit enables to read durations in the first format, i.e. "H+:MM:SS[.F+]"
parent 0ead72a4
......@@ -55,23 +55,21 @@ ParseDuration(const char *duration) noexcept
{
char *endptr;
unsigned result = ParseUnsigned(duration, &endptr);
int hours = ParseInt(duration, &endptr);
if (endptr == duration || *endptr != ':')
return SignedSongTime::Negative();
result *= 60;
duration = endptr + 1;
result += ParseUnsigned(duration, &endptr);
unsigned minutes = ParseUnsigned(duration, &endptr);
if (endptr == duration || *endptr != ':')
return SignedSongTime::Negative();
result *= 60;
duration = endptr + 1;
result += ParseUnsigned(duration, &endptr);
if (endptr == duration || *endptr != 0)
double seconds = ParseDouble(duration, &endptr);
if (endptr == duration || *endptr != 0 || seconds < 0.0)
return SignedSongTime::Negative();
return SignedSongTime::FromS(result);
return SignedSongTime::FromS((((hours * 60) + minutes) * 60) + seconds);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment