static int GetWeekDayNumberFromStr()

in src/aws-cpp-sdk-core/source/utils/DateTimeCommon.cpp [43:178]


static int GetWeekDayNumberFromStr(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 'S':
    case 's':
        next = timeString[++index];
        switch(next)
        {
        case 'A':
        case 'a':
            next = timeString[++index];
            switch (next)
            {
            case 'T':
            case 't':
                return 6;
            default:
                return -1;
            }
        case 'U':
        case 'u':
            next = timeString[++index];
            switch (next)
            {
            case 'N':
            case 'n':
                return 0;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'T':
    case 't':
        next = timeString[++index];
        switch (next)
        {
        case 'H':
        case 'h':
            next = timeString[++index];
            switch(next)
            {
            case 'U':
            case 'u':
                return 4;
            default:
                return -1;
            }
        case 'U':
        case 'u':
            next = timeString[++index];
            switch(next)
            {
            case 'E':
            case 'e':
                return 2;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'M':
    case 'm':
        next = timeString[++index];
        switch(next)
        {
        case 'O':
        case 'o':
            next = timeString[++index];
            switch (next)
            {
            case 'N':
            case 'n':
                return 1;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'W':
    case 'w':
        next = timeString[++index];
        switch (next)
        {
        case 'E':
        case 'e':
            next = timeString[++index];
            switch (next)
            {
            case 'D':
            case 'd':
                return 3;
            default:
                return -1;
            }
        default:
            return -1;
        }
    case 'F':
    case 'f':
        next = timeString[++index];
        switch (next)
        {
        case 'R':
        case 'r':
            next = timeString[++index];
            switch (next)
            {
            case 'I':
            case 'i':
                return 5;
            default:
                return -1;
            }
        default:
            return -1;
        }
    default:
        return -1;
    }
}