Title: String Utility
Description: Collection of string handling utilities
Copyright: Copyright (c) 2001
Company: SuperLink Software, Inc.
| Method from org.apache.cocoon.poi.util.StringUtil Detail: |
public static String getFromUnicode(byte[] string) {
return getFromUnicode(string, 0, string.length / 2);
}
given a byte array of 16-bit unicode characters, compress to
8-bit and return a string |
public static String getFromUnicode(byte[] string,
int offset,
int len) throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
if ((offset < 0) || (offset >= string.length))
{
throw new ArrayIndexOutOfBoundsException("Illegal offset");
}
if ((len < 0) || (((string.length - offset) / 2) < len))
{
throw new IllegalArgumentException("Illegal length");
}
byte[] bstring = new byte[ len ];
int index = offset + 1; // start with low bits.
for (int k = 0; k < len; k++)
{
bstring[ k ] = string[ index ];
index += 2;
}
return new String(bstring);
}
given a byte array of 16-bit unicode characters, compress to
8-bit and return a string |
public static void putCompressedUnicode(String input,
byte[] output,
int offset) {
char[] temp = input.toCharArray();
for (int k = 0; k < temp.length; k++)
{
output[ offset + k ] = ( byte ) temp[ k ];
}
}
|
public static void putUncompressedUnicode(String input,
byte[] output,
int offset) {
char[] temp = input.toCharArray();
for (int k = 0; k < temp.length; k++)
{
output[ offset + (2 * k) ] = ( byte ) temp[ k ];
output[ offset + (2 * k) + 1 ] = ( byte ) (temp[ k ] > > 8);
}
}
Write uncompressed unicode |