Go to the documentation of this file.00001
00013 #include "split.h"
00014
00015 using namespace std;
00016
00017
00018 size_t qrk::split(std::vector<std::string>& tokens,
00019 const std::string& line, const char* split_pattern,
00020 bool continious_pattern)
00021 {
00022 string buffer = line;
00023 char* q = &buffer[0];
00024 size_t n = line.size();
00025 for (size_t i = 0; i < n; ++i, ++q) {
00026 for (const char* p = split_pattern; *p != '\0'; ++p) {
00027 if (*q == *p) {
00028 *q = '\0';
00029 break;
00030 }
00031 }
00032 }
00033
00034 for (size_t i = 0; i < n; ++i) {
00035 if ((buffer[i] != '\0') || (! continious_pattern)) {
00036 string line = &buffer[i];
00037 tokens.push_back(line);
00038 i += line.size();
00039 }
00040 }
00041 return tokens.size();
00042 }