FIXED: Kiwix-serve sporadic invisible search box with non-latin contents

This commit is contained in:
kelson42 2012-02-27 17:57:26 +00:00
parent 8f89edf17c
commit b17f6a6d01
1 changed files with 5 additions and 2 deletions

View File

@ -18,7 +18,6 @@
*/ */
#include "regexTools.h" #include "regexTools.h"
#include <iostream>
std::map<std::string, RegexMatcher*> regexCache; std::map<std::string, RegexMatcher*> regexCache;
@ -57,12 +56,16 @@ bool matchRegex(const std::string &content, const std::string &regex) {
void appendToFirstOccurence(std::string &content, const std::string regex, const std::string &replacement) { void appendToFirstOccurence(std::string &content, const std::string regex, const std::string &replacement) {
ucnv_setDefaultName("UTF-8"); ucnv_setDefaultName("UTF-8");
UnicodeString ucontent = UnicodeString(content.c_str()); UnicodeString ucontent = UnicodeString(content.c_str());
UnicodeString ureplacement = UnicodeString(replacement.c_str());
RegexMatcher *matcher = buildRegex(regex); RegexMatcher *matcher = buildRegex(regex);
matcher->reset(ucontent); matcher->reset(ucontent);
if (matcher->find()) { if (matcher->find()) {
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
content.insert(matcher->end(status), replacement); ucontent.insert(matcher->end(status), ureplacement);
std::string tmp;
ucontent.toUTF8String(tmp);
content=tmp;
} }
} }