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.1 2005/03/15 00:06:30 bernie
17 *#* Simpler, smaller, faster.
24 * Convert a formatted base-10 ASCII number to unsigned long binary representation.
26 * Unlike the standard strtoul(), this function has an interface
27 * that makes it better suited for protocol parsers. It's also
28 * much simpler and smaller than a full featured strtoul().
30 * \param first Pointer to first byte of input range (STL-style).
31 * \param last Pointer to end of input range (STL-style).
32 * Pass NULL to parse up to the first \0.
33 * \param val Pointer to converted value.
35 * \return true for success, false for failure.
39 bool strtoul10(const char *first, const char *last, unsigned long *val)
46 for(/*nop*/; first != last && *first != '\0'; ++first)
48 if ((*first < '0') || (*first > '9'))
51 *val = (*val * 10L) + (*first - '0');
59 * Convert a formatted base-10 ASCII number to signed long binary representation.
63 bool strtol10(const char *first, const char *last, long *val)
65 bool negative = false;
68 ++first; /* skip unary plus sign */
69 else if (*first == '-')
75 bool result = strtoul10(first, last, (unsigned long *)val);