Revision: 18665 http://sourceforge.net/p/jmol/code/18665 Author: hansonr Date: 2013-09-18 22:06:41 +0000 (Wed, 18 Sep 2013) Log Message: ----------- Safari bug with characters did not get fixed in 13.2
Modified Paths: -------------- branches/v13_2/Jmol/src/org/jmol/util/Parser.java Modified: branches/v13_2/Jmol/src/org/jmol/util/Parser.java =================================================================== --- branches/v13_2/Jmol/src/org/jmol/util/Parser.java 2013-09-18 19:38:18 UTC (rev 18664) +++ branches/v13_2/Jmol/src/org/jmol/util/Parser.java 2013-09-18 22:06:41 UTC (rev 18665) @@ -369,7 +369,7 @@ 0.000000001f }; - private final static float[] tensScale = { 10, 100, 1000, 10000, 100000, 1000000 }; + private final static float[] tensScale = { 10f, 100f, 1000f, 10000f, 100000f, 1000000f }; /** * A float parser that is 30% faster than Float.parseFloat(x) and also accepts @@ -395,35 +395,56 @@ ++ich; negative = true; } - char ch = 0; - int ival = 0; - while (ich < ichMax && (ch = str.charAt(ich)) >= '0' && ch <= '9') { - ival = (ival << 3) + (ival << 1) + (ch - '0'); + // looks crazy, but if we don't do this, Google Closure Compiler will + // write code that Safari will misinterpret in a VERY nasty way -- + // getting totally confused as to long integers and double values + + // This is Safari figuring out the values of the numbers on the line (x, y, then z): + + // ATOM 1241 CD1 LEU A 64 -2.206 36.532 31.576 1.00 60.60 C + // e=1408749273 + // -e =-1408749273 + // ATOM 1241 CD1 LEU A 64 -2.206 36.532 31.576 1.00 60.60 C + // e=-1821066134 + // e=36.532 + // ATOM 1241 CD1 LEU A 64 -2.206 36.532 31.576 1.00 60.60 C + // e=-1133871366 + // e=31.576 + // + // "e" values are just before and after the "value = -value" statement. + + int ch = 0; + float ival = 0f; + float ival2 = 0f; + while (ich < ichMax && (ch = str.charAt(ich)) >= 48 && ch <= 57) { + ival = (ival * 10f) + (ch - 48)*1f; ++ich; digitSeen = true; } boolean isDecimal = false; - int ival2 = 0; int iscale = 0; int nzero = (ival == 0 ? -1 : 0); if (ch == '.') { isDecimal = true; - while (++ich < ichMax && (ch = str.charAt(ich)) >= '0' && ch <= '9') { + while (++ich < ichMax && (ch = str.charAt(ich)) >= 48 && ch <= 57) { digitSeen = true; if (nzero < 0) { - if (ch == '0') { + if (ch == 48) { nzero--; continue; } nzero = -nzero; } if (iscale < decimalScale.length) { - ival2 = (ival2 << 3) + (ival2 << 1) + (ch - '0'); + ival2 = (ival2 * 10f) + (ch - 48)*1f; iscale++; } } } float value; + + // Safari breaks here intermittently converting integers to floats + if (!digitSeen) { value = Float.NaN; } else if (ival2 > 0) { @@ -441,8 +462,6 @@ value = ival; } boolean isExponent = false; - if (!digitSeen) - value = Float.NaN; if (ich < ichMax && (ch == 'E' || ch == 'e' || ch == 'D')) { isExponent = true; if (++ich >= ichMax) @@ -461,22 +480,69 @@ else if (exponent != 0) value *= Math.pow(10, exponent); } else { - next[0] = ich; // the exponent code finds its own ichNextParse + next[0] = ich; // the exponent code finds its own ichNextParse } + // believe it or not, Safari reports the long-equivalent of the + // float value here, then later the float value, after no operation! if (negative) value = -value; if (value == Float.POSITIVE_INFINITY) - value= Float.MAX_VALUE; - return (!isStrict - || (!isExponent || isDecimal) && checkTrailingText(str, next[0], ichMax) - ? value : Float.NaN); + value = Float.MAX_VALUE; + return (!isStrict || (!isExponent || isDecimal) + && checkTrailingText(str, next[0], ichMax) ? value : Float.NaN); } + +// private static float parseFloatCheckedOld(String str, int ichMax, int[] next, boolean isStrict) { +// float value = 0; +// int ich = next[0]; +// if (isStrict && str.indexOf('\n') != str.lastIndexOf('\n')) +// return Float.NaN; +// while (ich < ichMax && isWhiteSpace(str, ich)) +// ++ich; +// boolean negative = false; +// if (ich < ichMax && str.charAt(ich) == '-') { +// ++ich; +// negative = true; +// } +// char ch = 0; +// int ich0 = ich; +// boolean isDecimal = false; +// while (ich < ichMax && (Character.isDigit(ch = str.charAt(ich)) || ch == '.')) { +// ++ich; +// if (ch == '.') { +// if (isDecimal) +// return Float.NaN; +// isDecimal = true; +// } +// } +// boolean isDouble = false; +// boolean isExponent = false; +// if (ich != ich0 && ich < ichMax && (ch == 'E' || ch == 'e' || (isDouble = (ch == 'D')))) { +// isExponent = true; +// if (++ich >= ichMax || ((ch = str.charAt(ich)) == '+' || ch == '-') && ++ich >= ichMax) +// return Float.NaN; +// while (ich < ichMax && Character.isDigit(str.charAt(ich))) { +// ++ich; +// } +// } +// next[0] = ich; +// if (ich0 == ich) +// return Float.NaN; +// value = fVal(isDouble ? str.substring(ich0, ich).replace('D','E') : str.substring(ich0, ich)); +// if (value == Float.POSITIVE_INFINITY) +// value= Float.MAX_VALUE; +// if (negative) +// value = -value; +// return (!isStrict +// || (!isExponent || isDecimal) && checkTrailingText(str, next[0], ichMax) +// ? value : Float.NaN); +// } + private static boolean checkTrailingText(String str, int ich, int ichMax) { //number must be pure -- no additional characters other than white space or ; char ch; - while (ich < ichMax && ((ch = str.charAt(ich)) == ' ' - || ch == '\t' || ch == '\n' || ch == ';')) + while (ich < ichMax && (Character.isWhitespace(ch = str.charAt(ich)) || ch == ';')) ++ich; return (ich == ichMax); } @@ -503,16 +569,16 @@ int ich = next[0]; if (ich < 0) return Integer.MIN_VALUE; - char ch; + int ch; while (ich < ichMax && isWhiteSpace(str, ich)) ++ich; boolean negative = false; - if (ich < ichMax && str.charAt(ich) == '-') { + if (ich < ichMax && str.charAt(ich) == 45) { //"-" negative = true; ++ich; } - while (ich < ichMax && (ch = str.charAt(ich)) >= '0' && ch <= '9') { - value = value * 10 + (ch - '0'); + while (ich < ichMax && (ch = str.charAt(ich)) >= 48 && ch <= 57) { + value = value * 10 + (ch - 48); digitSeen = true; ++ich; } @@ -696,5 +762,5 @@ return Float.parseFloat(s); } } - + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99! 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk _______________________________________________ Jmol-commits mailing list Jmol-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-commits