Chromium Code Reviews| Index: src/conversions.cc |
| diff --git a/src/conversions.cc b/src/conversions.cc |
| index 1d5ed35f93c83510146bb4bf518bbc51347d8672..616c707fd9a156309c80ebf7318438a6b61d1b70 100644 |
| --- a/src/conversions.cc |
| +++ b/src/conversions.cc |
| @@ -29,8 +29,13 @@ |
| #include <limits.h> |
| #include <cmath> |
| +#include "v8.h" |
| + |
| +#include "assert-scope.h" |
| +#include "conversions.h" |
| #include "conversions-inl.h" |
| #include "dtoa.h" |
| +#include "factory.h" |
| #include "list-inl.h" |
| #include "strtod.h" |
| #include "utils.h" |
| @@ -44,6 +49,49 @@ namespace v8 { |
| namespace internal { |
| +namespace { |
| + |
| +// C++-style iterator adaptor for StringCharacterStream |
| +// (unlike C++ iterators the end-marker has different type). |
| +class StringCharacterStreamIterator { |
| + public: |
| + class EndMarker {}; |
| + |
| + explicit StringCharacterStreamIterator(StringCharacterStream* stream); |
| + |
| + uint16_t operator*() const; |
| + void operator++(); |
| + bool operator==(EndMarker const&) const { return end_; } |
| + bool operator!=(EndMarker const& m) const { return !end_; } |
| + |
| + private: |
| + StringCharacterStream* const stream_; |
| + uint16_t current_; |
| + bool end_; |
| +}; |
| + |
| + |
| +StringCharacterStreamIterator::StringCharacterStreamIterator( |
| + StringCharacterStream* stream) : stream_(stream) { |
| + ++(*this); |
| +} |
| + |
| +uint16_t StringCharacterStreamIterator::operator*() const { |
| + return current_; |
| +} |
| + |
| + |
| +void StringCharacterStreamIterator::operator++() { |
| + end_ = !stream_->HasMore(); |
| + if (!end_) { |
| + current_ = stream_->GetNext(); |
| + } |
| +} |
| +} // End anonymous namespace. |
| + |
| + |
| + |
|
Michael Starzinger
2014/04/28 08:39:16
nit: Two lines of white-space ought'a be enough fo
|
| + |
| double StringToDouble(UnicodeCache* unicode_cache, |
| const char* str, int flags, double empty_string_val) { |
| // We cast to const uint8_t* here to avoid instantiating the |
| @@ -460,4 +508,21 @@ char* DoubleToRadixCString(double value, int radix) { |
| return builder.Finalize(); |
| } |
| +double StringToDouble(UnicodeCache* unicode_cache, |
| + String* string, |
| + int flags, |
| + double empty_string_val) { |
| + DisallowHeapAllocation no_gc; |
| + String::FlatContent flat = string->GetFlatContent(); |
| + // ECMA-262 section 15.1.2.3, empty string is NaN |
| + if (flat.IsAscii()) { |
| + return StringToDouble( |
| + unicode_cache, flat.ToOneByteVector(), flags, empty_string_val); |
| + } else { |
| + return StringToDouble( |
| + unicode_cache, flat.ToUC16Vector(), flags, empty_string_val); |
| + } |
| +} |
| + |
| + |
| } } // namespace v8::internal |