double CSSTokenizerInputStream::getDouble(unsigned start, unsigned end) { ASSERT(start <= end && ((m_offset + end) <= m_stringLength)); bool isResultOK = false; double result = 0.0; if (start < end) { if (m_string->is8Bit()) result = charactersToDouble(m_string->characters8() + m_offset + start, end - start, &isResultOK); else result = charactersToDouble(m_string->characters16() + m_offset + start, end - start, &isResultOK); } // FIXME: It looks like callers ensure we have a valid number return isResultOK ? result : 0.0; }
static bool parseTransformNumberArguments(CharType*& pos, CharType* end, unsigned expectedCount, CSSFunctionValue* transformValue) { while (expectedCount) { size_t delimiter = WTF::find(pos, end - pos, expectedCount == 1 ? ')' : ','); if (delimiter == kNotFound) return false; unsigned argumentLength = static_cast<unsigned>(delimiter); bool ok; double number = charactersToDouble(pos, argumentLength, &ok); if (!ok) return false; transformValue->append(cssValuePool().createValue(number, CSSPrimitiveValue::CSS_NUMBER)); pos += argumentLength + 1; --expectedCount; } return true; }
static inline bool parseSimpleLength(const CharacterType* characters, unsigned length, CSSPrimitiveValue::UnitType& unit, double& number) { if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') { length -= 2; unit = CSSPrimitiveValue::CSS_PX; } else if (length > 1 && characters[length - 1] == '%') { length -= 1; unit = CSSPrimitiveValue::CSS_PERCENTAGE; } // We rely on charactersToDouble for validation as well. The function // will set "ok" to "false" if the entire passed-in character range does // not represent a double. bool ok; number = charactersToDouble(characters, length, &ok); return ok; }
static Length parseLength(const UChar* data, unsigned length) { if (length == 0) return Length(1, Relative); unsigned i = 0; while (i < length && isSpaceOrNewline(data[i])) ++i; if (i < length && (data[i] == '+' || data[i] == '-')) ++i; while (i < length && isASCIIDigit(data[i])) ++i; unsigned intLength = i; while (i < length && (isASCIIDigit(data[i]) || data[i] == '.')) ++i; unsigned doubleLength = i; // IE quirk: Skip whitespace between the number and the % character (20 % => 20%). while (i < length && isSpaceOrNewline(data[i])) ++i; bool ok; UChar next = (i < length) ? data[i] : ' '; if (next == '%') { // IE quirk: accept decimal fractions for percentages. double r = charactersToDouble(data, doubleLength, &ok); if (ok) return Length(r, Percent); return Length(1, Relative); } int r = charactersToIntStrict(data, intLength, &ok); if (next == '*') { if (ok) return Length(r, Relative); return Length(1, Relative); } if (ok) return Length(r, Fixed); return Length(0, Relative); }
static inline bool parseSimpleLength(const CharacterType* characters, unsigned length, CSSPrimitiveValue::UnitType& unit, double& number) { if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') { length -= 2; unit = CSSPrimitiveValue::UnitType::Pixels; } else if (length > 1 && characters[length - 1] == '%') { length -= 1; unit = CSSPrimitiveValue::UnitType::Percentage; } // We rely on charactersToDouble for validation as well. The function // will set "ok" to "false" if the entire passed-in character range does // not represent a double. bool ok; number = charactersToDouble(characters, length, &ok); if (!ok) return false; number = clampTo<double>(number, -std::numeric_limits<float>::max(), std::numeric_limits<float>::max()); return true; }
double StringImpl::toDouble(bool* ok) { return charactersToDouble(m_data, m_length, ok); }
float charactersToFloat(const UChar* data, size_t length, bool* ok) { // FIXME: This will return ok even when the string fits into a double but not a float. return narrowPrecisionToFloat(charactersToDouble(data, length, ok)); }