]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/translit/answers/unaccent.cpp
1 /***********************************************************************
2 * © 2016 and later: Unicode, Inc. and others.
3 * License & terms of use: http://www.unicode.org/copyright.html#License
4 ***********************************************************************
6 * Copyright (c) 1999-2002, International Business Machines Corporation and
7 * others. All Rights Reserved.
8 ***********************************************************************/
15 UnaccentTransliterator::UnaccentTransliterator() :
16 normalizer("", Normalizer::DECOMP
),
17 Transliterator("Unaccent", 0) {
23 UnaccentTransliterator::~UnaccentTransliterator() {
27 * Remove accents from a character using Normalizer.
29 UChar
UnaccentTransliterator::unaccent(UChar c
) const {
31 UErrorCode status
= U_ZERO_ERROR
;
32 UnaccentTransliterator
* t
= (UnaccentTransliterator
*)this;
34 t
->normalizer
.setText(str
, status
);
35 if (U_FAILURE(status
)) {
38 return (UChar
) t
->normalizer
.next();
42 * Implement Transliterator API
44 void UnaccentTransliterator::handleTransliterate(Replaceable
& text
,
45 UTransPosition
& index
,
46 UBool incremental
) const {
47 UnicodeString
str("a");
48 while (index
.start
< index
.limit
) {
49 UChar c
= text
.charAt(index
.start
);
50 UChar d
= unaccent(c
);
53 text
.handleReplaceBetween(index
.start
, index
.start
+1, str
);