Created
August 19, 2020 17:34
-
-
Save radgeRayden/f98d1801092b5b99f98aca1cff8290fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spice escape-pattern (str) | |
import UTF-8 | |
using import itertools | |
str as:= string | |
let new-pattern = | |
->> str UTF-8.decoder | |
retain | |
inline (c) | |
switch c | |
pass (UTF-8.char "[") | |
pass (UTF-8.char "]") | |
pass (UTF-8.char "\\") | |
pass (UTF-8.char "^") | |
pass (UTF-8.char "$") | |
pass (UTF-8.char ".") | |
pass (UTF-8.char "|") | |
pass (UTF-8.char "?") | |
pass (UTF-8.char "*") | |
pass (UTF-8.char "+") | |
pass (UTF-8.char "(") | |
pass (UTF-8.char ")") | |
pass (UTF-8.char "{") | |
pass (UTF-8.char "}") | |
do | |
UTF-8.char "\\" | |
default | |
-1 | |
map | |
inline (code-point) | |
code-point | |
flatten | |
filter | |
(x) -> (x != -1) | |
UTF-8.encoder | |
string.collector 256 | |
`[new-pattern] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment