in src/aws-cpp-sdk-core/source/utils/DateTimeCommon.cpp [924:1079]
void Parse() override
{
size_t len = strlen(m_toParse);
//DOS check
if (len > MAX_LEN)
{
AWS_LOGSTREAM_WARN(CLASS_TAG, "Incoming String to parse too long with length: " << len)
m_error = true;
return;
}
size_t index = 0;
size_t stateStartIndex = 0;
const int finalState = 7;
while (m_state <= finalState && !m_error && index < len)
{
char c = m_toParse[index];
switch (m_state)
{
// On year: %Y
case 0:
if (isdigit(c))
{
m_parsedTimestamp.tm_year = m_parsedTimestamp.tm_year * 10 + (c - '0');
if (index - stateStartIndex == 3)
{
m_state = 1;
stateStartIndex = index + 1;
m_parsedTimestamp.tm_year -= 1900;
}
}
else
{
m_error = true;
}
break;
// On month: %m
case 1:
if (isdigit(c))
{
m_parsedTimestamp.tm_mon = m_parsedTimestamp.tm_mon * 10 + (c - '0');
if (index - stateStartIndex == 1)
{
m_state = 2;
stateStartIndex = index + 1;
m_parsedTimestamp.tm_mon -= 1;
}
}
else
{
m_error = true;
}
break;
// On month day: %d
case 2:
if (c == 'T' && index - stateStartIndex == 2)
{
m_state = 3;
stateStartIndex = index + 1;
}
else if (isdigit(c))
{
m_parsedTimestamp.tm_mday = m_parsedTimestamp.tm_mday * 10 + (c - '0');
}
else
{
m_error = true;
}
break;
// On hour: %H
case 3:
if (isdigit(c))
{
m_parsedTimestamp.tm_hour = m_parsedTimestamp.tm_hour * 10 + (c - '0');
if (index - stateStartIndex == 1)
{
m_state = 4;
stateStartIndex = index + 1;
}
}
else
{
m_error = true;
}
break;
// On minute: %M
case 4:
if (isdigit(c))
{
m_parsedTimestamp.tm_min = m_parsedTimestamp.tm_min * 10 + (c - '0');
if (index - stateStartIndex == 1)
{
m_state = 5;
stateStartIndex = index + 1;
}
}
else
{
m_error = true;
}
break;
// On second: %S
case 5:
if (isdigit(c))
{
m_parsedTimestamp.tm_sec = m_parsedTimestamp.tm_sec * 10 + (c - '0');
if (index - stateStartIndex == 1)
{
m_state = 6;
stateStartIndex = index + 1;
}
}
else
{
m_error = true;
}
break;
// On TZ: Z or 000Z
case 6:
if ((c == 'Z' || c == '+' || c == '-' ) && (index - stateStartIndex == 0 || index - stateStartIndex == 3))
{
m_tz[0] = c;
m_state = 7;
stateStartIndex = index + 1;
}
else if (!isdigit(c) || index - stateStartIndex > 3)
{
m_error = true;
}
break;
case 7:
if ((isdigit(c) || c == ':') && (index - stateStartIndex < 5))
{
m_tz[1 + index - stateStartIndex] = c;
}
else
{
m_error = true;
}
break;
default:
m_error = true;
break;
}
index++;
}
if (m_tz[0] != 0)
{
m_utcAssumed = IsUTCTimeZoneDesignator(m_tz);
}
m_error = (m_error || m_state != finalState);
}