summaryrefslogtreecommitdiff
path: root/libjava/gnu/gcj/convert/natInput_SJIS.cc
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/gnu/gcj/convert/natInput_SJIS.cc
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libjava/gnu/gcj/convert/natInput_SJIS.cc')
-rw-r--r--libjava/gnu/gcj/convert/natInput_SJIS.cc76
1 files changed, 76 insertions, 0 deletions
diff --git a/libjava/gnu/gcj/convert/natInput_SJIS.cc b/libjava/gnu/gcj/convert/natInput_SJIS.cc
new file mode 100644
index 000000000..c7f11ade0
--- /dev/null
+++ b/libjava/gnu/gcj/convert/natInput_SJIS.cc
@@ -0,0 +1,76 @@
+/* Copyright (C) 1999 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+#include <gcj/cni.h>
+#include <gnu/gcj/convert/Input_SJIS.h>
+
+#define ERROR_CHAR 0xFFFD
+
+extern unsigned short JIS0208_to_Unicode[84][94];
+extern unsigned short JIS0212_to_Unicode[76][94];
+
+jint
+gnu::gcj::convert::Input_SJIS::read(jcharArray outbuffer, jint outpos,
+ jint count)
+{
+ jint start_outpos = outpos;
+ for (;;)
+ {
+ if (outpos - start_outpos >= count)
+ break;
+ if (inpos >= inlength)
+ break;
+ int b = ((unsigned char*) elements(inbuffer))[inpos++];
+ if (first_byte == 0)
+ {
+ if (b < 128)
+ {
+#if 1
+ // Technically, we should translate 0x5c to Yen symbol;
+ // in practice, it is not clear.
+ if (b == 0x5c)
+ b = 0x00A5; // Yen sign.
+#endif
+ elements(outbuffer)[outpos++] = (char) b;
+ }
+ else if (b >= 0xA1 && b <= 0xDF)
+ {
+ b += 0xFF61 - 0xA1;
+ elements(outbuffer)[outpos++] = b;
+ }
+ else
+ first_byte = b;
+ }
+ else
+ {
+ // From Lunde: "CJKV Informatio Processing", O'Reilly, 1999, p 420:
+ bool adjust = b < 159;
+ int rowOffset = first_byte < 160 ? 112 : 176;
+ int cellOffset = adjust ? (b > 127 ? 32 : 31) : 126;
+ first_byte = ((first_byte - rowOffset) << 1) - adjust;
+ b -= cellOffset;
+
+ first_byte -= 33;
+ b -= 33;
+
+ if ((unsigned) first_byte >= 84 || (unsigned) b >= 94)
+ b = ERROR_CHAR;
+ else
+ {
+ b = JIS0208_to_Unicode[first_byte][b];
+ if (b == 0)
+ b = ERROR_CHAR;
+ }
+ elements(outbuffer)[outpos++] = b;
+
+ first_byte = 0;
+ }
+ }
+ return outpos - start_outpos;
+}