diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-11-17 20:06:13 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-11-20 16:17:19 -0800 |
commit | 49b863afbd7e78dcc07d20df6652a969d919921e (patch) | |
tree | 00212d2a05792a822e8f8e2d3475f7f6193f0632 | |
parent | e557d7bc37def93fb56196dd286b6a337fdfa0c4 (diff) | |
download | txr-49b863afbd7e78dcc07d20df6652a969d919921e.tar.gz txr-49b863afbd7e78dcc07d20df6652a969d919921e.tar.bz2 txr-49b863afbd7e78dcc07d20df6652a969d919921e.zip |
Renaming html filters to get rid of underscore.
* filter.c (to_html_k, from_html_k, to_html_relaxed_k):
Variables removed.
(tohtml_k, tohtml_star_k, fromhtml_k): New keyword
symbol variables.
(to_html_table): Array renamed to tohtml_table.
(to_html_relaxed_table): Renamed to tohtml_star_table.
(from_html_table): Renamed to fromhtml_table.
(html_encode): Refers to tohtml_k.
(html_encode_star): Refers to tohtml_star_k.
(html_decode): Refers to fromhtml_k.
(filter_init): Initialize new symbol variables. Remove old
registrations. Register filters under old names too.
* txr.1: Document new names.
-rw-r--r-- | filter.c | 34 | ||||
-rw-r--r-- | txr.1 | 24 |
2 files changed, 31 insertions, 27 deletions
@@ -44,8 +44,8 @@ #include "stream.h" val filters; -val filter_k, lfilt_k, rfilt_k, to_html_k, from_html_k; -val to_html_relaxed_k; +val filter_k, lfilt_k, rfilt_k, tohtml_k, fromhtml_k; +val tohtml_star_k; val upcase_k, downcase_k; val topercent_k, frompercent_k, tourl_k, fromurl_k; val tonumber_k, toint_k, tofloat_k, hextoint_k; @@ -276,7 +276,7 @@ val register_filter(val sym, val table) return sethash(filters, sym, build_filter_from_list(table)); } -static struct filter_pair to_html_table[] = { +static struct filter_pair tohtml_table[] = { { wli("<"), wli("<") }, { wli(">"), wli(">") }, { wli("&"), wli("&") }, @@ -285,14 +285,14 @@ static struct filter_pair to_html_table[] = { { 0, 0 } }; -static struct filter_pair to_html_relaxed_table[] = { +static struct filter_pair tohtml_star_table[] = { { wli("<"), wli("<") }, { wli(">"), wli(">") }, { wli("&"), wli("&") }, { 0, 0 } }; -static struct filter_pair from_html_table[] = { +static struct filter_pair fromhtml_table[] = { { wli("""), wli("\"") }, { wli("&"), wli("&") }, { wli("'"), wli("'") }, @@ -680,17 +680,17 @@ val url_decode(val str, val space_plus) static val html_encode(val str) { - return trie_filter_string(get_filter(to_html_k), str); + return trie_filter_string(get_filter(tohtml_k), str); } static val html_encode_star(val str) { - return trie_filter_string(get_filter(to_html_relaxed_k), str); + return trie_filter_string(get_filter(tohtml_star_k), str); } static val html_decode(val str) { - return trie_filter_string(get_filter(from_html_k), str); + return trie_filter_string(get_filter(fromhtml_k), str); } void filter_init(void) @@ -701,9 +701,9 @@ void filter_init(void) filter_k = intern(lit("filter"), keyword_package); lfilt_k = intern(lit("lfilt"), keyword_package); rfilt_k = intern(lit("rfilt"), keyword_package); - to_html_k = intern(lit("to_html"), keyword_package); - to_html_relaxed_k = intern(lit("to_html_relaxed"), keyword_package); - from_html_k = intern(lit("from_html"), keyword_package); + tohtml_k = intern(lit("tohtml"), keyword_package); + tohtml_star_k = intern(lit("tohtml*"), keyword_package); + fromhtml_k = intern(lit("fromhtml"), keyword_package); upcase_k = intern(lit("upcase"), keyword_package); downcase_k = intern(lit("downcase"), keyword_package); topercent_k = intern(lit("topercent"), keyword_package); @@ -715,14 +715,18 @@ void filter_init(void) tofloat_k = intern(lit("tofloat"), keyword_package); hextoint_k = intern(lit("hextoint"), keyword_package); - sethash(filters, to_html_k, build_filter(to_html_table, t)); - sethash(filters, to_html_relaxed_k, build_filter(to_html_relaxed_table, t)); + sethash(filters, tohtml_k, build_filter(tohtml_table, t)); + sethash(filters, tohtml_star_k, build_filter(tohtml_star_table, t)); { - val trie = build_filter(from_html_table, nil); + val trie = build_filter(fromhtml_table, nil); trie_add(trie, lit("&#"), func_n1(html_numeric_handler)); trie_compress(mkcloc(trie)); - sethash(filters, from_html_k, trie); + sethash(filters, fromhtml_k, trie); } + sethash(filters, intern(lit("to_html"), keyword_package), + get_filter(tohtml_k)); + sethash(filters, intern(lit("from_html"), keyword_package), + get_filter(fromhtml_k)); sethash(filters, upcase_k, func_n1(upcase_str)); sethash(filters, downcase_k, func_n1(downcase_str)); sethash(filters, topercent_k, curry_12_1(func_n2(url_encode), nil)); @@ -5523,7 +5523,7 @@ is equivalent to For a description of filters, see Output Filtering below. Of course, compound filters like -.code (:from_html :upcase) +.code (:fromhtml :upcase) are supported with all these keywords. The filters apply across arbitrary patterns and nested data. @@ -7622,22 +7622,22 @@ This is discussed in the next section Function Filters below. Built-in filters named by keywords: -.coIP :to_html +.coIP :tohtml Filter text to HTML, representing special characters using HTML ampersand sequences. For instance .code > is replaced by .codn > . -.coIP :to_html_relaxed +.coIP :tohtml* Filter text to HTML, representing special characters using HTML ampersand sequences. Unlike -.codn :to_html , +.codn :tohtml , this filter doesn't treat the single and double quote characters. It is not suitable for preparing HTML fragments which end up inserted into HTML tag attributes. -.coIP :from_html +.coIP :fromhtml Filter text with HTML codes into text in which the codes are replaced by the corresponding characters. For instance .code > @@ -7738,11 +7738,11 @@ Examples: To escape HTML characters in all variable substitutions occurring in an output clause, specify -.code :filter :to_html +.code :filter :tohtml in the directive: .cblk - @(output :filter :to_html) + @(output :filter :tohtml) ... @(end) .cble @@ -7751,7 +7751,7 @@ To filter an individual variable, add the syntax to the variable spec: .cblk @(output) - @{x :filter :to_html} + @{x :filter :tohtml} @(end) .cble @@ -7759,7 +7759,7 @@ Multiple filters can be applied at the same time. For instance: .cblk @(output) - @{x :filter (:upcase :to_html)} + @{x :filter (:upcase :tohtml)} @(end) .cble @@ -7771,14 +7771,14 @@ For instance, suppose the original text is HTML, containing codes like .codn " . The compound filter -.code (:upcase :from_html) +.code (:upcase :fromhtml) will not work because .code " will turn to .code " which no longer be recognized by the -.code :from_html +.code :fromhtml filter, since the entity names in HTML codes are case-sensitive. @@ -8049,7 +8049,7 @@ and to upper case and HTML encode: .cblk - @(filter (:upcase :to_html) a b c) + @(filter (:upcase :tohtml) a b c) .cble .SH* EXCEPTIONS |