mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Time: Add assertions for issues parsing an ISO8601 formatted string
This commit is contained in:
parent
1294562075
commit
ea37e71f87
1 changed files with 29 additions and 1 deletions
|
|
@ -462,17 +462,26 @@ Time Time::fromISO8601 (StringRef iso)
|
||||||
auto year = parseFixedSizeIntAndSkip (t, 4, '-');
|
auto year = parseFixedSizeIntAndSkip (t, 4, '-');
|
||||||
|
|
||||||
if (year < 0)
|
if (year < 0)
|
||||||
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
auto month = parseFixedSizeIntAndSkip (t, 2, '-');
|
auto month = parseFixedSizeIntAndSkip (t, 2, '-');
|
||||||
|
|
||||||
if (month < 0)
|
if (month < 0)
|
||||||
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
auto day = parseFixedSizeIntAndSkip (t, 2, 0);
|
auto day = parseFixedSizeIntAndSkip (t, 2, 0);
|
||||||
|
|
||||||
if (day < 0)
|
if (day < 0)
|
||||||
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
int hours = 0, minutes = 0, milliseconds = 0;
|
int hours = 0, minutes = 0, milliseconds = 0;
|
||||||
|
|
||||||
|
|
@ -482,17 +491,26 @@ Time Time::fromISO8601 (StringRef iso)
|
||||||
hours = parseFixedSizeIntAndSkip (t, 2, ':');
|
hours = parseFixedSizeIntAndSkip (t, 2, ':');
|
||||||
|
|
||||||
if (hours < 0)
|
if (hours < 0)
|
||||||
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
minutes = parseFixedSizeIntAndSkip (t, 2, ':');
|
minutes = parseFixedSizeIntAndSkip (t, 2, ':');
|
||||||
|
|
||||||
if (minutes < 0)
|
if (minutes < 0)
|
||||||
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
auto seconds = parseFixedSizeIntAndSkip (t, 2, 0);
|
auto seconds = parseFixedSizeIntAndSkip (t, 2, 0);
|
||||||
|
|
||||||
if (seconds < 0)
|
if (seconds < 0)
|
||||||
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
if (*t == '.' || *t == ',')
|
if (*t == '.' || *t == ',')
|
||||||
{
|
{
|
||||||
|
|
@ -500,8 +518,11 @@ Time Time::fromISO8601 (StringRef iso)
|
||||||
milliseconds = parseFixedSizeIntAndSkip (t, 3, 0);
|
milliseconds = parseFixedSizeIntAndSkip (t, 3, 0);
|
||||||
|
|
||||||
if (milliseconds < 0)
|
if (milliseconds < 0)
|
||||||
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
milliseconds += 1000 * seconds;
|
milliseconds += 1000 * seconds;
|
||||||
}
|
}
|
||||||
|
|
@ -513,18 +534,25 @@ Time Time::fromISO8601 (StringRef iso)
|
||||||
auto offsetHours = parseFixedSizeIntAndSkip (t, 2, ':');
|
auto offsetHours = parseFixedSizeIntAndSkip (t, 2, ':');
|
||||||
|
|
||||||
if (offsetHours < 0)
|
if (offsetHours < 0)
|
||||||
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
auto offsetMinutes = parseFixedSizeIntAndSkip (t, 2, 0);
|
auto offsetMinutes = parseFixedSizeIntAndSkip (t, 2, 0);
|
||||||
|
|
||||||
if (offsetMinutes < 0)
|
if (offsetMinutes < 0)
|
||||||
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
auto offsetMs = (offsetHours * 60 + offsetMinutes) * 60 * 1000;
|
auto offsetMs = (offsetHours * 60 + offsetMinutes) * 60 * 1000;
|
||||||
milliseconds += nextChar == '-' ? offsetMs : -offsetMs; // NB: this seems backwards but is correct!
|
milliseconds += nextChar == '-' ? offsetMs : -offsetMs; // NB: this seems backwards but is correct!
|
||||||
}
|
}
|
||||||
else if (nextChar != 0 && nextChar != 'Z')
|
else if (nextChar != 0 && nextChar != 'Z')
|
||||||
{
|
{
|
||||||
|
jassertfalse;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue