File tree 3 files changed +9
-3
lines changed
3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 1
1
/// Replaces all occurrences of a pattern in the content with the provided replace text.
2
2
pub fun replace(source, search, replace) {
3
- return "\$\{source//{search}/{replace}}"
3
+ search = trust $ echo \$\{{nameof search}//\\\\/\\\\\\\\} $
4
+ replace = trust $ echo \$\{{nameof replace}//\\\\/\\\\\\\\} $
5
+ return trust $ echo \$\{{nameof source}//{search}/{replace}} $
4
6
}
5
7
6
8
/// Replaces the first occurrence of a pattern in the content with the provided replace text.
7
9
pub fun replace_once(source, search, replace) {
8
- return "\$\{source/{search}/{replace}}"
10
+ search = replace(search, "\\", "\\\\")
11
+ replace = replace(replace, "\\", "\\\\")
12
+ return trust $ echo \$\{{nameof source}/{search}/{replace}} $
9
13
}
10
14
11
15
/// Replaces all occurrences of a regex pattern in the content with the provided replace text.
Original file line number Diff line number Diff line change @@ -2,7 +2,9 @@ import * from "std/text"
2
2
3
3
// Output
4
4
// apple apple
5
+ // apple
5
6
6
7
main {
7
8
echo replace("banana banana", "banana", "apple")
9
+ echo replace("\\", "\\", "apple")
8
10
}
Original file line number Diff line number Diff line change 1
1
import * from "std/text"
2
2
main {
3
- echo replace_once("Succinctly", "inctly", "eeded")
3
+ echo replace_once("Succinctly\\ ", "inctly\\ ", "eeded")
4
4
}
You can’t perform that action at this time.
0 commit comments