aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPer Bothner <bothner@gcc.gnu.org>1999-04-16 10:22:02 -0700
committerPer Bothner <bothner@gcc.gnu.org>1999-04-16 10:22:02 -0700
commit2012fd2db0eae2abfc09c43fc58ebd605c1a1da9 (patch)
tree2a12dcf74335a9116c0605d4bd6fa63a1a66e2fe
parentc80eb46728381731106e0f54725cd1b8285c3a15 (diff)
downloadgcc-2012fd2db0eae2abfc09c43fc58ebd605c1a1da9.zip
gcc-2012fd2db0eae2abfc09c43fc58ebd605c1a1da9.tar.gz
gcc-2012fd2db0eae2abfc09c43fc58ebd605c1a1da9.tar.bz2
UnicodeToBytes.java (write(String,int,int,char[])): New overloading, allows greater efficiency.
� * gnu/gcj/convert/UnicodeToBytes.java (write(String,int,int,char[])): New overloading, allows greater efficiency. * gnu/gcj/convert/Output_8859_1.java (write(String,int,int,char[])): New overloading (for efficiency - avoids copying). * gnu/gcj/convert/Output_UTF8.java: Fix typo: 0xC0 -> 0c3F. * gnu/gcj/convert/Input_UTF8.java: Fix typos in bit masks. From-SVN: r26494
-rw-r--r--libjava/gnu/gcj/convert/Input_UTF8.java10
-rw-r--r--libjava/gnu/gcj/convert/Output_8859_1.java22
-rw-r--r--libjava/gnu/gcj/convert/UnicodeToBytes.java23
3 files changed, 51 insertions, 4 deletions
diff --git a/libjava/gnu/gcj/convert/Input_UTF8.java b/libjava/gnu/gcj/convert/Input_UTF8.java
index c706a52..0bb5c48 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 <bothner@cygnus.com>
+ * @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 ef6e211..8dd9f43 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 <bothner@cygnus.com>
+ * @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 4b772f9..7ab92a8 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);
+ }
+
}