Add kiwix::removeAccents for Android

This commit is contained in:
Kelson 2016-10-14 16:59:32 +02:00
parent 2889d7c651
commit 75da598ba8
2 changed files with 14 additions and 14 deletions

View File

@ -33,6 +33,19 @@ void kiwix::loadICUExternalTables() {
#endif
}
std::string kiwix::removeAccents(const std::string &text) {
loadICUExternalTables();
ucnv_setDefaultName("UTF-8");
UErrorCode status = U_ZERO_ERROR;
Transliterator *removeAccentsTrans = Transliterator::createInstance("Lower; NFD; [:M:] remove; NFC", UTRANS_FORWARD, status);
UnicodeString ustring = UnicodeString(text.c_str());
removeAccentsTrans->transliterate(ustring);
delete removeAccentsTrans;
std::string unaccentedText;
ustring.toUTF8String(unaccentedText);
return unaccentedText;
}
#ifndef __ANDROID__
/* Prepare integer for display */
@ -59,19 +72,6 @@ std::string kiwix::beautifyFileSize(const unsigned int number) {
}
}
std::string kiwix::removeAccents(const std::string &text) {
loadICUExternalTables();
ucnv_setDefaultName("UTF-8");
UErrorCode status = U_ZERO_ERROR;
Transliterator *removeAccentsTrans = Transliterator::createInstance("Lower; NFD; [:M:] remove; NFC", UTRANS_FORWARD, status);
UnicodeString ustring = UnicodeString(text.c_str());
removeAccentsTrans->transliterate(ustring);
delete removeAccentsTrans;
std::string unaccentedText;
ustring.toUTF8String(unaccentedText);
return unaccentedText;
}
void kiwix::printStringInHexadecimal(UnicodeString s) {
std::cout << std::showbase << std::hex;
for (int i=0; i<s.length(); i++) {

View File

@ -40,7 +40,6 @@ namespace kiwix {
#ifndef __ANDROID__
std::string removeAccents(const std::string &text);
std::string beautifyInteger(const unsigned int number);
std::string beautifyFileSize(const unsigned int number);
std::string urlEncode(const std::string &c);
@ -51,6 +50,7 @@ namespace kiwix {
#endif
std::string removeAccents(const std::string &text);
void loadICUExternalTables();
std::string urlDecode(const std::string &c);