From 4eb8d195bd804339d42ff869cda2d8cc8dbb4c64 Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Wed, 26 Jun 2002 12:25:44 +0000 Subject: [PATCH] This supposidly makes japanese text work. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352724 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/record/UnicodeString.java | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/UnicodeString.java b/src/java/org/apache/poi/hssf/record/UnicodeString.java index d56b660d4..af594a667 100644 --- a/src/java/org/apache/poi/hssf/record/UnicodeString.java +++ b/src/java/org/apache/poi/hssf/record/UnicodeString.java @@ -292,17 +292,43 @@ public class UnicodeString public int serialize(int offset, byte [] data) { + int charsize = 1; + + if (getOptionFlags() == 1) + { + charsize = 2; + } + + // byte[] retval = new byte[ 3 + (getString().length() * charsize)]; LittleEndian.putShort(data, 0 + offset, getCharCount()); data[ 2 + offset ] = getOptionFlags(); - if (!isUncompressedUnicode()) - { - StringUtil.putCompressedUnicode(getString(), data, 0x3 + offset); +// System.out.println("Unicode: We've got "+retval[2]+" for our option flag"); + try { + String unicodeString = new +String(getString().getBytes("Unicode"),"Unicode"); + if (getOptionFlags() == 0) + { + StringUtil.putCompressedUnicode(unicodeString, data, 0x3 + +offset); + } + else + { + StringUtil.putUncompressedUnicode(unicodeString, data, + 0x3 + offset); + } } - else - { - StringUtil.putUncompressedUnicode(getString(), data, - 0x3 + offset); + catch (Exception e) { + if (getOptionFlags() == 0) + { + StringUtil.putCompressedUnicode(getString(), data, 0x3 + + offset); + } + else + { + StringUtil.putUncompressedUnicode(getString(), data, + 0x3 + offset); + } } return getRecordSize(); }