summaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>1999-04-16 17:22:02 +0000
committerbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>1999-04-16 17:22:02 +0000
commitf7fdfabb16bac8562669335a5d1ca582fb97ede7 (patch)
tree2a12dcf74335a9116c0605d4bd6fa63a1a66e2fe /libjava
parent7cec1e64c0dc8d6c88b25b997fd5a22d1a717bc0 (diff)
downloadgcc-f7fdfabb16bac8562669335a5d1ca582fb97ede7.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@26494 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-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 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 <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 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 <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 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);
+ }
+
}