| 1 |
// Copyright 2012 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview Object which fetches Unicode codepoint names that are locally |
| 17 |
* stored in a bundled database. Currently, only invisible characters are |
| 18 |
* covered by this database. See the goog.i18n.uChar.RemoteNameFetcher class for |
| 19 |
* a remote database option. |
| 20 |
*/ |
| 21 |
|
| 22 |
goog.provide('goog.i18n.uChar.LocalNameFetcher'); |
| 23 |
|
| 24 |
goog.require('goog.i18n.uChar.NameFetcher'); |
| 25 |
goog.require('goog.i18n.uCharNames'); |
| 26 |
goog.require('goog.log'); |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
/** |
| 31 |
* Builds the NameFetcherLocal object. This is a simple object which retrieves |
| 32 |
* character names from a local bundled database. This database only covers |
| 33 |
* invisible characters. See the goog.i18n.uChar class for more details. |
| 34 |
* |
| 35 |
* @constructor |
| 36 |
* @implements {goog.i18n.uChar.NameFetcher} |
| 37 |
* @final |
| 38 |
*/ |
| 39 |
goog.i18n.uChar.LocalNameFetcher = function() {}; |
| 40 |
|
| 41 |
|
| 42 |
/** |
| 43 |
* A reference to the LocalNameFetcher logger. |
| 44 |
* |
| 45 |
* @type {goog.log.Logger} |
| 46 |
* @private |
| 47 |
*/ |
| 48 |
goog.i18n.uChar.LocalNameFetcher.logger_ = |
| 49 |
goog.log.getLogger('goog.i18n.uChar.LocalNameFetcher'); |
| 50 |
|
| 51 |
|
| 52 |
/** @override */ |
| 53 |
goog.i18n.uChar.LocalNameFetcher.prototype.prefetch = function(character) {}; |
| 54 |
|
| 55 |
|
| 56 |
/** @override */ |
| 57 |
goog.i18n.uChar.LocalNameFetcher.prototype.getName = function( |
| 58 |
character, callback) { |
| 59 |
var localName = goog.i18n.uCharNames.toName(character); |
| 60 |
if (!localName) { |
| 61 |
goog.i18n.uChar.LocalNameFetcher.logger_.warning( |
| 62 |
'No local name defined for character ' + character); |
| 63 |
} |
| 64 |
callback(localName); |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
/** @override */ |
| 69 |
goog.i18n.uChar.LocalNameFetcher.prototype.isNameAvailable = function( |
| 70 |
character) { |
| 71 |
return !!goog.i18n.uCharNames.toName(character); |
| 72 |
}; |