| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 private: | 160 private: |
| 161 Vector<Token> m_tokens; | 161 Vector<Token> m_tokens; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 protected: | 164 protected: |
| 165 Tokens parse(const String& formatString) | 165 Tokens parse(const String& formatString) |
| 166 { | 166 { |
| 167 TokenHandler handler; | 167 TokenHandler handler; |
| 168 if (!DateTimeFormat::parse(formatString, handler)) | 168 if (!DateTimeFormat::parse(formatString, handler)) |
| 169 return Tokens(Token("*failed*")); | 169 return Tokens(Token("*failed*")); |
| 170 return handler.tokens(); | 170 return handler.getTokens(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 FieldType single(const char ch) | 173 FieldType single(const char ch) |
| 174 { | 174 { |
| 175 char formatString[2]; | 175 char formatString[2]; |
| 176 formatString[0] = ch; | 176 formatString[0] = ch; |
| 177 formatString[1] = 0; | 177 formatString[1] = 0; |
| 178 TokenHandler handler; | 178 TokenHandler handler; |
| 179 if (!DateTimeFormat::parse(formatString, handler)) | 179 if (!DateTimeFormat::parse(formatString, handler)) |
| 180 return DateTimeFormat::FieldTypeInvalid; | 180 return DateTimeFormat::FieldTypeInvalid; |
| 181 return handler.fieldType(0); | 181 return handler.fieldType(0); |
| 182 } | 182 } |
| 183 | 183 |
| 184 private: | 184 private: |
| 185 class TokenHandler : public DateTimeFormat::TokenHandler { | 185 class TokenHandler : public DateTimeFormat::TokenHandler { |
| 186 public: | 186 public: |
| 187 ~TokenHandler() override { } | 187 ~TokenHandler() override { } |
| 188 | 188 |
| 189 FieldType fieldType(int index) const | 189 FieldType fieldType(int index) const |
| 190 { | 190 { |
| 191 return index >=0 && index < static_cast<int>(m_tokens.size()) ? m_to
kens[index].fieldType : DateTimeFormat::FieldTypeInvalid; | 191 return index >=0 && index < static_cast<int>(m_tokens.size()) ? m_to
kens[index].fieldType : DateTimeFormat::FieldTypeInvalid; |
| 192 } | 192 } |
| 193 | 193 |
| 194 Tokens tokens() const { return Tokens(m_tokens); } | 194 Tokens getTokens() const { return Tokens(m_tokens); } |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 void visitField(FieldType fieldType, int count) override | 197 void visitField(FieldType fieldType, int count) override |
| 198 { | 198 { |
| 199 m_tokens.append(Token(fieldType, count)); | 199 m_tokens.append(Token(fieldType, count)); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void visitLiteral(const String& string) override | 202 void visitLiteral(const String& string) override |
| 203 { | 203 { |
| 204 m_tokens.append(Token(string)); | 204 m_tokens.append(Token(string)); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('R')); | 331 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('R')); |
| 332 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('T')); | 332 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('T')); |
| 333 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('U')); | 333 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('U')); |
| 334 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('V')); | 334 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('V')); |
| 335 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('X')); | 335 EXPECT_EQ(DateTimeFormat::FieldTypeInvalid, single('X')); |
| 336 } | 336 } |
| 337 | 337 |
| 338 } // namespace blink | 338 } // namespace blink |
| 339 | 339 |
| 340 #endif | 340 #endif |
| OLD | NEW |