mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-29 23:54:14 +00:00
util/string.h: support 'int' for 'ascii_to'
This patch complements the 'long' version of the 'ascii_to' conversion function by an 'int' version. Fixes #4583
This commit is contained in:
parent
d0a33e34da
commit
5319f36788
@ -459,20 +459,21 @@ namespace Genode {
|
||||
|
||||
|
||||
/**
|
||||
* Read signed long value from string
|
||||
* Read signed value from string
|
||||
*
|
||||
* \return number of consumed characters
|
||||
*/
|
||||
inline size_t ascii_to(const char *s, long &result)
|
||||
template <typename T>
|
||||
inline size_t ascii_to_signed(const char *s, T &result)
|
||||
{
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
/* read sign */
|
||||
int sign = (*s == '-') ? -1 : 1;
|
||||
|
||||
if (*s == '-' || *s == '+') { s++; i++; }
|
||||
|
||||
unsigned long value = 0;
|
||||
T value = 0;
|
||||
|
||||
size_t const j = ascii_to_unsigned(s, value, 0);
|
||||
|
||||
@ -484,6 +485,28 @@ namespace Genode {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read signed long value from string
|
||||
*
|
||||
* \return number of consumed characters
|
||||
*/
|
||||
inline size_t ascii_to(const char *s, long &result)
|
||||
{
|
||||
return ascii_to_signed<long>(s, result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read signed integer value from string
|
||||
*
|
||||
* \return number of consumed characters
|
||||
*/
|
||||
inline size_t ascii_to(const char *s, int &result)
|
||||
{
|
||||
return ascii_to_signed<int>(s, result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read 'Number_of_bytes' value from string and handle the size suffixes
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user