diff options
-rw-r--r-- | prism/enc/pm_encoding.h | 1 | ||||
-rw-r--r-- | prism/enc/pm_tables.c | 35 | ||||
-rw-r--r-- | prism/prism.c | 1 | ||||
-rw-r--r-- | test/prism/encoding_test.rb | 1 |
4 files changed, 38 insertions, 0 deletions
diff --git a/prism/enc/pm_encoding.h b/prism/enc/pm_encoding.h index c6addba9c1..4c7bb56b43 100644 --- a/prism/enc/pm_encoding.h +++ b/prism/enc/pm_encoding.h @@ -164,6 +164,7 @@ extern pm_encoding_t pm_encoding_cp850; extern pm_encoding_t pm_encoding_cp852; extern pm_encoding_t pm_encoding_cp855; extern pm_encoding_t pm_encoding_euc_jp; +extern pm_encoding_t pm_encoding_gb1988; extern pm_encoding_t pm_encoding_gbk; extern pm_encoding_t pm_encoding_ibm437; extern pm_encoding_t pm_encoding_ibm720; diff --git a/prism/enc/pm_tables.c b/prism/enc/pm_tables.c index 01ca103bff..6de14a075a 100644 --- a/prism/enc/pm_tables.c +++ b/prism/enc/pm_tables.c @@ -98,6 +98,30 @@ static uint8_t pm_encoding_cp855_table[256] = { /** * Each element of the following table contains a bitfield that indicates a + * piece of information about the corresponding GB1988 character. + */ +static uint8_t pm_encoding_gb1988_table[256] = { +// 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2x + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, // 3x + 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // 4x + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, // 5x + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 6x + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, // 7x + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Ax + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Bx + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Cx + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Dx + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Ex + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Fx +}; + +/** + * Each element of the following table contains a bitfield that indicates a * piece of information about the corresponding IBM437 character. */ static uint8_t pm_encoding_ibm437_table[256] = { @@ -1268,6 +1292,7 @@ pm_encoding_koi8_r_char_width(const uint8_t *b, PRISM_ATTRIBUTE_UNUSED ptrdiff_t PRISM_ENCODING_TABLE(cp850) PRISM_ENCODING_TABLE(cp852) PRISM_ENCODING_TABLE(cp855) +PRISM_ENCODING_TABLE(gb1988) PRISM_ENCODING_TABLE(ibm437) PRISM_ENCODING_TABLE(ibm720) PRISM_ENCODING_TABLE(ibm737) @@ -1367,6 +1392,16 @@ pm_encoding_t pm_encoding_cp855 = { .multibyte = false }; +/** GB1988 */ +pm_encoding_t pm_encoding_gb1988 = { + .name = "GB1988", + .char_width = pm_encoding_single_char_width, + .alnum_char = pm_encoding_gb1988_alnum_char, + .alpha_char = pm_encoding_gb1988_alpha_char, + .isupper_char = pm_encoding_gb1988_isupper_char, + .multibyte = false +}; + /** IBM437 */ pm_encoding_t pm_encoding_ibm437 = { .name = "IBM437", diff --git a/prism/prism.c b/prism/prism.c index 5de401e311..2b3d2074cf 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -6101,6 +6101,7 @@ parser_lex_magic_comment_encoding_value(pm_parser_t *parser, const uint8_t *star ENCODING1("filesystem", pm_encoding_utf_8); break; case 'G': case 'g': + ENCODING1("GB1988", pm_encoding_gb1988); ENCODING1("GBK", pm_encoding_gbk); break; case 'I': case 'i': diff --git a/test/prism/encoding_test.rb b/test/prism/encoding_test.rb index 24e6f1c157..460408a0b8 100644 --- a/test/prism/encoding_test.rb +++ b/test/prism/encoding_test.rb @@ -12,6 +12,7 @@ module Prism Encoding::CP850 => 0x00...0x100, Encoding::CP852 => 0x00...0x100, Encoding::CP855 => 0x00...0x100, + Encoding::GB1988 => 0x00...0x100, Encoding::IBM437 => 0x00...0x100, Encoding::IBM720 => 0x00...0x100, Encoding::IBM737 => 0x00...0x100, |