From: <ha...@us...> - 2007-02-17 05:14:48
|
Revision: 6839 http://svn.sourceforge.net/jmol/?rev=6839&view=rev Author: hansonr Date: 2007-02-16 21:14:47 -0800 (Fri, 16 Feb 2007) Log Message: ----------- 11.1 static parser and Adapter methods Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/smarter/AdfReader.java trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollectionReader.java trunk/Jmol/src/org/jmol/adapter/smarter/CsfReader.java trunk/Jmol/src/org/jmol/adapter/smarter/CubeReader.java trunk/Jmol/src/org/jmol/adapter/smarter/FoldingXyzReader.java trunk/Jmol/src/org/jmol/adapter/smarter/GamessReader.java trunk/Jmol/src/org/jmol/adapter/smarter/GaussianReader.java trunk/Jmol/src/org/jmol/adapter/smarter/GhemicalMMReader.java trunk/Jmol/src/org/jmol/adapter/smarter/HinReader.java trunk/Jmol/src/org/jmol/adapter/smarter/JmolDataReader.java trunk/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java trunk/Jmol/src/org/jmol/adapter/smarter/MopacReader.java trunk/Jmol/src/org/jmol/adapter/smarter/NWChemReader.java trunk/Jmol/src/org/jmol/adapter/smarter/OdysseyReader.java trunk/Jmol/src/org/jmol/adapter/smarter/PdbReader.java trunk/Jmol/src/org/jmol/adapter/smarter/PsiReader.java trunk/Jmol/src/org/jmol/adapter/smarter/QchemReader.java trunk/Jmol/src/org/jmol/adapter/smarter/ShelxReader.java trunk/Jmol/src/org/jmol/adapter/smarter/SpartanArchive.java trunk/Jmol/src/org/jmol/adapter/smarter/SpartanReader.java trunk/Jmol/src/org/jmol/adapter/smarter/V3000Reader.java trunk/Jmol/src/org/jmol/adapter/smarter/WebMOReader.java trunk/Jmol/src/org/jmol/adapter/smarter/XyzReader.java trunk/Jmol/src/org/jmol/util/Parser.java Modified: trunk/Jmol/src/org/jmol/adapter/smarter/AdfReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/AdfReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/AdfReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -76,7 +76,7 @@ iHaveAtoms = true; readCoordinates(); } else if (line.indexOf("Energy:") >= 0) { - String[] tokens = getTokens(line); + String[] tokens = getTokens(); energy = tokens[1]; } else if (line.indexOf("Vibrations") >= 0) { readFrequencies(); @@ -111,7 +111,7 @@ atomSetCollection.setAtomSetName("" + energy); // start with an empty name discardLinesUntilStartsWith(" -----"); while (readLine() != null && !line.startsWith(" -----")) { - String[] tokens = getTokens(line); + String[] tokens = getTokens(); if (tokens.length < 5) continue; String symbol = tokens[1]; @@ -160,7 +160,7 @@ } if (line == null || line.indexOf(".") < 0) return; - frequencies = getTokens(line); + frequencies = getTokens(); readLine(); // -------- -------- -------- int frequencyCount = frequencies.length; int firstModelAtom = atomSetCollection.atomCount; @@ -174,7 +174,7 @@ } int atomPt = 0; while (readLine() != null && line.indexOf(".") >= 0) { - tokens = getTokens(line); + tokens = getTokens(); String symbol = tokens[0].substring(tokens[0].indexOf(".") + 1); if (JmolConstants.elementNumberFromSymbol(symbol) < 1) continue; Modified: trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollectionReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollectionReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/AtomSetCollectionReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -73,7 +73,7 @@ * */ -abstract class AtomSetCollectionReader extends Parser { +abstract class AtomSetCollectionReader { AtomSetCollection atomSetCollection; BufferedReader reader; String line, prevline; @@ -92,6 +92,90 @@ int[] latticeCells = new int[3]; int desiredSpaceGroupIndex; + int[] next = new int[1]; + + // parser functions are static, so they need notstatic counterparts + + + String[] getTokens() { + return Parser.getTokens( line); + } + + String[] getTokens(String s) { + return Parser.getTokens(s); + } + + String[] getTokens(String s, int iStart) { + return Parser.getTokens(s, iStart); + } + + float parseFloat() { + return Parser.parseFloat(line, next); + } + + float parseFloat(String s) { + next[0] = 0; + return Parser.parseFloat(s, next); + } + + float parseFloat(String s, int iStart, int iEnd) { + next[0] = iStart; + return Parser.parseFloat(s, iEnd, next); + } + + int parseInt() { + return Parser.parseInt(line, next); + } + + int parseInt(String s) { + next[0] = 0; + return Parser.parseInt(s, next); + } + + int parseInt(String s, int iStart) { + next[0] = iStart; + return Parser.parseInt(s, next); + } + + int parseInt(String s, int iStart, int iEnd) { + next[0] = iStart; + return Parser.parseInt(s, iEnd, next); + } + + String parseToken() { + return Parser.parseToken(line, next); + } + + String parseToken(String s) { + next[0] = 0; + return Parser.parseToken(s, next); + } + + String parseTokenNext(String s) { + return Parser.parseToken(s, next); + } + + String parseToken(String s, int iStart, int iEnd) { + next[0] = iStart; + return Parser.parseToken(s, iEnd, next); + } + + String parseTrimmed(String s) { + next[0] = 0; + return Parser.parseTrimmed(s, next); + } + + String parseTrimmed(String s, int iStart) { + next[0] = iStart; + return Parser.parseTrimmed(s, next); + } + + String parseTrimmed(String s, int iStart, int iEnd) { + next[0] = iStart; + return Parser.parseTrimmed(s, iEnd, next); + } + + // load options: boolean doApplySymmetry; Modified: trunk/Jmol/src/org/jmol/adapter/smarter/CsfReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/CsfReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/CsfReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -83,7 +83,7 @@ byte[] fieldMap, int[] fieldTypes, boolean[] propertyReferenced) throws Exception { - String tokens[] = getTokens(line); + String tokens[] = getTokens(); String field; int fieldCount = -1; for (int ipt = tokens.length; --ipt >= 0; ) { @@ -134,7 +134,7 @@ break; String thisAtomID = null; String thisBondID = null; - String tokens[] = getTokens(line); + String tokens[] = getTokens(); for (int i = 0; i < fieldCount; ++i) { String field = tokens[i]; switch (fieldTypes[i]) { @@ -210,7 +210,7 @@ for (; readLine() != null; ) { if (line.startsWith("property_flags:")) break; - String tokens[] = getTokens(line); + String tokens[] = getTokens(); Atom atom = new Atom(); for (int i = 0; i < fieldCount; i++) { String field = tokens[i]; @@ -275,7 +275,7 @@ if (line.startsWith("property_flags:")) break; String thisBondID = null; - String tokens[] = getTokens(line); + String tokens[] = getTokens(); for (int i = 0; i < fieldCount; ++i) { String field = tokens[i]; switch (fieldTypes[i]) { @@ -333,7 +333,7 @@ for (; readLine() != null;) { if (line.startsWith("property_flags:")) break; - String tokens[] = getTokens(line); + String tokens[] = getTokens(); if (parseInt(tokens[0]) != thisvibID) { thisvibID = parseInt(tokens[0]); atomSetCollection.cloneFirstAtomSetWithBonds(nBonds); @@ -356,7 +356,7 @@ for (; readLine() != null; ) { if (line.startsWith("property_flags:")) break; - String tokens[] = getTokens(line); + String tokens[] = getTokens(); int thisvib = -1; for (int i = 0; i < fieldCount; ++i) { String field = tokens[i]; Modified: trunk/Jmol/src/org/jmol/adapter/smarter/CubeReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/CubeReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/CubeReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -91,9 +91,9 @@ void readAtomCountAndOrigin() throws Exception { readLine(); atomCount = parseInt(line); - origin[0] = parseFloat(line, ichNextParse); - origin[1] = parseFloat(line, ichNextParse); - origin[2] = parseFloat(line, ichNextParse); + origin[0] = parseFloat(); + origin[1] = parseFloat(); + origin[2] = parseFloat(); if (atomCount < 0) { atomCount = -atomCount; negativeAtomCount = true; @@ -111,9 +111,9 @@ float[] voxelVector = new float[3]; voxelVectors[voxelVectorIndex] = voxelVector; voxelCounts[voxelVectorIndex] = parseInt(line); - voxelVector[0] = parseFloat(line, ichNextParse); - voxelVector[1] = parseFloat(line, ichNextParse); - voxelVector[2] = parseFloat(line, ichNextParse); + voxelVector[0] = parseFloat(); + voxelVector[1] = parseFloat(); + voxelVector[2] = parseFloat(); } void readAtoms() throws Exception { @@ -121,10 +121,10 @@ readLine(); Atom atom = atomSetCollection.addNewAtom(); atom.elementNumber = (short)parseInt(line); //allowing atomicAndIsotope for JVXL format - atom.partialCharge = parseFloat(line, ichNextParse); - atom.x = parseFloat(line, ichNextParse) * ANGSTROMS_PER_BOHR; - atom.y = parseFloat(line, ichNextParse) * ANGSTROMS_PER_BOHR; - atom.z = parseFloat(line, ichNextParse) * ANGSTROMS_PER_BOHR; + atom.partialCharge = parseFloat(); + atom.x = parseFloat() * ANGSTROMS_PER_BOHR; + atom.y = parseFloat() * ANGSTROMS_PER_BOHR; + atom.z = parseFloat() * ANGSTROMS_PER_BOHR; } } Modified: trunk/Jmol/src/org/jmol/adapter/smarter/FoldingXyzReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/FoldingXyzReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/FoldingXyzReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -84,7 +84,7 @@ //Logger.debug("Line: " + line); Atom atom = atomSetCollection.addNewAtom(); parseInt(line); - atom.atomName = parseToken(line, ichNextParse); + atom.atomName = parseToken(); if (atom.atomName != null) { int carCount = 1; if (atom.atomName.length() >= 2) { @@ -100,15 +100,15 @@ } atom.elementSymbol = atom.atomName.substring(0, carCount); } - atom.x = parseFloat(line, ichNextParse); - atom.y = parseFloat(line, ichNextParse); - atom.z = parseFloat(line, ichNextParse); + atom.x = parseFloat(); + atom.y = parseFloat(); + atom.z = parseFloat(); // Memorise bond informations int bondCount = 0; bonds[i] = new int[5]; int bondNum = Integer.MIN_VALUE; - while ((bondNum = parseInt(line, ichNextParse)) > 0) { + while ((bondNum = parseInt()) > 0) { if (bondCount == bonds[i].length) { bonds[i] = ArrayUtil.setLength(bonds[i], bondCount + 1); } Modified: trunk/Jmol/src/org/jmol/adapter/smarter/GamessReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/GamessReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/GamessReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -189,7 +189,7 @@ readLine(); Hashtable slater = null; while (readLine() != null && line.indexOf("TOTAL") < 0) { - tokens = getTokens(line); + tokens = getTokens(); switch (tokens.length) { case 1: atomCount++; @@ -265,7 +265,7 @@ int nThisLine = 0; while (readLine() != null && line.indexOf("--") < 0 && line.indexOf(".....") < 0) { - String[] tokens = getTokens(line); + String[] tokens = getTokens(); Logger.debug(tokens.length + " --- " + line); if (line.length() == 0) { for (int i = 0; i < nThisLine; i++) { @@ -313,7 +313,7 @@ while (line != null && line.indexOf("FREQUENCY:") >= 0) { int lineBaseFreqCount = totalFrequencyCount; int lineFreqCount = 0; - String[] tokens = getTokens(line); + String[] tokens = getTokens(); for (int i = 0; i < tokens.length; i++) { float frequency = parseFloat(tokens[i]); if (tokens[i].equals("I")) @@ -330,11 +330,11 @@ String[] intensities = null; readLine(); if (line.indexOf("MASS") >= 0) { - red_masses = getTokens(line); + red_masses = getTokens(); readLine(); } if (line.indexOf("INTENS") >= 0) { - intensities = getTokens(line); + intensities = getTokens(); } for (int i = 0; i < lineFreqCount; i++) { ++totalFrequencyCount; Modified: trunk/Jmol/src/org/jmol/adapter/smarter/GaussianReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/GaussianReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/GaussianReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -225,7 +225,7 @@ * */ private void setEnergy() { - String tokens[] = getTokens(line); + String tokens[] = getTokens(); energyKey = "Energy"; energyString = tokens[1]; atomSetCollection.setAtomSetNames("Energy = "+tokens[1], equivalentAtomSets); @@ -261,12 +261,12 @@ private void readAtoms() throws Exception { atomSetCollection.newAtomSet(); atomSetCollection.setAtomSetName(""); // start with an empty name - String path = getTokens(line)[0]; // path = type of orientation + String path = getTokens()[0]; // path = type of orientation discardLines(4); String tokens[]; while (readLine() != null && !line.startsWith(" --")) { - tokens = getTokens(line); // get the tokens in the line + tokens = getTokens(); // get the tokens in the line Atom atom = atomSetCollection.addNewAtom(); atom.elementNumber = (byte)parseInt(tokens[STD_ORIENTATION_ATOMIC_NUMBER_OFFSET]); @@ -320,7 +320,7 @@ String[] tokens; while (readLine() != null && line.startsWith(" Atom")) { shellCount++; - tokens = getTokens(line); + tokens = getTokens(); Hashtable slater = new Hashtable(); if (!tokens[1].equals(lastAtom)) atomCount++; @@ -370,7 +370,7 @@ int nThisLine = 0; while (readLine() != null && line.toUpperCase().indexOf("DENS") < 0) { - String[] tokens = getTokens(line); + String[] tokens = getTokens(); int ptData = (line.charAt(5) == ' ' ? 2 : 4); if (line.indexOf(" ") == 0) { addMOData(nThisLine, data, mos); Modified: trunk/Jmol/src/org/jmol/adapter/smarter/GhemicalMMReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/GhemicalMMReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/GhemicalMMReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -113,7 +113,7 @@ if (atomIndex != i) throw new Exception("bad atom index in !Atoms" + "expected: " + i + " saw:" + atomIndex); - int elementNumber = parseInt(line, ichNextParse); + int elementNumber = parseInt(); Atom atom = atomSetCollection.addNewAtom(); atom.elementNumber = (byte)elementNumber; } @@ -124,8 +124,8 @@ for (int i = 0; i < bondCount; ++i) { readLine(); int atomIndex1 = parseInt(line); - int atomIndex2 = parseInt(line, ichNextParse); - String orderCode = parseToken(line, ichNextParse); + int atomIndex2 = parseInt(); + String orderCode = parseToken(); int order = 0; switch(orderCode.charAt(0)) { case 'C': // Conjugated (aromatic) @@ -150,9 +150,9 @@ throw new Exception("bad atom index in !Coord" + "expected: " + i + " saw:" + atomIndex); Atom atom = atomSetCollection.atoms[i]; - atom.x = parseFloat(line, ichNextParse) * 10; - atom.y = parseFloat(line, ichNextParse) * 10; - atom.z = parseFloat(line, ichNextParse) * 10; + atom.x = parseFloat() * 10; + atom.y = parseFloat() * 10; + atom.z = parseFloat() * 10; } } @@ -164,7 +164,7 @@ throw new Exception("bad atom index in !Charges" + "expected: " + i + " saw:" + atomIndex); Atom atom = atomSetCollection.atoms[i]; - atom.partialCharge = parseFloat(line, ichNextParse); + atom.partialCharge = parseFloat(); } } } Modified: trunk/Jmol/src/org/jmol/adapter/smarter/HinReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/HinReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/HinReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -87,8 +87,8 @@ String getMolName() { parseToken(line); - parseToken(line, ichNextParse); - return parseToken(line, ichNextParse); + parseToken(); + return parseToken(); } void processAtom() throws Exception { @@ -100,19 +100,19 @@ } Atom atom = atomSetCollection.addNewAtom(); - parseToken(line, ichNextParse); // discard - atom.elementSymbol = parseToken(line, ichNextParse); - parseToken(line, ichNextParse); // discard - parseToken(line, ichNextParse); // discard - atom.partialCharge = parseFloat(line, ichNextParse); - atom.x = parseFloat(line, ichNextParse); - atom.y = parseFloat(line, ichNextParse); - atom.z = parseFloat(line, ichNextParse); + parseToken(); // discard + atom.elementSymbol = parseToken(); + parseToken(); // discard + parseToken(); // discard + atom.partialCharge = parseFloat(); + atom.x = parseFloat(); + atom.y = parseFloat(); + atom.z = parseFloat(); - int bondCount = parseInt(line, ichNextParse); + int bondCount = parseInt(); for (int i = 0; i < bondCount; ++i) { - int otherAtomNumber = parseInt(line, ichNextParse); - String bondTypeToken = parseToken(line, ichNextParse); + int otherAtomNumber = parseInt(); + String bondTypeToken = parseToken(); if (otherAtomNumber > atomIndex) continue; int bondOrder; Modified: trunk/Jmol/src/org/jmol/adapter/smarter/JmolDataReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/JmolDataReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/JmolDataReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -62,7 +62,7 @@ for (int i = 0; i < modelAtomCount; ++i) { readLine(); Atom atom = atomSetCollection.addNewAtom(); - String[] tokens = getTokens(line); + String[] tokens = getTokens(); atom.elementSymbol = tokens[1]; atom.x = parseFloat(tokens[3]); atom.y = parseFloat(tokens[4]); Modified: trunk/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/Mol2Reader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -98,8 +98,8 @@ readLine(); line += " 0 0 0 0 0 0"; int atomCount = parseInt(line); - int bondCount = parseInt(line, ichNextParse); - int resCount = parseInt(line, ichNextParse); + int bondCount = parseInt(); + int resCount = parseInt(); readLine();//mol_type readLine();//charge_type boolean iHaveCharges = (line.indexOf("NO_CHARGES") != 0); @@ -180,9 +180,9 @@ void readCrystalInfo() throws Exception { // 4.1230 4.1230 4.1230 90.0000 90.0000 90.0000 221 1 readLine(); - ichNextParse = 0; + next[0] = 0; for (int i = 0; i < 6; i++) - setUnitCellItem(i, parseFloat(line, ichNextParse)); - setSpaceGroupName(line.substring(ichNextParse, line.length()).trim()); + setUnitCellItem(i, parseFloat()); + setSpaceGroupName(line.substring(next[0], line.length()).trim()); } } Modified: trunk/Jmol/src/org/jmol/adapter/smarter/MopacReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/MopacReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/MopacReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -109,8 +109,8 @@ if (atomNumber != expectedAtomNumber) throw new Exception("unexpected atom number in atomic charges"); Atom atom = atomSetCollection.addNewAtom(); - atom.elementSymbol = parseToken(line, ichNextParse); - atom.partialCharge = parseFloat(line, ichNextParse); + atom.elementSymbol = parseToken(); + atom.partialCharge = parseFloat(); } chargesFound = true; } @@ -157,16 +157,16 @@ ++expectedAtomNumber; if (atomNumber != expectedAtomNumber) throw new Exception("unexpected atom number in coordinates"); - String elementSymbol = parseToken(line, ichNextParse); + String elementSymbol = parseToken(); Atom atom = atomSetCollection.atoms[baseAtomIndex + atomNumber - 1]; if (atom == null) { atom = atomSetCollection.addNewAtom(); // if no charges were found first } atom.atomSerial = atomNumber; - atom.x = parseFloat(line, ichNextParse); - atom.y = parseFloat(line, ichNextParse); - atom.z = parseFloat(line, ichNextParse); + atom.x = parseFloat(); + atom.y = parseFloat(); + atom.z = parseFloat(); int atno = parseInt(elementSymbol); if (atno != Integer.MIN_VALUE) elementSymbol = getElementSymbol(atno); @@ -210,7 +210,7 @@ while (readLine() != null && line.indexOf("DESCRIPTION") < 0) if (line.indexOf("ROOT") >= 0) { - int frequencyCount = getTokens(line).length - 2; + int frequencyCount = getTokens().length - 2; data = new String[nAtoms * 3 + 1][]; fillDataBlock(data); for (int i = 0; i < frequencyCount; ++i) { Modified: trunk/Jmol/src/org/jmol/adapter/smarter/NWChemReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/NWChemReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/NWChemReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -153,7 +153,7 @@ discardLines(2); if (readLine() == null) return; - String tokens[] = getTokens(line); + String tokens[] = getTokens(); atomSetCollection.setAtomSetProperties("Symmetry group name", tokens[tokens.length-1], equivalentAtomSets); } @@ -168,7 +168,7 @@ * <p>Determine whether it reports the energy, if so set the property and name(s) */ private void readTotal() { - String tokens[] = getTokens(line); + String tokens[] = getTokens(); try { if (tokens[2].startsWith("energy")) { // in an optimization an energy is reported in a follow up step @@ -187,7 +187,7 @@ if (readLine() == null) return; } - String tokens[] = getTokens(line); + String tokens[] = getTokens(); if (!haveEnergy) { // if didn't already have the energies, set them now setEnergies("E", tokens[2], equivalentAtomSets); } else { @@ -226,7 +226,7 @@ (inInput?SmarterJmolAdapter.PATH_SEPARATOR+"Input": SmarterJmolAdapter.PATH_SEPARATOR+"Geometry")); while (readLine() != null && line.length() > 0) { - tokens = getTokens(line); // get the tokens in the line + tokens = getTokens(); // get the tokens in the line if (tokens.length < 6) break; // if don't have enough of them: done Atom atom = atomSetCollection.addNewAtom(); atom.atomName = fixTag(tokens[1]); @@ -276,7 +276,7 @@ "Task "+taskNumber+ SmarterJmolAdapter.PATH_SEPARATOR+"Gradients"); while (readLine() != null && line.length() > 0) { - tokens = getTokens(line); // get the tokens in the line + tokens = getTokens(); // get the tokens in the line if (tokens.length < 8) break; // make sure I have enough tokens Atom atom = atomSetCollection.addNewAtom(); atom.atomName = fixTag(tokens[1]); @@ -397,7 +397,7 @@ atomSetCollection.newAtomSet(); atomSetCollection.setAtomSetProperty(SmarterJmolAdapter.PATH_KEY, path); while (readLine() != null && line.indexOf("---") < 0) { - tokens = getTokens(line); + tokens = getTokens(); Atom atom = atomSetCollection.addNewAtom(); atom.atomName = fixTag(tokens[0]); atom.x = parseFloat(tokens[2]) * AU2ANGSTROM; @@ -451,7 +451,7 @@ for (int i = 0; i < atomCount * 3; ++i) { if (readLine() == null) return; - tokens = getTokens(line); + tokens = getTokens(); for (int j = 0; j < nFreq; ++j) { Atom atom = atomSetCollection.atoms[firstModelAtom + j * atomCount + i / 3]; @@ -481,7 +481,7 @@ for (int i = totalFrequencies, idx = firstFrequencyAtomSetIndex; --i >= 0; idx++) { if (readLine() == null) return; - tokens = getTokens(line); + tokens = getTokens(); String frequencyString = tokens[1] + " cm**-1"; atomSetCollection.setAtomSetName(frequencyString, idx); atomSetCollection.setAtomSetProperty("Frequency", frequencyString, idx); @@ -510,7 +510,7 @@ // assign the partial charge if (readLine() == null) return; - tokens = getTokens(line); + tokens = getTokens(); atomSetCollection.atoms[i].partialCharge = parseInt(tokens[2]) - parseFloat(tokens[3]); } Modified: trunk/Jmol/src/org/jmol/adapter/smarter/OdysseyReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/OdysseyReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/OdysseyReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -76,7 +76,7 @@ atomCount = 0; while (readLine() != null && !line.startsWith("ENDCART")) { - String[] tokens = getTokens(line); + String[] tokens = getTokens(); int elementNumber = parseInt(tokens[0]); String elementSymbol = getElementSymbol(elementNumber); float x = parseFloat(tokens[1]); @@ -111,7 +111,7 @@ 1 7 1 */ while (readLine() != null && !line.startsWith("ENDHESS")) { - String[] tokens = getTokens(line); + String[] tokens = getTokens(); if (nAtoms == 0) { int sourceIndex = parseInt(tokens[0]) - 1; int targetIndex = parseInt(tokens[1]) - 1; Modified: trunk/Jmol/src/org/jmol/adapter/smarter/PdbReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/PdbReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/PdbReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -455,9 +455,9 @@ if (htElementsInGroup == null) htFormul.put(groupName, htElementsInGroup = new Hashtable()); // now, look for atom names in the formula - ichNextParse = 0; + next[0] = 0; String elementWithCount; - while ((elementWithCount = parseToken(formula, ichNextParse)) != null) { + while ((elementWithCount = parseTokenNext(formula)) != null) { if (elementWithCount.length() < 2) continue; char chFirst = elementWithCount.charAt(0); Modified: trunk/Jmol/src/org/jmol/adapter/smarter/PsiReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/PsiReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/PsiReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -131,7 +131,7 @@ } int atomPt = 0; while (readLine() != null && line.length() > 0) { - String[] tokens = getTokens(line); // get the tokens in the line + String[] tokens = getTokens(); // get the tokens in the line Atom atom = (isInitial ? atomSetCollection.addNewAtom() : atomSetCollection.atoms[atomPt++]); atom.elementNumber = (byte) parseInt(tokens[0]); @@ -188,7 +188,7 @@ while (readLine() != null && line.startsWith(" -Basis set on")) { atomCenter = parseInt(line.substring(31)); while (readLine() != null && !line.startsWith(" )")) { - tokens = getTokens(line); + tokens = getTokens(); int ipt = 1; if (line.startsWith(" (")) { ipt = 2; @@ -332,7 +332,7 @@ Vector[] data = new Vector[5]; int nThisLine = 0; while (readLine() != null && line.toUpperCase().indexOf("DENS") < 0) { - String[] tokens = getTokens(line); + String[] tokens = getTokens(); int ptData = (line.charAt(5) == ' ' ? 2 : 4); if (line.indexOf(" ") == 0) { addMOData(nThisLine, data, mos); Modified: trunk/Jmol/src/org/jmol/adapter/smarter/QchemReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/QchemReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/QchemReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -88,7 +88,7 @@ discardLines(2); String[] tokens; while (readLine() != null && !line.startsWith(" --")) { - tokens = getTokens(line); + tokens = getTokens(); if (tokens.length < 5) continue; String symbol = tokens[1]; @@ -113,12 +113,12 @@ int modelNumber = 1; discardLinesUntilStartsWith(" Frequency:"); while (line != null && line.startsWith(" Frequency:")) { - String[] frequencies = getTokens(line); + String[] frequencies = getTokens(); int nModels = frequencies.length - 1; discardLines(4); for (int i = 0; i < atomCount; ++i) { readLine(); - String[] tokens = getTokens(line); + String[] tokens = getTokens(); for (int j = 0, offset = 0; j < nModels; j++) { float x = parseFloat(tokens[++offset]); float y = parseFloat(tokens[++offset]); @@ -151,6 +151,6 @@ void readPartialCharges() throws Exception { discardLines(3); for (int i = 0; i < atomCount && readLine() != null; ++i) - atomSetCollection.atoms[i].partialCharge = parseFloat(getTokens(line)[2]); + atomSetCollection.atoms[i].partialCharge = parseFloat(getTokens()[2]); } } Modified: trunk/Jmol/src/org/jmol/adapter/smarter/ShelxReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/ShelxReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/ShelxReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -151,7 +151,7 @@ void parseLattRecord() throws Exception { parseToken(line); - int latt = parseInt(line, ichNextParse); + int latt = parseInt(); atomSetCollection.setLatticeParameter(latt); } @@ -170,7 +170,7 @@ * CELL 7.11174 21.71704 30.95857 90.000 90.000 90.000 */ - String[] tokens = getTokens(line); + String[] tokens = getTokens(); int ioff = 1; if (isCmdf) { ioff = 0; @@ -235,10 +235,10 @@ // this line gives an atom, because any line not starting with // a SHELX command is an atom String atomName = parseToken(line); - int scatterFactor = parseInt(line, ichNextParse); - float a = parseFloat(line, ichNextParse); - float b = parseFloat(line, ichNextParse); - float c = parseFloat(line, ichNextParse); + int scatterFactor = parseInt(); + float a = parseFloat(); + float b = parseFloat(); + float c = parseFloat(); // skip the rest Atom atom = atomSetCollection.addNewAtom(); @@ -276,7 +276,7 @@ void processCmdfAtoms() throws Exception { while (readLine() != null && line.length() > 10) { Atom atom = atomSetCollection.addNewAtom(); - String[] tokens = getTokens(line); + String[] tokens = getTokens(); atom.elementSymbol = getSymbol(tokens[0]); setAtomCoord(atom, parseFloat(tokens[2]), parseFloat(tokens[3]), parseFloat(tokens[4])); Modified: trunk/Jmol/src/org/jmol/adapter/smarter/SpartanArchive.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/SpartanArchive.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/SpartanArchive.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -23,6 +23,7 @@ */ package org.jmol.adapter.smarter; +import org.jmol.util.Parser; import java.io.BufferedReader; import java.util.Vector; @@ -42,6 +43,11 @@ String calculationType = ""; BufferedReader reader; String line; + int[] next = new int[1]; + + String[] getTokens() { + return Parser.getTokens(line); + } AtomSetCollection atomSetCollection; AtomSetCollectionReader r; @@ -91,8 +97,8 @@ return atomCount; } - String[] getTokens(String info) { - return r.getTokens(info); + static String[] getTokens(String info) { + return Parser.getTokens(info); } int parseInt(String info) { @@ -122,7 +128,7 @@ void readAtoms() throws Exception { for (int i = 0; i < atomCount; i++) { readLine(); - String tokens[] = getTokens(line); + String tokens[] = getTokens(); float x = parseFloat(tokens[1]); float y = parseFloat(tokens[2]); float z = parseFloat(tokens[3]); @@ -192,7 +198,7 @@ int[] typeArray = new int[gaussianCount]; for (int i = 0; i < shellCount; i++) { readLine(); - String[] tokens = getTokens(line); + String[] tokens = getTokens(); Hashtable slater = new Hashtable(); int iBasis = parseInt(tokens[0]); String basisType; @@ -226,7 +232,7 @@ for (int i = 0; i < gaussianCount; i++) { float alpha = parseFloat(readLine()); readLine(); - String[] tokens = getTokens(line); + String[] tokens = getTokens(); int nData = tokens.length; float[] data = new float[nData + 1]; data[0] = alpha; @@ -301,7 +307,7 @@ void readDipole() throws Exception { //fall-back if no other dipole record readLine(); - String tokens[] = getTokens(line); + String tokens[] = getTokens(); if (tokens.length != 3) return; Vector3f dipole = new Vector3f(parseFloat(tokens[0]), @@ -310,7 +316,7 @@ } void readProperty() throws Exception { - String tokens[] = getTokens(line); + String tokens[] = getTokens(); if (tokens.length == 0) return; //Logger.debug("reading property line:" + line); @@ -336,7 +342,7 @@ value = getQuotedString("\""); vector.add(value); } else { - String tokens2[] = getTokens(line); + String tokens2[] = getTokens(); for (int i = 0; i < tokens2.length; i++) { if (isArray) { atomInfo.add(new Float(parseFloat(tokens2[i]))); @@ -398,7 +404,7 @@ int nValues = 3; float[] atomInfo = new float[3]; while (readLine() != null) { - String tokens2[] = getTokens(line); + String tokens2[] = getTokens(); for (int i = 0; i < tokens2.length; i++) { float f = parseFloat(tokens2[i]); atomInfo[i % nValues] = f; Modified: trunk/Jmol/src/org/jmol/adapter/smarter/SpartanReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/SpartanReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/SpartanReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -107,10 +107,10 @@ while (true) { discardLinesUntilNonBlank(); int lineBaseFreqCount = totalFrequencyCount; - ichNextParse = 16; + next[0] = 16; int lineFreqCount; for (lineFreqCount = 0; lineFreqCount < 3; ++lineFreqCount) { - float frequency = parseFloat(line, ichNextParse); + float frequency = parseFloat(); if (Float.isNaN(frequency)) break; //////////////// loop exit is here ++totalFrequencyCount; Modified: trunk/Jmol/src/org/jmol/adapter/smarter/V3000Reader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/V3000Reader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/V3000Reader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -77,7 +77,7 @@ newAtomSet(""); } else if (line.startsWith("M V30 COUNTS")) { headerAtomCount = parseInt(line, 13); - headerBondCount = parseInt(line, ichNextParse); + headerBondCount = parseInt(); } } if (line != null && !line.startsWith("$$$$")) @@ -90,15 +90,15 @@ if (line == null || (! line.startsWith("M V30 "))) throw new Exception("unrecognized atom"); Atom atom = new Atom(); - String[] tokens = getTokens(line); + String[] tokens = getTokens(); atom.atomSerial = parseInt(tokens[2]); atom.elementSymbol = tokens[3]; atom.x = parseFloat(tokens[4]); atom.y = parseFloat(tokens[5]); atom.z = parseFloat(tokens[6]); - parseInt(line, ichNextParse); // discard aamap + parseInt(); // discard aamap while (true) { - String option = parseToken(line, ichNextParse); + String option = parseToken(); if (option == null) break; if (option.startsWith("CHG=")) @@ -118,9 +118,9 @@ if (line == null || (! line.startsWith("M V30 "))) throw new Exception("unrecognized bond"); /*int bondSerial = */parseInt(line, 7); // currently unused - int order = parseInt(line, ichNextParse); - int atomSerial1 = parseInt(line, ichNextParse); - int atomSerial2 = parseInt(line, ichNextParse); + int order = parseInt(); + int atomSerial1 = parseInt(); + int atomSerial2 = parseInt(); atomSetCollection.addNewBondWithMappedSerialNumbers(atomSerial1, atomSerial2, order); Modified: trunk/Jmol/src/org/jmol/adapter/smarter/WebMOReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/WebMOReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/WebMOReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -94,7 +94,7 @@ void readHeader() throws Exception { while (readLine() != null && line.length() > 0) { moData.put("calculationType", "?"); - String[] tokens = getTokens(line); + String[] tokens = getTokens(); tokens[0] = tokens[0].substring(0, 1).toLowerCase() + tokens[0].substring(1, tokens[0].length()); String str = ""; @@ -126,7 +126,7 @@ while (line != null && (line.length() == 0 || line.charAt(0) != '[')) { if (line.length() != 0) { Atom atom = atomSetCollection.addNewAtom(); - String[] tokens = getTokens(line); + String[] tokens = getTokens(); if (isAtomicNumber) { atom.elementSymbol = getElementSymbol(parseInt(tokens[0])); } else { @@ -154,7 +154,7 @@ && (line.length() == 0 || line.charAt(0) != '[')) { if (line.length() == 0) continue; - String[] tokens = getTokens(line); + String[] tokens = getTokens(); int atomIndex1 = parseInt(tokens[0]); int atomIndex2 = parseInt(tokens[1]); int order = parseInt(tokens[2]); @@ -174,7 +174,7 @@ && (line.length() == 0 || line.charAt(0) != '[')) { if (line.length() == 0) continue; - String[] tokens = getTokens(line); + String[] tokens = getTokens(); info.put(tokens[0].substring(0, 1), tokens); } moData.put("atomicOrbitalOrder", info); @@ -205,7 +205,7 @@ while (readLine() != null && (line.length() == 0 || line.charAt(0) != '[')) { - String[] tokens = getTokens(line); + String[] tokens = getTokens(); if (tokens.length == 0) continue; if (tokens.length != 1) // VERY unlikely event -- might as well note it, though. @@ -253,7 +253,7 @@ int ndata = 0; while (readLine() != null && (line.length() == 0 || line.charAt(0) != '[')) { - String[] tokens = getTokens(line); + String[] tokens = getTokens(); if (tokens.length < 7) continue; float fdata[] = new float[2]; @@ -295,7 +295,7 @@ && (line.length() == 0 || line.charAt(0) != '[')) { if (line.length() == 0) continue; - String[] tokens = getTokens(line); + String[] tokens = getTokens(); data.add(tokens[1]); } float[] coefs = new float[data.size()]; Modified: trunk/Jmol/src/org/jmol/adapter/smarter/XyzReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/XyzReader.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/adapter/smarter/XyzReader.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -109,9 +109,9 @@ atom.elementNumber = (short)((isotope << 7) + JmolConstants.elementNumberFromSymbol(str)); atomSetCollection.setFileTypeName("xyzi"); } - atom.x = parseFloat(line, ichNextParse); - atom.y = parseFloat(line, ichNextParse); - atom.z = parseFloat(line, ichNextParse); + atom.x = parseFloat(); + atom.y = parseFloat(); + atom.z = parseFloat(); if (Float.isNaN(atom.x) || Float.isNaN(atom.y) || Float.isNaN(atom.z)) { Logger.warn("line cannot be read for XYZ atom data: " + line); atom.x = 0; @@ -121,7 +121,7 @@ setAtomCoord(atom); for (int j = 0; j < 4; ++j) isNaN[j] = - Float.isNaN(chargeAndOrVector[j] = parseFloat(line, ichNextParse)); + Float.isNaN(chargeAndOrVector[j] = parseFloat()); if (isNaN[0]) continue; if (isNaN[1]) { Modified: trunk/Jmol/src/org/jmol/util/Parser.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Parser.java 2007-02-16 06:11:57 UTC (rev 6838) +++ trunk/Jmol/src/org/jmol/util/Parser.java 2007-02-17 05:14:47 UTC (rev 6839) @@ -31,9 +31,7 @@ /// for adapter (and others?) /// - public int ichNextParse; - - public int[] markLines(String data, char eol) { + public static int[] markLines(String data, char eol) { int nLines = 0; for (int i = data.length(); --i >=0;) if (data.charAt(i) == eol) @@ -46,34 +44,30 @@ return lines; } - public float parseFloat(String str) { - return parseFloatChecked(str, 0, str.length()); - } - - public float parseFloat(String str, int ich) { + public static float parseFloat(String str, int[] next) { int cch = str.length(); - if (ich >= cch) + if (next[0] >= cch) return Float.NaN; - return parseFloatChecked(str, ich, cch); + return parseFloatChecked(str, cch, next); } - public float parseFloat(String str, int ichStart, int ichMax) { + public static float parseFloat(String str, int ichMax, int[] next) { int cch = str.length(); if (ichMax > cch) ichMax = cch; - if (ichStart >= ichMax) + if (next[0] >= ichMax) return Float.NaN; - return parseFloatChecked(str, ichStart, ichMax); + return parseFloatChecked(str, ichMax, next); } private final static float[] decimalScale = { 0.1f, 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f, 0.0000001f, 0.00000001f }; private final static float[] tensScale = { 10, 100, 1000, 10000, 100000, 1000000 }; - private float parseFloatChecked(String str, int ichStart, int ichMax) { + private static float parseFloatChecked(String str, int ichMax, int[] next) { boolean digitSeen = false; float value = 0; - int ich = ichStart; + int ich = next[0]; char ch; while (ich < ichMax && ((ch = str.charAt(ich)) == ' ' || ch == '\t')) ++ich; @@ -107,7 +101,8 @@ ch = str.charAt(ich); if ((ch == '+') && (++ich >= ichMax)) return Float.NaN; - int exponent = parseIntChecked(str, ich, ichMax); + next[0] = ich; + int exponent = parseIntChecked(str, ichMax, next); if (exponent == Integer.MIN_VALUE) return Float.NaN; if (exponent > 0) @@ -117,42 +112,31 @@ value *= ((-exponent < decimalScale.length) ? decimalScale[-exponent - 1] : Math.pow(10, exponent)); } else { - ichNextParse = ich; // the exponent code finds its own ichNextParse + next[0] = ich; // the exponent code finds its own ichNextParse } - //Logger.debug("parseFloat(" + str + "," + ichStart + "," + - // ichMax + ") -> " + value); return value; } - /** - * parses a string for an integer - * @param str - * @return integer or Integer.MIN_VALUE - */ - public int parseInt(String str) { - return parseIntChecked(str, 0, str.length()); - } - - public int parseInt(String str, int ich) { + public static int parseInt(String str, int[] next) { int cch = str.length(); - if (ich >= cch) + if (next[0] >= cch) return Integer.MIN_VALUE; - return parseIntChecked(str, ich, cch); + return parseIntChecked(str, cch, next); } - public int parseInt(String str, int ichStart, int ichMax) { + public static int parseInt(String str, int ichMax, int[] next) { int cch = str.length(); if (ichMax > cch) ichMax = cch; - if (ichStart >= ichMax) + if (next[0] >= ichMax) return Integer.MIN_VALUE; - return parseIntChecked(str, ichStart, ichMax); + return parseIntChecked(str, ichMax, next); } - private int parseIntChecked(String str, int ichStart, int ichMax) { + private static int parseIntChecked(String str, int ichMax, int[] next) { boolean digitSeen = false; int value = 0; - int ich = ichStart; + int ich = next[0]; char ch; while (ich < ichMax && ((ch = str.charAt(ich)) == ' ' || ch == '\t')) ++ich; @@ -170,17 +154,15 @@ value = Integer.MIN_VALUE; else if (negative) value = -value; - //Logger.debug("parseInt(" + str + "," + ichStart + "," + - // ichMax + ") -> " + value); - ichNextParse = ich; + next[0] = ich; return value; } - public String[] getTokens(String line) { + public static String[] getTokens(String line) { return getTokens(line, 0); } - public String[] getTokens(String line, int ich) { + public static String[] getTokens(String line, int ich) { if (line == null) return null; int cchLine = line.length(); @@ -188,18 +170,14 @@ return null; int tokenCount = countTokens(line, ich); String[] tokens = new String[tokenCount]; - ichNextParse = ich; + int[] next = new int[1]; + next[0] = ich; for (int i = 0; i < tokenCount; ++i) - tokens[i] = parseTokenChecked(line, ichNextParse, cchLine); - /* - Logger.debug("-----------\nline:" + line); - for (int i = 0; i < tokenCount; ++i) - Logger.debug("token[" + i + "]=" + tokens[i]); - */ + tokens[i] = parseTokenChecked(line, cchLine, next); return tokens; } - public int countTokens(String line, int ich) { + public static int countTokens(String line, int ich) { int tokenCount = 0; if (line != null) { int ichMax = line.length(); @@ -218,62 +196,54 @@ return tokenCount; } - public String parseToken(String str) { - return parseTokenChecked(str, 0, str.length()); - } - - public String parseToken(String str, int ich) { + public static String parseToken(String str, int[] next) { int cch = str.length(); - if (ich >= cch) + if (next[0] >= cch) return null; - return parseTokenChecked(str, ich, cch); + return parseTokenChecked(str, cch, next); } - public String parseToken(String str, int ichStart, int ichMax) { + public static String parseToken(String str, int ichMax, int[] next) { int cch = str.length(); if (ichMax > cch) ichMax = cch; - if (ichStart >= ichMax) + if (next[0] >= ichMax) return null; - return parseTokenChecked(str, ichStart, ichMax); + return parseTokenChecked(str, ichMax, next); } - private String parseTokenChecked(String str, int ichStart, int ichMax) { - int ich = ichStart; + private static String parseTokenChecked(String str, int ichMax, int[] next) { + int ich = next[0]; char ch; while (ich < ichMax && ((ch = str.charAt(ich)) == ' ' || ch == '\t')) ++ich; int ichNonWhite = ich; while (ich < ichMax && ((ch = str.charAt(ich)) != ' ' && ch != '\t')) ++ich; - ichNextParse = ich; + next[0] = ich; if (ichNonWhite == ich) return null; return str.substring(ichNonWhite, ich); } - public String parseTrimmed(String str) { - return parseTrimmedChecked(str, 0, str.length()); - } - - public String parseTrimmed(String str, int ich) { + public static String parseTrimmed(String str, int[] next) { int cch = str.length(); - if (ich >= cch) + if (next[0] >= cch) return ""; - return parseTrimmedChecked(str, ich, cch); + return parseTrimmedChecked(str, cch, next); } - public String parseTrimmed(String str, int ichStart, int ichMax) { + public static String parseTrimmed(String str, int ichMax, int[] next) { int cch = str.length(); if (ichMax > cch) ichMax = cch; - if (ichStart >= ichMax) + if (next[0] >= ichMax) return ""; - return parseTrimmedChecked(str, ichStart, ichMax); + return parseTrimmedChecked(str, ichMax, next); } - private String parseTrimmedChecked(String str, int ichStart, int ichMax) { - int ich = ichStart; + private static String parseTrimmedChecked(String str, int ichMax, int[] next) { + int ich = next[0]; char ch; while (ich < ichMax && ((ch = str.charAt(ich)) == ' ' || ch == '\t' || ch == '\n')) ++ich; @@ -282,11 +252,12 @@ --ichLast; if (ichLast < ich) return ""; - ichNextParse = ichLast + 1; + if (next != null) + next[0] = ichLast + 1; return str.substring(ich, ichLast + 1); } - public String concatTokens(String[] tokens, int iFirst, int iEnd) { + public static String concatTokens(String[] tokens, int iFirst, int iEnd) { String str = ""; String sep = ""; for (int i = iFirst; i < iEnd; i++) { @@ -298,7 +269,7 @@ return str; } - public String getString(String line, String strQuote) { + public static String getString(String line, String strQuote) { int i = line.indexOf(strQuote); int j = line.lastIndexOf(strQuote); return (j == i ? "" : line.substring(i + 1, j)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |