]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Extend MemBuf to trim whitespace
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 19 Sep 2012 10:35:16 +0000 (22:35 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 19 Sep 2012 10:35:16 +0000 (22:35 +1200)
src/MemBuf.cc
src/MemBuf.h

index c38693e531de093dfa66399e6aea8905f345dd6d..682d904eec7909954cdfa891b82d27c86539e977 100644 (file)
@@ -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)
 {
index 3c5f225d4642754cd59f74a47d12bbdc8c7c920d..408c44506d8d958381254912c7f12927ea5de037 100644 (file)
@@ -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