changeset 1717:c637a2a1023d

add String.replace
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 25 Jul 2022 11:16:53 -0600
parents b82767112d8e
children 5603ee8e2a71
files conv.txt src/luan/modules/String.luan src/luan/modules/StringLuan.java src/luan/modules/mmake.luan website/src/manual.html.luan
diffstat 5 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
diff -r b82767112d8e -r c637a2a1023d conv.txt
--- a/conv.txt	Sun Jul 24 23:43:03 2022 -0600
+++ b/conv.txt	Mon Jul 25 11:16:53 2022 -0600
@@ -7,6 +7,7 @@
 String.contains
 String.starts_with
 String.ends_with
+String.replace
 
 
 rename_to
diff -r b82767112d8e -r c637a2a1023d src/luan/modules/String.luan
--- a/src/luan/modules/String.luan	Sun Jul 24 23:43:03 2022 -0600
+++ b/src/luan/modules/String.luan	Mon Jul 25 11:16:53 2022 -0600
@@ -20,6 +20,7 @@
 String.regex = Boot.regex
 String.regex_quote = Pattern.quote
 String.rep = StringLuan.rep
+String.replace = StringLuan.replace
 String.reverse = StringLuan.reverse
 String.split = StringLuan.split
 String.starts_with = StringLuan.starts_with
diff -r b82767112d8e -r c637a2a1023d src/luan/modules/StringLuan.java
--- a/src/luan/modules/StringLuan.java	Sun Jul 24 23:43:03 2022 -0600
+++ b/src/luan/modules/StringLuan.java	Mon Jul 25 11:16:53 2022 -0600
@@ -262,4 +262,11 @@
 		return s.endsWith(s2);
 	}
 
+	public static String replace(String s,String target,String replacement) throws LuanException {
+		Utils.checkNotNull(s);
+		Utils.checkNotNull(target,2);
+		Utils.checkNotNull(replacement,3);
+		return s.replace(target,replacement);
+	}
+
 }
diff -r b82767112d8e -r c637a2a1023d src/luan/modules/mmake.luan
--- a/src/luan/modules/mmake.luan	Sun Jul 24 23:43:03 2022 -0600
+++ b/src/luan/modules/mmake.luan	Mon Jul 25 11:16:53 2022 -0600
@@ -5,7 +5,7 @@
 local print = Io.print
 local output_to = Io.output_to
 local String = require "luan:String.luan"
-local regex = String.regex
+local replace = String.replace
 local substring = String.sub
 local ends_with = String.ends_with
 local Time = require "luan:Time.luan"
@@ -46,9 +46,8 @@
 	end
 	local out = dir.child("Makefile").text_writer()
 	output_to(out,header)
-	local r = regex([[\$]])
 	for _, s in ipairs(javas) do
-		s = r.gsub(s,[[\$\$]])
+		s = replace(s,"$","$$")
 		out.write( "\\\n\t\t",  s , ".class" )
 	end
 	for _, s in ipairs(dirs) do
diff -r b82767112d8e -r c637a2a1023d website/src/manual.html.luan
--- a/website/src/manual.html.luan	Sun Jul 24 23:43:03 2022 -0600
+++ b/website/src/manual.html.luan	Mon Jul 25 11:16:53 2022 -0600
@@ -2688,6 +2688,16 @@
 <%
 						end
 					}
+					["String.replace"] = {
+						title = "<code>String.replace (s, target, replacement)</code>"
+						content = function()
+%>
+<p>
+Returns a string where each substring <code>target</code> in <code>s</code> is replaced by <code>replacement</code>.
+</p>
+<%
+						end
+					}
 					["String.reverse"] = {
 						title = "<code>String.reverse (s)</code>"
 						content = function()