OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 11 matching lines...) Expand all Loading... | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include <stdarg.h> | 28 #include <stdarg.h> |
29 #include <limits.h> | 29 #include <limits.h> |
30 #include <cmath> | 30 #include <cmath> |
31 | 31 |
32 #include "v8.h" | |
33 | |
34 #include "assert-scope.h" | |
35 #include "conversions.h" | |
32 #include "conversions-inl.h" | 36 #include "conversions-inl.h" |
33 #include "dtoa.h" | 37 #include "dtoa.h" |
38 #include "factory.h" | |
34 #include "list-inl.h" | 39 #include "list-inl.h" |
35 #include "strtod.h" | 40 #include "strtod.h" |
36 #include "utils.h" | 41 #include "utils.h" |
37 | 42 |
38 #ifndef _STLP_VENDOR_CSTD | 43 #ifndef _STLP_VENDOR_CSTD |
39 // STLPort doesn't import fpclassify into the std namespace. | 44 // STLPort doesn't import fpclassify into the std namespace. |
40 using std::fpclassify; | 45 using std::fpclassify; |
41 #endif | 46 #endif |
42 | 47 |
43 namespace v8 { | 48 namespace v8 { |
44 namespace internal { | 49 namespace internal { |
45 | 50 |
46 | 51 |
52 namespace { | |
53 | |
54 // C++-style iterator adaptor for StringCharacterStream | |
55 // (unlike C++ iterators the end-marker has different type). | |
56 class StringCharacterStreamIterator { | |
57 public: | |
58 class EndMarker {}; | |
59 | |
60 explicit StringCharacterStreamIterator(StringCharacterStream* stream); | |
61 | |
62 uint16_t operator*() const; | |
63 void operator++(); | |
64 bool operator==(EndMarker const&) const { return end_; } | |
65 bool operator!=(EndMarker const& m) const { return !end_; } | |
66 | |
67 private: | |
68 StringCharacterStream* const stream_; | |
69 uint16_t current_; | |
70 bool end_; | |
71 }; | |
72 | |
73 | |
74 StringCharacterStreamIterator::StringCharacterStreamIterator( | |
75 StringCharacterStream* stream) : stream_(stream) { | |
76 ++(*this); | |
77 } | |
78 | |
79 uint16_t StringCharacterStreamIterator::operator*() const { | |
80 return current_; | |
81 } | |
82 | |
83 | |
84 void StringCharacterStreamIterator::operator++() { | |
85 end_ = !stream_->HasMore(); | |
86 if (!end_) { | |
87 current_ = stream_->GetNext(); | |
88 } | |
89 } | |
90 } // End anonymous namespace. | |
91 | |
92 | |
93 | |
Michael Starzinger
2014/04/28 08:39:16
nit: Two lines of white-space ought'a be enough fo
| |
94 | |
47 double StringToDouble(UnicodeCache* unicode_cache, | 95 double StringToDouble(UnicodeCache* unicode_cache, |
48 const char* str, int flags, double empty_string_val) { | 96 const char* str, int flags, double empty_string_val) { |
49 // We cast to const uint8_t* here to avoid instantiating the | 97 // We cast to const uint8_t* here to avoid instantiating the |
50 // InternalStringToDouble() template for const char* as well. | 98 // InternalStringToDouble() template for const char* as well. |
51 const uint8_t* start = reinterpret_cast<const uint8_t*>(str); | 99 const uint8_t* start = reinterpret_cast<const uint8_t*>(str); |
52 const uint8_t* end = start + StrLength(str); | 100 const uint8_t* end = start + StrLength(str); |
53 return InternalStringToDouble(unicode_cache, start, end, flags, | 101 return InternalStringToDouble(unicode_cache, start, end, flags, |
54 empty_string_val); | 102 empty_string_val); |
55 } | 103 } |
56 | 104 |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 // If the number has a decimal part, leave room for the period. | 501 // If the number has a decimal part, leave room for the period. |
454 if (decimal_pos > 0) result_size++; | 502 if (decimal_pos > 0) result_size++; |
455 // Allocate result and fill in the parts. | 503 // Allocate result and fill in the parts. |
456 SimpleStringBuilder builder(result_size + 1); | 504 SimpleStringBuilder builder(result_size + 1); |
457 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); | 505 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); |
458 if (decimal_pos > 0) builder.AddCharacter('.'); | 506 if (decimal_pos > 0) builder.AddCharacter('.'); |
459 builder.AddSubstring(decimal_buffer, decimal_pos); | 507 builder.AddSubstring(decimal_buffer, decimal_pos); |
460 return builder.Finalize(); | 508 return builder.Finalize(); |
461 } | 509 } |
462 | 510 |
511 double StringToDouble(UnicodeCache* unicode_cache, | |
512 String* string, | |
513 int flags, | |
514 double empty_string_val) { | |
515 DisallowHeapAllocation no_gc; | |
516 String::FlatContent flat = string->GetFlatContent(); | |
517 // ECMA-262 section 15.1.2.3, empty string is NaN | |
518 if (flat.IsAscii()) { | |
519 return StringToDouble( | |
520 unicode_cache, flat.ToOneByteVector(), flags, empty_string_val); | |
521 } else { | |
522 return StringToDouble( | |
523 unicode_cache, flat.ToUC16Vector(), flags, empty_string_val); | |
524 } | |
525 } | |
526 | |
527 | |
463 } } // namespace v8::internal | 528 } } // namespace v8::internal |
OLD | NEW |