OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 26 matching lines...) Expand all Loading... |
37 public: | 37 public: |
38 | 38 |
39 // Parse the string as a date. If parsing succeeds, return true after | 39 // Parse the string as a date. If parsing succeeds, return true after |
40 // filling out the output array as follows (all integers are Smis): | 40 // filling out the output array as follows (all integers are Smis): |
41 // [0]: year | 41 // [0]: year |
42 // [1]: month (0 = Jan, 1 = Feb, ...) | 42 // [1]: month (0 = Jan, 1 = Feb, ...) |
43 // [2]: day | 43 // [2]: day |
44 // [3]: hour | 44 // [3]: hour |
45 // [4]: minute | 45 // [4]: minute |
46 // [5]: second | 46 // [5]: second |
47 // [6]: UTC offset in seconds, or null value if no timezone specified | 47 // [6]: millisecond |
| 48 // [7]: UTC offset in seconds, or null value if no timezone specified |
48 // If parsing fails, return false (content of output array is not defined). | 49 // If parsing fails, return false (content of output array is not defined). |
49 template <typename Char> | 50 template <typename Char> |
50 static bool Parse(Vector<Char> str, FixedArray* output); | 51 static bool Parse(Vector<Char> str, FixedArray* output); |
51 | 52 |
52 enum { | 53 enum { |
53 YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, UTC_OFFSET, OUTPUT_SIZE | 54 YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND, UTC_OFFSET, OUTPUT_SIZE |
54 }; | 55 }; |
55 | 56 |
56 private: | 57 private: |
57 // Range testing | 58 // Range testing |
58 static inline bool Between(int x, int lo, int hi) { | 59 static inline bool Between(int x, int lo, int hi) { |
59 return static_cast<unsigned>(x - lo) <= static_cast<unsigned>(hi - lo); | 60 return static_cast<unsigned>(x - lo) <= static_cast<unsigned>(hi - lo); |
60 } | 61 } |
61 // Indicates a missing value. | 62 // Indicates a missing value. |
62 static const int kNone = kMaxInt; | 63 static const int kNone = kMaxInt; |
63 | 64 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 int sign_; | 183 int sign_; |
183 int hour_; | 184 int hour_; |
184 int minute_; | 185 int minute_; |
185 }; | 186 }; |
186 | 187 |
187 class TimeComposer BASE_EMBEDDED { | 188 class TimeComposer BASE_EMBEDDED { |
188 public: | 189 public: |
189 TimeComposer() : index_(0), hour_offset_(kNone) {} | 190 TimeComposer() : index_(0), hour_offset_(kNone) {} |
190 bool IsEmpty() const { return index_ == 0; } | 191 bool IsEmpty() const { return index_ == 0; } |
191 bool IsExpecting(int n) const { | 192 bool IsExpecting(int n) const { |
192 return (index_ == 1 && IsMinute(n)) || (index_ == 2 && IsSecond(n)); | 193 return (index_ == 1 && IsMinute(n)) || |
| 194 (index_ == 2 && IsSecond(n)) || |
| 195 (index_ == 3 && IsMillisecond(n)); |
193 } | 196 } |
194 bool Add(int n) { | 197 bool Add(int n) { |
195 return index_ < kSize ? (comp_[index_++] = n, true) : false; | 198 return index_ < kSize ? (comp_[index_++] = n, true) : false; |
196 } | 199 } |
197 bool AddFinal(int n) { | 200 bool AddFinal(int n) { |
198 if (!Add(n)) return false; | 201 if (!Add(n)) return false; |
199 while (index_ < kSize) comp_[index_++] = 0; | 202 while (index_ < kSize) comp_[index_++] = 0; |
200 return true; | 203 return true; |
201 } | 204 } |
202 void SetHourOffset(int n) { hour_offset_ = n; } | 205 void SetHourOffset(int n) { hour_offset_ = n; } |
203 bool Write(FixedArray* output); | 206 bool Write(FixedArray* output); |
204 | 207 |
205 static bool IsMinute(int x) { return Between(x, 0, 59); } | 208 static bool IsMinute(int x) { return Between(x, 0, 59); } |
206 private: | 209 private: |
207 static bool IsHour(int x) { return Between(x, 0, 23); } | 210 static bool IsHour(int x) { return Between(x, 0, 23); } |
208 static bool IsHour12(int x) { return Between(x, 0, 12); } | 211 static bool IsHour12(int x) { return Between(x, 0, 12); } |
209 static bool IsSecond(int x) { return Between(x, 0, 59); } | 212 static bool IsSecond(int x) { return Between(x, 0, 59); } |
| 213 static bool IsMillisecond(int x) { return Between(x, 0, 999); } |
210 | 214 |
211 static const int kSize = 3; | 215 static const int kSize = 4; |
212 int comp_[kSize]; | 216 int comp_[kSize]; |
213 int index_; | 217 int index_; |
214 int hour_offset_; | 218 int hour_offset_; |
215 }; | 219 }; |
216 | 220 |
217 class DayComposer BASE_EMBEDDED { | 221 class DayComposer BASE_EMBEDDED { |
218 public: | 222 public: |
219 DayComposer() : index_(0), named_month_(kNone) {} | 223 DayComposer() : index_(0), named_month_(kNone) {} |
220 bool IsEmpty() const { return index_ == 0; } | 224 bool IsEmpty() const { return index_ == 0; } |
221 bool Add(int n) { | 225 bool Add(int n) { |
222 return index_ < kSize ? (comp_[index_++] = n, true) : false; | 226 return index_ < kSize ? (comp_[index_++] = n, true) : false; |
223 } | 227 } |
224 void SetNamedMonth(int n) { named_month_ = n; } | 228 void SetNamedMonth(int n) { named_month_ = n; } |
225 bool Write(FixedArray* output); | 229 bool Write(FixedArray* output); |
226 private: | 230 private: |
227 static bool IsMonth(int x) { return Between(x, 1, 12); } | 231 static bool IsMonth(int x) { return Between(x, 1, 12); } |
228 static bool IsDay(int x) { return Between(x, 1, 31); } | 232 static bool IsDay(int x) { return Between(x, 1, 31); } |
229 | 233 |
230 static const int kSize = 3; | 234 static const int kSize = 3; |
231 int comp_[kSize]; | 235 int comp_[kSize]; |
232 int index_; | 236 int index_; |
233 int named_month_; | 237 int named_month_; |
234 }; | 238 }; |
235 }; | 239 }; |
236 | 240 |
237 | 241 |
238 } } // namespace v8::internal | 242 } } // namespace v8::internal |
239 | 243 |
240 #endif // V8_DATEPARSER_H_ | 244 #endif // V8_DATEPARSER_H_ |
OLD | NEW |