Ejemplo n.º 1
0
StringPiece rtrimWhitespace(StringPiece sp) {
  // Spaces other than ' ' characters are less common but should be
  // checked.  This configuration where we loop on the ' '
  // separately from oddspaces was empirically fastest.

loop:
  for (; !sp.empty() && sp.back() == ' '; sp.pop_back()) {
  }
  if (!sp.empty() && is_oddspace(sp.back())) {
    sp.pop_back();
    goto loop;
  }

  return sp;
}
Ejemplo n.º 2
0
StringPiece trim(StringPiece sp, StringPiece chars) {
  for (; !sp.empty() && chars.find(sp.front()) != StringPiece::npos; ) {
    sp.pop_front();
  }
  for (; !sp.empty() && chars.find(sp.back()) != StringPiece::npos; ) {
    sp.pop_back();
  }
  return sp;
}