os: add Xml_attribute::value(String<N> *out)

This overload of the value member eases the retrieval of Genode::String
objects from XML attributes. So we won't need to deal with C-style
character buffers anymore.
This commit is contained in:
Norman Feske 2015-09-22 11:52:20 +02:00 committed by Christian Helmuth
parent c8ec7b6ffb
commit a80d944944
1 changed files with 12 additions and 5 deletions

View File

@ -119,11 +119,8 @@ class Genode::Xml_attribute
/**
* Return attribute value as null-terminated string
*
* \return true on success, or
* false if attribute is invalid
*/
bool value(char *dst, size_t max_len) const
void value(char *dst, size_t max_len) const
{
/*
* The value of 'max_len' denotes the maximum number of
@ -134,7 +131,6 @@ class Genode::Xml_attribute
*/
max_len = min(max_len, _value.len() - 2 + 1);
strncpy(dst, _value.start() + 1, max_len);
return true;
}
/**
@ -164,6 +160,17 @@ class Genode::Xml_attribute
return ascii_to(_value.start() + 1, *out) == _value.len() - 2;
}
/**
* Return attribute value as Genode::String
*/
template <size_t N>
void value(String<N> *out) const
{
char buf[N];
value(buf, sizeof(buf));
*out = String<N>(buf);
}
/**
* Return next attribute in attribute list
*/