From 739782259fb31d1b56fa6a688857a21566374e1a Mon Sep 17 00:00:00 2001 From: Luo Jinghua Date: Sat, 19 Nov 2011 20:36:51 +0800 Subject: SexyAppFramework: Added Split() to Common --- osframework/source/SexyAppFramework/Common.cpp | 21 +++++++++++++++++++++ osframework/source/SexyAppFramework/Common.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/osframework/source/SexyAppFramework/Common.cpp b/osframework/source/SexyAppFramework/Common.cpp index fd11918..7947763 100644 --- a/osframework/source/SexyAppFramework/Common.cpp +++ b/osframework/source/SexyAppFramework/Common.cpp @@ -1377,3 +1377,24 @@ int Sexy::GetEnvIntOption(const char *option, int value) return atoi(s); return value; } + +/////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +void Sexy::Split(const std::string& s, const std::string& delim, + std::vector& ret) +{ + size_t last = 0; + size_t index = s.find_first_of(delim, last); + + while (index != std::string::npos) + { + ret.push_back(s.substr(last, index - last)); + last = index + 1; + index = s.find_first_of(delim, last); + } + if (index - last > 0) + { + ret.push_back(s.substr(last, index-last)); + } +} + diff --git a/osframework/source/SexyAppFramework/Common.h b/osframework/source/SexyAppFramework/Common.h index ed4cd35..96b974c 100644 --- a/osframework/source/SexyAppFramework/Common.h +++ b/osframework/source/SexyAppFramework/Common.h @@ -198,6 +198,8 @@ namespace Sexy const char* GetEnv(const char* name); bool GetEnvOption(const char *option, bool value = false); int GetEnvIntOption(const char *option, int value = 0); + void Split(const std::string& s, const std::string& delim, + std::vector& ret); inline void inlineUpper(std::string &theData) { -- cgit v1.2.3