| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return value.isZero() ? Decimal(0) : value; | 114 return value.isZero() ? Decimal(0) : value; |
| 115 } | 115 } |
| 116 | 116 |
| 117 double parseToDoubleForNumberType(const String& string, double fallbackValue) | 117 double parseToDoubleForNumberType(const String& string, double fallbackValue) |
| 118 { | 118 { |
| 119 // http://www.whatwg.org/specs/web-apps/current-work/#floating-point-numbers | 119 // http://www.whatwg.org/specs/web-apps/current-work/#floating-point-numbers |
| 120 // String::toDouble() accepts leading + and whitespace characters, which are
not valid here. | 120 // String::toDouble() accepts leading + and whitespace characters, which are
not valid here. |
| 121 UChar firstCharacter = string[0]; | 121 UChar firstCharacter = string[0]; |
| 122 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha
racter)) | 122 if (firstCharacter != '-' && firstCharacter != '.' && !isASCIIDigit(firstCha
racter)) |
| 123 return fallbackValue; | 123 return fallbackValue; |
| 124 if (string.endsWith('.')) |
| 125 return fallbackValue; |
| 124 | 126 |
| 125 bool valid = false; | 127 bool valid = false; |
| 126 double value = string.toDouble(&valid); | 128 double value = string.toDouble(&valid); |
| 127 if (!valid) | 129 if (!valid) |
| 128 return fallbackValue; | 130 return fallbackValue; |
| 129 | 131 |
| 130 // NaN and infinity are considered valid by String::toDouble, but not valid
here. | 132 // NaN and infinity are considered valid by String::toDouble, but not valid
here. |
| 131 if (!std::isfinite(value)) | 133 if (!std::isfinite(value)) |
| 132 return fallbackValue; | 134 return fallbackValue; |
| 133 | 135 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 string = StringImpl::create8BitIfPossible(characters, size); | 411 string = StringImpl::create8BitIfPossible(characters, size); |
| 410 else if (width == Force8Bit) | 412 else if (width == Force8Bit) |
| 411 string = String::make8BitFrom16BitSource(characters, size); | 413 string = String::make8BitFrom16BitSource(characters, size); |
| 412 else | 414 else |
| 413 string = String(characters, size); | 415 string = String(characters, size); |
| 414 | 416 |
| 415 return string; | 417 return string; |
| 416 } | 418 } |
| 417 | 419 |
| 418 } | 420 } |
| OLD | NEW |