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