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
This commit is contained in:
parent
c80eb46728
commit
2012fd2db0
|
@ -8,6 +8,12 @@ details. */
|
||||||
|
|
||||||
package gnu.gcj.convert;
|
package gnu.gcj.convert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert UTF8 to Unicode.
|
||||||
|
* @author Per Bothner <bothner@cygnus.com>
|
||||||
|
* @date Match 1999.
|
||||||
|
*/
|
||||||
|
|
||||||
public class Input_UTF8 extends BytesToUnicode
|
public class Input_UTF8 extends BytesToUnicode
|
||||||
{
|
{
|
||||||
public String getName() { return "UTF8"; }
|
public String getName() { return "UTF8"; }
|
||||||
|
@ -84,12 +90,12 @@ public class Input_UTF8 extends BytesToUnicode
|
||||||
}
|
}
|
||||||
else // prefix byte
|
else // prefix byte
|
||||||
{
|
{
|
||||||
if ((b & 0xE) == 0xC0)
|
if ((b & 0xE0) == 0xC0)
|
||||||
{
|
{
|
||||||
partial = b & 0x1F;
|
partial = b & 0x1F;
|
||||||
partial_bytes_expected = 1;
|
partial_bytes_expected = 1;
|
||||||
}
|
}
|
||||||
else if ((b & 0xF) == 0xF0)
|
else if ((b & 0xF0) == 0xE0)
|
||||||
{
|
{
|
||||||
partial = b & 0xF;
|
partial = b & 0xF;
|
||||||
partial_bytes_expected = 2;
|
partial_bytes_expected = 2;
|
||||||
|
|
|
@ -8,6 +8,13 @@ details. */
|
||||||
|
|
||||||
package gnu.gcj.convert;
|
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 class Output_8859_1 extends UnicodeToBytes
|
||||||
{
|
{
|
||||||
public String getName() { return "8859_1"; }
|
public String getName() { return "8859_1"; }
|
||||||
|
@ -28,4 +35,19 @@ public class Output_8859_1 extends UnicodeToBytes
|
||||||
this.count = count;
|
this.count = count;
|
||||||
return inlength;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,11 +80,30 @@ public abstract class UnicodeToBytes
|
||||||
|
|
||||||
/** Convert chars to bytes.
|
/** Convert chars to bytes.
|
||||||
* Converted bytes are written to buf, starting at count.
|
* Converted bytes are written to buf, starting at count.
|
||||||
* @param inbuffer sources of characters to convert
|
* @param inbuffer source of characters to convert
|
||||||
* @param inpos index of initial character ininbuffer to convert
|
* @param inpos index of initial character in inbuffer to convert
|
||||||
* @param inlength number of characters to convert
|
* @param inlength number of characters to convert
|
||||||
* @return number of chars converted
|
* @return number of chars converted
|
||||||
* Also, this.count is increment by the number of bytes converted.
|
* Also, this.count is increment by the number of bytes converted.
|
||||||
*/
|
*/
|
||||||
public abstract int write (char[] inbuffer, int inpos, int inlength);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue