esctrn.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (c) 2001-2007, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. * Date Name Description
  9. * 11/20/2001 aliu Creation.
  10. **********************************************************************
  11. */
  12. #ifndef ESCTRN_H
  13. #define ESCTRN_H
  14. #include "unicode/utypes.h"
  15. #if !UCONFIG_NO_TRANSLITERATION
  16. #include "unicode/translit.h"
  17. U_NAMESPACE_BEGIN
  18. /**
  19. * A transliterator that converts Unicode characters to an escape
  20. * form. Examples of escape forms are "U+4E01" and "".
  21. * Escape forms have a prefix and suffix, either of which may be
  22. * empty, a radix, typically 16 or 10, a minimum digit count,
  23. * typically 1, 4, or 8, and a boolean that specifies whether
  24. * supplemental characters are handled as 32-bit code points or as two
  25. * 16-bit code units. Most escape forms handle 32-bit code points,
  26. * but some, such as the Java form, intentionally break them into two
  27. * surrogate pairs, for backward compatibility.
  28. *
  29. * <p>Some escape forms actually have two different patterns, one for
  30. * BMP characters (0..FFFF) and one for supplements (>FFFF). To
  31. * handle this, a second EscapeTransliterator may be defined that
  32. * specifies the pattern to be produced for supplementals. An example
  33. * of a form that requires this is the C form, which uses "\\uFFFF"
  34. * for BMP characters and "\\U0010FFFF" for supplementals.
  35. *
  36. * <p>This class is package private. It registers several standard
  37. * variants with the system which are then accessed via their IDs.
  38. *
  39. * @author Alan Liu
  40. */
  41. class EscapeTransliterator : public Transliterator {
  42. private:
  43. /**
  44. * The prefix of the escape form; may be empty, but usually isn't.
  45. */
  46. UnicodeString prefix;
  47. /**
  48. * The prefix of the escape form; often empty.
  49. */
  50. UnicodeString suffix;
  51. /**
  52. * The radix to display the number in. Typically 16 or 10. Must
  53. * be in the range 2 to 36.
  54. */
  55. int32_t radix;
  56. /**
  57. * The minimum number of digits. Typically 1, 4, or 8. Values
  58. * less than 1 are equivalent to 1.
  59. */
  60. int32_t minDigits;
  61. /**
  62. * If true, supplementals are handled as 32-bit code points. If
  63. * false, they are handled as two 16-bit code units.
  64. */
  65. UBool grokSupplementals;
  66. /**
  67. * The form to be used for supplementals. If this is null then
  68. * the same form is used for BMP characters and supplementals. If
  69. * this is not null and if grokSupplementals is true then the
  70. * prefix, suffix, radix, and minDigits of this object are used
  71. * for supplementals. This pointer is owned.
  72. */
  73. EscapeTransliterator* supplementalHandler;
  74. public:
  75. /**
  76. * Registers standard variants with the system. Called by
  77. * Transliterator during initialization.
  78. */
  79. static void registerIDs();
  80. /**
  81. * Constructs an escape transliterator with the given ID and
  82. * parameters. See the class member documentation for details.
  83. */
  84. EscapeTransliterator(const UnicodeString& ID,
  85. const UnicodeString& prefix, const UnicodeString& suffix,
  86. int32_t radix, int32_t minDigits,
  87. UBool grokSupplementals,
  88. EscapeTransliterator* adoptedSupplementalHandler);
  89. /**
  90. * Copy constructor.
  91. */
  92. EscapeTransliterator(const EscapeTransliterator&);
  93. /**
  94. * Destructor.
  95. */
  96. virtual ~EscapeTransliterator();
  97. /**
  98. * Transliterator API.
  99. */
  100. virtual EscapeTransliterator* clone() const;
  101. /**
  102. * ICU "poor man's RTTI", returns a UClassID for the actual class.
  103. */
  104. virtual UClassID getDynamicClassID() const;
  105. /**
  106. * ICU "poor man's RTTI", returns a UClassID for this class.
  107. */
  108. U_I18N_API static UClassID U_EXPORT2 getStaticClassID();
  109. protected:
  110. /**
  111. * Implements {@link Transliterator#handleTransliterate}.
  112. */
  113. virtual void handleTransliterate(Replaceable& text, UTransPosition& offset,
  114. UBool isIncremental) const;
  115. };
  116. U_NAMESPACE_END
  117. #endif /* #if !UCONFIG_NO_TRANSLITERATION */
  118. #endif