示例#1
0
StringPiece ltrimWhitespace(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.front() == ' '; sp.pop_front()) {
  }
  if (!sp.empty() && is_oddspace(sp.front())) {
    sp.pop_front();
    goto loop;
  }

  return sp;
}
示例#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;
}