From 2a13f2a1776f20e77586f906e3860d7877012ae5 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 5 Aug 2013 11:38:27 +0800 Subject: [PATCH] + add kiwix string split() functions in android builds --- src/common/stringTools.cpp | 64 +++++++++++++++++++------------------- src/common/stringTools.h | 9 +++--- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/common/stringTools.cpp b/src/common/stringTools.cpp index e5755392b..8e865d108 100644 --- a/src/common/stringTools.cpp +++ b/src/common/stringTools.cpp @@ -36,37 +36,6 @@ std::string kiwix::beautifyInteger(const unsigned int number) { return numberString; } -/* Split string in a token array */ -std::vector kiwix::split(const std::string & str, - const std::string & delims=" *-") -{ - std::string::size_type lastPos = str.find_first_not_of(delims, 0); - std::string::size_type pos = str.find_first_of(delims, lastPos); - std::vector tokens; - - while (std::string::npos != pos || std::string::npos != lastPos) - { - tokens.push_back(str.substr(lastPos, pos - lastPos)); - lastPos = str.find_first_not_of(delims, pos); - pos = str.find_first_of(delims, lastPos); - } - - return tokens; -} - -std::vector kiwix::split(const char* lhs, const char* rhs){ - const std::string m1 (lhs), m2 (rhs); - return split(m1, m2); -} - -std::vector kiwix::split(const char* lhs, const std::string& rhs){ - return split(lhs, rhs.c_str()); -} - -std::vector kiwix::split(const std::string& lhs, const char* rhs){ - return split(lhs.c_str(), rhs); -} - std::string kiwix::removeAccents(const std::string &text) { ucnv_setDefaultName("UTF-8"); UErrorCode status = U_ZERO_ERROR; @@ -194,6 +163,37 @@ std::string kiwix::urlDecode(const std::string &SRC) { #else +/* Split string in a token array */ +std::vector kiwix::split(const std::string & str, + const std::string & delims=" *-") +{ + std::string::size_type lastPos = str.find_first_not_of(delims, 0); + std::string::size_type pos = str.find_first_of(delims, lastPos); + std::vector tokens; + + while (std::string::npos != pos || std::string::npos != lastPos) + { + tokens.push_back(str.substr(lastPos, pos - lastPos)); + lastPos = str.find_first_not_of(delims, pos); + pos = str.find_first_of(delims, lastPos); + } + + return tokens; +} + +std::vector kiwix::split(const char* lhs, const char* rhs){ + const std::string m1 (lhs), m2 (rhs); + return split(m1, m2); +} + +std::vector kiwix::split(const char* lhs, const std::string& rhs){ + return split(lhs, rhs.c_str()); +} + +std::vector kiwix::split(const std::string& lhs, const char* rhs){ + return split(lhs.c_str(), rhs); +} + std::string kiwix::ucFirst (const std::string &word) { if (word.empty()) return ""; @@ -214,4 +214,4 @@ std::string kiwix::lcFirst (const std::string &word) { return new_string; } -#endif \ No newline at end of file +#endif diff --git a/src/common/stringTools.h b/src/common/stringTools.h index 532eaba74..f14fb5bf1 100644 --- a/src/common/stringTools.h +++ b/src/common/stringTools.h @@ -41,15 +41,16 @@ namespace kiwix { #ifndef __ANDROID__ std::string removeAccents(const std::string &text); std::string beautifyInteger(const unsigned int number); - std::vector split(const std::string&, const std::string&); - std::vector split(const char*, const char*); - std::vector split(const std::string&, const char*); - std::vector split(const char*, const std::string&); void printStringInHexadecimal(const char *s); void printStringInHexadecimal(UnicodeString s); #endif + std::vector split(const std::string&, const std::string&); + std::vector split(const char*, const char*); + std::vector split(const std::string&, const char*); + std::vector split(const char*, const std::string&); + std::string ucFirst(const std::string &word); std::string lcFirst(const std::string &word);