UnicodeToBytes.java (write(String,int,int,char[])): New overloading, allows greater...
authorPer Bothner <bothner@gcc.gnu.org>
Fri, 16 Apr 1999 17:22:02 +0000 (10:22 -0700)
committerPer Bothner <bothner@gcc.gnu.org>
Fri, 16 Apr 1999 17:22:02 +0000 (10:22 -0700)

* 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

libjava/gnu/gcj/convert/Input_UTF8.java
libjava/gnu/gcj/convert/Output_8859_1.java
libjava/gnu/gcj/convert/UnicodeToBytes.java

index c706a5259a738143e00167d2f12c61569a875126..0bb5c48a13ebbf4aa821ace295598ab6ed4a7835 100644 (file)
@@ -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;
index ef6e211f9f8e67dae81cce60e5db89b0901fb91e..8dd9f43d717f80204a6fe095f1518557a6951f4a 100644 (file)
@@ -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;
+  }
 }
index 4b772f96edac7c52b69ec80cd31e2cc854073a0a..7ab92a8eefaa4a3367d6f9490342637a30813b77 100644 (file)
@@ -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);
+  }
+
 }