private double completeCalculation() { if (charsIndex == 0 || (charsIndex == 1 && chars[0] == '-')) { // "" or "-" strictError(); // Strict requires at least one digit. return 0.0; // Treated as 0.0 (not -0.0) in non-strict. } else if (isExponent((byte) chars[charsIndex - 1])) { // Covers 12.0efrog strictError(); addExponentToResult(adjustExponent); } else if (isStrict && !isEOS()) { strictError(); // We know it is not whitespace at this point } else if (!wroteExponent && adjustExponent != 0) { addToResult((byte) 'E'); addExponentToResult(adjustExponent); } return SafeDoubleParser.parseDouble(new String(chars, 0, charsIndex)); }
private boolean parseDigits() { if (!isEOS()) { byte value = next(); if (isDigit(value)) { addToResult(value); } else if (value == '.') { addToResult(value); return parseDecimalDigits(); } else { return isEOS(); strictError(); while (!isEOS()) { byte value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { addToResult(value); addToResult(value); return parseDecimalDigits(); } else if (value == '_') { verifyNumberAfterUnderscore(); } else if (isExponent(value)) { addToResult(value); return parseExponent();
private boolean parseDigits() { if (!isEOS()) { byte value = next(); if (isDigit(value)) { addToResult(value); } else if (value == '.') { addToResult(value); return parseDecimalDigits(); } else { return isEOS(); strictError(); while (!isEOS()) { byte value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { addToResult(value); addToResult(value); return parseDecimalDigits(); } else if (value == '_') { verifyNumberAfterUnderscore(); } else if (isExponent(value)) { addToResult(value); return parseExponent();
private boolean parseDecimalDigits() { if (isEOS()) return strictError(); byte value = next(); strictError(); if (isEOS()) return strictError(); value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { if (!(value == '0' && significantDigitsProcessed == 0)) { // not a leading 0 addToResult(value); } else { return strictError(); while (!isEOS()) { value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { if (value == '0' && significantDigitsProcessed == 0) { // leading 0 } else { significantDigitsProcessed++; addToResult(value); } else if (isExponent(value)) { addToResult(value);
private boolean parseExponent() { if (eatUnderscores()) return isEOS(); byte value = next(); negative = true; } else if (value != '+') { previous(); // backup...not a sign-char while (!isEOS()) { value = next(); if (isDigit(value)) { if (digits < EXPONENT_DIGITS_LIMIT) { return tooLargeExponent(chars[0] == '-', negative); } else if (isWhitespace(value)) { skipWhitespace(); break; } else if (value == '_') { verifyNumberAfterUnderscore(); } else { strictError(); stopParsing(); break; addExponentToResult(exponent); wroteExponent = true; return isEOS(); // Exponent end of double...let's finish.
private boolean parseDigits() { if (!isEOS()) { byte value = next(); if (isDigit(value)) { addToResult(value); } else if (value == '.') { addToResult(value); return parseDecimalDigits(); } else { return isEOS(); strictError(); while (!isEOS()) { byte value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { addToResult(value); addToResult(value); return parseDecimalDigits(); } else if (value == '_') { verifyNumberAfterUnderscore(); } else if (isExponent(value)) { addToResult(value); return parseExponent();
private boolean parseDecimalDigits() { if (isEOS()) return strictError(); byte value = next(); strictError(); if (isEOS()) return strictError(); value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { if (!(value == '0' && significantDigitsProcessed == 0)) { // not a leading 0 addToResult(value); } else { return strictError(); while (!isEOS()) { value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { if (value == '0' && significantDigitsProcessed == 0) { // leading 0 } else { significantDigitsProcessed++; addToResult(value); } else if (isExponent(value)) { addToResult(value);
private boolean parseExponent() { if (eatUnderscores()) return isEOS(); byte value = next(); negative = true; } else if (value != '+') { previous(); // backup...not a sign-char while (!isEOS()) { value = next(); if (isDigit(value)) { if (digits < EXPONENT_DIGITS_LIMIT) { return tooLargeExponent(chars[0] == '-', negative); } else if (isWhitespace(value)) { skipWhitespace(); break; } else if (value == '_') { verifyNumberAfterUnderscore(); } else { strictError(); stopParsing(); break; addExponentToResult(exponent); wroteExponent = true; return isEOS(); // Exponent end of double...let's finish.
private boolean parseExponent() { if (eatUnderscores()) return isEOS(); byte value = next(); negative = true; } else if (value != '+') { previous(); // backup...not a sign-char while (!isEOS()) { value = next(); if (isDigit(value)) { if (digits < EXPONENT_DIGITS_LIMIT) { return tooLargeExponent(chars[0] == '-', negative); } else if (isWhitespace(value)) { skipWhitespace(); break; } else if (value == '_') { verifyNumberAfterUnderscore(); } else { strictError(); stopParsing(); break; addExponentToResult(exponent); wroteExponent = true; return isEOS(); // Exponent end of double...let's finish.
private boolean parseDigits() { if (!isEOS()) { byte value = next(); if (isDigit(value)) { addToResult(value); } else if (value == '.') { addToResult(value); return parseDecimalDigits(); } else { return isEOS(); strictError(); while (!isEOS()) { byte value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { addToResult(value); addToResult(value); return parseDecimalDigits(); } else if (value == '_') { verifyNumberAfterUnderscore(); } else if (isExponent(value)) { addToResult(value); return parseExponent();
private boolean parseDecimalDigits() { if (isEOS()) return strictError(); byte value = next(); strictError(); if (isEOS()) return strictError(); value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { if (!(value == '0' && significantDigitsProcessed == 0)) { // not a leading 0 addToResult(value); } else { return strictError(); while (!isEOS()) { value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { if (value == '0' && significantDigitsProcessed == 0) { // leading 0 } else { significantDigitsProcessed++; addToResult(value); } else if (isExponent(value)) { addToResult(value);
private boolean parseDecimalDigits() { if (isEOS()) return strictError(); byte value = next(); strictError(); if (isEOS()) return strictError(); value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { if (!(value == '0' && significantDigitsProcessed == 0)) { // not a leading 0 addToResult(value); } else { return strictError(); while (!isEOS()) { value = next(); if (isDigit(value)) { if (significantDigitsProcessed < SIGNIFICANT_DIGITS_LIMIT) { if (value == '0' && significantDigitsProcessed == 0) { // leading 0 } else { significantDigitsProcessed++; addToResult(value); } else if (isExponent(value)) { addToResult(value);
private boolean parseExponent() { if (eatUnderscores()) return isEOS(); byte value = next(); negative = true; } else if (value != '+') { previous(); // backup...not a sign-char while (!isEOS()) { value = next(); if (isDigit(value)) { if (digits < EXPONENT_DIGITS_LIMIT) { return tooLargeExponent(chars[0] == '-', negative); } else if (isWhitespace(value)) { skipWhitespace(); break; } else if (value == '_') { verifyNumberAfterUnderscore(); } else { strictError(); stopParsing(); break; addExponentToResult(exponent); wroteExponent = true; return isEOS(); // Exponent end of double...let's finish.
/** * Consume initial whitespace and underscores so that next character * examined is not whitespace. 1.9 and strict do not allow leading * underscores. Returns whether next position is at the end of the * string or not. * * Trivia: " _ _ _ _ 1".to_f == 1.0 in Ruby 1.8 */ private boolean skipWhitespace() { while (!isEOS()) { byte value = next(); if (isWhitespace(value)) continue; if (value != '_' || isStrict || is19) return previous(); } return true; }
/** * Consume initial whitespace and underscores so that next character * examined is not whitespace. 1.9 and strict do not allow leading * underscores. Returns whether next position is at the end of the * string or not. * * Trivia: " _ _ _ _ 1".to_f == 1.0 in Ruby 1.8 */ private boolean skipWhitespace() { while (!isEOS()) { byte value = next(); if (isWhitespace(value)) continue; if (value != '_' || isStrict || is19) return previous(); } return true; }
/** * Consume initial whitespace and underscores so that next character * examined is not whitespace. 1.9 and strict do not allow leading * underscores. Returns whether next position is at the end of the * string or not. * * Trivia: " _ _ _ _ 1".to_f == 1.0 in Ruby 1.8 */ private boolean skipWhitespace() { while (!isEOS()) { byte value = next(); if (isWhitespace(value)) continue; return previous(); } return true; }
/** * Consume initial whitespace and underscores so that next character * examined is not whitespace. 1.9 and strict do not allow leading * underscores. Returns whether next position is at the end of the * string or not. * * Trivia: " _ _ _ _ 1".to_f == 1.0 in Ruby 1.8 */ private boolean skipWhitespace() { while (!isEOS()) { byte value = next(); if (isWhitespace(value)) continue; return previous(); } return true; }
private double completeCalculation() { if (charsIndex == 0 || (charsIndex == 1 && chars[0] == '-')) { // "" or "-" strictError(); // Strict requires at least one digit. return 0.0; // Treated as 0.0 (not -0.0) in non-strict. } else if (isExponent((byte) chars[charsIndex - 1])) { // Covers 12.0efrog strictError(); addExponentToResult(adjustExponent); } else if (isStrict && !isEOS()) { strictError(); // We know it is not whitespace at this point } else if (!wroteExponent && adjustExponent != 0) { addToResult((byte) 'E'); addExponentToResult(adjustExponent); } return SafeDoubleParser.parseDouble(new String(chars, 0, charsIndex)); }
/** * Everything runs in 1.9+ mode now, so the `is19` parameter is vestigial. * However, in order to maintain binary compatibility with extensions we can't * just change the signature either. */ public double parse(ByteList list, boolean strict, boolean is19) { init(list, strict); if (skipWhitespace()) return completeCalculation(); if (parseOptionalSign()) return completeCalculation(); parseDigits(); if (result != -1.0) { // abnormal result return result; } return completeCalculation(); }
private double completeCalculation() { if (charsIndex == 0 || (charsIndex == 1 && chars[0] == '-')) { // "" or "-" strictError(); // Strict requires at least one digit. return 0.0; // Treated as 0.0 (not -0.0) in non-strict. } else if (isExponent((byte) chars[charsIndex - 1])) { // Covers 12.0efrog strictError(); addExponentToResult(adjustExponent); } else if (isStrict && !isEOS()) { strictError(); // We know it is not whitespace at this point } else if (!wroteExponent && adjustExponent != 0) { addToResult((byte) 'E'); addExponentToResult(adjustExponent); } return SafeDoubleParser.parseDouble(new String(chars, 0, charsIndex)); }