mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-20 11:39:14 +00:00
parent
0d4f48ca0b
commit
afed9cfd95
@ -595,18 +595,6 @@ class Genode::String
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... T>
|
||||
void _init(T &&... args)
|
||||
{
|
||||
/* initialize string content */
|
||||
Local_output output(_buf);
|
||||
Genode::print(output, args...);
|
||||
|
||||
/* add terminating null */
|
||||
_buf[output.num_chars()] = 0;
|
||||
_len = output.num_chars() + 1;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
constexpr static size_t size() { return CAPACITY; }
|
||||
@ -616,6 +604,12 @@ class Genode::String
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* The constructor accepts a non-zero number of arguments, which
|
||||
* are concatenated in the resulting 'String' object. In order to
|
||||
* generate the textual representation of the arguments, the
|
||||
* argument types must support the 'Output' interface, e.g., by
|
||||
* providing 'print' method.
|
||||
*
|
||||
* If the textual representation of the supplied arguments exceeds
|
||||
* 'CAPACITY', the resulting string gets truncated. The caller may
|
||||
* check for this condition by evaluating the 'length' of the
|
||||
@ -623,8 +617,17 @@ class Genode::String
|
||||
* may fit perfectly into the buffer or may have been truncated.
|
||||
* In general, it would be safe to assume the latter.
|
||||
*/
|
||||
template <typename T>
|
||||
String(T const &arg) { _init(arg); }
|
||||
template <typename T, typename... TAIL>
|
||||
String(T const &arg, TAIL &&... args)
|
||||
{
|
||||
/* initialize string content */
|
||||
Local_output output(_buf);
|
||||
Genode::print(output, arg, args...);
|
||||
|
||||
/* add terminating null */
|
||||
_buf[output.num_chars()] = 0;
|
||||
_len = output.num_chars() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
|
@ -32,5 +32,6 @@ compare_output_to {
|
||||
[init -> test-log] invalid hex range: [f8,08) (overflow!)
|
||||
[init -> test-log] negative hex char: 0xfe
|
||||
[init -> test-log] positive hex char: 0x02
|
||||
[init -> test-log] multiarg string: "parent -> child.7"
|
||||
[init -> test-log] Test done.
|
||||
}
|
||||
|
@ -26,5 +26,9 @@ void Component::construct(Genode::Env &env)
|
||||
log("invalid hex range: ", Hex_range<uint8_t>(0xf8, 0x10));
|
||||
log("negative hex char: ", Hex((char)-2LL, Hex::PREFIX, Hex::PAD));
|
||||
log("positive hex char: ", Hex((char) 2LL, Hex::PREFIX, Hex::PAD));
|
||||
|
||||
typedef String<128> Label;
|
||||
log("multiarg string: ", Label(Char('"'), "parent -> child.", 7, Char('"')));
|
||||
|
||||
log("Test done.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user