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.3 2006/07/19 12:56:28 bernie
17 *#* Convert to new Doxygen style.
19 *#* Revision 1.2 2005/04/11 18:10:45 bernie
22 *#* Revision 1.1 2005/03/15 00:06:30 bernie
23 *#* Simpler, smaller, faster.
30 * Convert a formatted base-10 ASCII number to unsigned long binary representation.
32 * Unlike the standard strtoul(), this function has an interface
33 * that makes it better suited for protocol parsers. It's also
34 * much simpler and smaller than a full featured strtoul().
36 * \param first Pointer to first byte of input range (STL-style).
37 * \param last Pointer to end of input range (STL-style).
38 * Pass NULL to parse up to the first \\0.
39 * \param val Pointer to converted value.
41 * \return true for success, false for failure.
45 bool strtoul10(const char *first, const char *last, unsigned long *val)
52 for(/*nop*/; first != last && *first != '\0'; ++first)
54 if ((*first < '0') || (*first > '9'))
57 *val = (*val * 10L) + (*first - '0');
65 * Convert a formatted base-10 ASCII number to signed long binary representation.
69 bool strtol10(const char *first, const char *last, long *val)
71 bool negative = false;
74 ++first; /* skip unary plus sign */
75 else if (*first == '-')
81 bool result = strtoul10(first, last, (unsigned long *)val);