anytrans.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ***********************************************************************
  5. * Copyright (c) 2002-2007, International Business Machines Corporation
  6. * and others. All Rights Reserved.
  7. ***********************************************************************
  8. * Date Name Description
  9. * 06/06/2002 aliu Creation.
  10. ***********************************************************************
  11. */
  12. #ifndef _ANYTRANS_H_
  13. #define _ANYTRANS_H_
  14. #include "unicode/utypes.h"
  15. #if !UCONFIG_NO_TRANSLITERATION
  16. #include "unicode/translit.h"
  17. #include "unicode/uscript.h"
  18. #include "uhash.h"
  19. U_NAMESPACE_BEGIN
  20. /**
  21. * A transliterator named Any-T or Any-T/V, where T is the target
  22. * script and V is the optional variant, that uses multiple
  23. * transliterators, all going to T or T/V, all with script sources.
  24. * The target must be a script. It partitions text into runs of the
  25. * same script, and then based on the script of each run,
  26. * transliterates from that script to the given target or
  27. * target/variant. Adjacent COMMON or INHERITED script characters are
  28. * included in each run.
  29. *
  30. * @author Alan Liu
  31. */
  32. class AnyTransliterator : public Transliterator {
  33. /**
  34. * Cache mapping UScriptCode values to Transliterator*.
  35. */
  36. UHashtable* cache;
  37. /**
  38. * The target or target/variant string.
  39. */
  40. UnicodeString target;
  41. /**
  42. * The target script code. Never USCRIPT_INVALID_CODE.
  43. */
  44. UScriptCode targetScript;
  45. public:
  46. /**
  47. * Destructor.
  48. */
  49. virtual ~AnyTransliterator();
  50. /**
  51. * Copy constructor.
  52. */
  53. AnyTransliterator(const AnyTransliterator&);
  54. /**
  55. * Transliterator API.
  56. */
  57. virtual AnyTransliterator* clone() const;
  58. /**
  59. * Implements {@link Transliterator#handleTransliterate}.
  60. */
  61. virtual void handleTransliterate(Replaceable& text, UTransPosition& index,
  62. UBool incremental) const;
  63. /**
  64. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  65. */
  66. virtual UClassID getDynamicClassID() const;
  67. /**
  68. * ICU "poor man's RTTI", returns a UClassID for this class.
  69. */
  70. U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
  71. private:
  72. /**
  73. * Private constructor
  74. * @param id the ID of the form S-T or S-T/V, where T is theTarget
  75. * and V is theVariant. Must not be empty.
  76. * @param theTarget the target name. Must not be empty, and must
  77. * name a script corresponding to theTargetScript.
  78. * @param theVariant the variant name, or the empty string if
  79. * there is no variant
  80. * @param theTargetScript the script code corresponding to
  81. * theTarget.
  82. * @param ec error code, fails if the internal hashtable cannot be
  83. * allocated
  84. */
  85. AnyTransliterator(const UnicodeString& id,
  86. const UnicodeString& theTarget,
  87. const UnicodeString& theVariant,
  88. UScriptCode theTargetScript,
  89. UErrorCode& ec);
  90. /**
  91. * Returns a transliterator from the given source to our target or
  92. * target/variant. Returns NULL if the source is the same as our
  93. * target script, or if the source is USCRIPT_INVALID_CODE.
  94. * Caches the result and returns the same transliterator the next
  95. * time. The caller does NOT own the result and must not delete
  96. * it.
  97. */
  98. Transliterator* getTransliterator(UScriptCode source) const;
  99. /**
  100. * Registers standard transliterators with the system. Called by
  101. * Transliterator during initialization.
  102. */
  103. static void registerIDs();
  104. friend class Transliterator; // for registerIDs()
  105. };
  106. U_NAMESPACE_END
  107. #endif /* #if !UCONFIG_NO_TRANSLITERATION */
  108. #endif