mirror of https://github.com/apache/poi.git
seperated out my experimental parsing stuff.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352455 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c9cffe9d37
commit
75dd68f99c
|
@ -77,44 +77,10 @@ public abstract class Ptg
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Ptg[] parse(String formula, int offset) {
|
|
||||||
List ptgs = new ArrayList();
|
|
||||||
|
|
||||||
while (offset < formula.length()) {
|
|
||||||
Ptg ptg = getNextToken(formula,offset);
|
|
||||||
offset += ptg.getStringLength();
|
|
||||||
ptgs.add(ptg);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ptg[] retval = new Ptg[ptgs.size()];
|
/*
|
||||||
retval = (Ptg[])ptgs.toArray(retval);
|
private static List ptgsToList(Class [] ptgs)
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String ptgsToString(Ptg[] ptgs) {
|
|
||||||
StringBuffer res = new StringBuffer();
|
|
||||||
for (int k =0; k < ptgs.length; k++) {
|
|
||||||
Ptg ptg = ptgs[k];
|
|
||||||
res.append(ptg.toFormulaString());
|
|
||||||
}
|
|
||||||
return res.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Ptg getNextToken(String formula, int offset) {
|
|
||||||
//later use array of reflected methods like RecordFactory
|
|
||||||
Ptg retval = null;
|
|
||||||
|
|
||||||
if (AddPtg.isNextStringToken(formula,offset)) {
|
|
||||||
retval = new AddPtg(formula,offset);
|
|
||||||
} else if (IntPtg.isNextStringToken(formula,offset)) {
|
|
||||||
retval = new IntPtg(formula,offset);
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("didn't parse "+formula+" at " +offset);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* private static List ptgsToList(Class [] ptgs)
|
|
||||||
{
|
{
|
||||||
List result = new ArrayList();
|
List result = new ArrayList();
|
||||||
Constructor constructor;
|
Constructor constructor;
|
||||||
|
@ -143,7 +109,7 @@ public abstract class Ptg
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
/*public static Ptg createPtg(byte [] data, int offset)
|
public static Ptg createPtg(byte [] data, int offset)
|
||||||
{
|
{
|
||||||
byte id = data[ offset + 0 ];
|
byte id = data[ offset + 0 ];
|
||||||
Ptg retval = null;
|
Ptg retval = null;
|
||||||
|
@ -193,9 +159,9 @@ public abstract class Ptg
|
||||||
retval = new ValueReferencePtg(data, offset);
|
retval = new ValueReferencePtg(data, offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ParenthesisPtg.sid :
|
// case ParenthesisPtg.sid :
|
||||||
retval = new ParenthesisPtg(data, offset);
|
// retval = new ParenthesisPtg(data, offset);
|
||||||
break;
|
// break;
|
||||||
|
|
||||||
case ValueVariableFunctionPtg.sid :
|
case ValueVariableFunctionPtg.sid :
|
||||||
retval = new ValueVariableFunctionPtg(data, offset);
|
retval = new ValueVariableFunctionPtg(data, offset);
|
||||||
|
@ -217,7 +183,7 @@ public abstract class Ptg
|
||||||
+ " (" + ( int ) id + ")");
|
+ " (" + ( int ) id + ")");
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
public abstract int getSize();
|
public abstract int getSize();
|
||||||
|
|
||||||
|
@ -249,10 +215,5 @@ public abstract class Ptg
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
if (args != null && args[0] != null) {
|
|
||||||
System.out.println("Parsed Formula="+ ptgsToString(parse(args[0],0)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue