summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaple Ong <maple.ong@gusto.com>2023-11-15 15:40:34 -0800
committergit <svn-admin@ruby-lang.org>2023-11-16 17:13:16 +0000
commit5277cf3eefd9401957349b4611caaaa65d99ec80 (patch)
treeae461c634c22779b9894c7def8db3c33e9235eda
parent81b35fe7297957d78715a812f6edecec23c6e3b2 (diff)
[ruby/prism] Add cp51932 encoding file
https://github.com/ruby/prism/commit/c67a0f4c78
-rw-r--r--prism/enc/pm_cp51932.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/prism/enc/pm_cp51932.c b/prism/enc/pm_cp51932.c
new file mode 100644
index 0000000000..75c9fb824f
--- /dev/null
+++ b/prism/enc/pm_cp51932.c
@@ -0,0 +1,57 @@
+#include "prism/enc/pm_encoding.h"
+
+static size_t
+pm_encoding_cp51932_char_width(const uint8_t *b, ptrdiff_t n) {
+ // These are the single byte characters.
+ if (*b < 0x80) {
+ return 1;
+ }
+
+ // These are the double byte characters.
+ if (
+ (n > 1) &&
+ ((b[0] >= 0xa1 && b[0] <= 0xfe) || (b[0] == 0x8e)) &&
+ (b[1] >= 0xa1 && b[1] <= 0xfe)
+ ) {
+ return 2;
+ }
+
+ return 0;
+}
+
+static size_t
+pm_encoding_cp51932_alpha_char(const uint8_t *b, ptrdiff_t n) {
+ if (pm_encoding_cp51932_char_width(b, n) == 1) {
+ return pm_encoding_ascii_alpha_char(b, n);
+ } else {
+ return 0;
+ }
+}
+
+static size_t
+pm_encoding_cp51932_alnum_char(const uint8_t *b, ptrdiff_t n) {
+ if (pm_encoding_cp51932_char_width(b, n) == 1) {
+ return pm_encoding_ascii_alnum_char(b, n);
+ } else {
+ return 0;
+ }
+}
+
+static bool
+pm_encoding_cp51932_isupper_char(const uint8_t *b, ptrdiff_t n) {
+ if (pm_encoding_cp51932_char_width(b, n) == 1) {
+ return pm_encoding_ascii_isupper_char(b, n);
+ } else {
+ return 0;
+ }
+}
+
+/** cp51932 encoding */
+pm_encoding_t pm_encoding_cp51932 = {
+ .name = "cp51932",
+ .char_width = pm_encoding_cp51932_char_width,
+ .alnum_char = pm_encoding_cp51932_alnum_char,
+ .alpha_char = pm_encoding_cp51932_alpha_char,
+ .isupper_char = pm_encoding_cp51932_isupper_char,
+ .multibyte = true
+};