void Parse()

in src/aws-cpp-sdk-core/source/utils/DateTimeCommon.cpp [721:882]


    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)
            {
                case 0:
                    if (c == '-' && index - stateStartIndex == 4)
                    {
                        m_state = 1;
                        stateStartIndex = index + 1;
                        m_parsedTimestamp.tm_year -= 1900;
                    }
                    else if (isdigit(c))
                    {
                        m_parsedTimestamp.tm_year = m_parsedTimestamp.tm_year * 10 + (c - '0');
                    }
                    else
                    {
                        m_error = true;
                    }
                    break;
                case 1:
                    if (c == '-' && index - stateStartIndex == 2)
                    {
                        m_state = 2;
                        stateStartIndex = index + 1;
                        m_parsedTimestamp.tm_mon -= 1;
                    }
                    else if (isdigit(c))
                    {
                        m_parsedTimestamp.tm_mon = m_parsedTimestamp.tm_mon * 10 + (c - '0');
                    }
                    else
                    {
                        m_error = true;
                    }

                    break;
                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;
                case 3:
                    if (c == ':' && index - stateStartIndex == 2)
                    {
                        m_state = 4;
                        stateStartIndex = index + 1;
                    }
                    else if (isdigit(c))
                    {
                        m_parsedTimestamp.tm_hour = m_parsedTimestamp.tm_hour * 10 + (c - '0');
                    }
                    else
                    {
                        m_error = true;
                    }

                    break;
                case 4:
                    if (c == ':' && index - stateStartIndex == 2)
                    {
                        m_state = 5;
                        stateStartIndex = index + 1;
                    }
                    else if (isdigit(c))
                    {
                        m_parsedTimestamp.tm_min = m_parsedTimestamp.tm_min * 10 + (c - '0');
                    }
                    else
                    {
                        m_error = true;
                    }

                    break;
                case 5:
                    if ((c == 'Z' || c == '+' || c == '-' ) && (index - stateStartIndex == 2))
                    {
                        m_tz[0] = c;
                        m_state = 7;
                        stateStartIndex = index + 1;
                    }
                    else if (c == '.' && index - stateStartIndex == 2)
                    {
                        m_state = 6;
                        stateStartIndex = index + 1;
                    }
                    else if (isdigit(c))
                    {
                        m_parsedTimestamp.tm_sec = m_parsedTimestamp.tm_sec * 10 + (c - '0');
                    }
                    else
                    {
                        m_error = true;
                    }

                    break;
                case 6:
                    if ((c == 'Z' || c == '+' || c == '-' ) &&
                        (index - stateStartIndex >= 3) &&
                        (index - stateStartIndex <= 9))
                    {
                        m_tz[0] = c;
                        m_state = 7;
                        stateStartIndex = index + 1;
                    }
                    else if(!isdigit(c))
                    {
                        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);
    }