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