MCPcopy Create free account
hub / github.com/apache/impala / TrimRunsInString

Function TrimRunsInString

be/src/gutil/strings/strip.cc:355–376  ·  view source on GitHub ↗

---------------------------------------------------------------------- TrimRunsInString Removes leading and trailing runs, and collapses middle runs of a set of characters into a single character (the first one specified in 'remove'). Useful for collapsing runs of repeated delimiters, whitespace, etc. E.g., TrimRunsInString(&s, " :,()") removes leading and trailing delimiter chars and collapses

Source from the content-addressed store, hash-verified

353// "first,last::(area)phone, ::zip" -> "first last area phone zip"
354// ----------------------------------------------------------------------
355void TrimRunsInString(string* s, StringPiece remove) {
356 string::iterator dest = s->begin();
357 string::iterator src_end = s->end();
358 for (string::iterator src = s->begin(); src != src_end; ) {
359 if (remove.find(*src) == StringPiece::npos) {
360 *(dest++) = *(src++);
361 } else {
362 // Skip to the end of this run of chars that are in 'remove'.
363 for (++src; src != src_end; ++src) {
364 if (remove.find(*src) == StringPiece::npos) {
365 if (dest != s->begin()) {
366 // This is an internal run; collapse it.
367 *(dest++) = remove[0];
368 }
369 *(dest++) = *(src++);
370 break;
371 }
372 }
373 }
374 }
375 s->erase(dest, src_end);
376}
377
378// ----------------------------------------------------------------------
379// RemoveNullsInString

Callers

nothing calls this directly

Calls 4

eraseMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected