summaryrefslogtreecommitdiff
path: root/libs/JSystem/src/JMessage/locale.cpp
blob: 78c4292f4e8e7a1c8c25fb5d94da1515acf21eb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "JSystem/JSystem.h" // IWYU pragma: keep

#include "JSystem/JMessage/locale.h"

int JMessage::locale::parseCharacter_ShiftJIS(const char** ppszText) {
    int c = *(u8*)*ppszText & 0xFF;
    (*ppszText)++;

    if (isLeadByte_ShiftJIS(c)) {
        c <<= 8;
        c |= *(u8*)*ppszText & 0xFF;
        (*ppszText)++;
    }

    return c;
}

int JMessage::locale::parseCharacter_UTF8(const char** ppszText) {
    int c = *(u8*)*ppszText & 0xFF;
    (*ppszText)++;

    if (c & 0x80) {
        if ((c & 0xE0) == 0xC0) {
            c &= 0x1F;
            c <<= 6;
            c |= (*(u8*)*ppszText & 0xFF) & 0x3F;
            (*ppszText)++;
        } else if ((c & 0xF0) == 0xE0) {
            c &= 0xF;
            c <<= 6;
            c |= (*(u8*)*ppszText & 0xFF) & 0x3F;
            (*ppszText)++;

            c <<= 6;
            c |= (*(u8*)*ppszText & 0xFF) & 0x3F;
            (*ppszText)++;
        } else if ((c & 0xF8) == 0xF0) {
            c &= 0x7;
            c <<= 6;
            c |= (*(u8*)*ppszText & 0xFF) & 0x3F;
            (*ppszText)++;

            c <<= 6;
            c |= (*(u8*)*ppszText & 0xFF) & 0x3F;
            (*ppszText)++;

            c <<= 6;
            c |= (*(u8*)*ppszText & 0xFF) & 0x3F;
            (*ppszText)++;
        } else {
            c = -1;
        }
    }

    return c;
}