]>
git.saurik.com Git - apple/icu.git/blob - icuSources/samples/translit/unaccent.cpp
b16a5a40cab76d9d7abbfefb2cde05aa8faf4044
1 /**********************************************************************
2 * © 2016 and later: Unicode, Inc. and others.
3 * License & terms of use: http://www.unicode.org/copyright.html#License
4 **********************************************************************
5 **********************************************************************
7 * Copyright (c) 1999-2003, International Business Machines Corporation and
8 * others. All Rights Reserved.
9 **********************************************************************/
13 const char UnaccentTransliterator::fgClassID
= 0;
18 UnaccentTransliterator::UnaccentTransliterator() :
19 normalizer("", UNORM_NFD
),
20 Transliterator("Unaccent", 0) {
26 UnaccentTransliterator::~UnaccentTransliterator() {
30 * Remove accents from a character using Normalizer.
32 UChar
UnaccentTransliterator::unaccent(UChar c
) const {
34 UErrorCode status
= U_ZERO_ERROR
;
35 UnaccentTransliterator
* t
= (UnaccentTransliterator
*)this;
37 t
->normalizer
.setText(str
, status
);
38 if (U_FAILURE(status
)) {
41 return (UChar
) t
->normalizer
.next();
45 * Implement Transliterator API
47 void UnaccentTransliterator::handleTransliterate(Replaceable
& text
,
48 UTransPosition
& index
,
49 UBool incremental
) const {
50 UnicodeString
str("a");
51 while (index
.start
< index
.limit
) {
52 UChar c
= text
.charAt(index
.start
);
53 UChar d
= unaccent(c
);
56 text
.handleReplaceBetween(index
.start
, index
.start
+1, str
);