23a088 | 2000-08-12 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
0917d3 | 2013-03-04 | Anders Johansson | |
|
978930 | 2010-09-06 | Martin Stjernholm | |
#define RXML_CONTEXT (_cur_rxml_context->get())
|
c1ee00 | 2001-06-29 | Martin Stjernholm | |
constant is_RXML_encodable = 1;
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
40c67c | 2001-07-09 | Martin Stjernholm | | #ifdef RXML_ENCODE_DEBUG
string _sprintf() {return "RXML.utils.pmod";}
#endif
|
6fae20 | 2001-05-19 | Martin Stjernholm | | constant short_format_length = 40;
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
32cd1c | 2008-10-13 | Martin Stjernholm | |
constant pike_cycle_depth = 0;
|
958fa9 | 2001-07-16 | Martin Stjernholm | | final string format_short (mixed val, void|int length)
|
6fae20 | 2001-05-19 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | {
|
6fae20 | 2001-05-19 | Martin Stjernholm | | string res = "";
|
958fa9 | 2001-07-16 | Martin Stjernholm | | if (!length) length = short_format_length;
|
6fae20 | 2001-05-19 | Martin Stjernholm | |
void format_val (mixed val)
{
if (arrayp (val) || multisetp (val)) {
string end;
if (multisetp (val)) res += "(<", end = ">)", val = indices (val);
else res += "({", end = "})";
|
958fa9 | 2001-07-16 | Martin Stjernholm | | if (sizeof (res) >= length) throw (0);
|
6fae20 | 2001-05-19 | Martin Stjernholm | | for (int i = 0; i < sizeof (val);) {
|
1293eb | 2001-06-18 | Martin Stjernholm | | format_val (val[i]);
if (++i < sizeof (val)) res += ", ";
|
958fa9 | 2001-07-16 | Martin Stjernholm | | if (sizeof (res) >= length) throw (0);
|
6fae20 | 2001-05-19 | Martin Stjernholm | | }
res += end;
}
else if (mappingp (val)) {
res += "([";
|
958fa9 | 2001-07-16 | Martin Stjernholm | | if (sizeof (res) >= length) throw (0);
|
652d44 | 2002-07-16 | Martin Stjernholm | | array ind = indices (val);
catch (ind = sort (ind));
|
6fae20 | 2001-05-19 | Martin Stjernholm | | for (int i = 0; i < sizeof (ind);) {
|
40c67c | 2001-07-09 | Martin Stjernholm | | format_val (ind[i]);
res += ": ";
|
958fa9 | 2001-07-16 | Martin Stjernholm | | if (sizeof (res) >= length) throw (0);
|
1293eb | 2001-06-18 | Martin Stjernholm | | format_val (val[ind[i]]);
if (++i < sizeof (ind)) res += ", ";
|
958fa9 | 2001-07-16 | Martin Stjernholm | | if (sizeof (res) >= length) throw (0);
|
6fae20 | 2001-05-19 | Martin Stjernholm | | }
res += "])";
}
|
7d1842 | 2008-09-28 | Martin Stjernholm | | else if (stringp (val)) {
if (sizeof (val) > length - sizeof (res)) {
|
6fae20 | 2001-05-19 | Martin Stjernholm | | sscanf (val, "%[ \t\n\r]", string lead);
if (sizeof (lead) > sizeof ("/.../") && sizeof (lead) < sizeof (val))
val = val[sizeof (lead)..], res += "/.../";
|
958fa9 | 2001-07-16 | Martin Stjernholm | | if (sizeof (val) > length - sizeof (res)) {
|
7d1842 | 2008-09-28 | Martin Stjernholm | | res += sprintf ("%q", val[..length - sizeof (res) - 1]);
|
6fae20 | 2001-05-19 | Martin Stjernholm | | throw (0);
}
}
|
7d1842 | 2008-09-28 | Martin Stjernholm | | res += sprintf ("%q", val);
|
6fae20 | 2001-05-19 | Martin Stjernholm | | }
|
7d1842 | 2008-09-28 | Martin Stjernholm | | else
res += sprintf ("%O", val);
|
6fae20 | 2001-05-19 | Martin Stjernholm | | };
mixed err = catch {
format_val (val);
return res;
};
if (err) throw (err);
return res + "/.../";
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final array return_zero (mixed... ignored) {return 0;}
final array return_empty_array (mixed... ignored) {return ({});}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | final mapping(string:string) return_empty_mapping (mixed... ignored)
{return ([]);}
final mapping(string:string) return_help_arg (mixed... ignored)
{return (["help": "help"]);}
|
978930 | 2010-09-06 | Martin Stjernholm | | protected string type_attribute_hint (RXML.Type type)
{
if (type == RXML.t_any)
if (RXML.Context ctx = RXML_CONTEXT)
if (ctx->frame && (<"set", "append">)[ctx->frame->tag->name] &&
zero_type (ctx->frame->args->type))
return "Maybe an attribute type=\"text/*\" is missing.\n";
return "";
}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | final mixed get_non_nil (RXML.Type type, mixed... vals)
{
int pos = -1;
do
if (++pos == sizeof (vals)) return RXML.nil;
while (vals[pos] == RXML.nil);
mixed res = vals[pos];
for (pos++; pos < sizeof (vals); pos++)
if (vals[pos] != RXML.nil)
RXML.parse_error (
|
978930 | 2010-09-06 | Martin Stjernholm | | "Cannot append another value %s to non-sequential "
"value of type %s.\n%s",
format_short (vals[pos]), type->name, type_attribute_hint (type));
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | return res;
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
final int(1..1)|string|array unknown_tag_error (object p, string str)
|
9265b5 | 2000-02-11 | Martin Stjernholm | | {
|
446bfa | 2001-06-21 | Martin Stjernholm | | p->context->handle_exception (
catch (RXML.parse_error (
|
978930 | 2010-09-06 | Martin Stjernholm | | "Unknown tag %s is not allowed in context of type %s.\n%s",
format_short (p->tag_name()), p->type->name,
type_attribute_hint (p->type))),
|
6f7737 | 2002-04-03 | Martin Stjernholm | | p, p->p_code);
|
9265b5 | 2000-02-11 | Martin Stjernholm | | return ({});
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final int(1..1)|string|array unknown_pi_tag_error (object p, string str)
{
sscanf (str, "%[^ \t\n\r]", str);
|
446bfa | 2001-06-21 | Martin Stjernholm | | p->context->handle_exception (
catch (RXML.parse_error (
|
978930 | 2010-09-06 | Martin Stjernholm | | "Unknown processing instruction %s not allowed "
"in context of type %s.\n%s",
format_short ("<" + p->tag_name() + str), p->type->name,
type_attribute_hint (p->type))),
|
6f7737 | 2002-04-03 | Martin Stjernholm | | p, p->p_code);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return ({});
}
final int(1..1)|string|array invalid_cdata_error (object p, string str)
{
|
446bfa | 2001-06-21 | Martin Stjernholm | | p->context->handle_exception (
catch (RXML.parse_error (
|
978930 | 2010-09-06 | Martin Stjernholm | | "CDATA text %O is not allowed in context of type %s.\n%s",
format_short (str), p->type->name,
type_attribute_hint (p->type))),
|
6f7737 | 2002-04-03 | Martin Stjernholm | | p, p->p_code);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return ({});
}
final int(1..1)|string|array output_error_cb (object p, string str)
|
f9dcf6 | 2000-02-13 | Martin Stjernholm | | {
|
446bfa | 2001-06-21 | Martin Stjernholm | | p->output_errors();
|
f9dcf6 | 2000-02-13 | Martin Stjernholm | | return ({str});
}
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
9f74bb | 2000-02-15 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final int(1..1)|string|array p_xml_comment_cb (object p, string str)
|
b1c1d3 | 2000-03-06 | Martin Stjernholm | |
{
|
446bfa | 2001-06-21 | Martin Stjernholm | | p->drain_output();
|
5eef02 | 2000-03-06 | Martin Stjernholm | | string name = p->parse_tag_name (str);
|
b1c1d3 | 2000-03-06 | Martin Stjernholm | | if (sizeof (name)) {
name = p->tag_name() + name;
if (string|array|function tdef = p->tags()[name]) {
if (stringp (tdef))
return ({tdef});
else if (arrayp (tdef))
return tdef[0] (p, p->parse_tag_args (str), @tdef[1..]);
else
return tdef (p, p->parse_tag_args (str));
}
else if (p->containers()[name])
|
446bfa | 2001-06-21 | Martin Stjernholm | | p->context->handle_exception (
catch (RXML.parse_error (
"Sorry, can't handle containers beginning with %s.\n",
|
6f7737 | 2002-04-03 | Martin Stjernholm | | p->tag_name())),
p, p->p_code);
|
b1c1d3 | 2000-03-06 | Martin Stjernholm | | }
return p->type->free_text ? 0 : ({});
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final int(1..1)|string|array p_xml_cdata_cb (object p, string str)
{
return ({str});
}
final int(1..1)|string|array p_xml_entity_cb (object p, string str)
|
26ff09 | 2000-01-21 | Martin Stjernholm | | {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | RXML.Type type = p->type;
|
26ff09 | 2000-01-21 | Martin Stjernholm | | string entity = p->tag_name();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (sizeof (entity))
|
cbf0e0 | 2004-05-21 | Henrik Grubbström (Grubba) | | switch(entity[0]) {
case ':': return ({"&", entity[1..], ";"});
case '#':
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (!p->type->entity_syntax) {
if (sscanf (entity,
(<"#x", "#X">)[entity[..1]] ? "%*2s%x%*c" : "%*c%d%*c",
int char) == 2)
catch (str = (string) ({char}));
}
|
cbf0e0 | 2004-05-21 | Henrik Grubbström (Grubba) | | break;
default:
if (has_value (entity, ".")) {
|
446bfa | 2001-06-21 | Martin Stjernholm | | p->drain_output();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | mixed value = p->handle_var (
entity,
|
1293eb | 2001-06-18 | Martin Stjernholm | | p->html_context() == "splice_arg" ? RXML.t_any_text : type);
|
cfe6c9 | 2006-08-22 | Martin Stjernholm | | if (value != RXML.nil && value != RXML.empty) p->add_value (value);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return ({});
}
|
cbf0e0 | 2004-05-21 | Henrik Grubbström (Grubba) | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return ({str});
|
26ff09 | 2000-01-21 | Martin Stjernholm | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final int(1..1)|string|array p_xml_compat_entity_cb (object p, string str)
|
26ff09 | 2000-01-21 | Martin Stjernholm | | {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | RXML.Type type = p->type;
|
26ff09 | 2000-01-21 | Martin Stjernholm | | string entity = p->tag_name();
|
b8e84a | 2000-03-04 | Martin Stjernholm | | if (sizeof (entity) && entity[0] != '#')
|
648aba | 2002-07-17 | Martin Stjernholm | | if (entity[0] == ':') return ({"&", entity[1..], ";"});
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | else if (has_value (entity, ".")) {
|
446bfa | 2001-06-21 | Martin Stjernholm | | p->drain_output();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | mixed value = p->handle_var (
entity,
|
1293eb | 2001-06-18 | Martin Stjernholm | | p->html_context() == "splice_arg" ? RXML.t_any_text : type);
|
cfe6c9 | 2006-08-22 | Martin Stjernholm | | if (value != RXML.nil && value != RXML.empty) p->add_value (value);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return ({});
}
return ({str});
|
26ff09 | 2000-01-21 | Martin Stjernholm | | }
|