diff options
author | plundblad@chromium.org <plundblad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-15 06:09:07 +0000 |
---|---|---|
committer | plundblad@chromium.org <plundblad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-15 06:09:07 +0000 |
commit | ab14287e6094078e7299fbb658991318304882ba (patch) | |
tree | 32e47b2b844de2449ead3466ec073c253aa27f9b /chrome/third_party | |
parent | de7928d2ef16116b4f0c39ec82165e07c8c67399 (diff) | |
download | chromium_src-ab14287e6094078e7299fbb658991318304882ba.zip chromium_src-ab14287e6094078e7299fbb658991318304882ba.tar.gz chromium_src-ab14287e6094078e7299fbb658991318304882ba.tar.bz2 |
ChromeVox migration: closure library.
This adds a few files from the closure library that ChromeVox uses.
The files are put under
chrome/third_party/chromevox/third_party/closure-library to make it clear
that these are for use by chromevox only. The intention is to keep this
subset small, over time, replace current uses in ChromeVox with native
JavaScript equivalents. There are already some local modifications to the
files to get rid of some large dependencies. See README.chromium for more
details.
BUG=371692
R=dmazzoni@chromium.org, dtseng@chromium.org
Review URL: https://codereview.chromium.org/274363002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270591 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/third_party')
13 files changed, 4186 insertions, 433 deletions
diff --git a/chrome/third_party/chromevox/chromevox.gyp b/chrome/third_party/chromevox/chromevox.gyp index 685cf7c..9c2c173 100644 --- a/chrome/third_party/chromevox/chromevox.gyp +++ b/chrome/third_party/chromevox/chromevox.gyp @@ -39,8 +39,7 @@ { 'destination': '<(PRODUCT_DIR)/resources/chromeos/chromevox/closure', 'files': [ - 'closure/base.js', - 'closure/closure_preinit.js', + 'third_party/closure-library/closure/goog/base.js', ], }, { diff --git a/chrome/third_party/chromevox/closure/closure_preinit.js b/chrome/third_party/chromevox/closure/closure_preinit.js deleted file mode 100644 index 511dbaa..0000000 --- a/chrome/third_party/chromevox/closure/closure_preinit.js +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/** - * @fileoverview Code to execute before Closure's base.js. - * - */ - -/** - * Tell Closure to load JavaScript code from the extension root directory. - * @type {boolean} - */ -window.CLOSURE_BASE_PATH = chrome.extension.getURL('/closure/'); - -/** - * Tell Closure not to load deps.js; it's included by manifest.json already. - * @type {boolean} - */ -window.CLOSURE_NO_DEPS = true; - -/** - * Array of urls that should be included next, in order. - * @type {Array} - * @private - */ -window.queue_ = []; - -/** - * Custom function for importing ChromeVox scripts. - * @param {string} src The JS file to import. - * @return {boolean} Whether the script was imported. - */ -window.CLOSURE_IMPORT_SCRIPT = function(src) { - // Only run our version of the import script - // when trying to inject ChromeVox scripts. - if (src.indexOf('chrome-extension://') == 0) { - if (!goog.inHtmlDocument_() || - goog.dependencies_.written[src]) { - return false; - } - goog.dependencies_.written[src] = true; - function loadNextScript() { - if (goog.global.queue_.length == 0) - return; - - var src = goog.global.queue_[0]; - - if (window.CLOSURE_USE_EXT_MESSAGES) { - var relativeSrc = src.substr(src.indexOf('closure/..') + 11); - chrome.extension.sendMessage( - {'srcFile': relativeSrc}, - function(response) { - try { - eval(response['code']); - } catch (e) { - console.error('Script error: ' + e + ' in ' + src); - } - goog.global.queue_ = goog.global.queue_.slice(1); - loadNextScript(); - }); - return; - } - window.console.log('Using XHR'); - - // Load the script by fetching its source and running 'eval' on it - // directly, with a magic comment that makes Chrome treat it like it - // loaded normally. Wait until it's fetched before loading the - // next script. - var xhr = new XMLHttpRequest(); - var url = src + '?' + new Date().getTime(); - xhr.onreadystatechange = function() { - if (xhr.readyState == 4) { - var scriptText = xhr.responseText; - // Add a magic comment to the bottom of the file so that - // Chrome knows the name of the script in the JavaScript debugger. - scriptText += '\n//# sourceURL=' + src + '\n'; - eval(scriptText); - goog.global.queue_ = goog.global.queue_.slice(1); - loadNextScript(); - } - }; - xhr.open('GET', url, false); - xhr.send(null); - } - goog.global.queue_.push(src); - if (goog.global.queue_.length == 1) { - loadNextScript(); - } - return true; - } else { - return goog.writeScriptTag_(src); - } -}; diff --git a/chrome/third_party/chromevox/third_party/closure-library/LICENSE b/chrome/third_party/chromevox/third_party/closure-library/LICENSE new file mode 100644 index 0000000..d9a10c0 --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/LICENSE @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS diff --git a/chrome/third_party/chromevox/third_party/closure-library/README.chromium b/chrome/third_party/chromevox/third_party/closure-library/README.chromium new file mode 100644 index 0000000..3a130ff --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/README.chromium @@ -0,0 +1,17 @@ +Name: Closure Library +URL: https://github.com/google/closure-library +Version: 5a4878ece3dd35230a21d745411ab0985cf99e15 +InfoURL: http://developers.google.com/closure/library +License: Apache 2.0 + +Description: +Closure Library is a powerful, low level JavaScript library designed +for building complex and scalable web applications. + +Local Modifications: +Only the files actually used by ChromeVox are kept. In addition: +- closure/goog/i18n/messageformat.js was changed to use + Number.prototype.toLocaleString and not depend on the number format classes + in the Closure library. +- Most of closure/goog/string/string.js was deleted. The only function + left is goog.string.subs as it is needed by goog.asserts. diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/asserts/asserts.js b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/asserts/asserts.js new file mode 100644 index 0000000..4afdac3 --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/asserts/asserts.js @@ -0,0 +1,316 @@ +// Copyright 2008 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Utilities to check the preconditions, postconditions and + * invariants runtime. + * + * Methods in this package should be given special treatment by the compiler + * for type-inference. For example, <code>goog.asserts.assert(foo)</code> + * will restrict <code>foo</code> to a truthy value. + * + * The compiler has an option to disable asserts. So code like: + * <code> + * var x = goog.asserts.assert(foo()); goog.asserts.assert(bar()); + * </code> + * will be transformed into: + * <code> + * var x = foo(); + * </code> + * The compiler will leave in foo() (because its return value is used), + * but it will remove bar() because it assumes it does not have side-effects. + * + */ + +goog.provide('goog.asserts'); +goog.provide('goog.asserts.AssertionError'); + +goog.require('goog.debug.Error'); +goog.require('goog.dom.NodeType'); +goog.require('goog.string'); + + +/** + * @define {boolean} Whether to strip out asserts or to leave them in. + */ +goog.define('goog.asserts.ENABLE_ASSERTS', goog.DEBUG); + + + +/** + * Error object for failed assertions. + * @param {string} messagePattern The pattern that was used to form message. + * @param {!Array.<*>} messageArgs The items to substitute into the pattern. + * @constructor + * @extends {goog.debug.Error} + * @final + */ +goog.asserts.AssertionError = function(messagePattern, messageArgs) { + messageArgs.unshift(messagePattern); + goog.debug.Error.call(this, goog.string.subs.apply(null, messageArgs)); + // Remove the messagePattern afterwards to avoid permenantly modifying the + // passed in array. + messageArgs.shift(); + + /** + * The message pattern used to format the error message. Error handlers can + * use this to uniquely identify the assertion. + * @type {string} + */ + this.messagePattern = messagePattern; +}; +goog.inherits(goog.asserts.AssertionError, goog.debug.Error); + + +/** @override */ +goog.asserts.AssertionError.prototype.name = 'AssertionError'; + + +/** + * Throws an exception with the given message and "Assertion failed" prefixed + * onto it. + * @param {string} defaultMessage The message to use if givenMessage is empty. + * @param {Array.<*>} defaultArgs The substitution arguments for defaultMessage. + * @param {string|undefined} givenMessage Message supplied by the caller. + * @param {Array.<*>} givenArgs The substitution arguments for givenMessage. + * @throws {goog.asserts.AssertionError} When the value is not a number. + * @private + */ +goog.asserts.doAssertFailure_ = + function(defaultMessage, defaultArgs, givenMessage, givenArgs) { + var message = 'Assertion failed'; + if (givenMessage) { + message += ': ' + givenMessage; + var args = givenArgs; + } else if (defaultMessage) { + message += ': ' + defaultMessage; + args = defaultArgs; + } + // The '' + works around an Opera 10 bug in the unit tests. Without it, + // a stack trace is added to var message above. With this, a stack trace is + // not added until this line (it causes the extra garbage to be added after + // the assertion message instead of in the middle of it). + throw new goog.asserts.AssertionError('' + message, args || []); +}; + + +/** + * Checks if the condition evaluates to true if goog.asserts.ENABLE_ASSERTS is + * true. + * @template T + * @param {T} condition The condition to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {T} The value of the condition. + * @throws {goog.asserts.AssertionError} When the condition evaluates to false. + */ +goog.asserts.assert = function(condition, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !condition) { + goog.asserts.doAssertFailure_('', null, opt_message, + Array.prototype.slice.call(arguments, 2)); + } + return condition; +}; + + +/** + * Fails if goog.asserts.ENABLE_ASSERTS is true. This function is useful in case + * when we want to add a check in the unreachable area like switch-case + * statement: + * + * <pre> + * switch(type) { + * case FOO: doSomething(); break; + * case BAR: doSomethingElse(); break; + * default: goog.assert.fail('Unrecognized type: ' + type); + * // We have only 2 types - "default:" section is unreachable code. + * } + * </pre> + * + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @throws {goog.asserts.AssertionError} Failure. + */ +goog.asserts.fail = function(opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS) { + throw new goog.asserts.AssertionError( + 'Failure' + (opt_message ? ': ' + opt_message : ''), + Array.prototype.slice.call(arguments, 1)); + } +}; + + +/** + * Checks if the value is a number if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {number} The value, guaranteed to be a number when asserts enabled. + * @throws {goog.asserts.AssertionError} When the value is not a number. + */ +goog.asserts.assertNumber = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isNumber(value)) { + goog.asserts.doAssertFailure_('Expected number but got %s: %s.', + [goog.typeOf(value), value], opt_message, + Array.prototype.slice.call(arguments, 2)); + } + return /** @type {number} */ (value); +}; + + +/** + * Checks if the value is a string if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {string} The value, guaranteed to be a string when asserts enabled. + * @throws {goog.asserts.AssertionError} When the value is not a string. + */ +goog.asserts.assertString = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isString(value)) { + goog.asserts.doAssertFailure_('Expected string but got %s: %s.', + [goog.typeOf(value), value], opt_message, + Array.prototype.slice.call(arguments, 2)); + } + return /** @type {string} */ (value); +}; + + +/** + * Checks if the value is a function if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {!Function} The value, guaranteed to be a function when asserts + * enabled. + * @throws {goog.asserts.AssertionError} When the value is not a function. + */ +goog.asserts.assertFunction = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isFunction(value)) { + goog.asserts.doAssertFailure_('Expected function but got %s: %s.', + [goog.typeOf(value), value], opt_message, + Array.prototype.slice.call(arguments, 2)); + } + return /** @type {!Function} */ (value); +}; + + +/** + * Checks if the value is an Object if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {!Object} The value, guaranteed to be a non-null object. + * @throws {goog.asserts.AssertionError} When the value is not an object. + */ +goog.asserts.assertObject = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isObject(value)) { + goog.asserts.doAssertFailure_('Expected object but got %s: %s.', + [goog.typeOf(value), value], + opt_message, Array.prototype.slice.call(arguments, 2)); + } + return /** @type {!Object} */ (value); +}; + + +/** + * Checks if the value is an Array if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {!Array} The value, guaranteed to be a non-null array. + * @throws {goog.asserts.AssertionError} When the value is not an array. + */ +goog.asserts.assertArray = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isArray(value)) { + goog.asserts.doAssertFailure_('Expected array but got %s: %s.', + [goog.typeOf(value), value], opt_message, + Array.prototype.slice.call(arguments, 2)); + } + return /** @type {!Array} */ (value); +}; + + +/** + * Checks if the value is a boolean if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {boolean} The value, guaranteed to be a boolean when asserts are + * enabled. + * @throws {goog.asserts.AssertionError} When the value is not a boolean. + */ +goog.asserts.assertBoolean = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isBoolean(value)) { + goog.asserts.doAssertFailure_('Expected boolean but got %s: %s.', + [goog.typeOf(value), value], opt_message, + Array.prototype.slice.call(arguments, 2)); + } + return /** @type {boolean} */ (value); +}; + + +/** + * Checks if the value is a DOM Element if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {!Element} The value, likely to be a DOM Element when asserts are + * enabled. + * @throws {goog.asserts.AssertionError} When the value is not a boolean. + */ +goog.asserts.assertElement = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && (!goog.isObject(value) || + value.nodeType != goog.dom.NodeType.ELEMENT)) { + goog.asserts.doAssertFailure_('Expected Element but got %s: %s.', + [goog.typeOf(value), value], opt_message, + Array.prototype.slice.call(arguments, 2)); + } + return /** @type {!Element} */ (value); +}; + + +/** + * Checks if the value is an instance of the user-defined type if + * goog.asserts.ENABLE_ASSERTS is true. + * + * The compiler may tighten the type returned by this function. + * + * @param {*} value The value to check. + * @param {function(new: T, ...)} type A user-defined constructor. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @throws {goog.asserts.AssertionError} When the value is not an instance of + * type. + * @return {!T} + * @template T + */ +goog.asserts.assertInstanceof = function(value, type, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !(value instanceof type)) { + goog.asserts.doAssertFailure_('instanceof check failed.', null, + opt_message, Array.prototype.slice.call(arguments, 3)); + } + return value; +}; + + +/** + * Checks that no enumerable keys are present in Object.prototype. Such keys + * would break most code that use {@code for (var ... in ...)} loops. + */ +goog.asserts.assertObjectPrototypeIsIntact = function() { + for (var key in Object.prototype) { + goog.asserts.fail(key + ' should not be enumerable in Object.prototype.'); + } +}; diff --git a/chrome/third_party/chromevox/closure/base.js b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/base.js index 55c5537..68f871b 100644 --- a/chrome/third_party/chromevox/closure/base.js +++ b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/base.js @@ -19,8 +19,6 @@ * global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects to * include their own deps file(s) from different locations. * - * @author pupius@google.com (Dan Pupius) - * @author arv@google.com (Erik Arvidsson) * * @provideGoog */ @@ -34,9 +32,9 @@ var COMPILED = false; /** - * Base namespace for the Closure library. Checks to see goog is - * already defined in the current scope before assigning to prevent - * clobbering if base.js is loaded more than once. + * Base namespace for the Closure library. Checks to see goog is already + * defined in the current scope before assigning to prevent clobbering if + * base.js is loaded more than once. * * @const */ @@ -52,15 +50,36 @@ goog.global = this; /** * A hook for overriding the define values in uncompiled mode. * - * In uncompiled mode, {@code CLOSURE_DEFINES} may be defined before loading - * base.js. If a key is defined in {@code CLOSURE_DEFINES}, {@code goog.define} - * will use the value instead of the default value. This allows flags to be - * overwritten without compilation (this is normally accomplished with the - * compiler's "define" flag). + * In uncompiled mode, {@code CLOSURE_UNCOMPILED_DEFINES} may be defined before + * loading base.js. If a key is defined in {@code CLOSURE_UNCOMPILED_DEFINES}, + * {@code goog.define} will use the value instead of the default value. This + * allows flags to be overwritten without compilation (this is normally + * accomplished with the compiler's "define" flag). * * Example: * <pre> - * var CLOSURE_DEFINES = {'goog.DEBUG', false}; + * var CLOSURE_UNCOMPILED_DEFINES = {'goog.DEBUG': false}; + * </pre> + * + * @type {Object.<string, (string|number|boolean)>|undefined} + */ +goog.global.CLOSURE_UNCOMPILED_DEFINES; + + +/** + * A hook for overriding the define values in uncompiled or compiled mode, + * like CLOSURE_UNCOMPILED_DEFINES but effective in compiled code. In + * uncompiled code CLOSURE_UNCOMPILED_DEFINES takes precedence. + * + * Also unlike CLOSURE_UNCOMPILED_DEFINES the values must be number, boolean or + * string literals or the compiler will emit an error. + * + * While any @define value may be set, only those set with goog.define will be + * effective for uncompiled code. + * + * Example: + * <pre> + * var CLOSURE_DEFINES = {'goog.DEBUG': false}; * </pre> * * @type {Object.<string, (string|number|boolean)>|undefined} @@ -69,9 +88,23 @@ goog.global.CLOSURE_DEFINES; /** - * Builds an object structure for the provided namespace path, - * ensuring that names that already exist are not overwritten. For - * example: + * Returns true if the specified value is not undefined. + * WARNING: Do not use this to test if an object has a property. Use the in + * operator instead. + * + * @param {?} val Variable to test. + * @return {boolean} Whether variable is defined. + */ +goog.isDef = function(val) { + // void 0 always evaluates to undefined and hence we do not need to depend on + // the definition of the global variable named 'undefined'. + return val !== void 0; +}; + + +/** + * Builds an object structure for the provided namespace path, ensuring that + * names that already exist are not overwritten. For example: * "a.b.c" -> a = {};a.b={};a.b.c={}; * Used by goog.provide and goog.exportSymbol. * @param {string} name name of the object that this file defines. @@ -98,7 +131,7 @@ goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) { // Parentheses added to eliminate strict JS warning in Firefox. for (var part; parts.length && (part = parts.shift());) { - if (!parts.length && opt_object !== undefined) { + if (!parts.length && goog.isDef(opt_object)) { // last part and we have an object; use it cur[part] = opt_object; } else if (cur[part]) { @@ -112,9 +145,10 @@ goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) { /** * Defines a named value. In uncompiled mode, the value is retreived from - * CLOSURE_DEFINES if the object is defined and has the property specified, - * and otherwise used the defined defaultValue. When compiled, the default - * can be overridden using compiler command-line options. + * CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and + * has the property specified, and otherwise used the defined defaultValue. + * When compiled, the default can be overridden using compiler command-line + * options. * * @param {string} name The distinguished name to provide. * @param {string|number|boolean} defaultValue @@ -122,8 +156,13 @@ goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) { goog.define = function(name, defaultValue) { var value = defaultValue; if (!COMPILED) { - if (goog.global.CLOSURE_DEFINES && Object.prototype.hasOwnProperty.call( - goog.global.CLOSURE_DEFINES, name)) { + if (goog.global.CLOSURE_UNCOMPILED_DEFINES && + Object.prototype.hasOwnProperty.call( + goog.global.CLOSURE_UNCOMPILED_DEFINES, name)) { + value = goog.global.CLOSURE_UNCOMPILED_DEFINES[name]; + } else if (goog.global.CLOSURE_DEFINES && + Object.prototype.hasOwnProperty.call( + goog.global.CLOSURE_DEFINES, name)) { value = goog.global.CLOSURE_DEFINES[name]; } } @@ -171,7 +210,7 @@ goog.define('goog.LOCALE', 'en'); // default to en * external libraries like Prototype, Datejs, and JQuery and setting this flag * to false forces closure to use its own implementations when possible. * - * If your javascript can be loaded by a third party site and you are wary about + * If your JavaScript can be loaded by a third party site and you are wary about * relying on non-standard implementations, specify * "--define goog.TRUSTED_SITE=false" to the JSCompiler. */ @@ -179,9 +218,20 @@ goog.define('goog.TRUSTED_SITE', true); /** + * @define {boolean} Whether a project is expected to be running in strict mode. + * + * This define can be used to trigger alternate implementations compatible with + * running in EcmaScript Strict mode or warn about unavailable functionality. + * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode + */ +goog.define('goog.STRICT_MODE_COMPATIBLE', false); + + +/** * Creates object stubs for a namespace. The presence of one or more * goog.provide() calls indicate that the file defines the given - * objects/namespaces. Build tools also scan for provide/require statements + * objects/namespaces. Provided objects must not be null or undefined. + * Build tools also scan for provide/require statements * to discern dependencies, build dependency files (see deps.js), etc. * @see goog.require * @param {string} name Namespace provided by this file in the form @@ -216,9 +266,9 @@ goog.provide = function(name) { * Marks that the current file should only be used for testing, and never for * live code in production. * - * In the case of unit tests, the message may optionally be an exact - * namespace for the test (e.g. 'goog.stringTest'). The linter will then - * ignore the extra provide (if not explicitly defined in the code). + * In the case of unit tests, the message may optionally be an exact namespace + * for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra + * provide (if not explicitly defined in the code). * * @param {string=} opt_message Optional message to add to the error that's * raised when used in production code. @@ -232,6 +282,25 @@ goog.setTestOnly = function(opt_message) { }; +/** + * Forward declares a symbol. This is an indication to the compiler that the + * symbol may be used in the source yet is not required and may not be provided + * in compilation. + * + * The most common usage of forward declaration is code that takes a type as a + * function parameter but does not need to require it. By forward declaring + * instead of requiring, no hard dependency is made, and (if not required + * elsewhere) the namespace may never be required and thus, not be pulled + * into the JavaScript binary. If it is required elsewhere, it will be type + * checked as normal. + * + * + * @param {string} name The namespace to forward declare in the form of + * "goog.package.part". + */ +goog.forwardDeclare = function(name) {}; + + if (!COMPILED) { /** @@ -242,13 +311,14 @@ if (!COMPILED) { * @private */ goog.isProvided_ = function(name) { - return !goog.implicitNamespaces_[name] && !!goog.getObjectByName(name); + return !goog.implicitNamespaces_[name] && + goog.isDefAndNotNull(goog.getObjectByName(name)); }; /** * Namespaces implicitly defined by goog.provide. For example, - * goog.provide('goog.events.Event') implicitly declares - * that 'goog' and 'goog.events' must be namespaces. + * goog.provide('goog.events.Event') implicitly declares that 'goog' and + * 'goog.events' must be namespaces. * * @type {Object} * @private @@ -258,9 +328,10 @@ if (!COMPILED) { /** - * Returns an object based on its fully qualified external name. If you are - * using a compilation pass that renames property names beware that using this - * function will not find renamed properties. + * Returns an object based on its fully qualified external name. The object + * is not found if null or undefined. If you are using a compilation pass that + * renames property names beware that using this function will not find renamed + * properties. * * @param {string} name The fully qualified name. * @param {Object=} opt_obj The object within which to look; default is @@ -327,25 +398,16 @@ goog.addDependency = function(relPath, provides, requires) { }; -// MOE:begin_strip -/** - * Whether goog.require should throw an exception if it fails. - * @type {boolean} - */ -goog.useStrictRequires = false; - -// MOE:end_strip - -// NOTE(nnaze): The debug DOM loader was included in base.js as an orignal -// way to do "debug-mode" development. The dependency system can sometimes -// be confusing, as can the debug DOM loader's asyncronous nature. +// NOTE(nnaze): The debug DOM loader was included in base.js as an original way +// to do "debug-mode" development. The dependency system can sometimes be +// confusing, as can the debug DOM loader's asynchronous nature. // -// With the DOM loader, a call to goog.require() is not blocking -- the -// script will not load until some point after the current script. If a -// namespace is needed at runtime, it needs to be defined in a previous -// script, or loaded via require() with its registered dependencies. +// With the DOM loader, a call to goog.require() is not blocking -- the script +// will not load until some point after the current script. If a namespace is +// needed at runtime, it needs to be defined in a previous script, or loaded via +// require() with its registered dependencies. // User-defined namespaces may need their own deps file. See http://go/js_deps, // http://go/genjsdeps, or, externally, DepsWriter. // http://code.google.com/closure/library/docs/depswriter.html @@ -370,22 +432,21 @@ goog.define('goog.ENABLE_DEBUG_LOADER', true); /** - * Implements a system for the dynamic resolution of dependencies - * that works in parallel with the BUILD system. Note that all calls - * to goog.require will be stripped by the JSCompiler when the - * --closure_pass option is used. + * Implements a system for the dynamic resolution of dependencies that works in + * parallel with the BUILD system. Note that all calls to goog.require will be + * stripped by the JSCompiler when the --closure_pass option is used. * @see goog.provide - * @param {string} name Namespace to include (as was given in goog.provide()) - * in the form "goog.package.part". + * @param {string} name Namespace to include (as was given in goog.provide()) in + * the form "goog.package.part". */ goog.require = function(name) { - // if the object already exists we do not need do do anything - // TODO(arv): If we start to support require based on file name this has - // to change - // TODO(arv): If we allow goog.foo.* this has to change + // If the object already exists we do not need do do anything. + // TODO(arv): If we start to support require based on file name this has to + // change. + // TODO(arv): If we allow goog.foo.* this has to change. // TODO(arv): If we implement dynamic load after page load we should probably - // not remove this code for the compiled output + // not remove this code for the compiled output. if (!COMPILED) { if (goog.isProvided_(name)) { return; @@ -405,26 +466,15 @@ goog.require = function(name) { goog.global.console['error'](errorMessage); } - // MOE:begin_strip - - // NOTE(nicksantos): We could always throw an error, but this would break - // legacy users that depended on this failing silently. Instead, the - // compiler should warn us when there are invalid goog.require calls. - // For now, we simply give clients a way to turn strict mode on. - if (goog.useStrictRequires) { - // MOE:end_strip throw Error(errorMessage); - // MOE:begin_strip - } - // MOE:end_strip } }; /** - * Path for included scripts + * Path for included scripts. * @type {string} */ goog.basePath = ''; @@ -438,8 +488,7 @@ goog.global.CLOSURE_BASE_PATH; /** - * Whether to write out Closure's deps file. By default, - * the deps are written. + * Whether to write out Closure's deps file. By default, the deps are written. * @type {boolean|undefined} */ goog.global.CLOSURE_NO_DEPS; @@ -453,6 +502,7 @@ goog.global.CLOSURE_NO_DEPS; * * The function is passed the script source, which is a relative URI. It should * return true if the script was imported, false otherwise. + * @type {(function(string): boolean)|undefined} */ goog.global.CLOSURE_IMPORT_SCRIPT; @@ -480,19 +530,16 @@ goog.identityFunction = function(opt_returnValue, var_args) { /** * When defining a class Foo with an abstract method bar(), you can do: - * * Foo.prototype.bar = goog.abstractMethod * - * Now if a subclass of Foo fails to override bar(), an error - * will be thrown when bar() is invoked. + * Now if a subclass of Foo fails to override bar(), an error will be thrown + * when bar() is invoked. * - * Note: This does not take the name of the function to override as - * an argument because that would make it more difficult to obfuscate - * our JavaScript code. + * Note: This does not take the name of the function to override as an argument + * because that would make it more difficult to obfuscate our JavaScript code. * * @type {!Function} - * @throws {Error} when invoked to indicate the method should be - * overridden. + * @throws {Error} when invoked to indicate the method should be overridden. */ goog.abstractMethod = function() { throw Error('unimplemented abstract method'); @@ -500,8 +547,8 @@ goog.abstractMethod = function() { /** - * Adds a {@code getInstance} static method that always return the same instance - * object. + * Adds a {@code getInstance} static method that always returns the same + * instance object. * @param {!Function} ctor The constructor for the class to add the static * method to. */ @@ -538,8 +585,8 @@ goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER; if (goog.DEPENDENCIES_ENABLED) { /** - * Object used to keep track of urls that have already been added. This - * record allows the prevention of circular dependencies. + * Object used to keep track of urls that have already been added. This record + * allows the prevention of circular dependencies. * @type {Object} * @private */ @@ -548,7 +595,7 @@ if (goog.DEPENDENCIES_ENABLED) { /** * This object is used to keep track of dependencies and other data that is - * used for loading scripts + * used for loading scripts. * @private * @type {Object} */ @@ -556,10 +603,9 @@ if (goog.DEPENDENCIES_ENABLED) { pathToNames: {}, // 1 to many nameToPath: {}, // 1 to 1 requires: {}, // 1 to many - // used when resolving dependencies to prevent us from - // visiting the file twice + // Used when resolving dependencies to prevent us from visiting file twice. visited: {}, - written: {} // used to keep track of script files we have written + written: {} // Used to keep track of script files we have written. }; @@ -576,7 +622,7 @@ if (goog.DEPENDENCIES_ENABLED) { /** - * Tries to detect the base path of the base.js script that bootstraps Closure + * Tries to detect the base path of base.js script that bootstraps Closure. * @private */ goog.findBasePath_ = function() { @@ -660,7 +706,7 @@ if (goog.DEPENDENCIES_ENABLED) { * @private */ goog.writeScripts_ = function() { - // the scripts we need to write this time + // The scripts we need to write this time. var scripts = []; var seenScript = {}; var deps = goog.dependencies_; @@ -670,8 +716,8 @@ if (goog.DEPENDENCIES_ENABLED) { return; } - // we have already visited this one. We can get here if we have cyclic - // dependencies + // We have already visited this one. We can get here if we have cyclic + // dependencies. if (path in deps.visited) { if (!(path in seenScript)) { seenScript[path] = true; @@ -802,7 +848,7 @@ goog.typeOf = function(value) { if ((className == '[object Array]' || // In IE all non value types are wrapped as objects across window // boundaries (not iframe though) so we have to do object detection - // for this edge case + // for this edge case. typeof value.length == 'number' && typeof value.splice != 'undefined' && typeof value.propertyIsEnumerable != 'undefined' && @@ -832,17 +878,15 @@ goog.typeOf = function(value) { return 'function'; } - } else { return 'null'; } } else if (s == 'function' && typeof value.call == 'undefined') { - // In Safari typeof nodeList returns 'function', and on Firefox - // typeof behaves similarly for HTML{Applet,Embed,Object}Elements - // and RegExps. We would like to return object for those and we can - // detect an invalid function by making sure that the function - // object has a call method. + // In Safari typeof nodeList returns 'function', and on Firefox typeof + // behaves similarly for HTML{Applet,Embed,Object}, Elements and RegExps. We + // would like to return object for those and we can detect an invalid + // function by making sure that the function object has a call method. return 'object'; } return s; @@ -850,21 +894,8 @@ goog.typeOf = function(value) { /** - * Returns true if the specified value is not |undefined|. - * WARNING: Do not use this to test if an object has a property. Use the in - * operator instead. Additionally, this function assumes that the global - * undefined variable has not been redefined. - * @param {*} val Variable to test. - * @return {boolean} Whether variable is defined. - */ -goog.isDef = function(val) { - return val !== undefined; -}; - - -/** - * Returns true if the specified value is |null| - * @param {*} val Variable to test. + * Returns true if the specified value is null. + * @param {?} val Variable to test. * @return {boolean} Whether variable is null. */ goog.isNull = function(val) { @@ -873,8 +904,8 @@ goog.isNull = function(val) { /** - * Returns true if the specified value is defined and not null - * @param {*} val Variable to test. + * Returns true if the specified value is defined and not null. + * @param {?} val Variable to test. * @return {boolean} Whether variable is defined and not null. */ goog.isDefAndNotNull = function(val) { @@ -884,8 +915,8 @@ goog.isDefAndNotNull = function(val) { /** - * Returns true if the specified value is an array - * @param {*} val Variable to test. + * Returns true if the specified value is an array. + * @param {?} val Variable to test. * @return {boolean} Whether variable is an array. */ goog.isArray = function(val) { @@ -897,7 +928,7 @@ goog.isArray = function(val) { * Returns true if the object looks like an array. To qualify as array like * the value needs to be either a NodeList or an object with a Number length * property. - * @param {*} val Variable to test. + * @param {?} val Variable to test. * @return {boolean} Whether variable is an array. */ goog.isArrayLike = function(val) { @@ -907,9 +938,9 @@ goog.isArrayLike = function(val) { /** - * Returns true if the object looks like a Date. To qualify as Date-like - * the value needs to be an object and have a getFullYear() function. - * @param {*} val Variable to test. + * Returns true if the object looks like a Date. To qualify as Date-like the + * value needs to be an object and have a getFullYear() function. + * @param {?} val Variable to test. * @return {boolean} Whether variable is a like a Date. */ goog.isDateLike = function(val) { @@ -918,8 +949,8 @@ goog.isDateLike = function(val) { /** - * Returns true if the specified value is a string - * @param {*} val Variable to test. + * Returns true if the specified value is a string. + * @param {?} val Variable to test. * @return {boolean} Whether variable is a string. */ goog.isString = function(val) { @@ -928,8 +959,8 @@ goog.isString = function(val) { /** - * Returns true if the specified value is a boolean - * @param {*} val Variable to test. + * Returns true if the specified value is a boolean. + * @param {?} val Variable to test. * @return {boolean} Whether variable is boolean. */ goog.isBoolean = function(val) { @@ -938,8 +969,8 @@ goog.isBoolean = function(val) { /** - * Returns true if the specified value is a number - * @param {*} val Variable to test. + * Returns true if the specified value is a number. + * @param {?} val Variable to test. * @return {boolean} Whether variable is a number. */ goog.isNumber = function(val) { @@ -948,8 +979,8 @@ goog.isNumber = function(val) { /** - * Returns true if the specified value is a function - * @param {*} val Variable to test. + * Returns true if the specified value is a function. + * @param {?} val Variable to test. * @return {boolean} Whether variable is a function. */ goog.isFunction = function(val) { @@ -958,9 +989,9 @@ goog.isFunction = function(val) { /** - * Returns true if the specified value is an object. This includes arrays - * and functions. - * @param {*} val Variable to test. + * Returns true if the specified value is an object. This includes arrays and + * functions. + * @param {?} val Variable to test. * @return {boolean} Whether variable is an object. */ goog.isObject = function(val) { @@ -972,12 +1003,12 @@ goog.isObject = function(val) { /** - * Gets a unique ID for an object. This mutates the object so that further - * calls with the same object as a parameter returns the same value. The unique - * ID is guaranteed to be unique across the current session amongst objects that - * are passed into {@code getUid}. There is no guarantee that the ID is unique - * or consistent across sessions. It is unsafe to generate unique ID for - * function prototypes. + * Gets a unique ID for an object. This mutates the object so that further calls + * with the same object as a parameter returns the same value. The unique ID is + * guaranteed to be unique across the current session amongst objects that are + * passed into {@code getUid}. There is no guarantee that the ID is unique or + * consistent across sessions. It is unsafe to generate unique ID for function + * prototypes. * * @param {Object} obj The object to get the unique ID for. * @return {number} The unique ID for the object. @@ -994,6 +1025,19 @@ goog.getUid = function(obj) { /** + * Whether the given object is alreay assigned a unique ID. + * + * This does not modify the object. + * + * @param {Object} obj The object to check. + * @return {boolean} Whether there an assigned unique id for the object. + */ +goog.hasUid = function(obj) { + return !!obj[goog.UID_PROPERTY_]; +}; + + +/** * Removes the unique ID from an object. This is useful if the object was * previously mutated using {@code goog.getUid} in which case the mutation is * undone. @@ -1002,8 +1046,8 @@ goog.getUid = function(obj) { goog.removeUid = function(obj) { // TODO(arv): Make the type stricter, do not accept null. - // DOM nodes in IE are not instance of Object and throws exception - // for delete. Instead we try to use removeAttribute + // In IE, DOM nodes are not instances of Object and throw an exception if we + // try to delete. Instead we try to use removeAttribute. if ('removeAttribute' in obj) { obj.removeAttribute(goog.UID_PROPERTY_); } @@ -1017,7 +1061,7 @@ goog.removeUid = function(obj) { /** * Name for unique ID property. Initialized in a way to help avoid collisions - * with other closure javascript on the same page. + * with other closure JavaScript on the same page. * @type {string} * @private */ @@ -1085,15 +1129,15 @@ goog.cloneObject = function(obj) { /** * A native implementation of goog.bind. * @param {Function} fn A function to partially apply. - * @param {Object|undefined} selfObj Specifies the object which |this| should + * @param {Object|undefined} selfObj Specifies the object which this should * point to when the function is run. - * @param {...*} var_args Additional arguments that are partially - * applied to the function. + * @param {...*} var_args Additional arguments that are partially applied to the + * function. * @return {!Function} A partially-applied form of the function bind() was * invoked as a method of. * @private - * @suppress {deprecated} The compiler thinks that Function.prototype.bind - * is deprecated because some people have declared a pure-JS version. + * @suppress {deprecated} The compiler thinks that Function.prototype.bind is + * deprecated because some people have declared a pure-JS version. * Only the pure-JS version is truly deprecated. */ goog.bindNative_ = function(fn, selfObj, var_args) { @@ -1104,10 +1148,10 @@ goog.bindNative_ = function(fn, selfObj, var_args) { /** * A pure-JS implementation of goog.bind. * @param {Function} fn A function to partially apply. - * @param {Object|undefined} selfObj Specifies the object which |this| should + * @param {Object|undefined} selfObj Specifies the object which this should * point to when the function is run. - * @param {...*} var_args Additional arguments that are partially - * applied to the function. + * @param {...*} var_args Additional arguments that are partially applied to the + * function. * @return {!Function} A partially-applied form of the function bind() was * invoked as a method of. * @private @@ -1137,22 +1181,22 @@ goog.bindJs_ = function(fn, selfObj, var_args) { /** * Partially applies this function to a particular 'this object' and zero or * more arguments. The result is a new function with some arguments of the first - * function pre-filled and the value of |this| 'pre-specified'.<br><br> + * function pre-filled and the value of this 'pre-specified'. * - * Remaining arguments specified at call-time are appended to the pre- - * specified ones.<br><br> + * Remaining arguments specified at call-time are appended to the pre-specified + * ones. * - * Also see: {@link #partial}.<br><br> + * Also see: {@link #partial}. * * Usage: * <pre>var barMethBound = bind(myFunction, myObj, 'arg1', 'arg2'); * barMethBound('arg3', 'arg4');</pre> * * @param {?function(this:T, ...)} fn A function to partially apply. - * @param {T} selfObj Specifies the object which |this| should - * point to when the function is run. - * @param {...*} var_args Additional arguments that are partially - * applied to the function. + * @param {T} selfObj Specifies the object which this should point to when the + * function is run. + * @param {...*} var_args Additional arguments that are partially applied to the + * function. * @return {!Function} A partially-applied form of the function bind() was * invoked as a method of. * @template T @@ -1161,13 +1205,12 @@ goog.bindJs_ = function(fn, selfObj, var_args) { goog.bind = function(fn, selfObj, var_args) { // TODO(nicksantos): narrow the type signature. if (Function.prototype.bind && - // NOTE(nicksantos): Somebody pulled base.js into the default - // Chrome extension environment. This means that for Chrome extensions, - // they get the implementation of Function.prototype.bind that - // calls goog.bind instead of the native one. Even worse, we don't want - // to introduce a circular dependency between goog.bind and - // Function.prototype.bind, so we have to hack this to make sure it - // works correctly. + // NOTE(nicksantos): Somebody pulled base.js into the default Chrome + // extension environment. This means that for Chrome extensions, they get + // the implementation of Function.prototype.bind that calls goog.bind + // instead of the native one. Even worse, we don't want to introduce a + // circular dependency between goog.bind and Function.prototype.bind, so + // we have to hack this to make sure it works correctly. Function.prototype.bind.toString().indexOf('native code') != -1) { goog.bind = goog.bindNative_; } else { @@ -1186,17 +1229,17 @@ goog.bind = function(fn, selfObj, var_args) { * g(arg3, arg4); * * @param {Function} fn A function to partially apply. - * @param {...*} var_args Additional arguments that are partially - * applied to fn. + * @param {...*} var_args Additional arguments that are partially applied to fn. * @return {!Function} A partially-applied form of the function bind() was * invoked as a method of. */ goog.partial = function(fn, var_args) { var args = Array.prototype.slice.call(arguments, 1); return function() { - // Prepend the bound arguments to the current arguments. - var newArgs = Array.prototype.slice.call(arguments); - newArgs.unshift.apply(newArgs, args); + // Clone the array (with slice()) and append additional arguments + // to the existing arguments. + var newArgs = args.slice(); + newArgs.push.apply(newArgs, arguments); return fn.apply(this, newArgs); }; }; @@ -1234,7 +1277,7 @@ goog.now = (goog.TRUSTED_SITE && Date.now) || (function() { /** - * Evals javascript in the global scope. In IE this uses execScript, other + * Evals JavaScript in the global scope. In IE this uses execScript, other * browsers use goog.global.eval. If goog.global.eval does not evaluate in the * global scope (for example, in Safari), appends a script tag instead. * Throws an exception if neither execScript or eval is defined. @@ -1262,7 +1305,7 @@ goog.globalEval = function(script) { var scriptElt = doc.createElement('script'); scriptElt.type = 'text/javascript'; scriptElt.defer = false; - // Note(pupius): can't use .innerHTML since "t('<test>')" will fail and + // Note(user): can't use .innerHTML since "t('<test>')" will fail and // .text doesn't work in Safari 2. Therefore we append a text node. scriptElt.appendChild(doc.createTextNode(script)); doc.body.appendChild(scriptElt); @@ -1309,27 +1352,26 @@ goog.cssNameMappingStyle_; * * This function works in tandem with @see goog.setCssNameMapping. * - * Without any mapping set, the arguments are simple joined with a - * hyphen and passed through unaltered. + * Without any mapping set, the arguments are simple joined with a hyphen and + * passed through unaltered. * - * When there is a mapping, there are two possible styles in which - * these mappings are used. In the BY_PART style, each part (i.e. in - * between hyphens) of the passed in css name is rewritten according - * to the map. In the BY_WHOLE style, the full css name is looked up in - * the map directly. If a rewrite is not specified by the map, the - * compiler will output a warning. + * When there is a mapping, there are two possible styles in which these + * mappings are used. In the BY_PART style, each part (i.e. in between hyphens) + * of the passed in css name is rewritten according to the map. In the BY_WHOLE + * style, the full css name is looked up in the map directly. If a rewrite is + * not specified by the map, the compiler will output a warning. * - * When the mapping is passed to the compiler, it will replace calls - * to goog.getCssName with the strings from the mapping, e.g. + * When the mapping is passed to the compiler, it will replace calls to + * goog.getCssName with the strings from the mapping, e.g. * var x = goog.getCssName('foo'); * var y = goog.getCssName(this.baseClass, 'active'); * becomes: * var x= 'foo'; * var y = this.baseClass + '-active'; * - * If one argument is passed it will be processed, if two are passed - * only the modifier will be processed, as it is assumed the first - * argument was generated as a result of calling goog.getCssName. + * If one argument is passed it will be processed, if two are passed only the + * modifier will be processed, as it is assumed the first argument was generated + * as a result of calling goog.getCssName. * * @param {string} className The class name. * @param {string=} opt_modifier A modifier to be appended to the class name. @@ -1453,7 +1495,7 @@ goog.getMsg = function(str, opt_values) { * This is useful when introducing a new message that has not yet been * translated into all languages. * - * This function is a compiler primtive. Must be used in the form: + * This function is a compiler primitive. Must be used in the form: * <code>var x = goog.getMsgWithFallback(MSG_A, MSG_B);</code> * where MSG_A and MSG_B were initialized with goog.getMsg. * @@ -1468,17 +1510,14 @@ goog.getMsgWithFallback = function(a, b) { /** * Exposes an unobfuscated global namespace path for the given object. - * Note that fields of the exported object *will* be obfuscated, - * unless they are exported in turn via this function or - * goog.exportProperty + * Note that fields of the exported object *will* be obfuscated, unless they are + * exported in turn via this function or goog.exportProperty. * - * <p>Also handy for making public items that are defined in anonymous - * closures. + * Also handy for making public items that are defined in anonymous closures. * * ex. goog.exportSymbol('public.path.Foo', Foo); * - * ex. goog.exportSymbol('public.path.Foo.staticFunction', - * Foo.staticFunction); + * ex. goog.exportSymbol('public.path.Foo.staticFunction', Foo.staticFunction); * public.path.Foo.staticFunction(); * * ex. goog.exportSymbol('public.path.Foo.prototype.myMethod', @@ -1488,7 +1527,7 @@ goog.getMsgWithFallback = function(a, b) { * @param {string} publicPath Unobfuscated name to export. * @param {*} object Object the name should point to. * @param {Object=} opt_objectToExportTo The object to add the path to; default - * is |goog.global|. + * is goog.global. */ goog.exportSymbol = function(publicPath, object, opt_objectToExportTo) { goog.exportPath_(publicPath, object, opt_objectToExportTo); @@ -1522,16 +1561,16 @@ goog.exportProperty = function(object, publicName, symbol) { * goog.inherits(ChildClass, ParentClass); * * var child = new ChildClass('a', 'b', 'see'); - * child.foo(); // works + * child.foo(); // This works. * </pre> * - * In addition, a superclass' implementation of a method can be invoked - * as follows: + * In addition, a superclass' implementation of a method can be invoked as + * follows: * * <pre> * ChildClass.prototype.foo = function(a) { * ChildClass.superClass_.foo.call(this, a); - * // other code + * // Other code here. * }; * </pre> * @@ -1546,6 +1585,28 @@ goog.inherits = function(childCtor, parentCtor) { childCtor.prototype = new tempCtor(); /** @override */ childCtor.prototype.constructor = childCtor; + + /** + * Calls superclass constructor/method. + * + * This function is only available if you use goog.inherits to + * express inheritance relationships between classes. + * + * NOTE: This is a replacement for goog.base and for superClass_ + * property defined in childCtor. + * + * @param {!Object} me Should always be "this". + * @param {string} methodName The method name to call. Calling + * superclass constructor can be done with the special string + * 'constructor'. + * @param {...*} var_args The arguments to pass to superclass + * method/constructor. + * @return {*} The return value of the superclass method/constructor. + */ + childCtor.base = function(me, methodName, var_args) { + var args = Array.prototype.slice.call(arguments, 2); + return parentCtor.prototype[methodName].apply(me, args); + }; }; @@ -1553,36 +1614,34 @@ goog.inherits = function(childCtor, parentCtor) { * Call up to the superclass. * * If this is called from a constructor, then this calls the superclass - * contructor with arguments 1-N. + * constructor with arguments 1-N. * - * If this is called from a prototype method, then you must pass - * the name of the method as the second argument to this function. If - * you do not, you will get a runtime error. This calls the superclass' - * method with arguments 2-N. + * If this is called from a prototype method, then you must pass the name of the + * method as the second argument to this function. If you do not, you will get a + * runtime error. This calls the superclass' method with arguments 2-N. * - * This function only works if you use goog.inherits to express - * inheritance relationships between your classes. + * This function only works if you use goog.inherits to express inheritance + * relationships between your classes. * - * This function is a compiler primitive. At compile-time, the - * compiler will do macro expansion to remove a lot of - * the extra overhead that this function introduces. The compiler - * will also enforce a lot of the assumptions that this function - * makes, and treat it as a compiler error if you break them. + * This function is a compiler primitive. At compile-time, the compiler will do + * macro expansion to remove a lot of the extra overhead that this function + * introduces. The compiler will also enforce a lot of the assumptions that this + * function makes, and treat it as a compiler error if you break them. * * @param {!Object} me Should always be "this". * @param {*=} opt_methodName The method name if calling a super method. * @param {...*} var_args The rest of the arguments. * @return {*} The return value of the superclass method. + * @suppress {es5Strict} This method can not be used in strict mode, but + * all Closure Library consumers must depend on this file. */ goog.base = function(me, opt_methodName, var_args) { var caller = arguments.callee.caller; - if (goog.DEBUG) { - if (!caller) { - throw Error('arguments.caller not defined. goog.base() expects not ' + - 'to be running in strict mode. See ' + - 'http://www.ecma-international.org/ecma-262/5.1/#sec-C'); - } + if (goog.STRICT_MODE_COMPATIBLE || (goog.DEBUG && !caller)) { + throw Error('arguments.caller not defined. goog.base() cannot be used ' + + 'with strict mode code. See ' + + 'http://www.ecma-international.org/ecma-262/5.1/#sec-C'); } if (caller.superClass_) { @@ -1602,8 +1661,8 @@ goog.base = function(me, opt_methodName, var_args) { } } - // If we did not find the caller in the prototype chain, - // then one of two things happened: + // If we did not find the caller in the prototype chain, then one of two + // things happened: // 1) The caller is an instance method. // 2) This method was not called by the right caller. if (me[opt_methodName] === caller) { @@ -1618,133 +1677,30 @@ goog.base = function(me, opt_methodName, var_args) { /** * Allow for aliasing within scope functions. This function exists for - * uncompiled code - in compiled code the calls will be inlined and the - * aliases applied. In uncompiled code the function is simply run since the - * aliases as written are valid JavaScript. + * uncompiled code - in compiled code the calls will be inlined and the aliases + * applied. In uncompiled code the function is simply run since the aliases as + * written are valid JavaScript. * @param {function()} fn Function to call. This function can contain aliases * to namespaces (e.g. "var dom = goog.dom") or classes - * (e.g. "var Timer = goog.Timer"). + * (e.g. "var Timer = goog.Timer"). */ goog.scope = function(fn) { fn.call(goog.global); }; -// MOE:begin_strip - -// The section between this token and the end token below will be stripped -// automatically by the open source release scripts. Please leave in place. - -//============================================================================== -// Extending Function -//============================================================================== - - -/** - * @define {boolean} Whether to extend Function.prototype. - * Use --define='goog.MODIFY_FUNCTION_PROTOTYPES=false' to change. +/* + * To support uncompiled, strict mode bundles that use eval to divide source + * like so: + * eval('someSource;//# sourceUrl sourcefile.js'); + * We need to export the globally defined symbols "goog" and "COMPILED". + * Exporting "goog" breaks the compiler optimizations, so we required that + * be defined externally. + * NOTE: We don't use goog.exportSymbol here because we don't want to trigger + * extern generation when that compiler option is enabled. */ -goog.define('goog.MODIFY_FUNCTION_PROTOTYPES', true); - -if (goog.MODIFY_FUNCTION_PROTOTYPES) { - /** - * An alias to the {@link goog.bind()} global function. - * - * Usage: - * var g = f.bind(obj, arg1, arg2); - * g(arg3, arg4); - * - * @param {Object} selfObj Specifies the object to which |this| should point - * when the function is run. If the value is null or undefined, it will - * default to the global object. - * @param {...*} var_args Additional arguments that are partially - * applied to fn. - * @return {!Function} A partially-applied form of the Function on which - * bind() was invoked as a method. - * @deprecated Use the static function goog.bind instead. - * @suppress {duplicate} - */ - Function.prototype.bind = - Function.prototype.bind || function(selfObj, var_args) { - if (arguments.length > 1) { - var args = Array.prototype.slice.call(arguments, 1); - args.unshift(this, selfObj); - return goog.bind.apply(null, args); - } else { - return goog.bind(this, selfObj); - } - }; - - - /** - * An alias to the {@link goog.partial()} static function. - * - * Usage: - * var g = f.partial(arg1, arg2); - * g(arg3, arg4); - * - * @param {...*} var_args Additional arguments that are partially - * applied to fn. - * @return {!Function} A partially-applied form of the function partial() was - * invoked as a method of. - * @deprecated Use the static function goog.partial instead. - */ - Function.prototype.partial = function(var_args) { - var args = Array.prototype.slice.call(arguments); - args.unshift(this, null); - return goog.bind.apply(null, args); - }; - - - /** - * Inherit the prototype methods from one constructor into another. - * @param {Function} parentCtor Parent class. - * @see goog.inherits - * @deprecated Use the static function goog.inherits instead. - */ - Function.prototype.inherits = function(parentCtor) { - goog.inherits(this, parentCtor); - }; - - - /** - * Mixes in an object's properties and methods into the callee's prototype. - * Basically mixin based inheritance, thus providing an alternative method for - * adding properties and methods to a class' prototype. - * - * <pre> - * function X() {} - * X.mixin({ - * one: 1, - * two: 2, - * three: 3, - * doit: function() { return this.one + this.two + this.three; } - * }); - * - * function Y() { } - * Y.mixin(X.prototype); - * Y.prototype.four = 15; - * Y.prototype.doit2 = function() { return this.doit() + this.four; } - * }); - * - * // or - * - * function Y() { } - * Y.inherits(X); - * Y.mixin({ - * one: 10, - * four: 15, - * doit2: function() { return this.doit() + this.four; } - * }); - * </pre> - * - * @param {Object} source from which to copy properties. - * @see goog.mixin - * @deprecated Use the static function goog.object.extend instead. - */ - Function.prototype.mixin = function(source) { - goog.mixin(this.prototype, source); - }; +if (!COMPILED) { + goog.global['COMPILED'] = COMPILED; } -// MOE:end_strip + diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/debug/error.js b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/debug/error.js new file mode 100644 index 0000000..6fed470 --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/debug/error.js @@ -0,0 +1,54 @@ +// Copyright 2009 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Provides a base class for custom Error objects such that the + * stack is correctly maintained. + * + * You should never need to throw goog.debug.Error(msg) directly, Error(msg) is + * sufficient. + * + */ + +goog.provide('goog.debug.Error'); + + + +/** + * Base class for custom error objects. + * @param {*=} opt_msg The message associated with the error. + * @constructor + * @extends {Error} + */ +goog.debug.Error = function(opt_msg) { + + // Attempt to ensure there is a stack trace. + if (Error.captureStackTrace) { + Error.captureStackTrace(this, goog.debug.Error); + } else { + var stack = new Error().stack; + if (stack) { + this.stack = stack; + } + } + + if (opt_msg) { + this.message = String(opt_msg); + } +}; +goog.inherits(goog.debug.Error, Error); + + +/** @override */ +goog.debug.Error.prototype.name = 'CustomError'; diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/dom/nodetype.js b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/dom/nodetype.js new file mode 100644 index 0000000..cccb470 --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/dom/nodetype.js @@ -0,0 +1,48 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Definition of goog.dom.NodeType. + */ + +goog.provide('goog.dom.NodeType'); + + +/** + * Constants for the nodeType attribute in the Node interface. + * + * These constants match those specified in the Node interface. These are + * usually present on the Node object in recent browsers, but not in older + * browsers (specifically, early IEs) and thus are given here. + * + * In some browsers (early IEs), these are not defined on the Node object, + * so they are provided here. + * + * See http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247 + * @enum {number} + */ +goog.dom.NodeType = { + ELEMENT: 1, + ATTRIBUTE: 2, + TEXT: 3, + CDATA_SECTION: 4, + ENTITY_REFERENCE: 5, + ENTITY: 6, + PROCESSING_INSTRUCTION: 7, + COMMENT: 8, + DOCUMENT: 9, + DOCUMENT_TYPE: 10, + DOCUMENT_FRAGMENT: 11, + NOTATION: 12 +}; diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/i18n/messageformat.js b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/i18n/messageformat.js new file mode 100644 index 0000000..923af98 --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/i18n/messageformat.js @@ -0,0 +1,764 @@ +// Copyright 2010 The Closure Library Authors. All Rights Reserved +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Message/plural format library with locale support. + * + * Message format grammar: + * + * messageFormatPattern := string ( "{" messageFormatElement "}" string )* + * messageFormatElement := argumentIndex [ "," elementFormat ] + * elementFormat := "plural" "," pluralStyle + * | "selectordinal" "," ordinalStyle + * | "select" "," selectStyle + * pluralStyle := pluralFormatPattern + * ordinalStyle := selectFormatPattern + * selectStyle := selectFormatPattern + * pluralFormatPattern := [ "offset" ":" offsetIndex ] pluralForms* + * selectFormatPattern := pluralForms* + * pluralForms := stringKey "{" ( "{" messageFormatElement "}"|string )* "}" + * + * This is a subset of the ICU MessageFormatSyntax: + * http://userguide.icu-project.org/formatparse/messages + * See also http://go/plurals and http://go/ordinals for internal details. + * + * + * Message example: + * + * I see {NUM_PEOPLE, plural, offset:1 + * =0 {no one at all} + * =1 {{WHO}} + * one {{WHO} and one other person} + * other {{WHO} and # other people}} + * in {PLACE}. + * + * Calling format({'NUM_PEOPLE': 2, 'WHO': 'Mark', 'PLACE': 'Athens'}) would + * produce "I see Mark and one other person in Athens." as output. + * + * OR: + * + * {NUM_FLOOR, selectordinal, + * one {Take the elevator to the #st floor.} + * two {Take the elevator to the #nd floor.} + * few {Take the elevator to the #rd floor.} + * other {Take the elevator to the #th floor.}} + * + * Calling format({'NUM_FLOOR': 22}) would produce + * "Take the elevator to the 22nd floor". + * + * See messageformat_test.html for more examples. + */ + +goog.provide('goog.i18n.MessageFormat'); + +goog.require('goog.asserts'); +goog.require('goog.i18n.ordinalRules'); +goog.require('goog.i18n.pluralRules'); + + + +/** + * Constructor of MessageFormat. + * @param {string} pattern The pattern we parse and apply positional parameters + * to. + * @constructor + * @final + */ +goog.i18n.MessageFormat = function(pattern) { + /** + * All encountered literals during parse stage. Indices tell us the order of + * replacement. + * @type {!Array.<string>} + * @private + */ + this.literals_ = []; + + /** + * Input pattern gets parsed into objects for faster formatting. + * @type {!Array.<!Object>} + * @private + */ + this.parsedPattern_ = []; + + this.parsePattern_(pattern); +}; + + +/** + * Literal strings, including '', are replaced with \uFDDF_x_ for + * parsing purposes, and recovered during format phase. + * \uFDDF is a Unicode nonprinting character, not expected to be found in the + * typical message. + * @type {string} + * @private + */ +goog.i18n.MessageFormat.LITERAL_PLACEHOLDER_ = '\uFDDF_'; + + +/** + * Marks a string and block during parsing. + * @enum {number} + * @private + */ +goog.i18n.MessageFormat.Element_ = { + STRING: 0, + BLOCK: 1 +}; + + +/** + * Block type. + * @enum {number} + * @private + */ +goog.i18n.MessageFormat.BlockType_ = { + PLURAL: 0, + ORDINAL: 1, + SELECT: 2, + SIMPLE: 3, + STRING: 4, + UNKNOWN: 5 +}; + + +/** + * Mandatory option in both select and plural form. + * @type {string} + * @private + */ +goog.i18n.MessageFormat.OTHER_ = 'other'; + + +/** + * Regular expression for looking for string literals. + * @type {RegExp} + * @private + */ +goog.i18n.MessageFormat.REGEX_LITERAL_ = new RegExp("'([{}#].*?)'", 'g'); + + +/** + * Regular expression for looking for '' in the message. + * @type {RegExp} + * @private + */ +goog.i18n.MessageFormat.REGEX_DOUBLE_APOSTROPHE_ = new RegExp("''", 'g'); + + +/** + * Formats a message, treating '#' with special meaning representing + * the number (plural_variable - offset). + * @param {!Object} namedParameters Parameters that either + * influence the formatting or are used as actual data. + * I.e. in call to fmt.format({'NUM_PEOPLE': 5, 'NAME': 'Angela'}), + * object {'NUM_PEOPLE': 5, 'NAME': 'Angela'} holds positional parameters. + * 1st parameter could mean 5 people, which could influence plural format, + * and 2nd parameter is just a data to be printed out in proper position. + * @return {string} Formatted message. + */ +goog.i18n.MessageFormat.prototype.format = function(namedParameters) { + return this.format_(namedParameters, false); +}; + + +/** + * Formats a message, treating '#' as literary character. + * @param {!Object} namedParameters Parameters that either + * influence the formatting or are used as actual data. + * I.e. in call to fmt.format({'NUM_PEOPLE': 5, 'NAME': 'Angela'}), + * object {'NUM_PEOPLE': 5, 'NAME': 'Angela'} holds positional parameters. + * 1st parameter could mean 5 people, which could influence plural format, + * and 2nd parameter is just a data to be printed out in proper position. + * @return {string} Formatted message. + */ +goog.i18n.MessageFormat.prototype.formatIgnoringPound = + function(namedParameters) { + return this.format_(namedParameters, true); +}; + + +/** + * Formats a message. + * @param {!Object} namedParameters Parameters that either + * influence the formatting or are used as actual data. + * I.e. in call to fmt.format({'NUM_PEOPLE': 5, 'NAME': 'Angela'}), + * object {'NUM_PEOPLE': 5, 'NAME': 'Angela'} holds positional parameters. + * 1st parameter could mean 5 people, which could influence plural format, + * and 2nd parameter is just a data to be printed out in proper position. + * @param {boolean} ignorePound If true, treat '#' in plural messages as a + * literary character, else treat it as an ICU syntax character, resolving + * to the number (plural_variable - offset). + * @return {string} Formatted message. + * @private + */ +goog.i18n.MessageFormat.prototype.format_ = + function(namedParameters, ignorePound) { + if (this.parsedPattern_.length == 0) { + return ''; + } + + var result = []; + this.formatBlock_(this.parsedPattern_, namedParameters, ignorePound, result); + var message = result.join(''); + + if (!ignorePound) { + goog.asserts.assert(message.search('#') == -1, 'Not all # were replaced.'); + } + + while (this.literals_.length > 0) { + message = message.replace(this.buildPlaceholder_(this.literals_), + this.literals_.pop()); + } + + return message; +}; + + +/** + * Parses generic block and returns a formatted string. + * @param {!Array.<!Object>} parsedPattern Holds parsed tree. + * @param {!Object} namedParameters Parameters that either influence + * the formatting or are used as actual data. + * @param {boolean} ignorePound If true, treat '#' in plural messages as a + * literary character, else treat it as an ICU syntax character, resolving + * to the number (plural_variable - offset). + * @param {!Array.<!string>} result Each formatting stage appends its product + * to the result. + * @private + */ +goog.i18n.MessageFormat.prototype.formatBlock_ = function( + parsedPattern, namedParameters, ignorePound, result) { + for (var i = 0; i < parsedPattern.length; i++) { + switch (parsedPattern[i].type) { + case goog.i18n.MessageFormat.BlockType_.STRING: + result.push(parsedPattern[i].value); + break; + case goog.i18n.MessageFormat.BlockType_.SIMPLE: + var pattern = parsedPattern[i].value; + this.formatSimplePlaceholder_(pattern, namedParameters, result); + break; + case goog.i18n.MessageFormat.BlockType_.SELECT: + var pattern = parsedPattern[i].value; + this.formatSelectBlock_(pattern, namedParameters, ignorePound, result); + break; + case goog.i18n.MessageFormat.BlockType_.PLURAL: + var pattern = parsedPattern[i].value; + this.formatPluralOrdinalBlock_(pattern, + namedParameters, + goog.i18n.pluralRules.select, + ignorePound, + result); + break; + case goog.i18n.MessageFormat.BlockType_.ORDINAL: + var pattern = parsedPattern[i].value; + this.formatPluralOrdinalBlock_(pattern, + namedParameters, + goog.i18n.ordinalRules.select, + ignorePound, + result); + break; + default: + goog.asserts.fail('Unrecognized block type.'); + } + } +}; + + +/** + * Formats simple placeholder. + * @param {!Object} parsedPattern JSON object containing placeholder info. + * @param {!Object} namedParameters Parameters that are used as actual data. + * @param {!Array.<!string>} result Each formatting stage appends its product + * to the result. + * @private + */ +goog.i18n.MessageFormat.prototype.formatSimplePlaceholder_ = function( + parsedPattern, namedParameters, result) { + var value = namedParameters[parsedPattern]; + if (!goog.isDef(value)) { + result.push('Undefined parameter - ' + parsedPattern); + return; + } + + // Don't push the value yet, it may contain any of # { } in it which + // will break formatter. Insert a placeholder and replace at the end. + this.literals_.push(value); + result.push(this.buildPlaceholder_(this.literals_)); +}; + + +/** + * Formats select block. Only one option is selected. + * @param {!Object} parsedPattern JSON object containing select block info. + * @param {!Object} namedParameters Parameters that either influence + * the formatting or are used as actual data. + * @param {boolean} ignorePound If true, treat '#' in plural messages as a + * literary character, else treat it as an ICU syntax character, resolving + * to the number (plural_variable - offset). + * @param {!Array.<!string>} result Each formatting stage appends its product + * to the result. + * @private + */ +goog.i18n.MessageFormat.prototype.formatSelectBlock_ = function( + parsedPattern, namedParameters, ignorePound, result) { + var argumentIndex = parsedPattern.argumentIndex; + if (!goog.isDef(namedParameters[argumentIndex])) { + result.push('Undefined parameter - ' + argumentIndex); + return; + } + + var option = parsedPattern[namedParameters[argumentIndex]]; + if (!goog.isDef(option)) { + option = parsedPattern[goog.i18n.MessageFormat.OTHER_]; + goog.asserts.assertArray( + option, 'Invalid option or missing other option for select block.'); + } + + this.formatBlock_(option, namedParameters, ignorePound, result); +}; + + +/** + * Formats plural or selectordinal block. Only one option is selected and all # + * are replaced. + * @param {!Object} parsedPattern JSON object containing plural block info. + * @param {!Object} namedParameters Parameters that either influence + * the formatting or are used as actual data. + * @param {!function(number, number=):string} pluralSelector A select function + * from goog.i18n.pluralRules or goog.i18n.ordinalRules which determines + * which plural/ordinal form to use based on the input number's cardinality. + * @param {boolean} ignorePound If true, treat '#' in plural messages as a + * literary character, else treat it as an ICU syntax character, resolving + * to the number (plural_variable - offset). + * @param {!Array.<!string>} result Each formatting stage appends its product + * to the result. + * @private + */ +goog.i18n.MessageFormat.prototype.formatPluralOrdinalBlock_ = function( + parsedPattern, namedParameters, pluralSelector, ignorePound, result) { + var argumentIndex = parsedPattern.argumentIndex; + var argumentOffset = parsedPattern.argumentOffset; + var pluralValue = +namedParameters[argumentIndex]; + if (isNaN(pluralValue)) { + // TODO(user): Distinguish between undefined and invalid parameters. + result.push('Undefined or invalid parameter - ' + argumentIndex); + return; + } + var diff = pluralValue - argumentOffset; + + // Check if there is an exact match. + var option = parsedPattern[namedParameters[argumentIndex]]; + if (!goog.isDef(option)) { + goog.asserts.assert(diff >= 0, 'Argument index smaller than offset.'); + var item; + item = pluralSelector(diff); + goog.asserts.assertString(item, 'Invalid plural key.'); + + option = parsedPattern[item]; + + // If option is not provided fall back to "other". + if (!goog.isDef(option)) { + option = parsedPattern[goog.i18n.MessageFormat.OTHER_]; + } + + goog.asserts.assertArray( + option, 'Invalid option or missing other option for plural block.'); + } + + var pluralResult = []; + this.formatBlock_(option, namedParameters, ignorePound, pluralResult); + var plural = pluralResult.join(''); + goog.asserts.assertString(plural, 'Empty block in plural.'); + if (ignorePound) { + result.push(plural); + } else { + // TODO(plundblad): Might want to use a more specific number formatter. + var localeAwareDiff = diff.toLocaleString(); + result.push(plural.replace(/#/g, localeAwareDiff)); + } +}; + + +/** + * Parses input pattern into an array, for faster reformatting with + * different input parameters. + * Parsing is locale independent. + * @param {string} pattern MessageFormat pattern to parse. + * @private + */ +goog.i18n.MessageFormat.prototype.parsePattern_ = function(pattern) { + if (pattern) { + pattern = this.insertPlaceholders_(pattern); + + this.parsedPattern_ = this.parseBlock_(pattern); + } +}; + + +/** + * Replaces string literals with literal placeholders. + * Literals are string of the form '}...', '{...' and '#...' where ... is + * set of characters not containing ' + * Builds a dictionary so we can recover literals during format phase. + * @param {string} pattern Pattern to clean up. + * @return {string} Pattern with literals replaced with placeholders. + * @private + */ +goog.i18n.MessageFormat.prototype.insertPlaceholders_ = function(pattern) { + var literals = this.literals_; + var buildPlaceholder = goog.bind(this.buildPlaceholder_, this); + + // First replace '' with single quote placeholder since they can be found + // inside other literals. + pattern = pattern.replace( + goog.i18n.MessageFormat.REGEX_DOUBLE_APOSTROPHE_, + function() { + literals.push("'"); + return buildPlaceholder(literals); + }); + + pattern = pattern.replace( + goog.i18n.MessageFormat.REGEX_LITERAL_, + function(match, text) { + literals.push(text); + return buildPlaceholder(literals); + }); + + return pattern; +}; + + +/** + * Breaks pattern into strings and top level {...} blocks. + * @param {string} pattern (sub)Pattern to be broken. + * @return {!Array.<Object>} Each item is {type, value}. + * @private + */ +goog.i18n.MessageFormat.prototype.extractParts_ = function(pattern) { + var prevPos = 0; + var inBlock = false; + var braceStack = []; + var results = []; + + var braces = /[{}]/g; + braces.lastIndex = 0; // lastIndex doesn't get set to 0 so we have to. + var match; + + while (match = braces.exec(pattern)) { + var pos = match.index; + if (match[0] == '}') { + var brace = braceStack.pop(); + goog.asserts.assert(goog.isDef(brace) && brace == '{', + 'No matching { for }.'); + + if (braceStack.length == 0) { + // End of the block. + var part = {}; + part.type = goog.i18n.MessageFormat.Element_.BLOCK; + part.value = pattern.substring(prevPos, pos); + results.push(part); + prevPos = pos + 1; + inBlock = false; + } + } else { + if (braceStack.length == 0) { + inBlock = true; + var substring = pattern.substring(prevPos, pos); + if (substring != '') { + results.push({ + type: goog.i18n.MessageFormat.Element_.STRING, + value: substring + }); + } + prevPos = pos + 1; + } + braceStack.push('{'); + } + } + + // Take care of the final string, and check if the braceStack is empty. + goog.asserts.assert(braceStack.length == 0, + 'There are mismatched { or } in the pattern.'); + + var substring = pattern.substring(prevPos); + if (substring != '') { + results.push({ + type: goog.i18n.MessageFormat.Element_.STRING, + value: substring + }); + } + + return results; +}; + + +/** + * A regular expression to parse the plural block, extracting the argument + * index and offset (if any). + * @type {RegExp} + * @private + */ +goog.i18n.MessageFormat.PLURAL_BLOCK_RE_ = + /^\s*(\w+)\s*,\s*plural\s*,(?:\s*offset:(\d+))?/; + + +/** + * A regular expression to parse the ordinal block, extracting the argument + * index. + * @type {RegExp} + * @private + */ +goog.i18n.MessageFormat.ORDINAL_BLOCK_RE_ = /^\s*(\w+)\s*,\s*selectordinal\s*,/; + + +/** + * A regular expression to parse the select block, extracting the argument + * index. + * @type {RegExp} + * @private + */ +goog.i18n.MessageFormat.SELECT_BLOCK_RE_ = /^\s*(\w+)\s*,\s*select\s*,/; + + +/** + * Detects which type of a block is the pattern. + * @param {string} pattern Content of the block. + * @return {goog.i18n.MessageFormat.BlockType_} One of the block types. + * @private + */ +goog.i18n.MessageFormat.prototype.parseBlockType_ = function(pattern) { + if (goog.i18n.MessageFormat.PLURAL_BLOCK_RE_.test(pattern)) { + return goog.i18n.MessageFormat.BlockType_.PLURAL; + } + + if (goog.i18n.MessageFormat.ORDINAL_BLOCK_RE_.test(pattern)) { + return goog.i18n.MessageFormat.BlockType_.ORDINAL; + } + + if (goog.i18n.MessageFormat.SELECT_BLOCK_RE_.test(pattern)) { + return goog.i18n.MessageFormat.BlockType_.SELECT; + } + + if (/^\s*\w+\s*/.test(pattern)) { + return goog.i18n.MessageFormat.BlockType_.SIMPLE; + } + + return goog.i18n.MessageFormat.BlockType_.UNKNOWN; +}; + + +/** + * Parses generic block. + * @param {string} pattern Content of the block to parse. + * @return {!Array.<!Object>} Subblocks marked as strings, select... + * @private + */ +goog.i18n.MessageFormat.prototype.parseBlock_ = function(pattern) { + var result = []; + var parts = this.extractParts_(pattern); + for (var i = 0; i < parts.length; i++) { + var block = {}; + if (goog.i18n.MessageFormat.Element_.STRING == parts[i].type) { + block.type = goog.i18n.MessageFormat.BlockType_.STRING; + block.value = parts[i].value; + } else if (goog.i18n.MessageFormat.Element_.BLOCK == parts[i].type) { + var blockType = this.parseBlockType_(parts[i].value); + + switch (blockType) { + case goog.i18n.MessageFormat.BlockType_.SELECT: + block.type = goog.i18n.MessageFormat.BlockType_.SELECT; + block.value = this.parseSelectBlock_(parts[i].value); + break; + case goog.i18n.MessageFormat.BlockType_.PLURAL: + block.type = goog.i18n.MessageFormat.BlockType_.PLURAL; + block.value = this.parsePluralBlock_(parts[i].value); + break; + case goog.i18n.MessageFormat.BlockType_.ORDINAL: + block.type = goog.i18n.MessageFormat.BlockType_.ORDINAL; + block.value = this.parseOrdinalBlock_(parts[i].value); + break; + case goog.i18n.MessageFormat.BlockType_.SIMPLE: + block.type = goog.i18n.MessageFormat.BlockType_.SIMPLE; + block.value = parts[i].value; + break; + default: + goog.asserts.fail('Unknown block type.'); + } + } else { + goog.asserts.fail('Unknown part of the pattern.'); + } + result.push(block); + } + + return result; +}; + + +/** + * Parses a select type of a block and produces JSON object for it. + * @param {string} pattern Subpattern that needs to be parsed as select pattern. + * @return {!Object} Object with select block info. + * @private + */ +goog.i18n.MessageFormat.prototype.parseSelectBlock_ = function(pattern) { + var argumentIndex = ''; + var replaceRegex = goog.i18n.MessageFormat.SELECT_BLOCK_RE_; + pattern = pattern.replace(replaceRegex, function(string, name) { + argumentIndex = name; + return ''; + }); + var result = {}; + result.argumentIndex = argumentIndex; + + var parts = this.extractParts_(pattern); + // Looking for (key block)+ sequence. One of the keys has to be "other". + var pos = 0; + while (pos < parts.length) { + var key = parts[pos].value; + goog.asserts.assertString(key, 'Missing select key element.'); + + pos++; + goog.asserts.assert(pos < parts.length, + 'Missing or invalid select value element.'); + + if (goog.i18n.MessageFormat.Element_.BLOCK == parts[pos].type) { + var value = this.parseBlock_(parts[pos].value); + } else { + goog.asserts.fail('Expected block type.'); + } + result[key.replace(/\s/g, '')] = value; + pos++; + } + + goog.asserts.assertArray(result[goog.i18n.MessageFormat.OTHER_], + 'Missing other key in select statement.'); + return result; +}; + + +/** + * Parses a plural type of a block and produces JSON object for it. + * @param {string} pattern Subpattern that needs to be parsed as plural pattern. + * @return {!Object} Object with select block info. + * @private + */ +goog.i18n.MessageFormat.prototype.parsePluralBlock_ = function(pattern) { + var argumentIndex = ''; + var argumentOffset = 0; + var replaceRegex = goog.i18n.MessageFormat.PLURAL_BLOCK_RE_; + pattern = pattern.replace(replaceRegex, function(string, name, offset) { + argumentIndex = name; + if (offset) { + argumentOffset = parseInt(offset, 10); + } + return ''; + }); + + var result = {}; + result.argumentIndex = argumentIndex; + result.argumentOffset = argumentOffset; + + var parts = this.extractParts_(pattern); + // Looking for (key block)+ sequence. + var pos = 0; + while (pos < parts.length) { + var key = parts[pos].value; + goog.asserts.assertString(key, 'Missing plural key element.'); + + pos++; + goog.asserts.assert(pos < parts.length, + 'Missing or invalid plural value element.'); + + if (goog.i18n.MessageFormat.Element_.BLOCK == parts[pos].type) { + var value = this.parseBlock_(parts[pos].value); + } else { + goog.asserts.fail('Expected block type.'); + } + result[key.replace(/\s*(?:=)?(\w+)\s*/, '$1')] = value; + pos++; + } + + goog.asserts.assertArray(result[goog.i18n.MessageFormat.OTHER_], + 'Missing other key in plural statement.'); + + return result; +}; + + +/** + * Parses an ordinal type of a block and produces JSON object for it. + * For example the input string: + * '{FOO, selectordinal, one {Message A}other {Message B}}' + * Should result in the output object: + * { + * argumentIndex: 'FOO', + * argumentOffest: 0, + * one: [ { type: 4, value: 'Message A' } ], + * other: [ { type: 4, value: 'Message B' } ] + * } + * @param {string} pattern Subpattern that needs to be parsed as plural pattern. + * @return {!Object} Object with select block info. + * @private + */ +goog.i18n.MessageFormat.prototype.parseOrdinalBlock_ = function(pattern) { + var argumentIndex = ''; + var replaceRegex = goog.i18n.MessageFormat.ORDINAL_BLOCK_RE_; + pattern = pattern.replace(replaceRegex, function(string, name) { + argumentIndex = name; + return ''; + }); + + var result = {}; + result.argumentIndex = argumentIndex; + result.argumentOffset = 0; + + var parts = this.extractParts_(pattern); + // Looking for (key block)+ sequence. + var pos = 0; + while (pos < parts.length) { + var key = parts[pos].value; + goog.asserts.assertString(key, 'Missing ordinal key element.'); + + pos++; + goog.asserts.assert(pos < parts.length, + 'Missing or invalid ordinal value element.'); + + if (goog.i18n.MessageFormat.Element_.BLOCK == parts[pos].type) { + var value = this.parseBlock_(parts[pos].value); + } else { + goog.asserts.fail('Expected block type.'); + } + result[key.replace(/\s*(?:=)?(\w+)\s*/, '$1')] = value; + pos++; + } + + goog.asserts.assertArray(result[goog.i18n.MessageFormat.OTHER_], + 'Missing other key in selectordinal statement.'); + + return result; +}; + + +/** + * Builds a placeholder from the last index of the array. + * @param {!Array} literals All literals encountered during parse. + * @return {string} \uFDDF_ + last index + _. + * @private + */ +goog.i18n.MessageFormat.prototype.buildPlaceholder_ = function(literals) { + goog.asserts.assert(literals.length > 0, 'Literal array is empty.'); + + var index = (literals.length - 1).toString(10); + return goog.i18n.MessageFormat.LITERAL_PLACEHOLDER_ + index + '_'; +}; diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/i18n/ordinalrules.js b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/i18n/ordinalrules.js new file mode 100644 index 0000000..87f7bde --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/i18n/ordinalrules.js @@ -0,0 +1,733 @@ +// Copyright 2012 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Ordinal rules. + * + * This file is autogenerated by script: + * http://go/generate_pluralrules.py + * File generated from CLDR ver. 25 + * + * Before check in, this file could have been manually edited. This is to + * incorporate changes before we could fix CLDR. All manual modification must be + * documented in this section, and should be removed after those changes land to + * CLDR. + */ + +goog.provide('goog.i18n.ordinalRules'); +/** + * Ordinal pattern keyword + * @enum {string} + */ +goog.i18n.ordinalRules.Keyword = { + ZERO: 'zero', + ONE: 'one', + TWO: 'two', + FEW: 'few', + MANY: 'many', + OTHER: 'other' +}; + + +/** + * Default Ordinal select rule. + * @param {number} n The count of items. + * @param {number=} opt_precision optional, precision. + * @return {goog.i18n.ordinalRules.Keyword} Default value. + * @private + */ +goog.i18n.ordinalRules.defaultSelect_ = function(n, opt_precision) { + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Returns the fractional part of a number (3.1416 => 1416) + * @param {number} n The count of items. + * @return {number} The fractional part. + * @private + */ +goog.i18n.ordinalRules.decimals_ = function(n) { + var str = n + ''; + var result = str.indexOf('.'); + return (result == -1) ? 0 : str.length - result - 1; +}; + +/** + * Calculates v and f as per CLDR plural rules. + * The short names for parameters / return match the CLDR syntax and UTS #35 + * (http://unicode.org/reports/tr35/tr35-numbers.html#Plural_rules_syntax) + * @param {number} n The count of items. + * @param {number=} opt_precision optional, precision. + * @return {!Object} The v and f. + * @private + */ +goog.i18n.ordinalRules.get_vf_ = function(n, opt_precision) { + var DEFAULT_DIGITS = 3; + + if (undefined === opt_precision) { + var v = Math.min(goog.i18n.ordinalRules.decimals_(n), DEFAULT_DIGITS); + } else { + var v = opt_precision; + } + + var base = Math.pow(10, v); + var f = ((n * base) | 0) % base; + + return {v: v, f: f}; +}; + +/** + * Calculates w and t as per CLDR plural rules. + * The short names for parameters / return match the CLDR syntax and UTS #35 + * (http://unicode.org/reports/tr35/tr35-numbers.html#Plural_rules_syntax) + * @param {number} v Calculated previously. + * @param {number} f Calculated previously. + * @return {!Object} The w and t. + * @private + */ +goog.i18n.ordinalRules.get_wt_ = function(v, f) { + if (f === 0) { + return {w: 0, t: 0}; + } + + while ((f % 10) === 0) { + f /= 10; + v--; + } + + return {w: v, t: f}; +}; + +/** + * Ordinal select rules for en locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.enSelect_ = function(n, opt_precision) { + if (n % 10 == 1 && n % 100 != 11) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if (n % 10 == 2 && n % 100 != 12) { + return goog.i18n.ordinalRules.Keyword.TWO; + } + if (n % 10 == 3 && n % 100 != 13) { + return goog.i18n.ordinalRules.Keyword.FEW; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for sv locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.svSelect_ = function(n, opt_precision) { + if ((n % 10 == 1 || n % 10 == 2) && n % 100 != 11 && n % 100 != 12) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for hu locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.huSelect_ = function(n, opt_precision) { + if (n == 1 || n == 5) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for kk locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.kkSelect_ = function(n, opt_precision) { + if (n % 10 == 6 || n % 10 == 9 || n % 10 == 0 && n != 0) { + return goog.i18n.ordinalRules.Keyword.MANY; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for mr locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.mrSelect_ = function(n, opt_precision) { + if (n == 1) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if (n == 2 || n == 3) { + return goog.i18n.ordinalRules.Keyword.TWO; + } + if (n == 4) { + return goog.i18n.ordinalRules.Keyword.FEW; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for sq locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.sqSelect_ = function(n, opt_precision) { + if (n == 1) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if (n % 10 == 4 && n % 100 != 14) { + return goog.i18n.ordinalRules.Keyword.MANY; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for bn locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.bnSelect_ = function(n, opt_precision) { + if (n == 1 || n == 5 || n == 7 || n == 8 || n == 9 || n == 10) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if (n == 2 || n == 3) { + return goog.i18n.ordinalRules.Keyword.TWO; + } + if (n == 4) { + return goog.i18n.ordinalRules.Keyword.FEW; + } + if (n == 6) { + return goog.i18n.ordinalRules.Keyword.MANY; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for gu locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.guSelect_ = function(n, opt_precision) { + if (n == 1) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if (n == 2 || n == 3) { + return goog.i18n.ordinalRules.Keyword.TWO; + } + if (n == 4) { + return goog.i18n.ordinalRules.Keyword.FEW; + } + if (n == 6) { + return goog.i18n.ordinalRules.Keyword.MANY; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for ka locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.kaSelect_ = function(n, opt_precision) { + var i = n | 0; + if (i == 1) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if (i == 0 || (i % 100 >= 2 && i % 100 <= 20 || i % 100 == 40 || i % 100 == 60 || i % 100 == 80)) { + return goog.i18n.ordinalRules.Keyword.MANY; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for fr locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.frSelect_ = function(n, opt_precision) { + if (n == 1) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for ne locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.neSelect_ = function(n, opt_precision) { + if (n >= 1 && n <= 4) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for cy locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.cySelect_ = function(n, opt_precision) { + if (n == 0 || n == 7 || n == 8 || n == 9) { + return goog.i18n.ordinalRules.Keyword.ZERO; + } + if (n == 1) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if (n == 2) { + return goog.i18n.ordinalRules.Keyword.TWO; + } + if (n == 3 || n == 4) { + return goog.i18n.ordinalRules.Keyword.FEW; + } + if (n == 5 || n == 6) { + return goog.i18n.ordinalRules.Keyword.MANY; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for az locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.azSelect_ = function(n, opt_precision) { + var i = n | 0; + if ((i % 10 == 1 || i % 10 == 2 || i % 10 == 5 || i % 10 == 7 || i % 10 == 8) || (i % 100 == 20 || i % 100 == 50 || i % 100 == 70 || i % 100 == 80)) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if ((i % 10 == 3 || i % 10 == 4) || (i % 1000 == 100 || i % 1000 == 200 || i % 1000 == 300 || i % 1000 == 400 || i % 1000 == 500 || i % 1000 == 600 || i % 1000 == 700 || i % 1000 == 800 || i % 1000 == 900)) { + return goog.i18n.ordinalRules.Keyword.FEW; + } + if (i == 0 || i % 10 == 6 || (i % 100 == 40 || i % 100 == 60 || i % 100 == 90)) { + return goog.i18n.ordinalRules.Keyword.MANY; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for ca locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.caSelect_ = function(n, opt_precision) { + if (n == 1 || n == 3) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if (n == 2) { + return goog.i18n.ordinalRules.Keyword.TWO; + } + if (n == 4) { + return goog.i18n.ordinalRules.Keyword.FEW; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for it locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.itSelect_ = function(n, opt_precision) { + if (n == 11 || n == 8 || n == 80 || n == 800) { + return goog.i18n.ordinalRules.Keyword.MANY; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Ordinal select rules for mk locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.ordinalRules.Keyword} Locale-specific ordinal value. + * @private + */ +goog.i18n.ordinalRules.mkSelect_ = function(n, opt_precision) { + var i = n | 0; + if (i % 10 == 1 && i % 100 != 11) { + return goog.i18n.ordinalRules.Keyword.ONE; + } + if (i % 10 == 2 && i % 100 != 12) { + return goog.i18n.ordinalRules.Keyword.TWO; + } + if ((i % 10 == 7 || i % 10 == 8) && i % 100 != 17 && i % 100 != 18) { + return goog.i18n.ordinalRules.Keyword.MANY; + } + return goog.i18n.ordinalRules.Keyword.OTHER; +}; + +/** + * Selected Ordinal rules by locale. + */ +goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +if (goog.LOCALE == 'af') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'am') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ar') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'az') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.azSelect_; +} +if (goog.LOCALE == 'bg') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'bn') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.bnSelect_; +} +if (goog.LOCALE == 'br') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ca') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.caSelect_; +} +if (goog.LOCALE == 'chr') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'cs') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'cy') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.cySelect_; +} +if (goog.LOCALE == 'da') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'de') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'de_AT' || goog.LOCALE == 'de-AT') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'de_CH' || goog.LOCALE == 'de-CH') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'el') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'en') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +} +if (goog.LOCALE == 'en_AU' || goog.LOCALE == 'en-AU') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +} +if (goog.LOCALE == 'en_GB' || goog.LOCALE == 'en-GB') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +} +if (goog.LOCALE == 'en_IE' || goog.LOCALE == 'en-IE') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +} +if (goog.LOCALE == 'en_IN' || goog.LOCALE == 'en-IN') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +} +if (goog.LOCALE == 'en_ISO' || goog.LOCALE == 'en-ISO') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +} +if (goog.LOCALE == 'en_SG' || goog.LOCALE == 'en-SG') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +} +if (goog.LOCALE == 'en_US' || goog.LOCALE == 'en-US') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +} +if (goog.LOCALE == 'en_ZA' || goog.LOCALE == 'en-ZA') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.enSelect_; +} +if (goog.LOCALE == 'es') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'es_419' || goog.LOCALE == 'es-419') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'es_ES' || goog.LOCALE == 'es-ES') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'et') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'eu') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'fa') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'fi') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'fil') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'fr') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'fr_CA' || goog.LOCALE == 'fr-CA') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'gl') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'gsw') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'gu') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.guSelect_; +} +if (goog.LOCALE == 'haw') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'he') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'hi') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.guSelect_; +} +if (goog.LOCALE == 'hr') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'hu') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.huSelect_; +} +if (goog.LOCALE == 'hy') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'id') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'in') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'is') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'it') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.itSelect_; +} +if (goog.LOCALE == 'iw') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ja') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ka') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.kaSelect_; +} +if (goog.LOCALE == 'kk') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.kkSelect_; +} +if (goog.LOCALE == 'km') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'kn') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ko') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ky') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ln') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'lo') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'lt') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'lv') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'mk') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.mkSelect_; +} +if (goog.LOCALE == 'ml') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'mn') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'mo') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'mr') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.mrSelect_; +} +if (goog.LOCALE == 'ms') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'mt') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'my') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'nb') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ne') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.neSelect_; +} +if (goog.LOCALE == 'nl') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'no') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'no_NO' || goog.LOCALE == 'no-NO') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'or') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'pa') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'pl') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'pt') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'pt_BR' || goog.LOCALE == 'pt-BR') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'pt_PT' || goog.LOCALE == 'pt-PT') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ro') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'ru') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'sh') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'si') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'sk') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'sl') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'sq') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.sqSelect_; +} +if (goog.LOCALE == 'sr') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'sv') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.svSelect_; +} +if (goog.LOCALE == 'sw') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ta') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'te') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'th') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'tl') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'tr') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'uk') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'ur') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'uz') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'vi') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.frSelect_; +} +if (goog.LOCALE == 'zh') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'zh_CN' || goog.LOCALE == 'zh-CN') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'zh_HK' || goog.LOCALE == 'zh-HK') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'zh_TW' || goog.LOCALE == 'zh-TW') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} +if (goog.LOCALE == 'zu') { + goog.i18n.ordinalRules.select = goog.i18n.ordinalRules.defaultSelect_; +} diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/i18n/pluralrules.js b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/i18n/pluralrules.js new file mode 100644 index 0000000..20dc954 --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/i18n/pluralrules.js @@ -0,0 +1,1100 @@ +// Copyright 2012 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Plural rules. + * + * This file is autogenerated by script: + * http://go/generate_pluralrules.py + * File generated from CLDR ver. 25 + * + * Before check in, this file could have been manually edited. This is to + * incorporate changes before we could fix CLDR. All manual modification must be + * documented in this section, and should be removed after those changes land to + * CLDR. + */ + +goog.provide('goog.i18n.pluralRules'); +/** + * Plural pattern keyword + * @enum {string} + */ +goog.i18n.pluralRules.Keyword = { + ZERO: 'zero', + ONE: 'one', + TWO: 'two', + FEW: 'few', + MANY: 'many', + OTHER: 'other' +}; + + +/** + * Default Plural select rule. + * @param {number} n The count of items. + * @param {number=} opt_precision optional, precision. + * @return {goog.i18n.pluralRules.Keyword} Default value. + * @private + */ +goog.i18n.pluralRules.defaultSelect_ = function(n, opt_precision) { + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Returns the fractional part of a number (3.1416 => 1416) + * @param {number} n The count of items. + * @return {number} The fractional part. + * @private + */ +goog.i18n.pluralRules.decimals_ = function(n) { + var str = n + ''; + var result = str.indexOf('.'); + return (result == -1) ? 0 : str.length - result - 1; +}; + +/** + * Calculates v and f as per CLDR plural rules. + * The short names for parameters / return match the CLDR syntax and UTS #35 + * (http://unicode.org/reports/tr35/tr35-numbers.html#Plural_rules_syntax) + * @param {number} n The count of items. + * @param {number=} opt_precision optional, precision. + * @return {!Object} The v and f. + * @private + */ +goog.i18n.pluralRules.get_vf_ = function(n, opt_precision) { + var DEFAULT_DIGITS = 3; + + if (undefined === opt_precision) { + var v = Math.min(goog.i18n.pluralRules.decimals_(n), DEFAULT_DIGITS); + } else { + var v = opt_precision; + } + + var base = Math.pow(10, v); + var f = ((n * base) | 0) % base; + + return {v: v, f: f}; +}; + +/** + * Calculates w and t as per CLDR plural rules. + * The short names for parameters / return match the CLDR syntax and UTS #35 + * (http://unicode.org/reports/tr35/tr35-numbers.html#Plural_rules_syntax) + * @param {number} v Calculated previously. + * @param {number} f Calculated previously. + * @return {!Object} The w and t. + * @private + */ +goog.i18n.pluralRules.get_wt_ = function(v, f) { + if (f === 0) { + return {w: 0, t: 0}; + } + + while ((f % 10) === 0) { + f /= 10; + v--; + } + + return {w: v, t: f}; +}; + +/** + * Plural select rules for ga locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.gaSelect_ = function(n, opt_precision) { + if (n == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n == 2) { + return goog.i18n.pluralRules.Keyword.TWO; + } + if (n >= 3 && n <= 6) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (n >= 7 && n <= 10) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for ro locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.roSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (i == 1 && vf.v == 0) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (vf.v != 0 || n == 0 || n != 1 && n % 100 >= 1 && n % 100 <= 19) { + return goog.i18n.pluralRules.Keyword.FEW; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for fil locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.filSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (vf.v == 0 && (i == 1 || i == 2 || i == 3) || vf.v == 0 && i % 10 != 4 && i % 10 != 6 && i % 10 != 9 || vf.v != 0 && vf.f % 10 != 4 && vf.f % 10 != 6 && vf.f % 10 != 9) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for fr locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.frSelect_ = function(n, opt_precision) { + var i = n | 0; + if (i == 0 || i == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for en locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.enSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (i == 1 && vf.v == 0) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for mt locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.mtSelect_ = function(n, opt_precision) { + if (n == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n == 0 || n % 100 >= 2 && n % 100 <= 10) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (n % 100 >= 11 && n % 100 <= 19) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for da locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.daSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + var wt = goog.i18n.pluralRules.get_wt_(vf.v, vf.f); + if (n == 1 || wt.t != 0 && (i == 0 || i == 1)) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for gv locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.gvSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (vf.v == 0 && i % 10 == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (vf.v == 0 && i % 10 == 2) { + return goog.i18n.pluralRules.Keyword.TWO; + } + if (vf.v == 0 && (i % 100 == 0 || i % 100 == 20 || i % 100 == 40 || i % 100 == 60 || i % 100 == 80)) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (vf.v != 0) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for cy locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.cySelect_ = function(n, opt_precision) { + if (n == 0) { + return goog.i18n.pluralRules.Keyword.ZERO; + } + if (n == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n == 2) { + return goog.i18n.pluralRules.Keyword.TWO; + } + if (n == 3) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (n == 6) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for br locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.brSelect_ = function(n, opt_precision) { + if (n % 10 == 1 && n % 100 != 11 && n % 100 != 71 && n % 100 != 91) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n % 10 == 2 && n % 100 != 12 && n % 100 != 72 && n % 100 != 92) { + return goog.i18n.pluralRules.Keyword.TWO; + } + if ((n % 10 >= 3 && n % 10 <= 4 || n % 10 == 9) && (n % 100 < 10 || n % 100 > 19) && (n % 100 < 70 || n % 100 > 79) && (n % 100 < 90 || n % 100 > 99)) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (n != 0 && n % 1000000 == 0) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for es locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.esSelect_ = function(n, opt_precision) { + if (n == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for si locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.siSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if ((n == 0 || n == 1) || i == 0 && vf.f == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for sl locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.slSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (vf.v == 0 && i % 100 == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (vf.v == 0 && i % 100 == 2) { + return goog.i18n.pluralRules.Keyword.TWO; + } + if (vf.v == 0 && i % 100 >= 3 && i % 100 <= 4 || vf.v != 0) { + return goog.i18n.pluralRules.Keyword.FEW; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for tzm locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.tzmSelect_ = function(n, opt_precision) { + if (n >= 0 && n <= 1 || n >= 11 && n <= 99) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for sr locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.srSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (vf.v == 0 && i % 10 == 1 && i % 100 != 11 || vf.f % 10 == 1 && vf.f % 100 != 11) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (vf.v == 0 && i % 10 >= 2 && i % 10 <= 4 && (i % 100 < 12 || i % 100 > 14) || vf.f % 10 >= 2 && vf.f % 10 <= 4 && (vf.f % 100 < 12 || vf.f % 100 > 14)) { + return goog.i18n.pluralRules.Keyword.FEW; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for hi locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.hiSelect_ = function(n, opt_precision) { + var i = n | 0; + if (i == 0 || n == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for mk locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.mkSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (vf.v == 0 && i % 10 == 1 || vf.f % 10 == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for ar locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.arSelect_ = function(n, opt_precision) { + if (n == 0) { + return goog.i18n.pluralRules.Keyword.ZERO; + } + if (n == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n == 2) { + return goog.i18n.pluralRules.Keyword.TWO; + } + if (n % 100 >= 3 && n % 100 <= 10) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (n % 100 >= 11 && n % 100 <= 99) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for iu locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.iuSelect_ = function(n, opt_precision) { + if (n == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n == 2) { + return goog.i18n.pluralRules.Keyword.TWO; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for cs locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.csSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (i == 1 && vf.v == 0) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (i >= 2 && i <= 4 && vf.v == 0) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (vf.v != 0) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for pt_PT locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.pt_PTSelect_ = function(n, opt_precision) { + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (n == 1 && vf.v == 0) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for be locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.beSelect_ = function(n, opt_precision) { + if (n % 10 == 1 && n % 100 != 11) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (n % 10 == 0 || n % 10 >= 5 && n % 10 <= 9 || n % 100 >= 11 && n % 100 <= 14) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for ak locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.akSelect_ = function(n, opt_precision) { + if (n >= 0 && n <= 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for pt locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.ptSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + var wt = goog.i18n.pluralRules.get_wt_(vf.v, vf.f); + if (i == 1 && vf.v == 0 || i == 0 && wt.t == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for pl locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.plSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (i == 1 && vf.v == 0) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (vf.v == 0 && i % 10 >= 2 && i % 10 <= 4 && (i % 100 < 12 || i % 100 > 14)) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (vf.v == 0 && i != 1 && i % 10 >= 0 && i % 10 <= 1 || vf.v == 0 && i % 10 >= 5 && i % 10 <= 9 || vf.v == 0 && i % 100 >= 12 && i % 100 <= 14) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for ru locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.ruSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (vf.v == 0 && i % 10 == 1 && i % 100 != 11) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (vf.v == 0 && i % 10 >= 2 && i % 10 <= 4 && (i % 100 < 12 || i % 100 > 14)) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (vf.v == 0 && i % 10 == 0 || vf.v == 0 && i % 10 >= 5 && i % 10 <= 9 || vf.v == 0 && i % 100 >= 11 && i % 100 <= 14) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for lag locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.lagSelect_ = function(n, opt_precision) { + var i = n | 0; + if (n == 0) { + return goog.i18n.pluralRules.Keyword.ZERO; + } + if ((i == 0 || i == 1) && n != 0) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for shi locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.shiSelect_ = function(n, opt_precision) { + var i = n | 0; + if (i == 0 || n == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n >= 2 && n <= 10) { + return goog.i18n.pluralRules.Keyword.FEW; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for he locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.heSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (i == 1 && vf.v == 0) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (i == 2 && vf.v == 0) { + return goog.i18n.pluralRules.Keyword.TWO; + } + if (vf.v == 0 && (n < 0 || n > 10) && n % 10 == 0) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for is locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.isSelect_ = function(n, opt_precision) { + var i = n | 0; + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + var wt = goog.i18n.pluralRules.get_wt_(vf.v, vf.f); + if (wt.t == 0 && i % 10 == 1 && i % 100 != 11 || wt.t != 0) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for lt locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.ltSelect_ = function(n, opt_precision) { + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (n % 10 == 1 && (n % 100 < 11 || n % 100 > 19)) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n % 10 >= 2 && n % 10 <= 9 && (n % 100 < 11 || n % 100 > 19)) { + return goog.i18n.pluralRules.Keyword.FEW; + } + if (vf.f != 0) { + return goog.i18n.pluralRules.Keyword.MANY; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for gd locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.gdSelect_ = function(n, opt_precision) { + if (n == 1 || n == 11) { + return goog.i18n.pluralRules.Keyword.ONE; + } + if (n == 2 || n == 12) { + return goog.i18n.pluralRules.Keyword.TWO; + } + if (n >= 3 && n <= 10 || n >= 13 && n <= 19) { + return goog.i18n.pluralRules.Keyword.FEW; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for lv locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.lvSelect_ = function(n, opt_precision) { + var vf = goog.i18n.pluralRules.get_vf_(n, opt_precision); + if (n % 10 == 0 || n % 100 >= 11 && n % 100 <= 19 || vf.v == 2 && vf.f % 100 >= 11 && vf.f % 100 <= 19) { + return goog.i18n.pluralRules.Keyword.ZERO; + } + if (n % 10 == 1 && n % 100 != 11 || vf.v == 2 && vf.f % 10 == 1 && vf.f % 100 != 11 || vf.v != 2 && vf.f % 10 == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Plural select rules for ksh locale + * + * @param {number} n The count of items. + * @param {number=} opt_precision Precision for number formatting, if not default. + * @return {goog.i18n.pluralRules.Keyword} Locale-specific plural value. + * @private + */ +goog.i18n.pluralRules.kshSelect_ = function(n, opt_precision) { + if (n == 0) { + return goog.i18n.pluralRules.Keyword.ZERO; + } + if (n == 1) { + return goog.i18n.pluralRules.Keyword.ONE; + } + return goog.i18n.pluralRules.Keyword.OTHER; +}; + +/** + * Selected Plural rules by locale. + */ +goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +if (goog.LOCALE == 'af') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'am') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.hiSelect_; +} +if (goog.LOCALE == 'ar') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.arSelect_; +} +if (goog.LOCALE == 'az') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'bg') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'bn') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.hiSelect_; +} +if (goog.LOCALE == 'br') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.brSelect_; +} +if (goog.LOCALE == 'ca') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'chr') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'cs') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.csSelect_; +} +if (goog.LOCALE == 'cy') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.cySelect_; +} +if (goog.LOCALE == 'da') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.daSelect_; +} +if (goog.LOCALE == 'de') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'de_AT' || goog.LOCALE == 'de-AT') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'de_CH' || goog.LOCALE == 'de-CH') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'el') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'en') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'en_AU' || goog.LOCALE == 'en-AU') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'en_GB' || goog.LOCALE == 'en-GB') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'en_IE' || goog.LOCALE == 'en-IE') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'en_IN' || goog.LOCALE == 'en-IN') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'en_ISO' || goog.LOCALE == 'en-ISO') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'en_SG' || goog.LOCALE == 'en-SG') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'en_US' || goog.LOCALE == 'en-US') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'en_ZA' || goog.LOCALE == 'en-ZA') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'es') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'es_419' || goog.LOCALE == 'es-419') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'es_ES' || goog.LOCALE == 'es-ES') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'et') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'eu') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'fa') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.hiSelect_; +} +if (goog.LOCALE == 'fi') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'fil') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.filSelect_; +} +if (goog.LOCALE == 'fr') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.frSelect_; +} +if (goog.LOCALE == 'fr_CA' || goog.LOCALE == 'fr-CA') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.frSelect_; +} +if (goog.LOCALE == 'gl') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'gsw') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'gu') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.hiSelect_; +} +if (goog.LOCALE == 'haw') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'he') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.heSelect_; +} +if (goog.LOCALE == 'hi') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.hiSelect_; +} +if (goog.LOCALE == 'hr') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.srSelect_; +} +if (goog.LOCALE == 'hu') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'hy') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.frSelect_; +} +if (goog.LOCALE == 'id') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'in') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'is') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.isSelect_; +} +if (goog.LOCALE == 'it') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'iw') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.heSelect_; +} +if (goog.LOCALE == 'ja') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'ka') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'kk') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'km') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'kn') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.hiSelect_; +} +if (goog.LOCALE == 'ko') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'ky') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'ln') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.akSelect_; +} +if (goog.LOCALE == 'lo') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'lt') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.ltSelect_; +} +if (goog.LOCALE == 'lv') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.lvSelect_; +} +if (goog.LOCALE == 'mk') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.mkSelect_; +} +if (goog.LOCALE == 'ml') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'mn') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'mo') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.roSelect_; +} +if (goog.LOCALE == 'mr') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.hiSelect_; +} +if (goog.LOCALE == 'ms') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'mt') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.mtSelect_; +} +if (goog.LOCALE == 'my') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'nb') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'ne') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'nl') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'no') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'no_NO' || goog.LOCALE == 'no-NO') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'or') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'pa') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.akSelect_; +} +if (goog.LOCALE == 'pl') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.plSelect_; +} +if (goog.LOCALE == 'pt') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.ptSelect_; +} +if (goog.LOCALE == 'pt_BR' || goog.LOCALE == 'pt-BR') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.ptSelect_; +} +if (goog.LOCALE == 'pt_PT' || goog.LOCALE == 'pt-PT') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.pt_PTSelect_; +} +if (goog.LOCALE == 'ro') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.roSelect_; +} +if (goog.LOCALE == 'ru') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.ruSelect_; +} +if (goog.LOCALE == 'sh') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.srSelect_; +} +if (goog.LOCALE == 'si') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.siSelect_; +} +if (goog.LOCALE == 'sk') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.csSelect_; +} +if (goog.LOCALE == 'sl') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.slSelect_; +} +if (goog.LOCALE == 'sq') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'sr') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.srSelect_; +} +if (goog.LOCALE == 'sv') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'sw') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'ta') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'te') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'th') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'tl') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.filSelect_; +} +if (goog.LOCALE == 'tr') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'uk') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.ruSelect_; +} +if (goog.LOCALE == 'ur') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.enSelect_; +} +if (goog.LOCALE == 'uz') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.esSelect_; +} +if (goog.LOCALE == 'vi') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'zh') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'zh_CN' || goog.LOCALE == 'zh-CN') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'zh_HK' || goog.LOCALE == 'zh-HK') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'zh_TW' || goog.LOCALE == 'zh-TW') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.defaultSelect_; +} +if (goog.LOCALE == 'zu') { + goog.i18n.pluralRules.select = goog.i18n.pluralRules.hiSelect_; +} diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/object/object.js b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/object/object.js new file mode 100644 index 0000000..e181ffb --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/object/object.js @@ -0,0 +1,637 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Utilities for manipulating objects/maps/hashes. + */ + +goog.provide('goog.object'); + + +/** + * Calls a function for each element in an object/map/hash. + * + * @param {Object.<K,V>} obj The object over which to iterate. + * @param {function(this:T,V,?,Object.<K,V>):?} f The function to call + * for every element. This function takes 3 arguments (the element, the + * index and the object) and the return value is ignored. + * @param {T=} opt_obj This is used as the 'this' object within f. + * @template T,K,V + */ +goog.object.forEach = function(obj, f, opt_obj) { + for (var key in obj) { + f.call(opt_obj, obj[key], key, obj); + } +}; + + +/** + * Calls a function for each element in an object/map/hash. If that call returns + * true, adds the element to a new object. + * + * @param {Object.<K,V>} obj The object over which to iterate. + * @param {function(this:T,V,?,Object.<K,V>):boolean} f The function to call + * for every element. This + * function takes 3 arguments (the element, the index and the object) + * and should return a boolean. If the return value is true the + * element is added to the result object. If it is false the + * element is not included. + * @param {T=} opt_obj This is used as the 'this' object within f. + * @return {!Object.<K,V>} a new object in which only elements that passed the + * test are present. + * @template T,K,V + */ +goog.object.filter = function(obj, f, opt_obj) { + var res = {}; + for (var key in obj) { + if (f.call(opt_obj, obj[key], key, obj)) { + res[key] = obj[key]; + } + } + return res; +}; + + +/** + * For every element in an object/map/hash calls a function and inserts the + * result into a new object. + * + * @param {Object.<K,V>} obj The object over which to iterate. + * @param {function(this:T,V,?,Object.<K,V>):R} f The function to call + * for every element. This function + * takes 3 arguments (the element, the index and the object) + * and should return something. The result will be inserted + * into a new object. + * @param {T=} opt_obj This is used as the 'this' object within f. + * @return {!Object.<K,R>} a new object with the results from f. + * @template T,K,V,R + */ +goog.object.map = function(obj, f, opt_obj) { + var res = {}; + for (var key in obj) { + res[key] = f.call(opt_obj, obj[key], key, obj); + } + return res; +}; + + +/** + * Calls a function for each element in an object/map/hash. If any + * call returns true, returns true (without checking the rest). If + * all calls return false, returns false. + * + * @param {Object.<K,V>} obj The object to check. + * @param {function(this:T,V,?,Object.<K,V>):boolean} f The function to + * call for every element. This function + * takes 3 arguments (the element, the index and the object) and should + * return a boolean. + * @param {T=} opt_obj This is used as the 'this' object within f. + * @return {boolean} true if any element passes the test. + * @template T,K,V + */ +goog.object.some = function(obj, f, opt_obj) { + for (var key in obj) { + if (f.call(opt_obj, obj[key], key, obj)) { + return true; + } + } + return false; +}; + + +/** + * Calls a function for each element in an object/map/hash. If + * all calls return true, returns true. If any call returns false, returns + * false at this point and does not continue to check the remaining elements. + * + * @param {Object.<K,V>} obj The object to check. + * @param {?function(this:T,V,?,Object.<K,V>):boolean} f The function to + * call for every element. This function + * takes 3 arguments (the element, the index and the object) and should + * return a boolean. + * @param {T=} opt_obj This is used as the 'this' object within f. + * @return {boolean} false if any element fails the test. + * @template T,K,V + */ +goog.object.every = function(obj, f, opt_obj) { + for (var key in obj) { + if (!f.call(opt_obj, obj[key], key, obj)) { + return false; + } + } + return true; +}; + + +/** + * Returns the number of key-value pairs in the object map. + * + * @param {Object} obj The object for which to get the number of key-value + * pairs. + * @return {number} The number of key-value pairs in the object map. + */ +goog.object.getCount = function(obj) { + // JS1.5 has __count__ but it has been deprecated so it raises a warning... + // in other words do not use. Also __count__ only includes the fields on the + // actual object and not in the prototype chain. + var rv = 0; + for (var key in obj) { + rv++; + } + return rv; +}; + + +/** + * Returns one key from the object map, if any exists. + * For map literals the returned key will be the first one in most of the + * browsers (a know exception is Konqueror). + * + * @param {Object} obj The object to pick a key from. + * @return {string|undefined} The key or undefined if the object is empty. + */ +goog.object.getAnyKey = function(obj) { + for (var key in obj) { + return key; + } +}; + + +/** + * Returns one value from the object map, if any exists. + * For map literals the returned value will be the first one in most of the + * browsers (a know exception is Konqueror). + * + * @param {Object.<K,V>} obj The object to pick a value from. + * @return {V|undefined} The value or undefined if the object is empty. + * @template K,V + */ +goog.object.getAnyValue = function(obj) { + for (var key in obj) { + return obj[key]; + } +}; + + +/** + * Whether the object/hash/map contains the given object as a value. + * An alias for goog.object.containsValue(obj, val). + * + * @param {Object.<K,V>} obj The object in which to look for val. + * @param {V} val The object for which to check. + * @return {boolean} true if val is present. + * @template K,V + */ +goog.object.contains = function(obj, val) { + return goog.object.containsValue(obj, val); +}; + + +/** + * Returns the values of the object/map/hash. + * + * @param {Object.<K,V>} obj The object from which to get the values. + * @return {!Array.<V>} The values in the object/map/hash. + * @template K,V + */ +goog.object.getValues = function(obj) { + var res = []; + var i = 0; + for (var key in obj) { + res[i++] = obj[key]; + } + return res; +}; + + +/** + * Returns the keys of the object/map/hash. + * + * @param {Object} obj The object from which to get the keys. + * @return {!Array.<string>} Array of property keys. + */ +goog.object.getKeys = function(obj) { + var res = []; + var i = 0; + for (var key in obj) { + res[i++] = key; + } + return res; +}; + + +/** + * Get a value from an object multiple levels deep. This is useful for + * pulling values from deeply nested objects, such as JSON responses. + * Example usage: getValueByKeys(jsonObj, 'foo', 'entries', 3) + * + * @param {!Object} obj An object to get the value from. Can be array-like. + * @param {...(string|number|!Array.<number|string>)} var_args A number of keys + * (as strings, or numbers, for array-like objects). Can also be + * specified as a single array of keys. + * @return {*} The resulting value. If, at any point, the value for a key + * is undefined, returns undefined. + */ +goog.object.getValueByKeys = function(obj, var_args) { + var isArrayLike = goog.isArrayLike(var_args); + var keys = isArrayLike ? var_args : arguments; + + // Start with the 2nd parameter for the variable parameters syntax. + for (var i = isArrayLike ? 0 : 1; i < keys.length; i++) { + obj = obj[keys[i]]; + if (!goog.isDef(obj)) { + break; + } + } + + return obj; +}; + + +/** + * Whether the object/map/hash contains the given key. + * + * @param {Object} obj The object in which to look for key. + * @param {*} key The key for which to check. + * @return {boolean} true If the map contains the key. + */ +goog.object.containsKey = function(obj, key) { + return key in obj; +}; + + +/** + * Whether the object/map/hash contains the given value. This is O(n). + * + * @param {Object.<K,V>} obj The object in which to look for val. + * @param {V} val The value for which to check. + * @return {boolean} true If the map contains the value. + * @template K,V + */ +goog.object.containsValue = function(obj, val) { + for (var key in obj) { + if (obj[key] == val) { + return true; + } + } + return false; +}; + + +/** + * Searches an object for an element that satisfies the given condition and + * returns its key. + * @param {Object.<K,V>} obj The object to search in. + * @param {function(this:T,V,string,Object.<K,V>):boolean} f The + * function to call for every element. Takes 3 arguments (the value, + * the key and the object) and should return a boolean. + * @param {T=} opt_this An optional "this" context for the function. + * @return {string|undefined} The key of an element for which the function + * returns true or undefined if no such element is found. + * @template T,K,V + */ +goog.object.findKey = function(obj, f, opt_this) { + for (var key in obj) { + if (f.call(opt_this, obj[key], key, obj)) { + return key; + } + } + return undefined; +}; + + +/** + * Searches an object for an element that satisfies the given condition and + * returns its value. + * @param {Object.<K,V>} obj The object to search in. + * @param {function(this:T,V,string,Object.<K,V>):boolean} f The function + * to call for every element. Takes 3 arguments (the value, the key + * and the object) and should return a boolean. + * @param {T=} opt_this An optional "this" context for the function. + * @return {V} The value of an element for which the function returns true or + * undefined if no such element is found. + * @template T,K,V + */ +goog.object.findValue = function(obj, f, opt_this) { + var key = goog.object.findKey(obj, f, opt_this); + return key && obj[key]; +}; + + +/** + * Whether the object/map/hash is empty. + * + * @param {Object} obj The object to test. + * @return {boolean} true if obj is empty. + */ +goog.object.isEmpty = function(obj) { + for (var key in obj) { + return false; + } + return true; +}; + + +/** + * Removes all key value pairs from the object/map/hash. + * + * @param {Object} obj The object to clear. + */ +goog.object.clear = function(obj) { + for (var i in obj) { + delete obj[i]; + } +}; + + +/** + * Removes a key-value pair based on the key. + * + * @param {Object} obj The object from which to remove the key. + * @param {*} key The key to remove. + * @return {boolean} Whether an element was removed. + */ +goog.object.remove = function(obj, key) { + var rv; + if ((rv = key in obj)) { + delete obj[key]; + } + return rv; +}; + + +/** + * Adds a key-value pair to the object. Throws an exception if the key is + * already in use. Use set if you want to change an existing pair. + * + * @param {Object.<K,V>} obj The object to which to add the key-value pair. + * @param {string} key The key to add. + * @param {V} val The value to add. + * @template K,V + */ +goog.object.add = function(obj, key, val) { + if (key in obj) { + throw Error('The object already contains the key "' + key + '"'); + } + goog.object.set(obj, key, val); +}; + + +/** + * Returns the value for the given key. + * + * @param {Object.<K,V>} obj The object from which to get the value. + * @param {string} key The key for which to get the value. + * @param {R=} opt_val The value to return if no item is found for the given + * key (default is undefined). + * @return {V|R|undefined} The value for the given key. + * @template K,V,R + */ +goog.object.get = function(obj, key, opt_val) { + if (key in obj) { + return obj[key]; + } + return opt_val; +}; + + +/** + * Adds a key-value pair to the object/map/hash. + * + * @param {Object.<K,V>} obj The object to which to add the key-value pair. + * @param {string} key The key to add. + * @param {V} value The value to add. + * @template K,V + */ +goog.object.set = function(obj, key, value) { + obj[key] = value; +}; + + +/** + * Adds a key-value pair to the object/map/hash if it doesn't exist yet. + * + * @param {Object.<K,V>} obj The object to which to add the key-value pair. + * @param {string} key The key to add. + * @param {V} value The value to add if the key wasn't present. + * @return {V} The value of the entry at the end of the function. + * @template K,V + */ +goog.object.setIfUndefined = function(obj, key, value) { + return key in obj ? obj[key] : (obj[key] = value); +}; + + +/** + * Does a flat clone of the object. + * + * @param {Object.<K,V>} obj Object to clone. + * @return {!Object.<K,V>} Clone of the input object. + * @template K,V + */ +goog.object.clone = function(obj) { + // We cannot use the prototype trick because a lot of methods depend on where + // the actual key is set. + + var res = {}; + for (var key in obj) { + res[key] = obj[key]; + } + return res; + // We could also use goog.mixin but I wanted this to be independent from that. +}; + + +/** + * Clones a value. The input may be an Object, Array, or basic type. Objects and + * arrays will be cloned recursively. + * + * WARNINGS: + * <code>goog.object.unsafeClone</code> does not detect reference loops. Objects + * that refer to themselves will cause infinite recursion. + * + * <code>goog.object.unsafeClone</code> is unaware of unique identifiers, and + * copies UIDs created by <code>getUid</code> into cloned results. + * + * @param {*} obj The value to clone. + * @return {*} A clone of the input value. + */ +goog.object.unsafeClone = function(obj) { + var type = goog.typeOf(obj); + if (type == 'object' || type == 'array') { + if (obj.clone) { + return obj.clone(); + } + var clone = type == 'array' ? [] : {}; + for (var key in obj) { + clone[key] = goog.object.unsafeClone(obj[key]); + } + return clone; + } + + return obj; +}; + + +/** + * Returns a new object in which all the keys and values are interchanged + * (keys become values and values become keys). If multiple keys map to the + * same value, the chosen transposed value is implementation-dependent. + * + * @param {Object} obj The object to transpose. + * @return {!Object} The transposed object. + */ +goog.object.transpose = function(obj) { + var transposed = {}; + for (var key in obj) { + transposed[obj[key]] = key; + } + return transposed; +}; + + +/** + * The names of the fields that are defined on Object.prototype. + * @type {Array.<string>} + * @private + */ +goog.object.PROTOTYPE_FIELDS_ = [ + 'constructor', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'toLocaleString', + 'toString', + 'valueOf' +]; + + +/** + * Extends an object with another object. + * This operates 'in-place'; it does not create a new Object. + * + * Example: + * var o = {}; + * goog.object.extend(o, {a: 0, b: 1}); + * o; // {a: 0, b: 1} + * goog.object.extend(o, {b: 2, c: 3}); + * o; // {a: 0, b: 2, c: 3} + * + * @param {Object} target The object to modify. Existing properties will be + * overwritten if they are also present in one of the objects in + * {@code var_args}. + * @param {...Object} var_args The objects from which values will be copied. + */ +goog.object.extend = function(target, var_args) { + var key, source; + for (var i = 1; i < arguments.length; i++) { + source = arguments[i]; + for (key in source) { + target[key] = source[key]; + } + + // For IE the for-in-loop does not contain any properties that are not + // enumerable on the prototype object (for example isPrototypeOf from + // Object.prototype) and it will also not include 'replace' on objects that + // extend String and change 'replace' (not that it is common for anyone to + // extend anything except Object). + + for (var j = 0; j < goog.object.PROTOTYPE_FIELDS_.length; j++) { + key = goog.object.PROTOTYPE_FIELDS_[j]; + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } +}; + + +/** + * Creates a new object built from the key-value pairs provided as arguments. + * @param {...*} var_args If only one argument is provided and it is an array + * then this is used as the arguments, otherwise even arguments are used as + * the property names and odd arguments are used as the property values. + * @return {!Object} The new object. + * @throws {Error} If there are uneven number of arguments or there is only one + * non array argument. + */ +goog.object.create = function(var_args) { + var argLength = arguments.length; + if (argLength == 1 && goog.isArray(arguments[0])) { + return goog.object.create.apply(null, arguments[0]); + } + + if (argLength % 2) { + throw Error('Uneven number of arguments'); + } + + var rv = {}; + for (var i = 0; i < argLength; i += 2) { + rv[arguments[i]] = arguments[i + 1]; + } + return rv; +}; + + +/** + * Creates a new object where the property names come from the arguments but + * the value is always set to true + * @param {...*} var_args If only one argument is provided and it is an array + * then this is used as the arguments, otherwise the arguments are used + * as the property names. + * @return {!Object} The new object. + */ +goog.object.createSet = function(var_args) { + var argLength = arguments.length; + if (argLength == 1 && goog.isArray(arguments[0])) { + return goog.object.createSet.apply(null, arguments[0]); + } + + var rv = {}; + for (var i = 0; i < argLength; i++) { + rv[arguments[i]] = true; + } + return rv; +}; + + +/** + * Creates an immutable view of the underlying object, if the browser + * supports immutable objects. + * + * In default mode, writes to this view will fail silently. In strict mode, + * they will throw an error. + * + * @param {!Object.<K,V>} obj An object. + * @return {!Object.<K,V>} An immutable view of that object, or the + * original object if this browser does not support immutables. + * @template K,V + */ +goog.object.createImmutableView = function(obj) { + var result = obj; + if (Object.isFrozen && !Object.isFrozen(obj)) { + result = Object.create(obj); + Object.freeze(result); + } + return result; +}; + + +/** + * @param {!Object} obj An object. + * @return {boolean} Whether this is an immutable view of the object. + */ +goog.object.isImmutableView = function(obj) { + return !!Object.isFrozen && Object.isFrozen(obj); +}; diff --git a/chrome/third_party/chromevox/third_party/closure-library/closure/goog/string/string.js b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/string/string.js new file mode 100644 index 0000000..af10460 --- /dev/null +++ b/chrome/third_party/chromevox/third_party/closure-library/closure/goog/string/string.js @@ -0,0 +1,47 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Utilities for string manipulation. + */ + + +/** + * Namespace for string utilities + */ +goog.provide('goog.string'); + + +/** + * Does simple python-style string substitution. + * subs("foo%s hot%s", "bar", "dog") becomes "foobar hotdog". + * @param {string} str The string containing the pattern. + * @param {...*} var_args The items to substitute into the pattern. + * @return {string} A copy of {@code str} in which each occurrence of + * {@code %s} has been replaced an argument from {@code var_args}. + */ +goog.string.subs = function(str, var_args) { + var splitParts = str.split('%s'); + var returnString = ''; + + var subsArguments = Array.prototype.slice.call(arguments, 1); + while (subsArguments.length && + // Replace up to the last split part. We are inserting in the + // positions between split parts. + splitParts.length > 1) { + returnString += splitParts.shift() + subsArguments.shift(); + } + + return returnString + splitParts.join('%s'); // Join unused '%s' +}; |