mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 09:03:32 +02:00
436 lines
24 KiB
C
436 lines
24 KiB
C
#include "neonucleus.h"
|
|
|
|
// both tables copied from: https://github.com/MightyPirates/OpenComputers/blob/52da41b5e171b43fea80342dc75d808f97a0f797/src/main/scala/li/cil/oc/util/FontUtils.scala
|
|
|
|
static const unsigned char nn_unicode_charWidth_table[] = {
|
|
16, 16, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 16, 33, 16, 16, 16, 34, 35, 36,
|
|
37, 38, 39, 40, 16, 16, 41, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 42, 43, 16, 16, 44, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 45, 16, 46, 47, 48, 49, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 50, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 51, 16, 16, 52,
|
|
53, 16, 54, 55, 56, 16, 16, 16, 16, 16, 16, 57, 16, 16, 58, 16, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
|
|
69, 70, 16, 71, 72, 73, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 74, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 75, 76, 16, 16, 16, 77, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 78, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 79, 80, 16, 16, 16, 16, 16, 16, 16, 81, 16, 16, 16, 16, 16, 82, 83, 84, 16, 16, 16, 16, 16, 85,
|
|
86, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 248, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 254, 255, 255, 255, 255, 191, 182, 0, 0, 0, 0, 0, 0, 0, 63, 0, 255, 23, 0, 0, 0, 0, 0, 248, 255,
|
|
255, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 191, 159, 61, 0, 0, 0, 128, 2, 0, 0, 0, 255, 255, 255,
|
|
7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 255, 1, 0, 0, 0, 0, 0, 0, 248, 15, 32, 0, 0, 192, 251, 239, 62, 0, 0,
|
|
0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 255, 255, 255, 255,
|
|
255, 7, 0, 0, 0, 0, 0, 0, 20, 254, 33, 254, 0, 12, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 16, 30, 32, 0, 0, 12, 0, 0,
|
|
64, 6, 0, 0, 0, 0, 0, 0, 16, 134, 57, 2, 0, 0, 0, 35, 0, 6, 0, 0, 0, 0, 0, 0, 16, 190, 33, 0, 0, 12, 0, 0,
|
|
252, 2, 0, 0, 0, 0, 0, 0, 144, 30, 32, 64, 0, 12, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 1, 32, 0, 0, 0, 0, 0, 0, 17,
|
|
0, 0, 0, 0, 0, 0, 192, 193, 61, 96, 0, 12, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 144, 64, 48, 0, 0, 12, 0, 0, 0, 3, 0,
|
|
0, 0, 0, 0, 0, 24, 30, 32, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
242, 7, 128, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 242, 31, 0, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 160,
|
|
2, 0, 0, 0, 0, 0, 0, 254, 127, 223, 224, 255, 254, 255, 255, 255, 31, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 224, 253, 102, 0, 0, 0, 195, 1, 0, 30, 0, 100, 32, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 0, 0, 0, 28, 0, 0, 0, 12, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 176, 63, 64, 254,
|
|
15, 32, 0, 0, 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 135, 1, 4, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
128, 9, 0, 0, 0, 0, 0, 0, 64, 127, 229, 31, 248, 159, 0, 0, 0, 0, 0, 0, 255, 127, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
15, 0, 0, 0, 0, 0, 208, 23, 4, 0, 0, 0, 0, 248, 15, 0, 3, 0, 0, 0, 60, 59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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255,
|
|
255, 255, 255, 255, 127, 248, 255, 255, 255, 255, 255, 31, 32, 0, 16, 0, 0, 248, 254, 255, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 249, 219, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 7, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
};
|
|
static const unsigned char nn_unicode_charWidth_wide_table[] = {
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 18, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 19, 16, 20, 21, 22, 16, 16, 16, 23, 16, 16, 24, 25, 26, 27, 28, 17,
|
|
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 29,
|
|
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
|
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
|
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
|
17, 17, 17, 17, 17, 17, 17, 17, 30, 16, 16, 16, 16, 31, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
|
17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
|
17, 17, 17, 17, 17, 17, 17, 32, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 16, 16, 16, 33,
|
|
34, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 35, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
|
17, 17, 17, 17, 17, 17, 36, 17, 17, 37, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 38, 39, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
16, 16, 16, 16, 16, 16, 16, 40, 41, 42, 43, 44, 45, 46, 47, 16, 48, 49, 16, 16, 16, 16,
|
|
16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 1, 0, 0, 0, 80, 184, 0, 0, 0, 0, 0, 0, 0, 224,
|
|
0, 0, 0, 1, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 251, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 15, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 0, 0, 0, 255, 15, 255, 255, 255, 255,
|
|
255, 255, 255, 127, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 254, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 224, 255, 255, 255, 255, 255, 254, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 7, 255, 255, 255, 255, 15, 0,
|
|
255, 255, 255, 255, 255, 127, 255, 255, 255, 255, 255, 0, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 31, 255, 255, 255, 255, 255, 255, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,
|
|
255, 255, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 3, 0, 0, 255, 255, 255, 255, 247, 255, 127, 15, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 7, 0, 255, 255, 255, 127, 0, 0, 0, 0, 0,
|
|
0, 7, 0, 240, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
15, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 254, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 255, 255, 255,
|
|
255, 255, 15, 255, 1, 3, 0, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255,
|
|
1, 224, 191, 255, 255, 255, 255, 255, 255, 255, 255, 223, 255, 255, 15, 0, 255, 255, 255, 255,
|
|
255, 135, 15, 0, 255, 255, 17, 255, 255, 255, 255, 255, 255, 255, 255, 127, 253, 255, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
159, 255, 255, 255, 255, 255, 255, 255, 63, 0, 120, 255, 255, 255, 0, 0, 4, 0, 0, 96, 0, 16, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 255, 255,
|
|
255, 255, 255, 255, 255, 255, 63, 16, 39, 0, 0, 24, 240, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 15, 0,
|
|
0, 0, 224, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 123, 252, 255, 255, 255,
|
|
255, 231, 199, 255, 255, 255, 231, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 15, 7, 7, 0, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
};
|
|
|
|
static nn_bool_t nn_unicode_is_continuation(unsigned char byte) {
|
|
return (byte >> 6) == 0b10;
|
|
}
|
|
|
|
nn_bool_t nn_unicode_isValidCodepoint(const char *s) {
|
|
if(s[0] <= 0x7F) {
|
|
return true;
|
|
} else if((s[0] >> 5) == 0b110) {
|
|
if (!nn_unicode_is_continuation(s[1])) {
|
|
return false;
|
|
}
|
|
} else if((s[0] >> 4) == 0b1110) {
|
|
if (!nn_unicode_is_continuation(s[1])) {
|
|
return false;
|
|
}
|
|
if (!nn_unicode_is_continuation(s[2])) {
|
|
return false;
|
|
}
|
|
} else if((s[0] >> 3) == 0b11110) {
|
|
if (!nn_unicode_is_continuation(s[1])) {
|
|
return false;
|
|
}
|
|
if (!nn_unicode_is_continuation(s[2])) {
|
|
return false;
|
|
}
|
|
if (!nn_unicode_is_continuation(s[3])) {
|
|
return false;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
nn_bool_t nn_unicode_validate(const char *b) {
|
|
const unsigned char* s = (const unsigned char*)b;
|
|
while (*s) {
|
|
if(s[0] <= 0x7F) {
|
|
s++;
|
|
} else if((s[0] >> 5) == 0b110) {
|
|
if (!nn_unicode_is_continuation(s[1])) {
|
|
return false;
|
|
}
|
|
s += 2;
|
|
} else if((s[0] >> 4) == 0b1110) {
|
|
if (!nn_unicode_is_continuation(s[1])) {
|
|
return false;
|
|
}
|
|
if (!nn_unicode_is_continuation(s[2])) {
|
|
return false;
|
|
}
|
|
s += 3;
|
|
} else if((s[0] >> 3) == 0b11110) {
|
|
if (!nn_unicode_is_continuation(s[1])) {
|
|
return false;
|
|
}
|
|
if (!nn_unicode_is_continuation(s[2])) {
|
|
return false;
|
|
}
|
|
if (!nn_unicode_is_continuation(s[3])) {
|
|
return false;
|
|
}
|
|
s += 4;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// A general unicode library, which assumes unicode encoding.
|
|
// It is used to power the Lua architecture's Unicode API re-implementation.
|
|
// It can also just be used to deal with unicode.
|
|
|
|
char *nn_unicode_char(nn_Alloc *alloc, unsigned int *codepoints, nn_size_t codepointCount) {
|
|
nn_size_t len = 0;
|
|
for (nn_size_t i = 0; i < codepointCount; i++) {
|
|
unsigned int codepoint = codepoints[i];
|
|
len += nn_unicode_codepointSize(codepoint);
|
|
}
|
|
|
|
char *buf = nn_alloc(alloc, len+1);
|
|
if (buf == NULL) return buf;
|
|
|
|
nn_size_t j = 0;
|
|
for (nn_size_t i = 0; i < codepointCount; i++) {
|
|
int codepoint = codepoints[i];
|
|
nn_size_t codepointLen = 0;
|
|
char c[NN_MAXIMUM_UNICODE_BUFFER];
|
|
nn_unicode_codepointToChar(c, codepoint, &codepointLen);
|
|
nn_memcpy(buf + j, c, codepointLen);
|
|
j += codepointLen;
|
|
}
|
|
buf[j] = '\0';
|
|
|
|
return buf;
|
|
}
|
|
|
|
unsigned int *nn_unicode_codepoints(nn_Alloc *alloc, const char *s, nn_size_t *len) {
|
|
nn_size_t l = nn_unicode_len(s);
|
|
unsigned int *buf = nn_alloc(alloc, sizeof(unsigned int) * l);
|
|
if(buf == NULL) return NULL;
|
|
if(len != NULL) *len = l;
|
|
nn_size_t cur = 0;
|
|
nn_size_t bufidx = 0;
|
|
while(s[cur] != 0) {
|
|
unsigned int point = nn_unicode_codepointAt(s, cur);
|
|
cur += nn_unicode_codepointSize(point);
|
|
buf[bufidx++] = point;
|
|
}
|
|
return buf;
|
|
}
|
|
|
|
nn_size_t nn_unicode_len(const char *b) {
|
|
nn_size_t count = 0;
|
|
const unsigned char* s = (const unsigned char*)b;
|
|
while (*s) {
|
|
count++;
|
|
if(s[0] <= 0x7F) {
|
|
s++;
|
|
} else if((s[0] >> 5) == 0b110) {
|
|
s += 2;
|
|
} else if((s[0] >> 4) == 0b1110) {
|
|
s += 3;
|
|
} else if((s[0] >> 3) == 0b11110) {
|
|
s += 4;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
|
|
unsigned int nn_unicode_codepointAt(const char *s, nn_size_t byteOffset) {
|
|
unsigned int point = 0;
|
|
const unsigned char *b = (const unsigned char *)s + byteOffset;
|
|
|
|
const unsigned char subpartMask = 0b111111;
|
|
// look into nn_unicode_codepointToChar as well.
|
|
if(b[0] <= 0x7F) {
|
|
return b[0];
|
|
} else if((b[0] >> 5) == 0b110) {
|
|
point += ((unsigned int)(b[0] & 0b11111)) << 6;
|
|
point += ((unsigned int)(b[1] & subpartMask));
|
|
} else if((b[0] >> 4) == 0b1110) {
|
|
point += ((unsigned int)(b[0] & 0b1111)) << 12;
|
|
point += ((unsigned int)(b[1] & subpartMask)) << 6;
|
|
point += ((unsigned int)(b[2] & subpartMask));
|
|
} else if((b[0] >> 3) == 0b11110) {
|
|
point += ((unsigned int)(b[0] & 0b111)) << 18;
|
|
point += ((unsigned int)(b[1] & subpartMask)) << 12;
|
|
point += ((unsigned int)(b[2] & subpartMask)) << 6;
|
|
point += ((unsigned int)(b[3] & subpartMask));
|
|
}
|
|
return point;
|
|
}
|
|
|
|
nn_size_t nn_unicode_codepointSize(unsigned int codepoint) {
|
|
if (codepoint <= 0x007f) {
|
|
return 1;
|
|
} else if (codepoint <= 0x07ff) {
|
|
return 2;
|
|
} else if (codepoint <= 0xffff) {
|
|
return 3;
|
|
} else if (codepoint <= 0x10ffff) {
|
|
return 4;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
void nn_unicode_codepointToChar(char *buffer, unsigned int codepoint, nn_size_t *len) {
|
|
nn_size_t codepointSize = nn_unicode_codepointSize(codepoint);
|
|
if(len != NULL) *len = codepointSize;
|
|
|
|
nn_memset(buffer, 0, 4); // Clear static array
|
|
|
|
if (codepointSize == 1) {
|
|
buffer[0] = (char)codepoint;
|
|
} else if (codepointSize == 2) {
|
|
buffer[0] = 0b11000000 + ((codepoint >> 6) & 0b11111);
|
|
buffer[1] = 0b10000000 + (codepoint & 0b111111);
|
|
} else if (codepointSize == 3) {
|
|
buffer[0] = 0b11100000 + ((codepoint >> 12) & 0b1111);
|
|
buffer[1] = 0b10000000 + ((codepoint >> 6) & 0b111111);
|
|
buffer[2] = 0b10000000 + (codepoint & 0b111111);
|
|
} else if (codepointSize == 4) {
|
|
buffer[0] = 0b11110000 + ((codepoint >> 18) & 0b111);
|
|
buffer[1] = 0b10000000 + ((codepoint >> 12) & 0b111111);
|
|
buffer[2] = 0b10000000 + ((codepoint >> 6) & 0b111111);
|
|
buffer[3] = 0b10000000 + (codepoint & 0b111111);
|
|
}
|
|
}
|
|
|
|
// copied straight from opencomputers and musl's libc
|
|
// https://github.com/MightyPirates/OpenComputers/blob/52da41b5e171b43fea80342dc75d808f97a0f797/src/main/scala/li/cil/oc/util/FontUtils.scala#L205
|
|
// https://git.musl-libc.org/cgit/musl/tree/src/ctype/wcwidth.c
|
|
nn_size_t nn_unicode_charWidth(unsigned int codepoint) {
|
|
if (codepoint < 0xff) {
|
|
if (((codepoint + 1) & 0x7f) >= 0x21) {
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
} else if ((codepoint & 0xfffeffff) < 0xfffe) {
|
|
if ((nn_unicode_charWidth_table[nn_unicode_charWidth_table[codepoint>>8]*32+((codepoint&255)>>3)]>>(codepoint&7))&1)
|
|
return 0;
|
|
if ((nn_unicode_charWidth_wide_table[nn_unicode_charWidth_wide_table[codepoint>>8]*32+((codepoint&255)>>3)]>>(codepoint&7))&1)
|
|
return 2;
|
|
return 1;
|
|
} else if (codepoint-0x20000 < 0x20000) {
|
|
return 2;
|
|
} else if (codepoint == 0xe0001 || codepoint-0xe0020 < 0x5f || codepoint-0xe0100 < 0xef) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
nn_size_t nn_unicode_wlen(const char *s) {
|
|
nn_size_t wlen = 0;
|
|
while (*s) {
|
|
unsigned int codepoint = nn_unicode_codepointAt(s, 0);
|
|
nn_size_t codepointSize = nn_unicode_codepointSize(codepoint);
|
|
wlen += nn_unicode_charWidth(codepoint);
|
|
s += codepointSize;
|
|
}
|
|
return wlen;
|
|
}
|
|
|
|
// NOT IMPLEMENTED YET
|
|
|
|
unsigned int nn_unicode_upperCodepoint(unsigned int codepoint);
|
|
char *nn_unicode_upper(nn_Alloc *alloc, const char *s);
|
|
unsigned int nn_unicode_lowerCodepoint(unsigned int codepoint);
|
|
char *nn_unicode_lower(nn_Alloc *alloc, const char *s);
|
|
|
|
unsigned int nn_unicode_nextCodepointPermissive(const char *s, nn_size_t *index) {
|
|
nn_size_t i = *index;
|
|
if(nn_unicode_isValidCodepoint(s + i)) {
|
|
// TODO: handle edge-case where suboptimial encoding is used
|
|
unsigned int p = nn_unicode_codepointAt(s, i);
|
|
*index = i + nn_unicode_codepointSize(p);
|
|
return p;
|
|
}
|
|
unsigned int p = (unsigned char)s[i];
|
|
*index = i + 1;
|
|
return p;
|
|
}
|
|
|
|
nn_size_t nn_unicode_lenPermissive(const char *b) {
|
|
nn_size_t len = 0;
|
|
nn_size_t cur = 0;
|
|
while(b[cur]) {
|
|
nn_unicode_nextCodepointPermissive(b, &cur);
|
|
len++;
|
|
}
|
|
return len;
|
|
}
|
|
|
|
nn_size_t nn_unicode_wlenPermissive(const char *s) {
|
|
nn_size_t wlen = 0;
|
|
nn_size_t cur = 0;
|
|
while (s[cur]) {
|
|
unsigned int codepoint = nn_unicode_nextCodepointPermissive(s, &cur);
|
|
wlen += nn_unicode_charWidth(codepoint);
|
|
}
|
|
return wlen;
|
|
}
|
|
|
|
nn_intptr_t nn_unicode_indexPermissive(const char *s, nn_size_t codepointIndex) {
|
|
nn_size_t bytes = 0;
|
|
while(true) {
|
|
if(codepointIndex == 0) return bytes;
|
|
nn_unicode_nextCodepointPermissive(s, &bytes);
|
|
codepointIndex--;
|
|
}
|
|
}
|