From: wessels <> Date: Tue, 22 Nov 2005 06:06:51 +0000 (+0000) Subject: Added StringToInt(), currently used when parsing chunked encoding messages. X-Git-Tag: SQUID_3_0_PRE4~512 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=053b1f591949d28e7c170dd9920028cbff12bfb5;p=thirdparty%2Fsquid.git Added StringToInt(), currently used when parsing chunked encoding messages. This was added for ICAP integration. --- diff --git a/src/Parsing.cc b/src/Parsing.cc index 6e7e5a7b68..1b8c036512 100644 --- a/src/Parsing.cc +++ b/src/Parsing.cc @@ -1,6 +1,6 @@ /* - * $Id: Parsing.cc,v 1.1 2005/01/03 16:08:25 robertc Exp $ + * $Id: Parsing.cc,v 1.2 2005/11/21 23:06:51 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -72,3 +72,22 @@ GetInteger(void) return i; } +bool +StringToInt(const char *s, int &result, const char **p, int base) +{ + if (s) { + char *ptr = 0; + const int h = (int) strtol(s, &ptr, base); + + if (ptr != s && ptr) { + result = h; + + if (p) + *p = ptr; + + return true; + } + } + + return false; +} diff --git a/src/Parsing.h b/src/Parsing.h index e4f5d599e7..182251e9ac 100644 --- a/src/Parsing.h +++ b/src/Parsing.h @@ -1,6 +1,6 @@ /* - * $Id: Parsing.h,v 1.1 2005/01/03 16:08:25 robertc Exp $ + * $Id: Parsing.h,v 1.2 2005/11/21 23:06:51 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -42,4 +42,7 @@ extern long xatol(const char *token); extern int xatoi(const char *token); extern int GetInteger(void); +// on success, returns true and sets *p (if any) to the end of the integer +extern bool StringToInt(const char *str, int &result, const char **p, int base); + #endif /* SQUID_PARSING_H */