summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-11-11 23:41:53 -0500
committergit <svn-admin@ruby-lang.org>2023-11-16 17:39:32 +0000
commitba937eee0bad0de702bd19cfb467aad67c8d33c0 (patch)
treed1f5b60e049c82b59c734044d7e79c81e83a54bd
parentf60b974393d76126bf6fc4566f7bf4c754c3ca70 (diff)
[ruby/prism] IBM437 encoding
https://github.com/ruby/prism/commit/d60329eeb5
-rw-r--r--prism/enc/pm_encoding.h1
-rw-r--r--prism/enc/pm_tables.c35
-rw-r--r--prism/prism.c1
-rw-r--r--test/prism/encoding_test.rb1
4 files changed, 38 insertions, 0 deletions
diff --git a/prism/enc/pm_encoding.h b/prism/enc/pm_encoding.h
index 0d7a414383..f9a457fb39 100644
--- a/prism/enc/pm_encoding.h
+++ b/prism/enc/pm_encoding.h
@@ -164,6 +164,7 @@ 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_gbk;
+extern pm_encoding_t pm_encoding_ibm437;
extern pm_encoding_t pm_encoding_iso_8859_1;
extern pm_encoding_t pm_encoding_iso_8859_2;
extern pm_encoding_t pm_encoding_iso_8859_3;
diff --git a/prism/enc/pm_tables.c b/prism/enc/pm_tables.c
index 9bb56e81ce..0e3f4a6fa3 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 IBM437 character.
+ */
+static uint8_t pm_encoding_ibm437_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 ISO-8859-1 character.
*/
static uint8_t pm_encoding_iso_8859_1_table[256] = {
@@ -764,6 +788,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(ibm437)
PRISM_ENCODING_TABLE(iso_8859_1)
PRISM_ENCODING_TABLE(iso_8859_2)
PRISM_ENCODING_TABLE(iso_8859_3)
@@ -842,6 +867,16 @@ pm_encoding_t pm_encoding_cp855 = {
.multibyte = false
};
+/** IBM437 */
+pm_encoding_t pm_encoding_ibm437 = {
+ .name = "IBM437",
+ .char_width = pm_encoding_single_char_width,
+ .alnum_char = pm_encoding_ibm437_alnum_char,
+ .alpha_char = pm_encoding_ibm437_alpha_char,
+ .isupper_char = pm_encoding_ibm437_isupper_char,
+ .multibyte = false
+};
+
/** ISO-8859-1 */
pm_encoding_t pm_encoding_iso_8859_1 = {
.name = "ISO-8859-1",
diff --git a/prism/prism.c b/prism/prism.c
index e9cbe08a68..93964a8e45 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -6072,6 +6072,7 @@ parser_lex_magic_comment_encoding_value(pm_parser_t *parser, const uint8_t *star
ENCODING1("CP852", pm_encoding_cp852);
ENCODING1("CP855", pm_encoding_cp855);
ENCODING2("GBK", "CP936", pm_encoding_gbk);
+ ENCODING2("IBM437", "CP437", pm_encoding_ibm437);
ENCODING2("ISO-8859-1", "ISO8859-1", pm_encoding_iso_8859_1);
ENCODING2("ISO-8859-2", "ISO8859-2", pm_encoding_iso_8859_2);
ENCODING2("ISO-8859-3", "ISO8859-3", pm_encoding_iso_8859_3);
diff --git a/test/prism/encoding_test.rb b/test/prism/encoding_test.rb
index bd0911e96e..2c01f9e06d 100644
--- a/test/prism/encoding_test.rb
+++ b/test/prism/encoding_test.rb
@@ -14,6 +14,7 @@ module Prism
Encoding::CP855,
Encoding::EUC_JP,
Encoding::GBK,
+ Encoding::IBM437,
Encoding::ISO_8859_1,
Encoding::ISO_8859_2,
Encoding::ISO_8859_3,