From 0c741e0058376bdbd7fa0feab79398549cff61c4 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Tue, 27 Jul 2010 00:29:56 +0100 Subject: [PATCH] Implement (and test) UK encoding page --- src/encoding.c | 33 +++++++++++++++++++++++++++++++++ t/14state_encoding.test | 14 ++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 t/14state_encoding.test diff --git a/src/encoding.c b/src/encoding.c index 61cbe3ca..c0a4a7ad 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -172,6 +172,38 @@ static VTermEncoding encoding_usascii = { .decode = &decode_usascii, }; +struct StaticTableEncoding { + const VTermEncoding enc; + const uint32_t chars[128]; +}; + +static int decode_table(VTermEncoding *enc, uint32_t cp[], int *cpi, int cplen, + const char bytes[], size_t *pos, size_t bytelen) +{ + struct StaticTableEncoding *table = (struct StaticTableEncoding *)enc; + + for(; *pos < bytelen; (*pos)++) { + unsigned char c = (bytes[*pos]) & 0x7f; + + if(c < 0x20) + return 0; + + if(table->chars[c]) + cp[(*cpi)++] = table->chars[c]; + else + cp[(*cpi)++] = c; + } + + return 1; +} + +static const struct StaticTableEncoding encoding_uk = { + { .decode = &decode_table }, + { + ['$'] = 0x00a3, + } +}; + static struct { VTermEncodingType type; char designation; @@ -179,6 +211,7 @@ static struct { } encodings[] = { { ENC_UTF8, 'u', &encoding_utf8 }, + { ENC_SINGLE_94, 'A', (VTermEncoding*)&encoding_uk }, { ENC_SINGLE_94, 'B', &encoding_usascii }, { 0, 0 }, }; diff --git a/t/14state_encoding.test b/t/14state_encoding.test new file mode 100644 index 00000000..d0a71bf1 --- /dev/null +++ b/t/14state_encoding.test @@ -0,0 +1,14 @@ +INIT +UTF8 1 +WANTSTATE g + +!Default +RESET +PUSH '$' + putglyph 0x23 1 0,0 + +!Designate G0=UK +RESET +PUSH "\e(A" +PUSH '$' + putglyph 0x00a3 1 0,0