From 5d8593805f8da696f80a6803770c5c633cc60885 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 5 Aug 2013 13:11:35 +0800 Subject: [PATCH] + fixes for Android --- src/common/stringTools.cpp | 60 +++++++++++++++++--------------------- src/common/stringTools.h | 16 +++++----- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/src/common/stringTools.cpp b/src/common/stringTools.cpp index 8e865d108..cdc07c281 100644 --- a/src/common/stringTools.cpp +++ b/src/common/stringTools.cpp @@ -48,30 +48,6 @@ std::string kiwix::removeAccents(const std::string &text) { return unaccentedText; } -std::string kiwix::ucFirst (const std::string &word) { - if (word.empty()) - return ""; - - std::string ucFirstWord; - UnicodeString firstLetter = UnicodeString(word.substr(0, 1).c_str()); - UnicodeString ucFirstLetter = firstLetter.toUpper(); - ucFirstLetter.toUTF8String(ucFirstWord); - ucFirstWord += word.substr(1); - return ucFirstWord; -} - -std::string kiwix::lcFirst (const std::string &word) { - if (word.empty()) - return ""; - - std::string ucFirstWord; - UnicodeString firstLetter = UnicodeString(word.substr(0, 1).c_str()); - UnicodeString ucFirstLetter = firstLetter.toLower(); - ucFirstLetter.toUTF8String(ucFirstWord); - ucFirstWord += word.substr(1); - return ucFirstWord; -} - void kiwix::printStringInHexadecimal(UnicodeString s) { std::cout << std::showbase << std::hex; for (int i=0; i kiwix::split(const std::string & str, @@ -198,20 +174,36 @@ std::string kiwix::ucFirst (const std::string &word) { if (word.empty()) return ""; - std::string new_string = word; - new_string[0] = toupper(new_string[0]); + std::string ucFirstWord; - return new_string; +#ifdef __ANDROID__ + ucFirstWord = word; + ucFirstWord[0] = toupper(ucFirstWord[0]); +#else + UnicodeString firstLetter = UnicodeString(word.substr(0, 1).c_str()); + UnicodeString ucFirstLetter = firstLetter.toUpper(); + ucFirstLetter.toUTF8String(ucFirstWord); + ucFirstWord += word.substr(1); +#endif + + return ucFirstWord; } std::string kiwix::lcFirst (const std::string &word) { if (word.empty()) return ""; - std::string new_string = word; - new_string[0] = tolower(new_string[0]); - - return new_string; -} + std::string ucFirstWord; +#ifdef __ANDROID__ + ucFirstWord = word; + ucFirstWord[0] = tolower(ucFirstWord[0]); +#else + UnicodeString firstLetter = UnicodeString(word.substr(0, 1).c_str()); + UnicodeString ucFirstLetter = firstLetter.toLower(); + ucFirstLetter.toUTF8String(ucFirstWord); + ucFirstWord += word.substr(1); #endif + + return ucFirstWord; +} diff --git a/src/common/stringTools.h b/src/common/stringTools.h index f14fb5bf1..47cbc6f9e 100644 --- a/src/common/stringTools.h +++ b/src/common/stringTools.h @@ -29,7 +29,7 @@ #include #include #include - #endif +#endif #include #include @@ -38,12 +38,17 @@ #include namespace kiwix { + #ifndef __ANDROID__ + std::string removeAccents(const std::string &text); std::string beautifyInteger(const unsigned int number); - + std::string urlEncode(const std::string &c); + std::string urlDecode(const std::string &c); void printStringInHexadecimal(const char *s); void printStringInHexadecimal(UnicodeString s); + void stringReplacement(std::string& str, const std::string& oldStr, const std::string& newStr); + #endif std::vector split(const std::string&, const std::string&); @@ -53,13 +58,6 @@ namespace kiwix { std::string ucFirst(const std::string &word); std::string lcFirst(const std::string &word); - -#ifndef __ANDROID__ - void stringReplacement(std::string& str, const std::string& oldStr, const std::string& newStr); - - std::string urlEncode(const std::string &c); - std::string urlDecode(const std::string &c); -#endif } #endif