localnamefetcher.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * @fileoverview Object which fetches Unicode codepoint names that are locally
  16. * stored in a bundled database. Currently, only invisible characters are
  17. * covered by this database. See the goog.i18n.uChar.RemoteNameFetcher class for
  18. * a remote database option.
  19. */
  20. goog.provide('goog.i18n.uChar.LocalNameFetcher');
  21. goog.require('goog.i18n.uChar.NameFetcher');
  22. goog.require('goog.i18n.uCharNames');
  23. goog.require('goog.log');
  24. /**
  25. * Builds the NameFetcherLocal object. This is a simple object which retrieves
  26. * character names from a local bundled database. This database only covers
  27. * invisible characters. See the goog.i18n.uChar class for more details.
  28. *
  29. * @constructor
  30. * @implements {goog.i18n.uChar.NameFetcher}
  31. * @final
  32. */
  33. goog.i18n.uChar.LocalNameFetcher = function() {};
  34. /**
  35. * A reference to the LocalNameFetcher logger.
  36. *
  37. * @type {goog.log.Logger}
  38. * @private
  39. */
  40. goog.i18n.uChar.LocalNameFetcher.logger_ =
  41. goog.log.getLogger('goog.i18n.uChar.LocalNameFetcher');
  42. /** @override */
  43. goog.i18n.uChar.LocalNameFetcher.prototype.prefetch = function(character) {};
  44. /** @override */
  45. goog.i18n.uChar.LocalNameFetcher.prototype.getName = function(
  46. character, callback) {
  47. var localName = goog.i18n.uCharNames.toName(character);
  48. if (!localName) {
  49. goog.i18n.uChar.LocalNameFetcher.logger_.warning(
  50. 'No local name defined for character ' + character);
  51. }
  52. callback(localName);
  53. };
  54. /** @override */
  55. goog.i18n.uChar.LocalNameFetcher.prototype.isNameAvailable = function(
  56. character) {
  57. return !!goog.i18n.uCharNames.toName(character);
  58. };