Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index 3893ccb6ef22ee4ca4c9cae0313d870536245a70..bfb2bee526da27b765743d34ee1e8aa6277bf191 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -16907,6 +16907,35 @@ RawString* String::ToLowerCase(const String& str, Heap::Space space) { |
| return Transform(CaseMapping::ToLower, str, space); |
| } |
| +bool String::ParseDouble(const String& str, |
| + intptr_t start, intptr_t end, |
| + double* result) { |
| + ASSERT(0 <= start); |
| + ASSERT(start <= end); |
| + ASSERT(end <= str.Length()); |
| + int length = end - start; |
|
Ivan Posva
2014/07/03 19:44:14
Please always use intptr_t.
Lasse Reichstein Nielsen
2014/07/04 06:46:01
Ack, yes. Will do.
|
| + NoGCScope no_gc; |
| + const uint8_t* startChar; |
| + if (str.IsOneByteString()) { |
| + startChar = OneByteString::CharAddr(str, start); |
| + } else if (str.IsExternalOneByteString()) { |
| + startChar = ExternalOneByteString::CharAddr(str, start); |
| + } else { |
| + uint8_t* chars = Isolate::Current()->current_zone()->Alloc<uint8_t>(length); |
| + for (int i = 0; i < length; i++) { |
|
Ivan Posva
2014/07/03 19:44:14
intptr_t
|
| + int ch = str.CharAt(start + i); |
|
Ivan Posva
2014/07/03 19:44:14
The return type of CharAt is int32_t.
Also it wou
Lasse Reichstein Nielsen
2014/07/04 06:46:01
Will do.
Didn't know about the CharAtFunc - nice!
|
| + if (ch < 128) { |
| + chars[i] = ch; |
| + } else { |
| + return false; // Not ASCII, so definitely not valid double numeral. |
| + } |
| + } |
| + startChar = chars; |
| + } |
| + return CStringToDouble(reinterpret_cast<const char*>(startChar), |
| + length, result); |
| +} |
| + |
| // Check to see if 'str1' matches 'str2' as is or |
| // once the private key separator is stripped from str2. |