1// Copyright 2013 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27// limitations under the License. 28 29 30/** 31 * List of available services. 32 */ 33var AVAILABLE_SERVICES = ['collator', 34 'numberformat', 35 'dateformat', 36 'breakiterator']; 37 38/** 39 * Caches available locales for each service. 40 */ 41var AVAILABLE_LOCALES = { 42 'collator': undefined, 43 'numberformat': undefined, 44 'dateformat': undefined, 45 'breakiterator': undefined 46}; 47 48/** 49 * Caches default ICU locale. 50 */ 51var DEFAULT_ICU_LOCALE = undefined; 52 53/** 54 * Unicode extension regular expression. 55 */ 56var UNICODE_EXTENSION_RE = new RegExp('-u(-[a-z0-9]{2,8})+', 'g'); 57 58/** 59 * Matches any Unicode extension. 60 */ 61var ANY_EXTENSION_RE = new RegExp('-[a-z0-9]{1}-.*', 'g'); 62 63/** 64 * Replace quoted text (single quote, anything but the quote and quote again). 65 */ 66var QUOTED_STRING_RE = new RegExp("'[^']+'", 'g'); 67 68/** 69 * Matches valid service name. 70 */ 71var SERVICE_RE = 72 new RegExp('^(collator|numberformat|dateformat|breakiterator)$'); 73 74/** 75 * Validates a language tag against bcp47 spec. 76 * Actual value is assigned on first run. 77 */ 78var LANGUAGE_TAG_RE = undefined; 79 80/** 81 * Helps find duplicate variants in the language tag. 82 */ 83var LANGUAGE_VARIANT_RE = undefined; 84 85/** 86 * Helps find duplicate singletons in the language tag. 87 */ 88var LANGUAGE_SINGLETON_RE = undefined; 89 90/** 91 * Matches valid IANA time zone names. 92 */ 93var TIMEZONE_NAME_CHECK_RE = 94 new RegExp('^([A-Za-z]+)/([A-Za-z]+)(?:_([A-Za-z]+))*$'); 95 96/** 97 * Maps ICU calendar names into LDML type. 98 */ 99var ICU_CALENDAR_MAP = { 100 'gregorian': 'gregory', 101 'japanese': 'japanese', 102 'buddhist': 'buddhist', 103 'roc': 'roc', 104 'persian': 'persian', 105 'islamic-civil': 'islamicc', 106 'islamic': 'islamic', 107 'hebrew': 'hebrew', 108 'chinese': 'chinese', 109 'indian': 'indian', 110 'coptic': 'coptic', 111 'ethiopic': 'ethiopic', 112 'ethiopic-amete-alem': 'ethioaa' 113}; 114 115/** 116 * Map of Unicode extensions to option properties, and their values and types, 117 * for a collator. 118 */ 119var COLLATOR_KEY_MAP = { 120 'kn': {'property': 'numeric', 'type': 'boolean'}, 121 'kf': {'property': 'caseFirst', 'type': 'string', 122 'values': ['false', 'lower', 'upper']} 123}; 124 125/** 126 * Map of Unicode extensions to option properties, and their values and types, 127 * for a number format. 128 */ 129var NUMBER_FORMAT_KEY_MAP = { 130 'nu': {'property': undefined, 'type': 'string'} 131}; 132 133/** 134 * Map of Unicode extensions to option properties, and their values and types, 135 * for a date/time format. 136 */ 137var DATETIME_FORMAT_KEY_MAP = { 138 'ca': {'property': undefined, 'type': 'string'}, 139 'nu': {'property': undefined, 'type': 'string'} 140}; 141 142/** 143 * Allowed -u-co- values. List taken from: 144 * http://unicode.org/repos/cldr/trunk/common/bcp47/collation.xml 145 */ 146var ALLOWED_CO_VALUES = [ 147 'big5han', 'dict', 'direct', 'ducet', 'gb2312', 'phonebk', 'phonetic', 148 'pinyin', 'reformed', 'searchjl', 'stroke', 'trad', 'unihan', 'zhuyin' 149]; 150 151/** 152 * Object attributes (configurable, writable, enumerable). 153 * To combine attributes, OR them. 154 * Values/names are copied from v8/include/v8.h:PropertyAttribute 155 */ 156var ATTRIBUTES = { 157 'NONE': 0, 158 'READ_ONLY': 1, 159 'DONT_ENUM': 2, 160 'DONT_DELETE': 4 161}; 162 163/** 164 * Error message for when function object is created with new and it's not 165 * a constructor. 166 */ 167var ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR = 168 'Function object that\'s not a constructor was created with new'; 169