use crate::{DecodeError, Decoder, EncodeError, Encoder, jisx, ksx};
pub struct EUCDecoder {
// G0 implicitly designate ASCII.
// Each buffer is assumed to be either 94, 96, 94^n, or 96^n.
// G1 buffer
g1: &'static [&'static [char]],
// G2 buffer
g2: &'static [&'static [char]],
// G3 buffer
g3: &'static [&'static [char]],
}
impl EUCDecoder {
/// If no error occurs, return `Ok((read_bytes, write_bytes))`.
fn decode(
&mut self,
src: &[u8],
dst: &mut String,
finish: bool,
) -> Result<(usize, usize), DecodeError> {
if src.is_empty() {
return if finish {
Ok((0, 0))
} else {
Err(DecodeError::InputIsEmpty)
};
}
let len = dst.capacity() - dst.len();
if len < 4 {
return Err(DecodeError::OutputTooShort);
}
let (mut read, mut write) = (0, 0);
macro_rules! malformed {
( $length:expr ) => {
Err(DecodeError::Malformed {
read,
write,
length: $length,
offset: 0,
})
};
}
while read < src.len() {
match src[read..] {
[0x8E, ..] | [0x8F, ..] => {
// SS2/SS3
let g = if src[read] == 0x8E {
&self.g2
} else {
&self.g3
};
read += 1;
if read >= src.len() {
if finish {
return malformed!(1);
}
break;
}
if src[read] < 0xA0 {
read += 1;
return malformed!(1);
}
let s = src[read] as usize - 0xA0;
read += 1;
if g.len() == 1 {
let c = g[0][s];
if g[0].len() <= s || g[0][s] == char::REPLACEMENT_CHARACTER {
return malformed!(2);
}
dst.push(c);
write += c.len_utf8();
} else {
if read >= src.len() {
if finish {
return malformed!(2);
}
break;
}
if src[read] < 0xA0 {
read += 1;
return malformed!(3);
}
let t = src[read] as usize - 0xA0;
read += 1;
if g.len() <= s || g[s].len() <= t || g[s][t] == char::REPLACEMENT_CHARACTER
{
return malformed!(3);
}
let c = g[s][t];
dst.push(c);
write += c.len_utf8();
}
}
_ => {
if src[read] < 0xA0 {
// GL (G0, ASCII) and CR
// I'm not sure if this is the correct way to handle CR...
// uconv seems to return the original value for EUC-JP/CN/KR.
// However, iconv appears to return the original value for EUC-JP/KR,
// but returns an error for EUC-CN.
let c = src[read] as char;
dst.push(c);
read += 1;
write += c.len_utf8();
} else {
// GR (G1)
if self.g1.len() > 1 {
// multibyte character
if read + 1 == src.len() {
// The second byte of multibyte characters cannot be read.
if finish {
read += 1;
return malformed!(1);
}
break;
}
let s = src[read] as usize - 0xA0;
if src[read + 1] < 0xA0 {
read += 2;
return malformed!(2);
}
let t = src[read + 1] as usize - 0xA0;
read += 2;
if self.g1.len() <= s
|| self.g1[s].len() <= t
|| self.g1[s][t] == char::REPLACEMENT_CHARACTER
{
return malformed!(2);
}
let c = self.g1[s][t];
dst.push(c);
write += c.len_utf8();
} else {
// singlebyte character
let c = self.g1[0][src[read] as usize - 0xA0];
read += 1;
if c == char::REPLACEMENT_CHARACTER {
return malformed!(1);
} else {
dst.push(c);
write += c.len_utf8();
}
}
}
}
}
if dst.capacity() - dst.len() < 4 {
break;
}
}
Ok((read, write))
}
}
pub struct EUCEncoder<
G1From,
G1To,
G2From,
G2To,
G3From,
G3To,
const G1DIM: u8,
const G2DIM: u8,
const G3DIM: u8,
> where
G1From: Into<u32> + 'static,
G1To: Into<u32> + 'static,
G2From: Into<u32> + 'static,
G2To: Into<u32> + 'static,
G3From: Into<u32> + 'static,
G3To: Into<u32> + 'static,
{
// G0 implicitly designate ASCII.
// G1 buffer
g1: &'static [(G1From, G1To)],
// G2 buffer
g2: &'static [(G2From, G2To)],
// G3 buffer
g3: &'static [(G3From, G3To)],
}
impl<G1From, G1To, G2From, G2To, G3From, G3To, const G1DIM: u8, const G2DIM: u8, const G3DIM: u8>
EUCEncoder<G1From, G1To, G2From, G2To, G3From, G3To, G1DIM, G2DIM, G3DIM>
where
G1From: Into<u32> + Copy,
G1To: Into<u32> + Copy,
G2From: Into<u32> + Copy,
G2To: Into<u32> + Copy,
G3From: Into<u32> + Copy,
G3To: Into<u32> + Copy,
{
/// If no error occurs, return `Ok((read_bytes, write_bytes))`.
fn encode(
&mut self,
src: &str,
dst: &mut [u8],
finish: bool,
) -> Result<(usize, usize), EncodeError> {
assert!(0 < G1DIM && G1DIM <= 2 && 0 < G2DIM && G2DIM <= 2 && 0 < G3DIM && G3DIM <= 2);
if src.is_empty() {
return if finish {
Ok((0, 0))
} else {
Err(EncodeError::InputIsEmpty)
};
}
if dst.len() < 3 {
return Err(EncodeError::OutputTooShort);
}
let (mut read, mut write) = (0, 0);
macro_rules! write_buffer {
( $dim:expr, $to:expr ) => {
if $dim == 1 {
assert!($to < u8::MAX as u32);
dst[write] = $to as u8 + 0xA0;
write += 1;
} else if $dim == 2 {
let to = $to + 0x8080;
dst[write] = (to >> 8) as u8;
dst[write + 1] = (to & 0xFF) as u8;
write += 2;
} else {
unreachable!();
}
};
}
for c in src.chars() {
read += c.len_utf8();
if c.is_ascii() || ((..'\u{A0}').contains(&c) && c != '\u{8E}' && c != '\u{8F}') {
dst[read] = c as u8;
write += 1;
} else if let Ok(pos) = self.g1.binary_search_by_key(&(c as u32), |e| e.0.into()) {
let to = self.g1[pos].1.into();
write_buffer!(G1DIM, to);
} else if let Ok(pos) = self.g2.binary_search_by_key(&(c as u32), |e| e.0.into()) {
dst[write] = 0x8E;
write += 1;
let to = self.g2[pos].1.into();
write_buffer!(G2DIM, to);
} else if let Ok(pos) = self.g3.binary_search_by_key(&(c as u32), |e| e.0.into()) {
dst[write] = 0x8F;
write += 1;
let to = self.g3[pos].1.into();
write_buffer!(G3DIM, to);
} else {
return Err(EncodeError::Unmappable { read, write, c });
}
if dst[write..].len() < 3 {
break;
}
}
Ok((read, write))
}
}
/// Encoding name for EUC-JP.
pub const EUCJP_NAME: &str = "EUC-JP";
/// Decoder for EUC-JP.
pub struct EUCJPDecoder {
decoder: EUCDecoder,
}
pub(crate) fn eucjp_decoder_factory() -> Box<dyn Decoder> {
static G2: &[&[char]] = &[jisx::JIS_X_0201_KATAKANA_DECODE_TABLE];
Box::new(EUCJPDecoder {
decoder: EUCDecoder {
g1: &jisx::JIS_X_0208_DECODE_TABLE,
g2: G2,
g3: &jisx::JIS_X_0212_DECODE_TABLE,
},
})
}
impl Decoder for EUCJPDecoder {
fn name(&self) -> &'static str {
EUCJP_NAME
}
fn decode(
&mut self,
src: &[u8],
dst: &mut String,
finish: bool,
) -> Result<(usize, usize), DecodeError> {
self.decoder.decode(src, dst, finish)
}
}
/// Encoder for EUC-JP.
pub struct EUCJPEncoder {
encoder: EUCEncoder<u16, u16, u16, u8, u16, u16, 2, 1, 2>,
}
pub(crate) fn eucjp_encoder_factory() -> Box<dyn Encoder> {
Box::new(EUCJPEncoder {
encoder: EUCEncoder {
g1: jisx::JIS_X_0208_ENCODE_TABLE,
g2: jisx::JIS_X_0201_KATAKANA_ENCODE_TABLE,
g3: jisx::JIS_X_0212_ENCODE_TABLE,
},
})
}
impl Encoder for EUCJPEncoder {
fn name(&self) -> &'static str {
EUCJP_NAME
}
fn encode(
&mut self,
src: &str,
dst: &mut [u8],
finish: bool,
) -> Result<(usize, usize), EncodeError> {
self.encoder.encode(src, dst, finish)
}
}
/// Encoding name for EUC-KR.
pub const EUCKR_NAME: &str = "EUC-KR";
/// Decoder for EUC-KR.
pub struct EUCKRDecoder {
decoder: EUCDecoder,
}
pub(crate) fn euckr_decoder_factory() -> Box<dyn Decoder> {
Box::new(EUCKRDecoder {
decoder: EUCDecoder {
g1: &ksx::KS_X_1001_DECODE_TABLE,
g2: &[&[]],
g3: &[&[]],
},
})
}
impl Decoder for EUCKRDecoder {
fn name(&self) -> &'static str {
EUCKR_NAME
}
fn decode(
&mut self,
src: &[u8],
dst: &mut String,
finish: bool,
) -> Result<(usize, usize), DecodeError> {
self.decoder.decode(src, dst, finish)
}
}
/// Encoder for EUC-KR.
pub struct EUCKREncoder {
encoder: EUCEncoder<u16, u16, u8, u8, u8, u8, 2, 1, 1>,
}
pub(crate) fn euckr_encoder_factory() -> Box<dyn Encoder> {
Box::new(EUCKREncoder {
encoder: EUCEncoder {
g1: ksx::KS_X_1001_ENCODE_TABLE,
g2: &[],
g3: &[],
},
})
}
impl Encoder for EUCKREncoder {
fn name(&self) -> &'static str {
EUCKR_NAME
}
fn encode(
&mut self,
src: &str,
dst: &mut [u8],
finish: bool,
) -> Result<(usize, usize), EncodeError> {
self.encoder.encode(src, dst, finish)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn eucjp_katakana_tests() {
let bytes = &[
0x8e, 0xb1, 0x8e, 0xb2, 0x8e, 0xb3, 0x8e, 0xb4, 0x8e, 0xb5, 0x8e, 0xb6, 0x8e, 0xb7,
0x8e, 0xb8, 0x8e, 0xb9, 0x8e, 0xba, 0x8e, 0xbb, 0x8e, 0xbc, 0x8e, 0xbd, 0x8e, 0xbe,
0x8e, 0xbf, 0x8e, 0xc0, 0x8e, 0xc1, 0x8e, 0xc2, 0x8e, 0xc3, 0x8e, 0xc4, 0x8e, 0xc5,
0x8e, 0xc6, 0x8e, 0xc7, 0x8e, 0xc8, 0x8e, 0xc9, 0x8e, 0xca, 0x8e, 0xcb, 0x8e, 0xcc,
0x8e, 0xcd, 0x8e, 0xce, 0x8e, 0xcf, 0x8e, 0xd0, 0x8e, 0xd1, 0x8e, 0xd2, 0x8e, 0xd3,
0x8e, 0xd4, 0x8e, 0xd5, 0x8e, 0xd6, 0x8e, 0xd7, 0x8e, 0xd8, 0x8e, 0xd9, 0x8e, 0xda,
0x8e, 0xdb, 0x8e, 0xdc, 0x8e, 0xa6, 0x8e, 0xdd,
];
let mut buf = String::with_capacity(512);
eucjp_decoder_factory()
.decode(bytes, &mut buf, true)
.unwrap();
assert_eq!(buf, "アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン");
}
#[test]
fn eucjp_kanji_tests() {
let bytes = &[
0xc4, 0xbf, 0xb9, 0xf1, 0xb2, 0xc8, 0xa5, 0xce, 0xce, 0xb4, 0xbe, 0xbb, 0xa5, 0xc8,
0xbf, 0xc3, 0xcc, 0xb1, 0xa5, 0xce, 0xb7, 0xc4, 0xca, 0xa1, 0xa5, 0xc8, 0xa5, 0xf2,
0xb0, 0xca, 0xa5, 0xc6, 0xc3, 0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, 0xbb, 0xf6, 0xa5, 0xf2, 0xbe, 0xa9, 0xbd, 0xe7, 0xa5,
0xb7, 0xc1, 0xea, 0xcd, 0xbf, 0xa5, 0xcb, 0xcf, 0xc2, 0xc3, 0xef, 0xb6, 0xa8, 0xc6,
0xb1, 0xa5, 0xb7, 0xb1, 0xd7, 0xa1, 0xb9, 0xb2, 0xe6, 0xa5, 0xab, 0xc4, 0xeb, 0xb9,
0xf1, 0xa5, 0xce, 0xb8, 0xf7, 0xb1, 0xc9, 0xa5, 0xf2, 0xc3, 0xe6, 0xb3, 0xb0, 0xa5,
0xcb, 0xc0, 0xeb, 0xcd, 0xc8, 0xa5, 0xb7, 0xc1, 0xc4, 0xbd, 0xa1, 0xa5, 0xce, 0xb0,
0xe4, 0xb6, 0xc8, 0xa5, 0xf2, 0xb1, 0xca, 0xb5, 0xd7, 0xa5, 0xcb, 0xf0, 0xdf, 0xb8,
0xc7, 0xa5, 0xca, 0xa5, 0xe9, 0xa5, 0xb7, 0xa5, 0xe0, 0xa5, 0xeb, 0xa5, 0xce, 0xb4,
0xf5, 0xcb, 0xbe, 0xa5, 0xf2, 0xc6, 0xb1, 0xa5, 0xaf, 0xa5, 0xb7, 0xba, 0xa1, 0xa5,
0xce, 0xc9, 0xe9, 0xc3, 0xb4, 0xa5, 0xf2, 0xca, 0xac, 0xa5, 0xc4, 0xa5, 0xcb, 0xb4,
0xae, 0xa5, 0xd5, 0xa5, 0xeb, 0xa5, 0xb3, 0xa5, 0xc8, 0xa5, 0xf2, 0xb5, 0xbf, 0xa5,
0xcf, 0xa5, 0xb5, 0xa5, 0xeb, 0xa5, 0xca, 0xa5, 0xea,
];
let mut buf = String::with_capacity(1024);
let (read, _) = eucjp_decoder_factory()
.decode(bytes, &mut buf, true)
.unwrap();
assert_eq!(read, bytes.len());
assert_eq!(
buf,
"朕国家ノ隆昌ト臣民ノ慶福トヲ以テ中心ノ欣栄トシ朕カ祖宗ニ承クルノ大権ニ依リ現在及将来ノ臣民ニ対シ此ノ不磨ノ大典ヲ宣布ス\n惟フニ我カ祖我カ宗ハ我カ臣民祖先ノ協力輔翼ニ倚リ我カ帝国ヲ肇造シ以テ無窮ニ垂レタリ此レ我カ神聖ナル祖宗ノ威徳ト並ニ臣民ノ忠実勇武ニシテ国ヲ愛シ公ニ殉ヒ以テ此ノ光輝アル国史ノ成跡ヲ貽シタルナリ朕我カ臣民ハ即チ祖宗ノ忠良ナル臣民ノ子孫ナルヲ回想シ其ノ朕カ意ヲ奉体シ朕カ事ヲ奨順シ相与ニ和衷協同シ益々我カ帝国ノ光栄ヲ中外ニ宣揚シ祖宗ノ遺業ヲ永久ニ鞏固ナラシムルノ希望ヲ同クシ此ノ負担ヲ分ツニ堪フルコトヲ疑ハサルナリ"
);
}
#[test]
fn euckr_kanji_hangul_tests() {
let bytes = &[
0xea, 0xed, 0xce, 0xf9, 0xc7, 0xd1, 0x20, 0xd5, 0xf6, 0xde, 0xc8, 0xbf, 0xcd, 0x20,
0xee, 0xee, 0xf7, 0xd6, 0xbf, 0xa1, 0x20, 0xba, 0xfb, 0xb3, 0xaa, 0xb4, 0xc2, 0x20,
0xbf, 0xec, 0xb8, 0xae, 0x20, 0xd3, 0xde, 0xf9, 0xdb, 0xcf, 0xd0, 0xda, 0xc5, 0xc0,
0xba, 0x20, 0x33, 0xa1, 0xa4, 0x31, 0x20, 0xea, 0xa1, 0xd4, 0xd1, 0xc0, 0xb8, 0xb7,
0xce, 0x20, 0xcb, 0xef, 0xd8, 0xa1, 0xb5, 0xc8, 0x20, 0xd3, 0xde, 0xf9, 0xdb, 0xda,
0xc5, 0xcf, 0xd0, 0xd7, 0xfc, 0xe3, 0xc1, 0xef, 0xd9, 0xdd, 0xa4, 0xc0, 0xc7, 0x20,
0xdb, 0xf6, 0xf7, 0xd6, 0xb0, 0xfa, 0x20, 0xdc, 0xf4, 0xeb, 0xf9, 0xbf, 0xa1, 0x20,
0xf9, 0xf7, 0xcb, 0xde, 0xc7, 0xd1, 0x20, 0x34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0x20, 0xb4, 0xd9, 0xc1, 0xfc, 0xc7,
0xcf, 0xb8, 0xe9, 0xbc, 0xad, 0x20, 0x31, 0x39, 0x34, 0x38, 0xd2, 0xb4, 0x20, 0x37,
0xea, 0xc5, 0x20, 0x31, 0x32, 0xec, 0xed, 0xbf, 0xa1, 0x20, 0xf0, 0xa4, 0xef, 0xd2,
0xb5, 0xc7, 0xb0, 0xed, 0x20, 0x38, 0xf3, 0xad, 0xbf, 0xa1, 0x20, 0xb0, 0xc9, 0xc3,
0xc4, 0x20, 0xcb, 0xc7, 0xef, 0xe1, 0xb5, 0xc8, 0x20, 0xfa, 0xca, 0xdb, 0xf6, 0xc0,
0xbb, 0x20, 0xc0, 0xcc, 0xc1, 0xa6, 0x20, 0xcf, 0xd0, 0xfc, 0xe5, 0xc0, 0xc7, 0x20,
0xec, 0xa1, 0xcc, 0xbd, 0xc0, 0xbb, 0x20, 0xb0, 0xc5, 0xc3, 0xc4, 0x20, 0xcf, 0xd0,
0xda, 0xc5, 0xf7, 0xe1, 0xf8, 0xf9, 0xbf, 0xa1, 0x20, 0xeb, 0xee, 0xc7, 0xcf, 0xbf,
0xa9, 0x20, 0xcb, 0xc7, 0xef, 0xe1, 0xc7, 0xd1, 0xb4, 0xd9, 0x2e,
];
let mut buf = String::with_capacity(2048);
let (read, _) = euckr_decoder_factory()
.decode(bytes, &mut buf, true)
.unwrap();
assert_eq!(read, bytes.len());
assert_eq!(
buf,
"悠久한 歷史와 傳統에 빛나는 우리 大韓國民은 3·1 運動으로 建立된 大韓民國臨時政府의 法統과 不義에 抗拒한 4·19 民主理念을 繼承하고, 祖國의 民主改革과 平和的統一의 使命에 立脚하여 正義·人道와 同胞愛로써 民族의 團結을 鞏固히 하고, 모든 社會的弊習과 不義를 打破하며, 自律과 調和를 바탕으로 自由民主的基本秩序를 더욱 確固히 하여 政治·經濟·社會·文化의 모든 領域에 있어서 各人의 機會를 均等히 하고, 能力을 最高度로 發揮하게 하며, 自由와 權利에 따르는 責任과 義務를 完遂하게 하여, 안으로는 國民生活의 均等한 向上을 期하고 밖으로는 恒久的인 世界平和와 人類共榮에 이바지함으로써 우리들과 우리들의 子孫의 安全과 自由와 幸福을 永遠히 確保할 것을 다짐하면서 1948年 7月 12日에 制定되고 8次에 걸쳐 改正된 憲法을 이제 國會의 議決을 거쳐 國民投票에 依하여 改正한다."
);
}
}