OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_DATEPARSER_INL_H_ | 5 #ifndef V8_DATEPARSER_INL_H_ |
6 #define V8_DATEPARSER_INL_H_ | 6 #define V8_DATEPARSER_INL_H_ |
7 | 7 |
8 #include "src/dateparser.h" | 8 #include "src/dateparser.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 template <typename Char> | 13 template <typename Char> |
14 bool DateParser::Parse(Vector<Char> str, | 14 bool DateParser::Parse(Vector<Char> str, |
15 FixedArray* out, | 15 FixedArray* out, |
16 UnicodeCache* unicode_cache) { | 16 UnicodeCache* unicode_cache) { |
17 ASSERT(out->length() >= OUTPUT_SIZE); | 17 DCHECK(out->length() >= OUTPUT_SIZE); |
18 InputReader<Char> in(unicode_cache, str); | 18 InputReader<Char> in(unicode_cache, str); |
19 DateStringTokenizer<Char> scanner(&in); | 19 DateStringTokenizer<Char> scanner(&in); |
20 TimeZoneComposer tz; | 20 TimeZoneComposer tz; |
21 TimeComposer time; | 21 TimeComposer time; |
22 DayComposer day; | 22 DayComposer day; |
23 | 23 |
24 // Specification: | 24 // Specification: |
25 // Accept ES5 ISO 8601 date-time-strings or legacy dates compatible | 25 // Accept ES5 ISO 8601 date-time-strings or legacy dates compatible |
26 // with Safari. | 26 // with Safari. |
27 // ES5 ISO 8601 dates: | 27 // ES5 ISO 8601 dates: |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 int n = in_->ReadUnsignedNumeral(); | 168 int n = in_->ReadUnsignedNumeral(); |
169 int length = in_->position() - pre_pos; | 169 int length = in_->position() - pre_pos; |
170 return DateToken::Number(n, length); | 170 return DateToken::Number(n, length); |
171 } | 171 } |
172 if (in_->Skip(':')) return DateToken::Symbol(':'); | 172 if (in_->Skip(':')) return DateToken::Symbol(':'); |
173 if (in_->Skip('-')) return DateToken::Symbol('-'); | 173 if (in_->Skip('-')) return DateToken::Symbol('-'); |
174 if (in_->Skip('+')) return DateToken::Symbol('+'); | 174 if (in_->Skip('+')) return DateToken::Symbol('+'); |
175 if (in_->Skip('.')) return DateToken::Symbol('.'); | 175 if (in_->Skip('.')) return DateToken::Symbol('.'); |
176 if (in_->Skip(')')) return DateToken::Symbol(')'); | 176 if (in_->Skip(')')) return DateToken::Symbol(')'); |
177 if (in_->IsAsciiAlphaOrAbove()) { | 177 if (in_->IsAsciiAlphaOrAbove()) { |
178 ASSERT(KeywordTable::kPrefixLength == 3); | 178 DCHECK(KeywordTable::kPrefixLength == 3); |
179 uint32_t buffer[3] = {0, 0, 0}; | 179 uint32_t buffer[3] = {0, 0, 0}; |
180 int length = in_->ReadWord(buffer, 3); | 180 int length = in_->ReadWord(buffer, 3); |
181 int index = KeywordTable::Lookup(buffer, length); | 181 int index = KeywordTable::Lookup(buffer, length); |
182 return DateToken::Keyword(KeywordTable::GetType(index), | 182 return DateToken::Keyword(KeywordTable::GetType(index), |
183 KeywordTable::GetValue(index), | 183 KeywordTable::GetValue(index), |
184 length); | 184 length); |
185 } | 185 } |
186 if (in_->SkipWhiteSpace()) { | 186 if (in_->SkipWhiteSpace()) { |
187 return DateToken::WhiteSpace(in_->position() - pre_pos); | 187 return DateToken::WhiteSpace(in_->position() - pre_pos); |
188 } | 188 } |
189 if (in_->SkipParentheses()) { | 189 if (in_->SkipParentheses()) { |
190 return DateToken::Unknown(); | 190 return DateToken::Unknown(); |
191 } | 191 } |
192 in_->Next(); | 192 in_->Next(); |
193 return DateToken::Unknown(); | 193 return DateToken::Unknown(); |
194 } | 194 } |
195 | 195 |
196 | 196 |
197 template <typename Char> | 197 template <typename Char> |
198 DateParser::DateToken DateParser::ParseES5DateTime( | 198 DateParser::DateToken DateParser::ParseES5DateTime( |
199 DateStringTokenizer<Char>* scanner, | 199 DateStringTokenizer<Char>* scanner, |
200 DayComposer* day, | 200 DayComposer* day, |
201 TimeComposer* time, | 201 TimeComposer* time, |
202 TimeZoneComposer* tz) { | 202 TimeZoneComposer* tz) { |
203 ASSERT(day->IsEmpty()); | 203 DCHECK(day->IsEmpty()); |
204 ASSERT(time->IsEmpty()); | 204 DCHECK(time->IsEmpty()); |
205 ASSERT(tz->IsEmpty()); | 205 DCHECK(tz->IsEmpty()); |
206 | 206 |
207 // Parse mandatory date string: [('-'|'+')yy]yyyy[':'MM[':'DD]] | 207 // Parse mandatory date string: [('-'|'+')yy]yyyy[':'MM[':'DD]] |
208 if (scanner->Peek().IsAsciiSign()) { | 208 if (scanner->Peek().IsAsciiSign()) { |
209 // Keep the sign token, so we can pass it back to the legacy | 209 // Keep the sign token, so we can pass it back to the legacy |
210 // parser if we don't use it. | 210 // parser if we don't use it. |
211 DateToken sign_token = scanner->Next(); | 211 DateToken sign_token = scanner->Next(); |
212 if (!scanner->Peek().IsFixedLengthNumber(6)) return sign_token; | 212 if (!scanner->Peek().IsFixedLengthNumber(6)) return sign_token; |
213 int sign = sign_token.ascii_sign(); | 213 int sign = sign_token.ascii_sign(); |
214 int year = scanner->Next().number(); | 214 int year = scanner->Next().number(); |
215 if (sign < 0 && year == 0) return sign_token; | 215 if (sign < 0 && year == 0) return sign_token; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // Successfully parsed ES5 Date Time String. Default to UTC if no TZ given. | 302 // Successfully parsed ES5 Date Time String. Default to UTC if no TZ given. |
303 if (tz->IsEmpty()) tz->Set(0); | 303 if (tz->IsEmpty()) tz->Set(0); |
304 day->set_iso_date(); | 304 day->set_iso_date(); |
305 return DateToken::EndOfInput(); | 305 return DateToken::EndOfInput(); |
306 } | 306 } |
307 | 307 |
308 | 308 |
309 } } // namespace v8::internal | 309 } } // namespace v8::internal |
310 | 310 |
311 #endif // V8_DATEPARSER_INL_H_ | 311 #endif // V8_DATEPARSER_INL_H_ |
OLD | NEW |