poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r711513 - in /poi/trunk/src: java/org/apache/poi/hssf/record/constant/ java/org/apache/poi/hssf/record/formula/ java/org/apache/poi/util/ testcases/org/apache/poi/hssf/record/constant/ testcases/org/apache/poi/hssf/record/formula/
Date Wed, 05 Nov 2008 05:45:18 GMT
Author: josh
Date: Tue Nov  4 21:45:17 2008
New Revision: 711513

URL: http://svn.apache.org/viewvc?rev=711513&view=rev
Log:
Converted ConstantValueParser to use plain Strings instead of UnicodeStrings

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
    poi/trunk/src/java/org/apache/poi/util/StringUtil.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
    poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java?rev=711513&r1=711512&r2=711513&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java Tue Nov
 4 21:45:17 2008
@@ -17,8 +17,6 @@
 
 package org.apache.poi.hssf.record.constant;
 
-import org.apache.poi.hssf.record.UnicodeString;
-import org.apache.poi.hssf.record.UnicodeString.UnicodeRecordStats;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianOutput;
 import org.apache.poi.util.StringUtil;
@@ -65,7 +63,7 @@
 			case TYPE_NUMBER:
 				return new Double(in.readDouble());
 			case TYPE_STRING:
-				return new UnicodeString(StringUtil.readUnicodeString(in));
+				return StringUtil.readUnicodeString(in);
 			case TYPE_BOOLEAN:
 				return readBoolean(in);
 			case TYPE_ERROR_CODE:
@@ -111,10 +109,8 @@
 		if(cls == Boolean.class || cls == Double.class || cls == ErrorConstant.class) {
 			return 8;
 		}
-		UnicodeString strVal = (UnicodeString)object;
-		UnicodeRecordStats urs = new UnicodeRecordStats();
-		strVal.getRecordSize(urs);
-		return urs.recordSize;
+		String strVal = (String)object;
+		return StringUtil.getEncodedSize(strVal);
 	}
 
 	public static void encode(LittleEndianOutput out, Object[] values) {
@@ -142,10 +138,10 @@
 			out.writeDouble(dVal.doubleValue());
 			return;
 		}
-		if (value instanceof UnicodeString) {
-			UnicodeString usVal = (UnicodeString) value;
+		if (value instanceof String) {
+			String val = (String) value;
 			out.writeByte(TYPE_STRING);
-			StringUtil.writeUnicodeString(out, usVal.getString());
+			StringUtil.writeUnicodeString(out, val);
 			return;
 		}
 		if (value instanceof ErrorConstant) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java?rev=711513&r1=711512&r2=711513&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java Tue Nov  4 21:45:17
2008
@@ -206,8 +206,8 @@
 		if (o == null) {
 			throw new RuntimeException("Array item cannot be null");
 		}
-		if (o instanceof UnicodeString) {
-			return "\"" + ((UnicodeString)o).getString() + "\"";
+		if (o instanceof String) {
+			return "\"" + (String)o + "\"";
 		}
 		if (o instanceof Double) {
 			return ((Double)o).toString();

Modified: poi/trunk/src/java/org/apache/poi/util/StringUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/StringUtil.java?rev=711513&r1=711512&r2=711513&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/StringUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/StringUtil.java Tue Nov  4 21:45:17 2008
@@ -163,6 +163,15 @@
 	}
 
 	/**
+	 * @return the number of bytes that would be written by {@link #writeUnicodeString(LittleEndianOutput,
String)}
+	 */
+	public static int getEncodedSize(String value) {
+		int result = 2 + 1;
+		result += value.length() * (StringUtil.hasMultibyte(value) ? 2 : 1);
+		return result;
+	}
+
+	/**
 	 * Takes a unicode (java) string, and returns it as 8 bit data (in ISO-8859-1
 	 * codepage).
 	 * (In Excel terms, write compressed 8 bit unicode)

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java?rev=711513&r1=711512&r2=711513&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
Tue Nov  4 21:45:17 2008
@@ -22,7 +22,6 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.record.TestcaseRecordInputStream;
-import org.apache.poi.hssf.record.UnicodeString;
 import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
 import org.apache.poi.util.HexRead;
 import org.apache.poi.util.LittleEndianByteArrayOutputStream;
@@ -36,7 +35,7 @@
 			Boolean.TRUE,
 			null,
 			new Double(1.1),
-			new UnicodeString("Sample text"),
+			"Sample text",
 			ErrorConstant.valueOf(HSSFErrorConstants.ERROR_DIV_0),
 		};
 	private static final byte[] SAMPLE_ENCODING = HexRead.readFromString(

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java?rev=711513&r1=711512&r2=711513&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java Tue Nov 
4 21:45:17 2008
@@ -66,10 +66,10 @@
 		
 		
 		assertEquals(Boolean.TRUE, values[0][0]);
-		assertEquals(new UnicodeString("ABCD"), values[0][1]);
+		assertEquals("ABCD", values[0][1]);
 		assertEquals(new Double(0), values[1][0]);
 		assertEquals(Boolean.FALSE, values[1][1]);
-		assertEquals(new UnicodeString("FG"), values[1][2]);
+		assertEquals("FG", values[1][2]);
 		
 		byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.length];
 		ptg.writeTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0));



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message