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