aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/data/text.lux45
1 files changed, 37 insertions, 8 deletions
diff --git a/stdlib/source/lux/data/text.lux b/stdlib/source/lux/data/text.lux
index b344a2ad9..91d520c3c 100644
--- a/stdlib/source/lux/data/text.lux
+++ b/stdlib/source/lux/data/text.lux
@@ -170,14 +170,43 @@
(def: #export (replace_all pattern replacement template)
(-> Text Text Text Text)
- (loop [left ""
- right template]
- (case (..split_with pattern right)
- (#.Some [pre post])
- (recur ($_ "lux text concat" left pre replacement) post)
-
- #.None
- ("lux text concat" left right))))
+ (for {@.old
+ (:coerce Text
+ ("jvm invokevirtual:java.lang.String:replace:java.lang.CharSequence,java.lang.CharSequence"
+ (:coerce (primitive "java.lang.String") template)
+ (:coerce (primitive "java.lang.CharSequence") pattern)
+ (:coerce (primitive "java.lang.CharSequence") replacement)))
+ @.jvm
+ (:coerce Text
+ ("jvm member invoke virtual" [] "java.lang.String" "replace" []
+ (:coerce (primitive "java.lang.String") template)
+ ["Ljava/lang/CharSequence;" (:coerce (primitive "java.lang.CharSequence") pattern)]
+ ["Ljava/lang/CharSequence;" (:coerce (primitive "java.lang.CharSequence") replacement)]))
+ @.js
+ (:coerce Text
+ ("js object do" "replaceAll" template [pattern replacement]))
+ @.python
+ (:coerce Text
+ ("python object do" "replace" template pattern replacement))
+ ## TODO @.lua
+ @.ruby
+ (:coerce Text
+ ("ruby object do" "gsub" template pattern replacement))
+ @.php
+ (:coerce Text
+ ("php apply" (:assume ("php constant" "str_replace"))
+ pattern replacement template))
+ ## TODO @.scheme
+ }
+ ## Inefficient default
+ (loop [left ""
+ right template]
+ (case (..split_with pattern right)
+ (#.Some [pre post])
+ (recur ($_ "lux text concat" left pre replacement) post)
+
+ #.None
+ ("lux text concat" left right)))))
(structure: #export equivalence
(Equivalence Text)