diff options
author | Eduardo Julian | 2018-07-11 21:17:42 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-07-11 21:17:42 -0400 |
commit | 0097e306a1e3b53e4cda304aac82b8778036eddf (patch) | |
tree | ee97d8986edd1c5d7162986a273fde0079fb5659 /stdlib/source/lux.lux | |
parent | f861af6c6bd57677ba4af2ee3275c69b11f68beb (diff) |
- Got rid of "lux text replace-once" and "lux text replace-all" extensions.
Diffstat (limited to 'stdlib/source/lux.lux')
-rw-r--r-- | stdlib/source/lux.lux | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 9dde82dc8..56fa96018 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -4144,9 +4144,33 @@ #import-refer {#refer-defs _referrals #refer-open _openings}}))))) +(def: (split at x) + (-> Nat Text (Maybe [Text Text])) + (case [(..clip2 +0 at x) (..clip1 at x)] + [(#.Some pre) (#.Some post)] + (#.Some [pre post]) + + _ + #.None)) + +(def: (split-with token sample) + (-> Text Text (Maybe [Text Text])) + (do ..Monad<Maybe> + [index (..index-of token sample) + pre+post' (split index sample) + #let [[pre post'] pre+post'] + _+post (split ("lux text size" token) post') + #let [[_ post] _+post]] + (wrap [pre post]))) + (def: (replace-all pattern value template) (-> Text Text Text Text) - ("lux text replace-all" template pattern value)) + (case (..split-with pattern template) + (#.Some [pre post]) + ($_ "lux text concat" pre value (replace-all pattern value post)) + + #.None + template)) (def: (count-ups ups input) (-> Nat Text Nat) |