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 UNESCTRN_H 13*0e209d39SAndroid Build Coastguard Worker #define UNESCTRN_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 escape forms to the 25*0e209d39SAndroid Build Coastguard Worker * characters they represent. Escape forms have a prefix, a suffix, a 26*0e209d39SAndroid Build Coastguard Worker * radix, and minimum and maximum digit counts. 27*0e209d39SAndroid Build Coastguard Worker * 28*0e209d39SAndroid Build Coastguard Worker * <p>This class is package private. It registers several standard 29*0e209d39SAndroid Build Coastguard Worker * variants with the system which are then accessed via their IDs. 30*0e209d39SAndroid Build Coastguard Worker * 31*0e209d39SAndroid Build Coastguard Worker * @author Alan Liu 32*0e209d39SAndroid Build Coastguard Worker */ 33*0e209d39SAndroid Build Coastguard Worker class UnescapeTransliterator : public Transliterator { 34*0e209d39SAndroid Build Coastguard Worker 35*0e209d39SAndroid Build Coastguard Worker private: 36*0e209d39SAndroid Build Coastguard Worker 37*0e209d39SAndroid Build Coastguard Worker /** 38*0e209d39SAndroid Build Coastguard Worker * The encoded pattern specification. The pattern consists of 39*0e209d39SAndroid Build Coastguard Worker * zero or more forms. Each form consists of a prefix, suffix, 40*0e209d39SAndroid Build Coastguard Worker * radix, minimum digit count, and maximum digit count. These 41*0e209d39SAndroid Build Coastguard Worker * values are stored as a five character header. That is, their 42*0e209d39SAndroid Build Coastguard Worker * numeric values are cast to 16-bit characters and stored in the 43*0e209d39SAndroid Build Coastguard Worker * string. Following these five characters, the prefix 44*0e209d39SAndroid Build Coastguard Worker * characters, then suffix characters are stored. Each form thus 45*0e209d39SAndroid Build Coastguard Worker * takes n+5 characters, where n is the total length of the prefix 46*0e209d39SAndroid Build Coastguard Worker * and suffix. The end is marked by a header of length one 47*0e209d39SAndroid Build Coastguard Worker * consisting of the character END. 48*0e209d39SAndroid Build Coastguard Worker */ 49*0e209d39SAndroid Build Coastguard Worker char16_t* spec; // owned; may not be nullptr 50*0e209d39SAndroid Build Coastguard Worker 51*0e209d39SAndroid Build Coastguard Worker public: 52*0e209d39SAndroid Build Coastguard Worker 53*0e209d39SAndroid Build Coastguard Worker /** 54*0e209d39SAndroid Build Coastguard Worker * Registers standard variants with the system. Called by 55*0e209d39SAndroid Build Coastguard Worker * Transliterator during initialization. 56*0e209d39SAndroid Build Coastguard Worker */ 57*0e209d39SAndroid Build Coastguard Worker static void registerIDs(); 58*0e209d39SAndroid Build Coastguard Worker 59*0e209d39SAndroid Build Coastguard Worker /** 60*0e209d39SAndroid Build Coastguard Worker * Constructor. Takes the encoded spec array (does not adopt it). 61*0e209d39SAndroid Build Coastguard Worker * @param ID the string identifier for this transliterator 62*0e209d39SAndroid Build Coastguard Worker * @param spec the encoded spec array 63*0e209d39SAndroid Build Coastguard Worker */ 64*0e209d39SAndroid Build Coastguard Worker UnescapeTransliterator(const UnicodeString& ID, 65*0e209d39SAndroid Build Coastguard Worker const char16_t *spec); 66*0e209d39SAndroid Build Coastguard Worker 67*0e209d39SAndroid Build Coastguard Worker /** 68*0e209d39SAndroid Build Coastguard Worker * Copy constructor. 69*0e209d39SAndroid Build Coastguard Worker */ 70*0e209d39SAndroid Build Coastguard Worker UnescapeTransliterator(const UnescapeTransliterator&); 71*0e209d39SAndroid Build Coastguard Worker 72*0e209d39SAndroid Build Coastguard Worker /** 73*0e209d39SAndroid Build Coastguard Worker * Destructor. 74*0e209d39SAndroid Build Coastguard Worker */ 75*0e209d39SAndroid Build Coastguard Worker virtual ~UnescapeTransliterator(); 76*0e209d39SAndroid Build Coastguard Worker 77*0e209d39SAndroid Build Coastguard Worker /** 78*0e209d39SAndroid Build Coastguard Worker * Transliterator API. 79*0e209d39SAndroid Build Coastguard Worker */ 80*0e209d39SAndroid Build Coastguard Worker virtual UnescapeTransliterator* clone() const override; 81*0e209d39SAndroid Build Coastguard Worker 82*0e209d39SAndroid Build Coastguard Worker /** 83*0e209d39SAndroid Build Coastguard Worker * ICU "poor man's RTTI", returns a UClassID for the actual class. 84*0e209d39SAndroid Build Coastguard Worker */ 85*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const override; 86*0e209d39SAndroid Build Coastguard Worker 87*0e209d39SAndroid Build Coastguard Worker /** 88*0e209d39SAndroid Build Coastguard Worker * ICU "poor man's RTTI", returns a UClassID for this class. 89*0e209d39SAndroid Build Coastguard Worker */ 90*0e209d39SAndroid Build Coastguard Worker U_I18N_API static UClassID U_EXPORT2 getStaticClassID(); 91*0e209d39SAndroid Build Coastguard Worker 92*0e209d39SAndroid Build Coastguard Worker protected: 93*0e209d39SAndroid Build Coastguard Worker 94*0e209d39SAndroid Build Coastguard Worker /** 95*0e209d39SAndroid Build Coastguard Worker * Implements {@link Transliterator#handleTransliterate}. 96*0e209d39SAndroid Build Coastguard Worker * @param text the buffer holding transliterated and 97*0e209d39SAndroid Build Coastguard Worker * untransliterated text 98*0e209d39SAndroid Build Coastguard Worker * @param offset the start and limit of the text, the position 99*0e209d39SAndroid Build Coastguard Worker * of the cursor, and the start and limit of transliteration. 100*0e209d39SAndroid Build Coastguard Worker * @param incremental if true, assume more text may be coming after 101*0e209d39SAndroid Build Coastguard Worker * pos.contextLimit. Otherwise, assume the text is complete. 102*0e209d39SAndroid Build Coastguard Worker */ 103*0e209d39SAndroid Build Coastguard Worker virtual void handleTransliterate(Replaceable& text, UTransPosition& offset, 104*0e209d39SAndroid Build Coastguard Worker UBool isIncremental) const override; 105*0e209d39SAndroid Build Coastguard Worker 106*0e209d39SAndroid Build Coastguard Worker }; 107*0e209d39SAndroid Build Coastguard Worker 108*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 109*0e209d39SAndroid Build Coastguard Worker 110*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_TRANSLITERATION */ 111*0e209d39SAndroid Build Coastguard Worker 112*0e209d39SAndroid Build Coastguard Worker #endif 113