1 /* Copyright (C) 1999 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 #include <gnu/gcj/convert/Input_SJIS.h>
13 #define ERROR_CHAR 0xFFFD
15 extern unsigned short JIS0208_to_Unicode
[84][94];
16 extern unsigned short JIS0212_to_Unicode
[76][94];
19 gnu::gcj::convert::Input_SJIS::read(jcharArray outbuffer
, jint outpos
,
22 jint start_outpos
= outpos
;
25 if (outpos
- start_outpos
>= count
)
27 if (inpos
>= inlength
)
29 int b
= ((unsigned char*) elements(inbuffer
))[inpos
++];
35 // Technically, we should translate 0x5c to Yen symbol;
36 // in practice, it is not clear.
38 b
= 0x00A5; // Yen sign.
40 elements(outbuffer
)[outpos
++] = (char) b
;
42 else if (b
>= 0xA1 && b
<= 0xDF)
45 elements(outbuffer
)[outpos
++] = b
;
52 // From Lunde: "CJKV Informatio Processing", O'Reilly, 1999, p 420:
53 bool adjust
= b
< 159;
54 int rowOffset
= first_byte
< 160 ? 112 : 176;
55 int cellOffset
= adjust
? (b
> 127 ? 32 : 31) : 126;
56 first_byte
= ((first_byte
- rowOffset
) << 1) - adjust
;
62 if ((unsigned) first_byte
>= 84 || (unsigned) b
>= 94)
66 b
= JIS0208_to_Unicode
[first_byte
][b
];
70 elements(outbuffer
)[outpos
++] = b
;
75 return outpos
- start_outpos
;