#include "jutil.h"
#include <string.h>
#include <ctype.h>
#include <SDL3/SDL.h>
namespace util
{
    int stringToInt(const char *value, std::vector<const char*> strings, std::vector<int> values)
    {
        char lowercase[255];
        strcpy(lowercase, value);
        for (int i=0; i<(int)strlen(value);++i) lowercase[i]=tolower(value[i]);

        const int max_size = strings.size()<values.size()?strings.size():values.size();
        for (int i=0;i<max_size;++i)
        {
            if (strcmp(lowercase, strings[i])==0) return values[i];
        }
        return values[0];
    }

    const bool strcomp(const char *a, const char* b)
    {
        if (a==nullptr || b==nullptr) return false;
        return (strcmp(a,b)==0);
    }

    const uint8_t scancode_to_char(const uint8_t scancode)
    {
        if (scancode == SDL_SCANCODE_0 || scancode == SDL_SCANCODE_KP_0) return '0';
        if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9) return scancode+19;
        if (scancode >= SDL_SCANCODE_KP_1 && scancode <= SDL_SCANCODE_KP_9) return scancode-40;
        if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) return scancode+61;
        //if (scancode == SDL_SCANCODE_MINUS) return '-';
        return '-';
    }
}