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; }
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; }