]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/translit/unaccent.cpp
1 /********************************************************************
3 * Copyright (c) 1999-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
9 const char UnaccentTransliterator::fgClassID
= 0;
14 UnaccentTransliterator::UnaccentTransliterator() :
15 normalizer("", UNORM_NFD
),
16 Transliterator("Unaccent", 0) {
22 UnaccentTransliterator::~UnaccentTransliterator() {
26 * Remove accents from a character using Normalizer.
28 UChar
UnaccentTransliterator::unaccent(UChar c
) const {
30 UErrorCode status
= U_ZERO_ERROR
;
31 UnaccentTransliterator
* t
= (UnaccentTransliterator
*)this;
33 t
->normalizer
.setText(str
, status
);
34 if (U_FAILURE(status
)) {
37 return (UChar
) t
->normalizer
.next();
41 * Implement Transliterator API
43 void UnaccentTransliterator::handleTransliterate(Replaceable
& text
,
44 UTransPosition
& index
,
45 UBool incremental
) const {
46 UnicodeString
str("a");
47 while (index
.start
< index
.limit
) {
48 UChar c
= text
.charAt(index
.start
);
49 UChar d
= unaccent(c
);
52 text
.handleReplaceBetween(index
.start
, index
.start
+1, str
);