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