DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Add-escapes - Escape Chars In A String
add-escapes: func [
"Insert the esc-with value before each instance of val, unless it's part of a list of things to ignore."
series [string!]
val [char!] "the char to escape"
esc-with [char!] "the char to escape it with"
/ignore special [block!] "block of strings to ignore"
/local rule=
][
rule=: copy/deep [
any [
; ignore rule will be added here if needed
mark: val (insert mark esc-with) skip
| skip
]
]
; If they have things they want us to ignore, add a rule at the
; beginning of the ANY rule, and a pipe symbol after it.
if special [
; rule=/2 is the ANY block
; pipe 1 is DELIMIT param
; pipe 2 is new rule 'OR separator
insert rule=/2 reduce [delimit copy special '| '|]
]
parse/all series rule=
series
]





