Exemplo n.º 1
0
static base::string remove_backslash_if_needed(const base::string& filename)
{
  if (!filename.empty() && base::is_path_separator(*(filename.end()-1))) {
    int len = filename.size();
#ifdef HAVE_DRIVES
    // if the name is C:\ or something like that, the backslash isn't
    // removed
    if (len == 3 && filename[1] == ':')
      return filename;
#else
    // this is just the root '/' slash
    if (len == 1)
      return filename;
#endif
    return base::remove_path_separator(filename);
  }
  return filename;
}
Exemplo n.º 2
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;
    }
  }
}