| @@ -74,7 +74,7 @@ Examples: | |||||
| split("abc", "+") // {"abc"} | split("abc", "+") // {"abc"} | ||||
| split("a++c", "+") // {"a", "", "c"} | split("a++c", "+") // {"a", "", "c"} | ||||
| split("", "+") // {} | split("", "+") // {} | ||||
| split("abc", "") // {"a", "b", "c"} | |||||
| split("abc", "") // throws rack::Exception | |||||
| */ | */ | ||||
| std::vector<std::string> split(const std::string& s, const std::string& seperator); | std::vector<std::string> split(const std::string& s, const std::string& seperator); | ||||
| @@ -206,20 +206,13 @@ bool CaseInsensitiveCompare::operator()(const std::string& a, const std::string& | |||||
| std::vector<std::string> split(const std::string& s, const std::string& separator) { | std::vector<std::string> split(const std::string& s, const std::string& separator) { | ||||
| if (separator.empty()) | |||||
| throw Exception("split(): separator cannot be empty string"); | |||||
| // Special case of empty string | // Special case of empty string | ||||
| if (s == "") | if (s == "") | ||||
| return {}; | return {}; | ||||
| std::vector<std::string> v; | std::vector<std::string> v; | ||||
| // Special case of empty separator | |||||
| if (separator == "") { | |||||
| for (char c : s) { | |||||
| std::string token(1, c); | |||||
| v.push_back(token); | |||||
| } | |||||
| return v; | |||||
| } | |||||
| size_t sepLen = separator.size(); | size_t sepLen = separator.size(); | ||||
| size_t start = 0; | size_t start = 0; | ||||
| size_t end; | size_t end; | ||||