aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/util
diff options
context:
space:
mode:
authorAndrew C. Oliver <acoliver@apache.org>2002-09-02 02:11:16 +0000
committerAndrew C. Oliver <acoliver@apache.org>2002-09-02 02:11:16 +0000
commit4c9734a2cbf6a095c2fc536b6fb3afb95e062c57 (patch)
tree2147012a7acb614e78cee995aee76dc19312e748 /src/java/org/apache/poi/util
parent8748ed6a08510f907dd14cc358418d0ecfe681ca (diff)
downloadpoi-4c9734a2cbf6a095c2fc536b6fb3afb95e062c57.tar.gz
poi-4c9734a2cbf6a095c2fc536b6fb3afb95e062c57.zip
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11010 - great patch by
sergei.... if he'd learn to do diff -u patches instead of the nasty kind I'd be loving his work alot right now ;-) PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352831 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/util')
-rw-r--r--src/java/org/apache/poi/util/StringUtil.java55
1 files changed, 40 insertions, 15 deletions
diff --git a/src/java/org/apache/poi/util/StringUtil.java b/src/java/org/apache/poi/util/StringUtil.java
index b1b5bc8414..059e36acd8 100644
--- a/src/java/org/apache/poi/util/StringUtil.java
+++ b/src/java/org/apache/poi/util/StringUtil.java
@@ -62,8 +62,14 @@ import java.text.FieldPosition;
/**
* Title: String Utility Description: Collection of string handling utilities
+ *
+ * Now it is quite confusing: the method pairs, in which
+ * one of them write data and other read written data are:
+ * putUncompressedUnicodeHigh and getFromUnicode
+ * putUncompressedUnicode and getFromUnicodeHigh
*
*@author Andrew C. Oliver
+ *@author Sergei Kozello (sergeikozello at mail.ru)
*@created May 10, 2002
*@version 1.0
*/
@@ -79,6 +85,8 @@ public class StringUtil {
* given a byte array of 16-bit unicode characters, compress to 8-bit and
* return a string
*
+ * { 0x16, 0x00 } -> 0x16
+ *
*@param string the byte array to be converted
*@param offset the initial offset into the
* byte array. it is assumed that string[ offset ] and string[ offset +
@@ -103,22 +111,37 @@ public class StringUtil {
if ((len < 0) || (((string.length - offset) / 2) < len)) {
throw new IllegalArgumentException("Illegal length");
}
- byte[] bstring = new byte[len];
- int index = offset;
- // start with high bits.
-
- for (int k = 0; k < len; k++) {
- bstring[k] = string[index];
- index += 2;
+
+ char[] chars = new char[ len ];
+ for ( int i = 0; i < chars.length; i++ ) {
+ chars[i] = (char)( string[ offset + ( 2*i ) ] +
+ ( string[ offset + ( 2*i+1 ) ] << 8 ) );
}
- return new String(bstring);
+
+ return new String( chars );
}
+ /**
+ * given a byte array of 16-bit unicode characters, compress to 8-bit and
+ * return a string
+ *
+ * { 0x16, 0x00 } -> 0x16
+ *
+ *@param string the byte array to be converted
+ *@return the converted string
+ */
+
+ public static String getFromUnicodeHigh( final byte[] string ) {
+ return getFromUnicodeHigh( string, 0, string.length / 2 );
+ }
+
/**
* given a byte array of 16-bit unicode characters, compress to 8-bit and
* return a string
+ *
+ * { 0x00, 0x16 } -> 0x16
*
*@param string the byte array to be converted
*@param offset the initial offset into the
@@ -144,21 +167,23 @@ public class StringUtil {
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;
+
+ char[] chars = new char[ len ];
+ for ( int i = 0; i < chars.length; i++ ) {
+ chars[i] = (char)( ( string[ offset + ( 2*i ) ] << 8 ) +
+ string[ offset + ( 2*i+1 ) ] );
}
- return new String(bstring);
+
+ return new String( chars );
}
/**
* given a byte array of 16-bit unicode characters, compress to 8-bit and
* return a string
+ *
+ * { 0x00, 0x16 } -> 0x16
*
*@param string the byte array to be converted
*@return the converted string