summaryrefslogtreecommitdiff
path: root/xmerge
diff options
context:
space:
mode:
authorMartin Maher <mmaher@openoffice.org>2003-02-03 16:30:43 +0000
committerMartin Maher <mmaher@openoffice.org>2003-02-03 16:30:43 +0000
commit9d2b3aa1c288f10038130e74b19376832ecd2b28 (patch)
treeadcda7817b888a76725dbbf97adbcb5a75a046e2 /xmerge
parentf16b31eae3ed3e395216856859b138125b2928c9 (diff)
Some bug fixes for token encoding and decoding
Diffstat (limited to 'xmerge')
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FormulaParser.java6
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FunctionLookup.java2
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenEncoder.java146
-rw-r--r--xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenFactory.java2
4 files changed, 74 insertions, 82 deletions
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FormulaParser.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FormulaParser.java
index a97944ac4b0e..643e517aec71 100644
--- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FormulaParser.java
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FormulaParser.java
@@ -198,7 +198,7 @@ public class FormulaParser {
* @return A boolean returning the result of the comparison
*/
private boolean isCellRefSpecialChar(char c) {
- return (c == ':') || (c == '$') || (c == '!');
+ return (c == ':') || (c == '$') || (c == '.');
}
/**
@@ -411,8 +411,8 @@ public class FormulaParser {
tokenVector.insertElementAt(tokenFactory.getFunctionToken(cell, numArgs), index);
} else {
- if(cell.indexOf('!')!=-1) {
- String cellRef = cell.substring(cell.indexOf('!') + 1, cell.length());
+ if(cell.indexOf('.')!=-1) {
+ String cellRef = cell.substring(cell.indexOf('.') + 1, cell.length());
if(cellRef.indexOf(':')!=-1) {
tokenVector.add(tokenFactory.getOperandToken(cell, "3D_CELL_AREA_REFERENCE"));
} else {
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FunctionLookup.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FunctionLookup.java
index 8b16eb332e5d..bcd16232d3e4 100644
--- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FunctionLookup.java
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/FunctionLookup.java
@@ -120,7 +120,7 @@ public class FunctionLookup implements SymbolLookup {
// Text
addEntry("RIGHT", TokenConstants.TRIGHT, -1);
addEntry("SUBSTITUTE", TokenConstants.TSUBSTITUTE, -1);
- addEntry("SEARCH", TokenConstants.TFIND, -1);
+ addEntry("FIND", TokenConstants.TFIND, -1);
addEntry("LEFT", TokenConstants.TLEFT, -1);
// Logical
addEntry("AND", TokenConstants.TAND, -1 );
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenEncoder.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenEncoder.java
index 68a084888b0e..a45d69e1eb3b 100644
--- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenEncoder.java
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenEncoder.java
@@ -116,34 +116,34 @@ public class TokenEncoder {
Vector tmpByteArray = null; // we use this cause we don't know till after
// the encoding takes place how big the byte [] will be
- index=0; // This class is declared static in
+ //index=0; // This class is declared static in
// FormulaHelper so better make sure our index is 0
if(t.getTokenType()==ParseToken.TOKEN_OPERATOR) {
- tmpByteArray = OperatorEncoder(t);
+ tmpByteArray = operatorEncoder(t);
} else if (t.getTokenType()==ParseToken.TOKEN_FUNCTION_VARIABLE || t.getTokenType()==ParseToken.TOKEN_FUNCTION_FIXED){
- tmpByteArray = FunctionEncoder(t);
+ tmpByteArray = functionEncoder(t);
} else { // Operands and functions
switch(t.getTokenID()) {
case TokenConstants.TNAME :
- tmpByteArray = NameDefinitionEncoder(t);
+ tmpByteArray = nameDefinitionEncoder(t);
break;
case TokenConstants.TREF3D :
- tmpByteArray = ThreeDCellRefEncoder(t);
+ tmpByteArray = threeDCellRefEncoder(t);
break;
case TokenConstants.TAREA3D:
- tmpByteArray = ThreeDAreaRefEncoder(t);
+ tmpByteArray = threeDAreaRefEncoder(t);
break;
case TokenConstants.TREF :
- tmpByteArray = CellRefEncoder(t);
+ tmpByteArray = cellRefEncoder(t);
break;
case TokenConstants.TAREA :
- tmpByteArray = AreaRefEncoder(t);
+ tmpByteArray = areaRefEncoder(t);
break;
case TokenConstants.TNUM :
- tmpByteArray = NumEncoder(t);
+ tmpByteArray = numEncoder(t);
break;
case TokenConstants.TSTRING :
- tmpByteArray = StringEncoder(t);
+ tmpByteArray = stringEncoder(t);
break;
default :
Debug.log(Debug.ERROR, "Encoder found unrecognized Token");
@@ -169,7 +169,7 @@ public class TokenEncoder {
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private Vector OperatorEncoder(Token t) {
+ private Vector operatorEncoder(Token t) {
Vector tmpByteArray = new Vector();
tmpByteArray.add(new Byte((byte)t.getTokenID()));
@@ -183,7 +183,7 @@ public class TokenEncoder {
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private Vector StringEncoder(Token t) throws IOException{
+ private Vector stringEncoder(Token t) throws IOException{
Vector tmpByteArray = new Vector();
tmpByteArray.add(new Byte((byte)t.getTokenID()));
@@ -203,7 +203,7 @@ public class TokenEncoder {
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private Vector NumEncoder(Token t) {
+ private Vector numEncoder(Token t) {
Vector tmpByteArray = new Vector();
@@ -316,22 +316,24 @@ public class TokenEncoder {
}
/**
- * A Cell Reference Encoder. It supports absolute and relative addressing
- * but not sheetnames.
+ * A Cell Reference Encoder (It supports absolute and relative addressing)
*
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private byte[] EncodeCellCoordinates() {
+ private byte[] encodeCellCoordinates(String cellCoordinates) {
int col = 0, row = 0;
int addressing = 0xC000;
- Debug.log(Debug.TRACE,"Encoding cell coordinates" + parseString);
- if(parseString.charAt(index)=='$') {
+
+ index = 0;
+ parseString = cellCoordinates;
+ Debug.log(Debug.TRACE,"Encoding cell coordinates " + cellCoordinates);
+ if(cellCoordinates.charAt(index)=='$') {
addressing &= 0x8000;
index++;
}
col = column();
- if(parseString.charAt(index)=='$') {
+ if(cellCoordinates.charAt(index)=='$') {
addressing &= 0x4000;
index++;
}
@@ -345,13 +347,12 @@ public class TokenEncoder {
}
/**
- * A Cell Reference Encoder. It supports absolute and relative addressing
- * but not sheetnames.
+ * A name definition Encoder
*
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private Vector NameDefinitionEncoder(Token t) {
+ private Vector nameDefinitionEncoder(Token t) {
Vector tmpByteArray = new Vector();
@@ -385,13 +386,12 @@ public class TokenEncoder {
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private Vector CellRefEncoder(Token t) {
+ private Vector cellRefEncoder(Token t) {
Vector tmpByteArray = new Vector();
- parseString = t.getValue();
tmpByteArray.add(new Byte((byte)t.getTokenID()));
- byte cellRefBytes[] = EncodeCellCoordinates();
+ byte cellRefBytes[] = encodeCellCoordinates(t.getValue());
for(int i = 0;i < cellRefBytes.length;i++) {
tmpByteArray.add(new Byte(cellRefBytes[i]));
}
@@ -399,13 +399,12 @@ public class TokenEncoder {
}
/**
- * A Cell Reference Encoder. It supports absolute and relative addressing
- * but not sheetnames.
+ * This function will find the sheetname index for a given String
*
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private short FindNameDefinitionIndex(String s) {
+ private short findSheetIndex(String s) {
short sheetIndex = 0;
String savedName;
@@ -415,7 +414,7 @@ public class TokenEncoder {
} else {
sheetName = s.substring(0,s.length());
}
- Debug.log(Debug.TRACE,"Searching for Name Definition : " + sheetName);
+ Debug.log(Debug.TRACE,"Searching for Worksheet : " + sheetName);
Vector names = wb.getWorksheetNames();
Enumeration e = names.elements();
do {
@@ -428,13 +427,12 @@ public class TokenEncoder {
}
/**
- * A Cell Reference Encoder. It supports absolute and relative addressing
- * but not sheetnames.
+ * A 3D Cell reference encoder
*
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private Vector ThreeDCellRefEncoder(Token t) {
+ private Vector threeDCellRefEncoder(Token t) {
Vector tmpByteArray = new Vector();
parseString = t.getValue();
@@ -446,41 +444,39 @@ public class TokenEncoder {
tmpByteArray.add(new Byte((byte)0x00));
}
- String sheetRef = parseString.substring(0, parseString.indexOf('!') + 1);
+ String sheetRef = parseString.substring(0, parseString.indexOf('.') + 1);
if (sheetRef.indexOf(':')!=-1) {
sheetRef = parseString.substring(0, parseString.indexOf(':'));
- short sheetNum1 = FindNameDefinitionIndex(sheetRef);
+ short sheetNum1 = findSheetIndex(sheetRef);
sheetRef = parseString.substring(parseString.indexOf(':') + 1, parseString.length());
- short sheetNum2 = FindNameDefinitionIndex(sheetRef);
+ short sheetNum2 = findSheetIndex(sheetRef);
tmpByteArray.add(new Byte((byte)sheetNum1));
tmpByteArray.add(new Byte((byte)0x00));
tmpByteArray.add(new Byte((byte)sheetNum2));
tmpByteArray.add(new Byte((byte)0x00));
} else {
- sheetRef = parseString.substring(0, parseString.indexOf('!'));
- short sheetNum = FindNameDefinitionIndex(sheetRef);
+ sheetRef = parseString.substring(0, parseString.indexOf('.'));
+ short sheetNum = findSheetIndex(sheetRef);
tmpByteArray.add(new Byte((byte)sheetNum));
tmpByteArray.add(new Byte((byte)0x00));
tmpByteArray.add(new Byte((byte)sheetNum));
tmpByteArray.add(new Byte((byte)0x00));
}
- parseString = parseString.substring(parseString.indexOf('!') + 1, parseString.length());
- Debug.log(Debug.TRACE,"Parsing : " + parseString);
- index=0;
- byte cellRefBytes[] = EncodeCellCoordinates();
+ String s = parseString.substring(parseString.indexOf('.') + 1, parseString.length());
+ Debug.log(Debug.TRACE,"Parsing : " + s);
+ byte cellRefBytes[] = encodeCellCoordinates(s);
for(int i = 0;i < cellRefBytes.length;i++) {
tmpByteArray.add(new Byte(cellRefBytes[i]));
}
return tmpByteArray;
}
/**
- * A Cell Reference Encoder. It supports absolute and relative addressing
- * but not sheetnames.
+ * A 3D Area Reference Encoder.
*
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private Vector ThreeDAreaRefEncoder(Token t) {
+ private Vector threeDAreaRefEncoder(Token t) {
Vector tmpByteArray = new Vector();
parseString = t.getValue();
@@ -492,37 +488,32 @@ public class TokenEncoder {
tmpByteArray.add(new Byte((byte)0x00));
}
- String sheetRef = parseString.substring(0, parseString.indexOf('!') + 1);
- if (sheetRef.indexOf(':')!=-1) {
- sheetRef = parseString.substring(0, parseString.indexOf(':'));
- short sheetNum1 = FindNameDefinitionIndex(sheetRef);
- sheetRef = parseString.substring(parseString.indexOf(':') + 1, parseString.length());
- short sheetNum2 = FindNameDefinitionIndex(sheetRef);
+ String param1= parseString.substring(0, parseString.indexOf(':'));
+ String cellRef1 = param1.substring(parseString.indexOf('.') + 1, param1.length());
+ String sheetRef1 = param1.substring(0, param1.indexOf('.'));
+ short sheetNum1 = findSheetIndex(sheetRef1);
+
+ String param2 = parseString.substring(parseString.indexOf(':') + 1, parseString.length());
+ Debug.log(Debug.TRACE,"param2: " + param2);
+ String cellRef2 = param2.substring(param2.indexOf('.') + 1, param2.length());
+ Debug.log(Debug.TRACE,"cellRef2: " + cellRef2);
+
+ if(param2.indexOf('.')==-1) {
tmpByteArray.add(new Byte((byte)sheetNum1));
tmpByteArray.add(new Byte((byte)0x00));
- tmpByteArray.add(new Byte((byte)sheetNum2));
+ tmpByteArray.add(new Byte((byte)sheetNum1));
tmpByteArray.add(new Byte((byte)0x00));
} else {
- sheetRef = parseString.substring(0, parseString.indexOf('!'));
- short sheetNum = FindNameDefinitionIndex(sheetRef);
- tmpByteArray.add(new Byte((byte)sheetNum));
+ String sheetRef2 = param2.substring(0, param2.indexOf('.'));
+ short sheetNum2 = findSheetIndex(sheetRef2);
+ tmpByteArray.add(new Byte((byte)sheetNum1));
tmpByteArray.add(new Byte((byte)0x00));
- tmpByteArray.add(new Byte((byte)sheetNum));
+ tmpByteArray.add(new Byte((byte)sheetNum2));
tmpByteArray.add(new Byte((byte)0x00));
}
- parseString = parseString.substring(parseString.indexOf('!') + 1, parseString.length());
- Debug.log(Debug.TRACE,"Parsing : " + parseString);
- index=0;
- byte cellRefBytes1[] = EncodeCellCoordinates();
-
- if(parseString.charAt(index)==':') {
- index++;
- } else {
- Debug.log(Debug.ERROR, "Invalid Cell Range, could not find :");
- }
-
- byte cellRefBytes2[] = EncodeCellCoordinates();
+ byte cellRefBytes1[] = encodeCellCoordinates(cellRef1);
+ byte cellRefBytes2[] = encodeCellCoordinates(cellRef2);
tmpByteArray.add(new Byte(cellRefBytes1[0]));
tmpByteArray.add(new Byte(cellRefBytes1[1]));
@@ -542,22 +533,23 @@ public class TokenEncoder {
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private Vector AreaRefEncoder(Token t) {
+ private Vector areaRefEncoder(Token t) {
Vector tmpByteArray = new Vector();
tmpByteArray.add(new Byte((byte)t.getTokenID()));
- parseString = t.getValue();
-
- byte cellRefBytes1[] = EncodeCellCoordinates();
+ String param = t.getValue();
+ String cellRef1 = new String();
+ String cellRef2 = new String();
- if(parseString.charAt(index)==':') {
- index++;
- } else {
+ if(param.indexOf(':')==-1) {
Debug.log(Debug.ERROR, "Invalid Cell Range, could not find :");
+ } else {
+ cellRef1 = param.substring(0, param.indexOf(':'));
+ cellRef2 = param.substring(param.indexOf(':') + 1, param.length());
}
-
- byte cellRefBytes2[] = EncodeCellCoordinates();
+ byte cellRefBytes1[] = encodeCellCoordinates(cellRef1);
+ byte cellRefBytes2[] = encodeCellCoordinates(cellRef2);
tmpByteArray.add(new Byte(cellRefBytes1[0]));
tmpByteArray.add(new Byte(cellRefBytes1[1]));
@@ -577,7 +569,7 @@ public class TokenEncoder {
* @param t <code>Token</code> to be encoded
* @return A <code>Vector</code> of pexcel <code>Byte</code>
*/
- private Vector FunctionEncoder(Token t) {
+ private Vector functionEncoder(Token t) {
Vector tmpByteArray = new Vector();
int id = t.getTokenID();
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenFactory.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenFactory.java
index 5f4f8ab0b780..240b06d243dd 100644
--- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenFactory.java
+++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/formula/TokenFactory.java
@@ -135,7 +135,7 @@ public class TokenFactory {
public Token getOperandToken(String s, String type) {
Token t;
- Debug.log(Debug.TRACE,"TokenFactory creating operand Token : " + s);
+ Debug.log(Debug.TRACE,"TokenFactory creating operand (" + type + ") Token : " + s);
t = new Token(s, ParseToken.TOKEN_OPERAND, operandLookup.getIDFromString(type), 0);
return t;