diff options
Diffstat (limited to 'stdlib/source/lux.lux')
-rw-r--r-- | stdlib/source/lux.lux | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index de071c35a..c18603b4b 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -3270,7 +3270,11 @@ (#Some idx) (list& ("lux text clip" 0 idx input) (text\split_all_with splitter - ("lux text clip" ("lux i64 +" 1 idx) ("lux text size" input) input))))) + (let [after_offset ("lux i64 +" 1 idx) + after_length ("lux i64 -" + after_offset + ("lux text size" input))] + ("lux text clip" after_offset after_length input)))))) (def: (nth idx xs) (All [a] @@ -3760,7 +3764,7 @@ (def: (split! at x) (-> Nat Text [Text Text]) [("lux text clip" 0 at x) - ("lux text clip" at ("lux text size" x) x)]) + ("lux text clip" at ("lux i64 -" at ("lux text size" x)) x)]) (def: (split_with token sample) (-> Text Text (Maybe [Text Text])) @@ -3770,14 +3774,17 @@ [_ post] (split! ("lux text size" token) post')]] (wrap [pre post]))) -(def: (replace_all pattern value template) +(def: (replace_all pattern replacement template) (-> Text Text Text Text) - (case (..split_with pattern template) - (#.Some [pre post]) - ($_ "lux text concat" pre value (replace_all pattern value post)) + ((: (-> Text Text Text) + (function (recur left right) + (case (..split_with pattern right) + (#.Some [pre post]) + (recur ($_ "lux text concat" left pre replacement) post) - #.None - template)) + #.None + ("lux text concat" left right)))) + "" template)) (def: contextual_reference "#") (def: self_reference ".") @@ -3837,7 +3844,7 @@ list\reverse (interpose ..module_separator) (text\join_with "")) - clean ("lux text clip" relatives ("lux text size" module) module) + clean ("lux text clip" relatives ("lux i64 -" relatives ("lux text size" module)) module) output (case ("lux text size" clean) 0 prefix _ ($_ text\compose prefix ..module_separator clean))] |