Example #1
0
void base::split_string(const base::string& string,
                        std::vector<base::string>& parts,
                        const base::string& separators)
{
  size_t elements = 1 + std::count_if(string.begin(), string.end(), is_separator(&separators));
  parts.reserve(elements);

  size_t beg = 0, end;
  while (true) {
    end = string.find_first_of(separators, beg);
    if (end != base::string::npos) {
      parts.push_back(string.substr(beg, end - beg));
      beg = end+1;
    }
    else {
      parts.push_back(string.substr(beg));
      break;
    }
  }
}
Example #2
0
void base::trim_string(const base::string& input, base::string& output)
{
  int i, j;

  for (i=0; i<(int)input.size(); ++i)
    if (!std::isspace(input.at(i)))
      break;

  for (j=(int)input.size()-1; j>i; --j)
    if (!std::isspace(input.at(j)))
      break;

  if (i < j)
    output = input.substr(i, j - i + 1);
  else
    output = "";
}