base: unify ascii_to conversion functions
This patch addresses the first point of the issue #1477, namely replacing the function-template magic by plain function overloads. Issue #1477
This commit is contained in:
parent
84a98e18ad
commit
d884cf1a9a
|
@ -264,28 +264,10 @@ namespace Genode {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert ASCII string to another type
|
|
||||||
*
|
|
||||||
* \param T destination type of conversion
|
|
||||||
* \param s null-terminated source string
|
|
||||||
* \param result destination pointer to conversion result
|
|
||||||
* \param base base, autodetected if set to 0
|
|
||||||
* \return number of consumed characters
|
|
||||||
*
|
|
||||||
* Please note that 'base' and 's_max_len' are not evaluated by all
|
|
||||||
* template specializations.
|
|
||||||
*/
|
|
||||||
template <typename T>
|
|
||||||
inline size_t ascii_to(const char *s, T *result, unsigned base = 0);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read unsigned long value from string
|
* Read unsigned long value from string
|
||||||
*/
|
*/
|
||||||
template <>
|
inline size_t ascii_to(const char *s, unsigned long *result, unsigned base = 0)
|
||||||
inline size_t ascii_to<unsigned long>(const char *s, unsigned long *result,
|
|
||||||
unsigned base)
|
|
||||||
{
|
{
|
||||||
unsigned long i = 0, value = 0;
|
unsigned long i = 0, value = 0;
|
||||||
|
|
||||||
|
@ -320,12 +302,10 @@ namespace Genode {
|
||||||
/**
|
/**
|
||||||
* Read unsigned int value from string
|
* Read unsigned int value from string
|
||||||
*/
|
*/
|
||||||
template <>
|
inline size_t ascii_to(const char *s, unsigned int *result, unsigned base = 10)
|
||||||
inline size_t ascii_to<unsigned int>(const char *s, unsigned int *result,
|
|
||||||
unsigned base)
|
|
||||||
{
|
{
|
||||||
unsigned long result_long = 0;
|
unsigned long result_long = 0;
|
||||||
size_t ret = ascii_to<unsigned long>(s, &result_long, base);
|
size_t ret = ascii_to(s, &result_long, base);
|
||||||
*result = result_long;
|
*result = result_long;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -334,8 +314,7 @@ namespace Genode {
|
||||||
/**
|
/**
|
||||||
* Read signed long value from string
|
* Read signed long value from string
|
||||||
*/
|
*/
|
||||||
template <>
|
inline size_t ascii_to(const char *s, long *result, unsigned base = 10)
|
||||||
inline size_t ascii_to<long>(const char *s, long *result, unsigned base)
|
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
@ -362,8 +341,7 @@ namespace Genode {
|
||||||
* This function scales the resulting size value according to the suffixes
|
* This function scales the resulting size value according to the suffixes
|
||||||
* for G (2^30), M (2^20), and K (2^10) if present.
|
* for G (2^30), M (2^20), and K (2^10) if present.
|
||||||
*/
|
*/
|
||||||
template <>
|
inline size_t ascii_to(const char *s, Number_of_bytes *result, unsigned base = 0)
|
||||||
inline size_t ascii_to(const char *s, Number_of_bytes *result, unsigned)
|
|
||||||
{
|
{
|
||||||
unsigned long res = 0;
|
unsigned long res = 0;
|
||||||
|
|
||||||
|
@ -387,8 +365,7 @@ namespace Genode {
|
||||||
/**
|
/**
|
||||||
* Read double float value from string
|
* Read double float value from string
|
||||||
*/
|
*/
|
||||||
template <>
|
inline size_t ascii_to(const char *s, double *result, unsigned base = 0)
|
||||||
inline size_t ascii_to<double>(const char *s, double *result, unsigned)
|
|
||||||
{
|
{
|
||||||
double v = 0.0; /* decimal part */
|
double v = 0.0; /* decimal part */
|
||||||
double d = 0.1; /* power of fractional digit */
|
double d = 0.1; /* power of fractional digit */
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
namespace Genode {
|
namespace Genode {
|
||||||
struct Color;
|
struct Color;
|
||||||
|
|
||||||
template <>
|
inline size_t ascii_to(const char *, Color *, unsigned base = 0);
|
||||||
inline size_t ascii_to<Color>(const char *, Color *, unsigned);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,9 +45,7 @@ struct Genode::Color
|
||||||
* \return number of consumed characters, or 0 if the string contains
|
* \return number of consumed characters, or 0 if the string contains
|
||||||
* no valid color
|
* no valid color
|
||||||
*/
|
*/
|
||||||
template <>
|
inline Genode::size_t Genode::ascii_to(const char *s, Genode::Color *result, unsigned)
|
||||||
inline Genode::size_t
|
|
||||||
Genode::ascii_to<Genode::Color>(const char *s, Genode::Color *result, unsigned)
|
|
||||||
{
|
{
|
||||||
/* validate string */
|
/* validate string */
|
||||||
if (strlen(s) < 7 || *s != '#') return 0;
|
if (strlen(s) < 7 || *s != '#') return 0;
|
||||||
|
|
Loading…
Reference in New Issue