mirror of
https://github.com/janet-lang/janet
synced 2024-11-07 17:29:54 +00:00
31 lines
591 B
Plaintext
31 lines
591 B
Plaintext
|
# Helper to generate core library mappings for janet
|
||
|
|
||
|
(def allsyms (all-symbols))
|
||
|
|
||
|
(def- escapes
|
||
|
{(get "|" 0) `\|`
|
||
|
(get "-" 0) `\-`
|
||
|
(get "+" 0) `\+`
|
||
|
(get "*" 0) `\*`
|
||
|
(get "^" 0) `\^`
|
||
|
(get "$" 0) `\$`
|
||
|
(get "?" 0) `\?`
|
||
|
38 "&"
|
||
|
60 "<"
|
||
|
62 ">"
|
||
|
34 """
|
||
|
39 "'"
|
||
|
47 "/"})
|
||
|
|
||
|
(defn- escape
|
||
|
"Escape special characters for HTML encoding."
|
||
|
[str]
|
||
|
(def buf @"")
|
||
|
(loop [byte :in str]
|
||
|
(if-let [rep escapes.byte]
|
||
|
(buffer/push-string buf rep)
|
||
|
(buffer/push-byte buf byte)))
|
||
|
buf)
|
||
|
|
||
|
(print (string/join (map escape allsyms)) "|"))
|