Created
June 29, 2017 16:13
-
-
Save rebolek/f5731bc1d9234ef15e2d4fe31f4f531f 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
Red [ | |
Title: "Replace with /CASE support" | |
] | |
replace: func [ | |
"Returns the series where a value is found, or NONE. " | |
series [series!] | |
pattern | |
value | |
/all | |
/case | |
/local many? len pos | |
][ | |
find*: function [series value case] [ | |
either case [find/case series value] [find series value] | |
] | |
if system/words/all [char? :pattern any-string? series] [ | |
pattern: form pattern | |
] | |
many?: any [system/words/all [series? :pattern any-string? series] | |
binary? series system/words/all [any-list? series any-list? :pattern] | |
] | |
len: either many? [length? pattern] [1] | |
either all [ | |
pos: series | |
either many? [ | |
while [pos: find* pos pattern case] [remove/part pos len | |
pos: insert pos value | |
] | |
] [ | |
while [pos: find* pos :pattern case] [ | |
pos: change pos value | |
] | |
] | |
] [ | |
if pos: find* series :pattern case [ | |
remove/part pos len | |
insert pos value | |
] | |
] | |
series | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment