Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: src/dateparser.h

Issue 6824071: Cleanup of ScannerConstants, now named UnicodeCache. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed review comments. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/conversions.cc ('k') | src/dateparser-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 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
11 // with the distribution. 11 // with the distribution.
(...skipping 30 matching lines...) Expand all
42 // [0]: year 42 // [0]: year
43 // [1]: month (0 = Jan, 1 = Feb, ...) 43 // [1]: month (0 = Jan, 1 = Feb, ...)
44 // [2]: day 44 // [2]: day
45 // [3]: hour 45 // [3]: hour
46 // [4]: minute 46 // [4]: minute
47 // [5]: second 47 // [5]: second
48 // [6]: millisecond 48 // [6]: millisecond
49 // [7]: UTC offset in seconds, or null value if no timezone specified 49 // [7]: UTC offset in seconds, or null value if no timezone specified
50 // If parsing fails, return false (content of output array is not defined). 50 // If parsing fails, return false (content of output array is not defined).
51 template <typename Char> 51 template <typename Char>
52 static bool Parse(Vector<Char> str, FixedArray* output); 52 static bool Parse(Vector<Char> str, FixedArray* output, UnicodeCache* cache);
53 53
54 enum { 54 enum {
55 YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND, UTC_OFFSET, OUTPUT_SIZE 55 YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND, UTC_OFFSET, OUTPUT_SIZE
56 }; 56 };
57 57
58 private: 58 private:
59 // Range testing 59 // Range testing
60 static inline bool Between(int x, int lo, int hi) { 60 static inline bool Between(int x, int lo, int hi) {
61 return static_cast<unsigned>(x - lo) <= static_cast<unsigned>(hi - lo); 61 return static_cast<unsigned>(x - lo) <= static_cast<unsigned>(hi - lo);
62 } 62 }
63 // Indicates a missing value. 63 // Indicates a missing value.
64 static const int kNone = kMaxInt; 64 static const int kNone = kMaxInt;
65 65
66 // InputReader provides basic string parsing and character classification. 66 // InputReader provides basic string parsing and character classification.
67 template <typename Char> 67 template <typename Char>
68 class InputReader BASE_EMBEDDED { 68 class InputReader BASE_EMBEDDED {
69 public: 69 public:
70 explicit InputReader(Vector<Char> s) 70 InputReader(UnicodeCache* unicode_cache, Vector<Char> s)
71 : index_(0), 71 : index_(0),
72 buffer_(s), 72 buffer_(s),
73 has_read_number_(false), 73 has_read_number_(false),
74 scanner_constants_(Isolate::Current()->scanner_constants()) { 74 unicode_cache_(unicode_cache) {
75 Next(); 75 Next();
76 } 76 }
77 77
78 // Advance to the next character of the string. 78 // Advance to the next character of the string.
79 void Next() { ch_ = (index_ < buffer_.length()) ? buffer_[index_++] : 0; } 79 void Next() { ch_ = (index_ < buffer_.length()) ? buffer_[index_++] : 0; }
80 80
81 // Read a string of digits as an unsigned number (cap just below kMaxInt). 81 // Read a string of digits as an unsigned number (cap just below kMaxInt).
82 int ReadUnsignedNumber() { 82 int ReadUnsignedNumber() {
83 has_read_number_ = true; 83 has_read_number_ = true;
84 int n; 84 int n;
(...skipping 30 matching lines...) Expand all
115 // The skip methods return whether they actually skipped something. 115 // The skip methods return whether they actually skipped something.
116 bool Skip(uint32_t c) { 116 bool Skip(uint32_t c) {
117 if (ch_ == c) { 117 if (ch_ == c) {
118 Next(); 118 Next();
119 return true; 119 return true;
120 } 120 }
121 return false; 121 return false;
122 } 122 }
123 123
124 bool SkipWhiteSpace() { 124 bool SkipWhiteSpace() {
125 if (scanner_constants_->IsWhiteSpace(ch_)) { 125 if (unicode_cache_->IsWhiteSpace(ch_)) {
126 Next(); 126 Next();
127 return true; 127 return true;
128 } 128 }
129 return false; 129 return false;
130 } 130 }
131 131
132 bool SkipParentheses() { 132 bool SkipParentheses() {
133 if (ch_ != '(') return false; 133 if (ch_ != '(') return false;
134 int balance = 0; 134 int balance = 0;
135 do { 135 do {
(...skipping 15 matching lines...) Expand all
151 int GetAsciiSignValue() const { return 44 - static_cast<int>(ch_); } 151 int GetAsciiSignValue() const { return 44 - static_cast<int>(ch_); }
152 152
153 // Indicates whether any (possibly empty!) numbers have been read. 153 // Indicates whether any (possibly empty!) numbers have been read.
154 bool HasReadNumber() const { return has_read_number_; } 154 bool HasReadNumber() const { return has_read_number_; }
155 155
156 private: 156 private:
157 int index_; 157 int index_;
158 Vector<Char> buffer_; 158 Vector<Char> buffer_;
159 bool has_read_number_; 159 bool has_read_number_;
160 uint32_t ch_; 160 uint32_t ch_;
161 ScannerConstants* scanner_constants_; 161 UnicodeCache* unicode_cache_;
162 }; 162 };
163 163
164 enum KeywordType { INVALID, MONTH_NAME, TIME_ZONE_NAME, AM_PM }; 164 enum KeywordType { INVALID, MONTH_NAME, TIME_ZONE_NAME, AM_PM };
165 165
166 // KeywordTable maps names of months, time zones, am/pm to numbers. 166 // KeywordTable maps names of months, time zones, am/pm to numbers.
167 class KeywordTable : public AllStatic { 167 class KeywordTable : public AllStatic {
168 public: 168 public:
169 // Look up a word in the keyword table and return an index. 169 // Look up a word in the keyword table and return an index.
170 // 'pre' contains a prefix of the word, zero-padded to size kPrefixLength 170 // 'pre' contains a prefix of the word, zero-padded to size kPrefixLength
171 // and 'len' is the word length. 171 // and 'len' is the word length.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 int comp_[kSize]; 256 int comp_[kSize];
257 int index_; 257 int index_;
258 int named_month_; 258 int named_month_;
259 }; 259 };
260 }; 260 };
261 261
262 262
263 } } // namespace v8::internal 263 } } // namespace v8::internal
264 264
265 #endif // V8_DATEPARSER_H_ 265 #endif // V8_DATEPARSER_H_
OLDNEW
« no previous file with comments | « src/conversions.cc ('k') | src/dateparser-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698