1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 23 * DAMAGE. 24 */ 25 26 #ifndef DateTimeFormat_h 27 #define DateTimeFormat_h 28 29 #include "wtf/Forward.h" 30 31 namespace WebCore { 32 33 // DateTimeFormat parses date time format defined in Unicode Technical 34 // standard 35, Locale Data Markup Language (LDML)[1]. 35 // [1] LDML http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns 36 class DateTimeFormat { 37 public: 38 enum FieldType { 39 FieldTypeInvalid, 40 FieldTypeLiteral, 41 42 // Era: AD 43 FieldTypeEra = 'G', 44 45 // Year: 1996 46 FieldTypeYear = 'y', 47 FieldTypeYearOfWeekOfYear = 'Y', 48 FieldTypeExtendedYear = 'u', 49 50 // Quater: Q2 51 FieldTypeQuater = 'Q', 52 FieldTypeQuaterStandAlone = 'q', 53 54 // Month: September 55 FieldTypeMonth = 'M', 56 FieldTypeMonthStandAlone = 'L', 57 58 // Week: 42 59 FieldTypeWeekOfYear = 'w', 60 FieldTypeWeekOfMonth = 'W', 61 62 // Day: 12 63 FieldTypeDayOfMonth = 'd', 64 FieldTypeDayOfYear = 'D', 65 FieldTypeDayOfWeekInMonth = 'F', 66 FieldTypeModifiedJulianDay = 'g', 67 68 // Week Day: Tuesday 69 FieldTypeDayOfWeek = 'E', 70 FieldTypeLocalDayOfWeek = 'e', 71 FieldTypeLocalDayOfWeekStandAlon = 'c', 72 73 // Period: AM or PM 74 FieldTypePeriod = 'a', 75 76 // Hour: 7 77 FieldTypeHour12 = 'h', 78 FieldTypeHour23 = 'H', 79 FieldTypeHour11 = 'K', 80 FieldTypeHour24 = 'k', 81 82 // Minute: 59 83 FieldTypeMinute = 'm', 84 85 // Second: 12 86 FieldTypeSecond = 's', 87 FieldTypeFractionalSecond = 'S', 88 FieldTypeMillisecondsInDay = 'A', 89 90 // Zone: PDT 91 FieldTypeZone = 'z', 92 FieldTypeRFC822Zone = 'Z', 93 FieldTypeNonLocationZone = 'v', 94 }; 95 96 class TokenHandler { 97 public: 98 virtual ~TokenHandler() { } 99 virtual void visitField(FieldType, int numberOfPatternCharacters) = 0; 100 virtual void visitLiteral(const String&) = 0; 101 }; 102 103 // Returns true if succeeded, false if failed. 104 static bool parse(const String&, TokenHandler&); 105 static void quoteAndAppendLiteral(const String&, StringBuilder&); 106 }; 107 108 } // namespace WebCore 109 110 #endif // DateTimeFormat_h 111