From 1177ec50a8c9e68a7e3a9b39e1990d10f9564f70 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Wed, 19 Sep 2012 22:35:16 +1200 Subject: [PATCH] Extend MemBuf to trim whitespace --- src/MemBuf.cc | 12 ++++++++++++ src/MemBuf.h | 2 ++ 2 files changed, 14 insertions(+) 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 -- 2.47.3