]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
SourceFormat Enforcement
authorAutomatic source maintenance <squidadm@squid-cache.org>
Mon, 2 Jun 2014 00:15:10 +0000 (18:15 -0600)
committerAutomatic source maintenance <squidadm@squid-cache.org>
Mon, 2 Jun 2014 00:15:10 +0000 (18:15 -0600)
src/parser/Tokenizer.cc
src/parser/Tokenizer.h
src/parser/testTokenizer.cc

index 6a664bafcfbe6ec5e5fde87379848d63b65ae506..a13e218ebe88a2e81280560a5076a5087db4ed0a 100644 (file)
@@ -107,7 +107,7 @@ Parser::Tokenizer::int64(int64_t & result, int base)
     }
     if (s >= end) return false;
     if (( base == 0 || base == 16) && *s == '0' && (s+1 <= end ) &&
-                    tolower(*(s+1)) == 'x') {
+            tolower(*(s+1)) == 'x') {
         s += 2;
         base = 16;
     }
index 93796fb25b0e8ddfc3f3a183b2c883ebf8b67ded..71526881e8c9f95f13316fd5afd417da48b75a08 100644 (file)
@@ -5,7 +5,8 @@
 #include "SBuf.h"
 
 /// Generic protocol-agnostic parsing tools
-namespace Parser {
+namespace Parser
+{
 
 /**
  * Lexical processor to tokenize a buffer.
@@ -17,77 +18,78 @@ namespace Parser {
  * Methods returning true consume bytes from the buffer.
  * Methods returning false have no side-effects.
  */
-class Tokenizer {
+class Tokenizer
+{
 public:
-   explicit Tokenizer(const SBuf &inBuf) : buf_(inBuf) {}
-
-   // return a copy the current contents of the parse buffer
-   const SBuf buf() const { return buf_; }
-
-   /// whether the end of the buffer has been reached
-   bool atEnd() const { return buf_.isEmpty(); }
-
-   /// the remaining unprocessed section of buffer
-   const SBuf& remaining() const { return buf_; }
-
-   /// reinitialize processing for a new buffer
-   void reset(const SBuf &newBuf) { buf_ = newBuf; }
-
-   /** Basic strtok(3):
-    *  Skips all leading delimiters (if any),
-    *  accumulates all characters up to the next delimiter (a token), and
-    *  skips all trailing delimiters.
-    *
-    *  Want to extract delimiters? Use prefix() instead.
-    *
-    * At least one terminating delimiter is required. \0 may be passed
-    * as a delimiter to treat end of buffer content as the end of token.
-    *
-    * \return false if no terminal delimiter is found.
-    */
-   bool token(SBuf &returnedToken, const CharacterSet &delimiters);
-
-   /** Accumulates all sequential permitted characters up to an optional length limit.
-    *
-    * \retval true one or more characters were found, the sequence (string) is placed in returnedToken
-    * \retval false no characters from the permitted set were found
-    */
-   bool prefix(SBuf &returnedToken, const CharacterSet &tokenChars, SBuf::size_type limit = SBuf::npos);
-
-   /** skips all sequential characters from the set, in any order
-    *
-    * \return whether one or more characters in the set were found
-    */
-   bool skip(const CharacterSet &tokenChars);
-
-   /** skips a given character sequence (string)
-    *
-    * \return whether the exact character sequence was found and skipped
-    */
-   bool skip(const SBuf &tokenToSkip);
-
-   /** skips a given single character
-    *
-    * \return whether the character was found and skipped
-    */
-   bool skip(const char tokenChar);
-
-   /** parse an unsigned int64_t at the beginning of the buffer
-    *
-    * strtoll(3)-alike function: tries to parse unsigned 64-bit integer
-    * at the beginning of the parse buffer, in the base specified by the user
-    * or guesstimated; consumes the parsed characters.
-    *
-    * \param result Output value. Not touched if parsing is unsuccessful.
-    * \param base   Specify base to do the parsing in, with the same restrictions
-    *               as strtoll. Defaults to 0 (meaning guess)
-    *
-    * \return whether the parsing was successful
-    */
-   bool int64(int64_t &result, int base = 0);
+    explicit Tokenizer(const SBuf &inBuf) : buf_(inBuf) {}
+
+    // return a copy the current contents of the parse buffer
+    const SBuf buf() const { return buf_; }
+
+    /// whether the end of the buffer has been reached
+    bool atEnd() const { return buf_.isEmpty(); }
+
+    /// the remaining unprocessed section of buffer
+    const SBuf& remaining() const { return buf_; }
+
+    /// reinitialize processing for a new buffer
+    void reset(const SBuf &newBuf) { buf_ = newBuf; }
+
+    /** Basic strtok(3):
+     *  Skips all leading delimiters (if any),
+     *  accumulates all characters up to the next delimiter (a token), and
+     *  skips all trailing delimiters.
+     *
+     *  Want to extract delimiters? Use prefix() instead.
+     *
+     * At least one terminating delimiter is required. \0 may be passed
+     * as a delimiter to treat end of buffer content as the end of token.
+     *
+     * \return false if no terminal delimiter is found.
+     */
+    bool token(SBuf &returnedToken, const CharacterSet &delimiters);
+
+    /** Accumulates all sequential permitted characters up to an optional length limit.
+     *
+     * \retval true one or more characters were found, the sequence (string) is placed in returnedToken
+     * \retval false no characters from the permitted set were found
+     */
+    bool prefix(SBuf &returnedToken, const CharacterSet &tokenChars, SBuf::size_type limit = SBuf::npos);
+
+    /** skips all sequential characters from the set, in any order
+     *
+     * \return whether one or more characters in the set were found
+     */
+    bool skip(const CharacterSet &tokenChars);
+
+    /** skips a given character sequence (string)
+     *
+     * \return whether the exact character sequence was found and skipped
+     */
+    bool skip(const SBuf &tokenToSkip);
+
+    /** skips a given single character
+     *
+     * \return whether the character was found and skipped
+     */
+    bool skip(const char tokenChar);
+
+    /** parse an unsigned int64_t at the beginning of the buffer
+     *
+     * strtoll(3)-alike function: tries to parse unsigned 64-bit integer
+     * at the beginning of the parse buffer, in the base specified by the user
+     * or guesstimated; consumes the parsed characters.
+     *
+     * \param result Output value. Not touched if parsing is unsuccessful.
+     * \param base   Specify base to do the parsing in, with the same restrictions
+     *               as strtoll. Defaults to 0 (meaning guess)
+     *
+     * \return whether the parsing was successful
+     */
+    bool int64(int64_t &result, int base = 0);
 
 private:
-   SBuf buf_; ///< yet unparsed input
+    SBuf buf_; ///< yet unparsed input
 };
 
 } /* namespace Parser */
index 4e4dfa5ae63d541a59e60443f0ea5af7c508b40c..ac4dec4bf088a8af65f0bfe049fd206a00ef214a 100644 (file)
@@ -6,9 +6,9 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( testTokenizer );
 
 SBuf text("GET http://resource.com/path HTTP/1.1\r\n"
-    "Host: resource.com\r\n"
-    "Cookie: laijkpk3422r j1noin \r\n"
-    "\r\n");
+          "Host: resource.com\r\n"
+          "Cookie: laijkpk3422r j1noin \r\n"
+          "\r\n");
 const CharacterSet alpha("alpha","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
 const CharacterSet whitespace("whitespace"," \r\n");
 const CharacterSet crlf("crlf","\r\n");