diff --git a/src/common/kiwix/searcher.cpp b/src/common/kiwix/searcher.cpp index 8bc300fc3..624101fb2 100644 --- a/src/common/kiwix/searcher.cpp +++ b/src/common/kiwix/searcher.cpp @@ -47,7 +47,8 @@ namespace kiwix { this->resultCountPerPage = resultEnd - resultStart; this->resultStart = resultStart; this->resultEnd = resultEnd; - searchInIndex(removeAccents(search), resultStart, resultEnd, verbose); + string unaccentedSearch = removeAccents(search); + searchInIndex(unaccentedSearch, resultStart, resultEnd, verbose); this->resultOffset = this->results.begin(); return; diff --git a/src/common/unaccent.cpp b/src/common/unaccent.cpp index aca183a70..0e7f865d7 100644 --- a/src/common/unaccent.cpp +++ b/src/common/unaccent.cpp @@ -22,13 +22,13 @@ UErrorCode status = U_ZERO_ERROR; Transliterator *trans = Transliterator::createInstance("Lower; NFD; [:M:] remove; NFC", UTRANS_FORWARD, status); -std::string &removeAccents(std::string &text) { +std::string removeAccents(const std::string &text) { ucnv_setDefaultName("UTF-8"); UnicodeString ustring = UnicodeString(text.c_str()); trans->transliterate(ustring); - text.clear(); - ustring.toUTF8String(text); - return text; + std::string unaccentedText; + ustring.toUTF8String(unaccentedText); + return unaccentedText; } void printStringInHexadecimal(UnicodeString s) { diff --git a/src/common/unaccent.h b/src/common/unaccent.h index 85e63d374..ae07b44ba 100644 --- a/src/common/unaccent.h +++ b/src/common/unaccent.h @@ -32,7 +32,7 @@ #include #include -std::string &removeAccents(std::string &text); +std::string removeAccents(const std::string &text); void printStringInHexadecimal(const char *s); void printStringInHexadecimal(UnicodeString s);