parent
b24edc1633
commit
b5bd6e0114
|
@ -248,6 +248,16 @@ class Genode::Xml_generator
|
||||||
_commit_content(content_buffer);
|
_commit_content(content_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append character, sanitize it if needed
|
||||||
|
*/
|
||||||
|
void append_sanitized(char const c)
|
||||||
|
{
|
||||||
|
Out_buffer content_buffer = _content_buffer(false);
|
||||||
|
content_buffer.append_sanitized(c);
|
||||||
|
_commit_content(content_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
void append_sanitized(char const *src, size_t src_len)
|
void append_sanitized(char const *src, size_t src_len)
|
||||||
{
|
{
|
||||||
Out_buffer content_buffer = _content_buffer(false);
|
Out_buffer content_buffer = _content_buffer(false);
|
||||||
|
@ -417,6 +427,33 @@ class Genode::Xml_generator
|
||||||
_curr_node->append_sanitized(str, str_len == ~0UL ? strlen(str) : str_len);
|
_curr_node->append_sanitized(str, str_len == ~0UL ? strlen(str) : str_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append printable objects to XML node as sanitized content
|
||||||
|
*
|
||||||
|
* This method must not be followed by calls of 'attribute'.
|
||||||
|
*/
|
||||||
|
template <typename... ARGS>
|
||||||
|
void append_content(ARGS &&... args)
|
||||||
|
{
|
||||||
|
struct Node_output : Genode::Output
|
||||||
|
{
|
||||||
|
Node &node; Node_output(Node &n) : node(n) { }
|
||||||
|
|
||||||
|
/******************************
|
||||||
|
** Genode::Output interface **
|
||||||
|
******************************/
|
||||||
|
|
||||||
|
void out_char(char c) override {
|
||||||
|
node.append_sanitized(c); }
|
||||||
|
|
||||||
|
void out_string(char const *str, size_t n) override {
|
||||||
|
node.append_sanitized(str, n); }
|
||||||
|
|
||||||
|
} output { *_curr_node };
|
||||||
|
|
||||||
|
Output::out_args(output, args...);
|
||||||
|
}
|
||||||
|
|
||||||
size_t used() const { return _out_buffer.used(); }
|
size_t used() const { return _out_buffer.used(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -226,6 +226,22 @@ void Component::construct(Genode::Env &env)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test arbitrary content
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
Xml_generator xml(dst, sizeof(dst), "data", [&] () {
|
||||||
|
xml.append_content(" ", 2 + 2, " == 2 + 2 == ", 4.0, " ");
|
||||||
|
});
|
||||||
|
|
||||||
|
Xml_node node(dst);
|
||||||
|
auto s = node.decoded_content<String<32>>();
|
||||||
|
if (s != " 4 == 2 + 2 == 4.0 ") {
|
||||||
|
error("decoded content does not match expect content");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log("--- XML generator test finished ---");
|
log("--- XML generator test finished ---");
|
||||||
genode_exit(0);
|
genode_exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user