|
|
|
@ -27,7 +27,7 @@ namespace Genode {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wrapper of 'size_t' for selecting 'ascii_to' specialization
|
|
|
|
|
* Wrapper of 'size_t' for selecting the 'ascii_to' function to parse byte values
|
|
|
|
|
*/
|
|
|
|
|
class Genode::Number_of_bytes
|
|
|
|
|
{
|
|
|
|
@ -266,8 +266,18 @@ namespace Genode {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read unsigned long value from string
|
|
|
|
|
*
|
|
|
|
|
* \param s source string
|
|
|
|
|
* \param result destination variable
|
|
|
|
|
* \param base integer base
|
|
|
|
|
* \return number of consumed characters
|
|
|
|
|
*
|
|
|
|
|
* If the base argument is 0, the integer base is detected based on the
|
|
|
|
|
* characters in front of the number. If the number is prefixed with "0x",
|
|
|
|
|
* a base of 16 is used, otherwise a base of 10.
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
@ -294,27 +304,42 @@ namespace Genode {
|
|
|
|
|
value = value*base + d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*result = value;
|
|
|
|
|
result = value;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read unsigned long value from string
|
|
|
|
|
*
|
|
|
|
|
* \return number of consumed characters
|
|
|
|
|
*/
|
|
|
|
|
inline size_t ascii_to(const char *s, unsigned long &result)
|
|
|
|
|
{
|
|
|
|
|
return ascii_to_unsigned_long(s, result, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read unsigned int value from string
|
|
|
|
|
*
|
|
|
|
|
* \return number of consumed characters
|
|
|
|
|
*/
|
|
|
|
|
inline size_t ascii_to(const char *s, unsigned int *result, unsigned base = 10)
|
|
|
|
|
inline size_t ascii_to(const char *s, unsigned int &result)
|
|
|
|
|
{
|
|
|
|
|
unsigned long result_long = 0;
|
|
|
|
|
size_t ret = ascii_to(s, &result_long, base);
|
|
|
|
|
*result = result_long;
|
|
|
|
|
size_t ret = ascii_to_unsigned_long(s, result_long, 0);
|
|
|
|
|
result = result_long;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read signed long value from string
|
|
|
|
|
*
|
|
|
|
|
* \return number of consumed characters
|
|
|
|
|
*/
|
|
|
|
|
inline size_t ascii_to(const char *s, long *result, unsigned base = 10)
|
|
|
|
|
inline size_t ascii_to(const char *s, long &result)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
@ -326,11 +351,11 @@ namespace Genode {
|
|
|
|
|
int j = 0;
|
|
|
|
|
unsigned long value = 0;
|
|
|
|
|
|
|
|
|
|
j = ascii_to(s, &value, base);
|
|
|
|
|
j = ascii_to_unsigned_long(s, value, 10);
|
|
|
|
|
|
|
|
|
|
if (!j) return i;
|
|
|
|
|
|
|
|
|
|
*result = sign*value;
|
|
|
|
|
result = sign*value;
|
|
|
|
|
return i + j;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -340,13 +365,15 @@ namespace Genode {
|
|
|
|
|
*
|
|
|
|
|
* This function scales the resulting size value according to the suffixes
|
|
|
|
|
* for G (2^30), M (2^20), and K (2^10) if present.
|
|
|
|
|
*
|
|
|
|
|
* \return number of consumed characters
|
|
|
|
|
*/
|
|
|
|
|
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 long res = 0;
|
|
|
|
|
|
|
|
|
|
/* convert numeric part of string */
|
|
|
|
|
int i = ascii_to(s, &res, 0);
|
|
|
|
|
int i = ascii_to_unsigned_long(s, res, 0);
|
|
|
|
|
|
|
|
|
|
/* handle suffixes */
|
|
|
|
|
if (i > 0)
|
|
|
|
@ -357,15 +384,17 @@ namespace Genode {
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*result = res;
|
|
|
|
|
result = res;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read double float value from string
|
|
|
|
|
*
|
|
|
|
|
* \return number of consumed characters
|
|
|
|
|
*/
|
|
|
|
|
inline size_t ascii_to(const char *s, double *result, unsigned base = 0)
|
|
|
|
|
inline size_t ascii_to(const char *s, double &result)
|
|
|
|
|
{
|
|
|
|
|
double v = 0.0; /* decimal part */
|
|
|
|
|
double d = 0.1; /* power of fractional digit */
|
|
|
|
@ -383,7 +412,7 @@ namespace Genode {
|
|
|
|
|
|
|
|
|
|
/* if no fractional part exists, return current value */
|
|
|
|
|
if (s[i] != '.') {
|
|
|
|
|
*result = neg ? -v : v;
|
|
|
|
|
result = neg ? -v : v;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -394,7 +423,7 @@ namespace Genode {
|
|
|
|
|
for (; s[i] && is_digit(s[i]); i++, d *= 0.1)
|
|
|
|
|
v += d*digit(s[i], false);
|
|
|
|
|
|
|
|
|
|
*result = neg ? -v : v;
|
|
|
|
|
result = neg ? -v : v;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|