From 38108f064e46a832ef16558fe8458f47cc1c8cd7 Mon Sep 17 00:00:00 2001 From: rgaudin Date: Fri, 16 May 2014 01:19:27 +0000 Subject: [PATCH] moved loadICUExternalTables code to stringTools so it can be used by kiwix-serve --- src/common/kiwix/searcher.cpp | 11 +---------- src/common/stringTools.cpp | 17 ++++++++++++++++- src/common/stringTools.h | 3 +++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/common/kiwix/searcher.cpp b/src/common/kiwix/searcher.cpp index a9201f010..73d2c37a8 100644 --- a/src/common/kiwix/searcher.cpp +++ b/src/common/kiwix/searcher.cpp @@ -34,16 +34,7 @@ namespace kiwix { resultRange(20) { template_ct2 = getResourceAsString("results.ct2"); -#ifdef __APPLE__ - string executablePath = getExecutablePath(); - string executableDirectory = removeLastPathElement(executablePath); - string datPath = computeAbsolutePath(executableDirectory, "icudt49l.dat"); - try { - u_setDataDirectory(datPath.c_str()); - } catch (exception &e) { - std::cerr << e.what() << std::endl; - } -#endif + loadICUExternalTables(); } diff --git a/src/common/stringTools.cpp b/src/common/stringTools.cpp index a83f853ee..f66eaa18f 100644 --- a/src/common/stringTools.cpp +++ b/src/common/stringTools.cpp @@ -19,6 +19,20 @@ #include "stringTools.h" +/* tell ICU where to find its dat file (tables) */ +void kiwix::loadICUExternalTables() { +#ifdef __APPLE__ + std::string executablePath = getExecutablePath(); + std::string executableDirectory = removeLastPathElement(executablePath); + std::string datPath = computeAbsolutePath(executableDirectory, "icudt49l.dat"); + try { + u_setDataDirectory(datPath.c_str()); + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } +#endif +} + #ifndef __ANDROID__ /* Prepare integer for display */ @@ -37,6 +51,7 @@ std::string kiwix::beautifyInteger(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); @@ -179,7 +194,7 @@ std::string kiwix::ucFirst (const std::string &word) { UnicodeString unicodeWord(word.c_str()); UnicodeString unicodeFirstLetter = UnicodeString(unicodeWord, 0, 1).toUpper(); unicodeWord.replace(0, 1, unicodeFirstLetter); - unicodeWord.toUTF8String(result); + unicodeWord.toUTF8String(result); return result; } diff --git a/src/common/stringTools.h b/src/common/stringTools.h index ed4d8a42e..b197cf067 100644 --- a/src/common/stringTools.h +++ b/src/common/stringTools.h @@ -35,6 +35,8 @@ #include #include +#include + namespace kiwix { #ifndef __ANDROID__ @@ -48,6 +50,7 @@ namespace kiwix { #endif + void loadICUExternalTables(); std::string urlDecode(const std::string &c); std::vector split(const std::string&, const std::string&);