Skip to content

Instantly share code, notes, and snippets.

@radgeRayden
Created August 19, 2020 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radgeRayden/f98d1801092b5b99f98aca1cff8290fe to your computer and use it in GitHub Desktop.
Save radgeRayden/f98d1801092b5b99f98aca1cff8290fe to your computer and use it in GitHub Desktop.
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