summaryrefslogtreecommitdiffstats
path: root/filter.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-09-26 23:37:32 -0700
committerKaz Kylheku <kaz@kylheku.com>2011-09-26 23:37:32 -0700
commit2722c5140685064be3df771eb9c0e0feff4fded0 (patch)
tree0ac812176a31881d869a369e137d81673a1f47db /filter.c
parent29b5d37a8577d83ae0c88b2e894287b990e6849e (diff)
downloadtxr-2722c5140685064be3df771eb9c0e0feff4fded0.tar.gz
txr-2722c5140685064be3df771eb9c0e0feff4fded0.tar.bz2
txr-2722c5140685064be3df771eb9c0e0feff4fded0.zip
Support &#NNNN; decimal escapes also.txr-037
* filter.c (html_hex_continue): Bail with nil if no digits are collected. The &#x; syntax is not translated to anything. (html_dec_continue): New function. (html_hex_handler): Function renamed to html_numeric_handler. (filter_init): Change function-based trie node over to html_numeric_handler.
Diffstat (limited to 'filter.c')
-rw-r--r--filter.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/filter.c b/filter.c
index 370df293..db298da6 100644
--- a/filter.c
+++ b/filter.c
@@ -491,6 +491,9 @@ static val html_hex_continue(val hexlist, val ch)
wchar_t out[2] = { 0 };
val iter;
+ if (nullp(hexlist))
+ return nil;
+
for (iter = nreverse(hexlist); iter; iter = cdr(iter)) {
val hexch = car(iter);
int val = wcschr(hexdigs, towupper(c_chr(hexch))) - hexdigs;
@@ -504,11 +507,34 @@ static val html_hex_continue(val hexlist, val ch)
}
}
-static val html_hex_handler(val ch)
+static val html_dec_continue(val declist, val ch)
+{
+ if (iswdigit(c_chr(ch))) {
+ return func_f1(cons(ch, declist), html_dec_continue);
+ } if (eq(ch, chr(';'))) {
+ wchar_t out[2] = { 0 };
+ val iter;
+
+ for (iter = nreverse(declist); iter; iter = cdr(iter)) {
+ val decch = car(iter);
+ int val = c_chr(decch) - '0';
+ out[0] *= 10;
+ out[0] += val;
+ }
+
+ return string(out);
+ } else {
+ return nil;
+ }
+}
+
+static val html_numeric_handler(val ch)
{
- if (!iswxdigit(c_chr(ch)))
+ if (eq(ch, chr('x')))
+ return func_f1(nil, html_hex_continue);
+ if (!iswdigit(c_chr(ch)))
return nil;
- return func_f1(cons(ch, nil), html_hex_continue);
+ return func_f1(cons(ch, nil), html_dec_continue);
}
val filters;
@@ -523,7 +549,7 @@ void filter_init(void)
sethash(filters, to_html_k, build_filter(to_html_table, t));
{
val trie = build_filter(from_html_table, nil);
- trie_add(trie, lit("&#x"), func_n1(html_hex_handler));
+ trie_add(trie, lit("&#"), func_n1(html_numeric_handler));
trie_compress(&trie);
sethash(filters, from_html_k, trie);
}