Files
AnyPS5/core/libs/prx/libSceIcu/CharacterDigits.cpp
T

55 lines
2.5 KiB
C++

#include "prx/libSceIcu/libSceIcu.hpp"
#include <array>
#include <cstdint>
namespace {
struct Range {
std::int32_t first;
std::int32_t last;
};
constexpr std::array<Range, 72> DecimalRanges{{
{0x30, 0x39}, {0x660, 0x669}, {0x6f0, 0x6f9}, {0x7c0, 0x7c9}, {0x966, 0x96f},
{0x9e6, 0x9ef}, {0xa66, 0xa6f}, {0xae6, 0xaef}, {0xb66, 0xb6f}, {0xbe6, 0xbef},
{0xc66, 0xc6f}, {0xce6, 0xcef}, {0xd66, 0xd6f}, {0xde6, 0xdef}, {0xe50, 0xe59},
{0xed0, 0xed9}, {0xf20, 0xf29}, {0x1040, 0x1049}, {0x1090, 0x1099}, {0x17e0, 0x17e9},
{0x1810, 0x1819}, {0x1946, 0x194f}, {0x19d0, 0x19d9}, {0x1a80, 0x1a89}, {0x1a90, 0x1a99},
{0x1b50, 0x1b59}, {0x1bb0, 0x1bb9}, {0x1c40, 0x1c49}, {0x1c50, 0x1c59}, {0xa620, 0xa629},
{0xa8d0, 0xa8d9}, {0xa900, 0xa909}, {0xa9d0, 0xa9d9}, {0xa9f0, 0xa9f9}, {0xaa50, 0xaa59},
{0xabf0, 0xabf9}, {0xff10, 0xff19}, {0x104a0, 0x104a9}, {0x10d30, 0x10d39}, {0x10d40, 0x10d49},
{0x11066, 0x1106f}, {0x110f0, 0x110f9}, {0x11136, 0x1113f}, {0x111d0, 0x111d9}, {0x112f0, 0x112f9},
{0x11450, 0x11459}, {0x114d0, 0x114d9}, {0x11650, 0x11659}, {0x116c0, 0x116c9}, {0x116d0, 0x116e3},
{0x11730, 0x11739}, {0x118e0, 0x118e9}, {0x11950, 0x11959}, {0x11bf0, 0x11bf9}, {0x11c50, 0x11c59},
{0x11d50, 0x11d59}, {0x11da0, 0x11da9}, {0x11de0, 0x11de9}, {0x11f50, 0x11f59}, {0x16130, 0x16139},
{0x16a60, 0x16a69}, {0x16ac0, 0x16ac9}, {0x16b50, 0x16b59}, {0x16d70, 0x16d79}, {0x1ccf0, 0x1ccf9},
{0x1d7ce, 0x1d7ff}, {0x1e140, 0x1e149}, {0x1e2f0, 0x1e2f9}, {0x1e4f0, 0x1e4f9}, {0x1e5f1, 0x1e5fa},
{0x1e950, 0x1e959}, {0x1fbf0, 0x1fbf9}
}};
std::int32_t DecimalValue(std::int32_t character) {
for (const auto& range : DecimalRanges)
if (character >= range.first && character <= range.last) return (character - range.first) % 10;
return -1;
}
}
extern "C" {
int APS5_VABI u_charDigitValue_nid_postfix(std::int32_t character) {
return DecimalValue(character);
}
int APS5_VABI u_digit_nid_postfix(std::int32_t character, std::int8_t radix) {
if (radix < 2 || radix > 36) return -1;
auto value = DecimalValue(character);
if (value < 0 && character >= 'A' && character <= 'Z') value = character - 'A' + 10;
if (value < 0 && character >= 'a' && character <= 'z') value = character - 'a' + 10;
if (value < 0 && character >= 0xff21 && character <= 0xff3a) value = character - 0xff17;
if (value < 0 && character >= 0xff41 && character <= 0xff5a) value = character - 0xff37;
return value < radix ? value : -1;
}
}