Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ruby/prism] Add MacJapanese encoding
MacJapanese (also aliased as MacJapan) is a modified Shift_JIS encoding, but is implemented identically in Ruby ruby/prism@9e0a097699
- Loading branch information
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "prism/enc/pm_encoding.h" | ||
|
||
static size_t | ||
pm_encoding_mac_japanese_char_width(const uint8_t *b, ptrdiff_t n) { | ||
// These are the single byte characters. | ||
if (*b < 0x80 || (*b >= 0xA1 && *b <= 0xDF)) { | ||
return 1; | ||
} | ||
|
||
// These are the double byte characters. | ||
if ( | ||
(n > 1) && | ||
((b[0] >= 0x81 && b[0] <= 0x9F) || (b[0] >= 0xE0 && b[0] <= 0xFC)) && | ||
(b[1] >= 0x40 && b[1] <= 0xFC) | ||
) { | ||
return 2; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static size_t | ||
pm_encoding_mac_japanese_alpha_char(const uint8_t *b, ptrdiff_t n) { | ||
if (pm_encoding_mac_japanese_char_width(b, n) == 1) { | ||
return pm_encoding_ascii_alpha_char(b, n); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
static size_t | ||
pm_encoding_mac_japanese_alnum_char(const uint8_t *b, ptrdiff_t n) { | ||
if (pm_encoding_mac_japanese_char_width(b, n) == 1) { | ||
return pm_encoding_ascii_alnum_char(b, n); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
static bool | ||
pm_encoding_mac_japanese_isupper_char(const uint8_t *b, ptrdiff_t n) { | ||
if (pm_encoding_mac_japanese_char_width(b, n) == 1) { | ||
return pm_encoding_ascii_isupper_char(b, n); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
/** MacJapanese encoding */ | ||
pm_encoding_t pm_encoding_mac_japanese = { | ||
.name = "MacJapanese", | ||
.char_width = pm_encoding_mac_japanese_char_width, | ||
.alnum_char = pm_encoding_mac_japanese_alnum_char, | ||
.alpha_char = pm_encoding_mac_japanese_alpha_char, | ||
.isupper_char = pm_encoding_mac_japanese_isupper_char, | ||
.multibyte = true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters