static int GetMonthNumberFromStr()

in src/aws-cpp-sdk-core/source/utils/DateTimeCommon.cpp [181:379]


static int GetMonthNumberFromStr(const char* timeString, size_t startIndex, size_t stopIndex)
{
    if (stopIndex - startIndex < 3)
    {
        return -1;
    }

    size_t index = startIndex;

    char c = timeString[index];
    char next = 0;

    //it's ugly but this should compile down to EXACTLY 3 comparisons and no memory allocations
    switch (c)
    {
    case 'M':
    case 'm':
        next = timeString[++index];
        switch (next)
        {
        case 'A':
        case 'a':
            next = timeString[++index];
            switch (next)
            {
            case 'Y':
            case 'y':
                return 4;
            case 'R':
            case 'r':
                return 2;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'A':
    case 'a':
        next = timeString[++index];
        switch (next)
        {
        case 'P':
        case 'p':
            next = timeString[++index];
            switch (next)
            {
            case 'R':
            case 'r':
                return 3;
            default:
                return -1;
            }
        case 'U':
        case 'u':
            next = timeString[++index];
            switch (next)
            {
            case 'G':
            case 'g':
                return 7;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'J':
    case 'j':
        next = timeString[++index];
        switch (next)
        {
        case 'A':
        case 'a':
            next = timeString[++index];
            switch (next)
            {
            case 'N':
            case 'n':
                return 0;
            default:
                return -1;
            }
        case 'U':
        case 'u':
            next = timeString[++index];
            switch (next)
            {
            case 'N':
            case 'n':
                return 5;
            case 'L':
            case 'l':
                return 6;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'F':
    case 'f':
        next = timeString[++index];
        switch (next)
        {
        case 'E':
        case 'e':
            next = timeString[++index];
            switch (next)
            {
            case 'B':
            case 'b':
                return 1;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'S':
    case 's':
        next = timeString[++index];
        switch (next)
        {
        case 'E':
        case 'e':
            next = timeString[++index];
            switch (next)
            {
            case 'P':
            case 'p':
                return 8;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'O':
    case 'o':
        next = timeString[++index];
        switch (next)
        {
        case 'C':
        case 'c':
            next = timeString[++index];
            switch (next)
            {
            case 'T':
            case 't':
                return 9;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'N':
    case 'n':
        next = timeString[++index];
        switch (next)
        {
        case 'O':
        case 'o':
            next = timeString[++index];
            switch (next)
            {
            case 'V':
            case 'v':
                return 10;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'D':
    case 'd':
        next = timeString[++index];
        switch (next)
        {
        case 'E':
        case 'e':
            next = timeString[++index];
            switch (next)
            {
            case 'C':
            case 'c':
                return 11;
            default:
                return -1;
            }
        default:
            return -1;
        }
    default:
        return -1;
    }
}