]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Interim: start implementing Parser::Tokenizer::int64
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 22 May 2014 20:37:12 +0000 (22:37 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 22 May 2014 20:37:12 +0000 (22:37 +0200)
src/parser/Tokenizer.cc
src/parser/Tokenizer.h

index 9be59279ccc4a3f8a0e560491f594196ba20a37f..469d0b62c68f3b9d1f003b0e9dbce6e1de1206f6 100644 (file)
@@ -55,3 +55,41 @@ Parser::Tokenizer::skip(const char tokenChar)
     }
     return false;
 }
+
+// adapted from compatr/strtoll.c
+bool
+Parser::Tokenizer::int64 (int64_t & result, int base)
+{
+    //register uint64_t acc;
+    register uint64_t cutoff;
+    bool neg = false;
+    static SBuf zerox("0x"), zero("0");
+
+    if (buf_.isEmpty())
+        return false;
+
+    if (buf_[0] == '-') {
+        neg = true;
+        buf_.consume(1);
+    }
+    if (buf_[0] == '+')
+        buf_.consume(1);
+    if (base == 0) {
+        if (buf_.startsWith(zerox))
+            base = 16;
+        else if (buf_.startsWith(zero))
+            base = 8;
+        else
+            base = 10;
+    }
+    if (base != 8 && base != 10 && base != 16)
+        return false;
+
+    // TODO: finish
+    cutoff = neg ? -(uint64_t) INT64_MIN : INT64_MAX;
+
+    // dummy to keep compiler happy. Remove before continuing
+    if (neg) result = cutoff;
+
+    return false;
+}
index a1dbdefb2d0b4ec6219b2b451e19cc4b6cf1655b..0296a7221d44be54192f0bee30ab365a42778970 100644 (file)
@@ -64,6 +64,22 @@ public:
     */
    bool skip(const char tokenChar);
 
+   /** parse an unsigned int64_t at the beginning of the buffer
+    *
+    * strtoull(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 parseing is unsuccessful
+    * \param base specify base to do the parsing in. Admitted values are
+    *   8, 10, 16 and 0, the latter specifying to use C syntax for guessing
+    *   the base
+    * \return true if the parsing was successful
+    */
+   bool uint64 (uint64_t & result, int base);
+
+   bool int64 (int64_t &result, int base);
+
 private:
    SBuf buf_; ///< yet unparsed input
 };