Home | History | Annotate | Download | only in translit
      1 /***********************************************************************
      2  * Copyright (C) 2016 and later: Unicode, Inc. and others.
      3  * License & terms of use: http://www.unicode.org/copyright.html#License
      4  ***********************************************************************
      5  ***********************************************************************
      6  * COPYRIGHT:
      7  * Copyright (c) 1999-2003, International Business Machines Corporation and
      8  * others. All Rights Reserved.
      9  ***********************************************************************/
     10 
     11 #include "unicode/translit.h"
     12 #include "unicode/normlzr.h"
     13 
     14 class UnaccentTransliterator : public Transliterator {
     15 
     16  public:
     17 
     18     /**
     19      * Constructor
     20      */
     21     UnaccentTransliterator();
     22 
     23     /**
     24      * Destructor
     25      */
     26     virtual ~UnaccentTransliterator();
     27 
     28  protected:
     29 
     30     /**
     31      * Implement Transliterator API
     32      */
     33     virtual void handleTransliterate(Replaceable& text,
     34                                      UTransPosition& index,
     35                                      UBool incremental) const;
     36 
     37  private:
     38 
     39     /**
     40      * Unaccent a single character using normalizer.
     41      */
     42     UChar unaccent(UChar c) const;
     43 
     44     Normalizer normalizer;
     45 
     46 public:
     47 
     48     /**
     49      * Return the class ID for this class.  This is useful only for
     50      * comparing to a return value from getDynamicClassID().  For example:
     51      * <pre>
     52      * .      Base* polymorphic_pointer = createPolymorphicObject();
     53      * .      if (polymorphic_pointer->getDynamicClassID() ==
     54      * .          Derived::getStaticClassID()) ...
     55      * </pre>
     56      * @return          The class ID for all objects of this class.
     57      * @stable ICU 2.0
     58      */
     59     static inline UClassID getStaticClassID(void) { return (UClassID)&fgClassID; };
     60 
     61     /**
     62      * Returns a unique class ID <b>polymorphically</b>.  This method
     63      * is to implement a simple version of RTTI, since not all C++
     64      * compilers support genuine RTTI.  Polymorphic operator==() and
     65      * clone() methods call this method.
     66      *
     67      * <p>Concrete subclasses of Transliterator that wish clients to
     68      * be able to identify them should implement getDynamicClassID()
     69      * and also a static method and data member:
     70      *
     71      * <pre>
     72      * static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
     73      * static char fgClassID;
     74      * </pre>
     75      *
     76      * Subclasses that do not implement this method will have a
     77      * dynamic class ID of Transliterator::getStatisClassID().
     78      *
     79      * @return The class ID for this object. All objects of a given
     80      * class have the same class ID.  Objects of other classes have
     81      * different class IDs.
     82      * @stable ICU 2.0
     83      */
     84     virtual UClassID getDynamicClassID(void) const { return getStaticClassID(); };
     85 
     86 private:
     87 
     88     /**
     89      * Class identifier for subclasses of Transliterator that do not
     90      * define their class (anonymous subclasses).
     91      */
     92     static const char fgClassID;
     93 };
     94