unaccent.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /***********************************************************************
  2. * © 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. #include "unicode/translit.h"
  11. #include "unicode/normlzr.h"
  12. using namespace icu;
  13. class UnaccentTransliterator : public Transliterator {
  14. public:
  15. /**
  16. * Constructor
  17. */
  18. UnaccentTransliterator();
  19. /**
  20. * Destructor
  21. */
  22. virtual ~UnaccentTransliterator();
  23. protected:
  24. /**
  25. * Implement Transliterator API
  26. */
  27. virtual void handleTransliterate(Replaceable& text,
  28. UTransPosition& index,
  29. UBool incremental) const;
  30. private:
  31. /**
  32. * Unaccent a single character using normalizer.
  33. */
  34. UChar unaccent(UChar c) const;
  35. Normalizer normalizer;
  36. public:
  37. /**
  38. * Return the class ID for this class. This is useful only for
  39. * comparing to a return value from getDynamicClassID(). For example:
  40. * <pre>
  41. * . Base* polymorphic_pointer = createPolymorphicObject();
  42. * . if (polymorphic_pointer->getDynamicClassID() ==
  43. * . Derived::getStaticClassID()) ...
  44. * </pre>
  45. * @return The class ID for all objects of this class.
  46. * @stable ICU 2.0
  47. */
  48. static inline UClassID getStaticClassID(void) { return (UClassID)&fgClassID; };
  49. /**
  50. * Returns a unique class ID <b>polymorphically</b>. This method
  51. * is to implement a simple version of RTTI, since not all C++
  52. * compilers support genuine RTTI. Polymorphic operator==() and
  53. * clone() methods call this method.
  54. *
  55. * <p>Concrete subclasses of Transliterator that wish clients to
  56. * be able to identify them should implement getDynamicClassID()
  57. * and also a static method and data member:
  58. *
  59. * <pre>
  60. * static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
  61. * static char fgClassID;
  62. * </pre>
  63. *
  64. * Subclasses that do not implement this method will have a
  65. * dynamic class ID of Transliterator::getStatisClassID().
  66. *
  67. * @return The class ID for this object. All objects of a given
  68. * class have the same class ID. Objects of other classes have
  69. * different class IDs.
  70. * @stable ICU 2.0
  71. */
  72. virtual UClassID getDynamicClassID(void) const { return getStaticClassID(); };
  73. private:
  74. /**
  75. * Class identifier for subclasses of Transliterator that do not
  76. * define their class (anonymous subclasses).
  77. */
  78. static const char fgClassID;
  79. };