From: Amos Jeffries Date: Wed, 19 Sep 2012 10:35:16 +0000 (+1200) Subject: Extend MemBuf to trim whitespace X-Git-Tag: SQUID_3_4_0_1~471^2~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1177ec50a8c9e68a7e3a9b39e1990d10f9564f70;p=thirdparty%2Fsquid.git Extend MemBuf to trim whitespace --- diff --git a/src/MemBuf.cc b/src/MemBuf.cc index c38693e531..682d904eec 100644 --- a/src/MemBuf.cc +++ b/src/MemBuf.cc @@ -220,6 +220,18 @@ void MemBuf::consume(mb_size_t shiftSize) PROF_stop(MemBuf_consume); } +/// removes all whitespace prefix bytes and "packs" by moving content left +void MemBuf::consumeWhitespace() +{ + PROF_start(MemBuf_consumeWhitespace); + const char *end = buf + contentSize(); + const char *p = buf; + for(; p<=end && xisspace(*p); ++p); + if (p-buf > 0) + consume(p-buf); + PROF_stop(MemBuf_consumeWhitespace); +} + // removes last tailSize bytes void MemBuf::truncate(mb_size_t tailSize) { diff --git a/src/MemBuf.h b/src/MemBuf.h index 3c5f225d46..408c44506d 100644 --- a/src/MemBuf.h +++ b/src/MemBuf.h @@ -81,6 +81,8 @@ public: /// \note there is currently no stretch() method to grow without appending void consume(mb_size_t sz); // removes sz bytes, moving content left + void consumeWhitespace(); // removes all prefix whitespace, moving content left + void append(const char *c, mb_size_t sz); // grows if needed and possible void appended(mb_size_t sz); // updates content size after external append void truncate(mb_size_t sz); // removes sz last bytes