diff --git a/libjava/gnu/gcj/convert/Input_UTF8.java b/libjava/gnu/gcj/convert/Input_UTF8.java index c706a5259a7..0bb5c48a13e 100644 --- a/libjava/gnu/gcj/convert/Input_UTF8.java +++ b/libjava/gnu/gcj/convert/Input_UTF8.java @@ -8,6 +8,12 @@ details. */ package gnu.gcj.convert; +/** + * Convert UTF8 to Unicode. + * @author Per Bothner + * @date Match 1999. + */ + public class Input_UTF8 extends BytesToUnicode { public String getName() { return "UTF8"; } @@ -84,12 +90,12 @@ public class Input_UTF8 extends BytesToUnicode } else // prefix byte { - if ((b & 0xE) == 0xC0) + if ((b & 0xE0) == 0xC0) { partial = b & 0x1F; partial_bytes_expected = 1; } - else if ((b & 0xF) == 0xF0) + else if ((b & 0xF0) == 0xE0) { partial = b & 0xF; partial_bytes_expected = 2; diff --git a/libjava/gnu/gcj/convert/Output_8859_1.java b/libjava/gnu/gcj/convert/Output_8859_1.java index ef6e211f9f8..8dd9f43d717 100644 --- a/libjava/gnu/gcj/convert/Output_8859_1.java +++ b/libjava/gnu/gcj/convert/Output_8859_1.java @@ -8,6 +8,13 @@ details. */ package gnu.gcj.convert; +/** + * Convert Unicode ISO-Latin-1 (8851-1) text. + * The high-order byte of each character is truncated. + * @author Per Bothner + * @date Match 1999. + */ + public class Output_8859_1 extends UnicodeToBytes { public String getName() { return "8859_1"; } @@ -28,4 +35,19 @@ public class Output_8859_1 extends UnicodeToBytes this.count = count; return inlength; } + + public int write (String str, int inpos, int inlength, char[] work) + { + int count = this.count; + byte[] buf = this.buf; + int avail = buf.length - count; + if (inlength > avail) + inlength = avail; + for (int i = inlength; --i >= 0; ) + { + buf[count++] = (byte) str.charAt(inpos++); + } + this.count = count; + return inlength; + } } diff --git a/libjava/gnu/gcj/convert/UnicodeToBytes.java b/libjava/gnu/gcj/convert/UnicodeToBytes.java index 4b772f96eda..7ab92a8eefa 100644 --- a/libjava/gnu/gcj/convert/UnicodeToBytes.java +++ b/libjava/gnu/gcj/convert/UnicodeToBytes.java @@ -80,11 +80,30 @@ public abstract class UnicodeToBytes /** Convert chars to bytes. * Converted bytes are written to buf, starting at count. - * @param inbuffer sources of characters to convert - * @param inpos index of initial character ininbuffer to convert + * @param inbuffer source of characters to convert + * @param inpos index of initial character in inbuffer to convert * @param inlength number of characters to convert * @return number of chars converted * Also, this.count is increment by the number of bytes converted. */ public abstract int write (char[] inbuffer, int inpos, int inlength); + + /** Convert chars to bytes. + * Converted bytes are written to buf, starting at count. + * @param str source of characters to convert + * @param inpos index of initial character in str to convert + * @param inlength number of characters to convert + * @param work if non-null, a buffer than can be used + * @return number of chars converted + * Also, this.count is increment by the number of bytes converted. + */ + public int write (String str, int inpos, int inlength, char[] work) + { + if (work == null) + work = new char[inlength]; + int srcEnd = inpos + (inlength > work.length ? work.length : inlength); + str.getChars(inpos, srcEnd, work, 0); + return write(work, inpos, inlength); + } + }