4 * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
8 * \brief Poor man's hex arrays (implementation).
11 * \author Bernardo Innocenti <bernie@develer.com>
16 *#* Revision 1.2 2005/04/11 18:10:45 bernie
19 *#* Revision 1.1 2005/03/15 00:06:30 bernie
20 *#* Simpler, smaller, faster.
27 * Convert a formatted base-10 ASCII number to unsigned long binary representation.
29 * Unlike the standard strtoul(), this function has an interface
30 * that makes it better suited for protocol parsers. It's also
31 * much simpler and smaller than a full featured strtoul().
33 * \param first Pointer to first byte of input range (STL-style).
34 * \param last Pointer to end of input range (STL-style).
35 * Pass NULL to parse up to the first \\0.
36 * \param val Pointer to converted value.
38 * \return true for success, false for failure.
42 bool strtoul10(const char *first, const char *last, unsigned long *val)
49 for(/*nop*/; first != last && *first != '\0'; ++first)
51 if ((*first < '0') || (*first > '9'))
54 *val = (*val * 10L) + (*first - '0');
62 * Convert a formatted base-10 ASCII number to signed long binary representation.
66 bool strtol10(const char *first, const char *last, long *val)
68 bool negative = false;
71 ++first; /* skip unary plus sign */
72 else if (*first == '-')
78 bool result = strtoul10(first, last, (unsigned long *)val);