File tree 1 file changed +6
-21
lines changed
1 file changed +6
-21
lines changed Original file line number Diff line number Diff line change 1
- // Replace this with builtin if/when we get around to writing one.
2
- #[allow_absurd_cast]
3
- fun bash_version(): Num {
4
- let major = trust $ echo "\$\{BASH_VERSINFO[0]}" $ as Num
5
- let minor = trust $ echo "\$\{BASH_VERSINFO[1]}" $ as Num
6
- return (major * 100) + minor
7
- }
8
-
9
1
/// Replaces all occurrences of a pattern in the content with the provided replace text.
10
2
pub fun replace(source, search, replace) {
11
3
// Here we use commands for assigning values to avoid the side effect of Amber
12
- // Escape `\` as `\\`.
13
- trust $ {nameof search}="\$\{{nameof search}//\\\\/\\\\\\\}" $
14
- if bash_version() >= 502 {
15
- trust $ {nameof replace}="\$\{{nameof replace}//\\\\/\\\\\\\\}" $
16
- }
17
-
18
- return trust $ echo "\$\{{nameof source}//{search}/{replace}}" $
4
+ let result = ""
5
+ trust $ {nameof result}="\$\{{nameof source}//\"\$\{{nameof search}}\"/\"\$\{{nameof replace}}\"}" $
6
+ return result
19
7
}
20
8
21
9
/// Replaces the first occurrence of a pattern in the content with the provided replace text.
22
10
pub fun replace_one(source, search, replace) {
23
11
// Here we use commands for assigning values to avoid the side effect of Amber
24
- trust $ {nameof search}="\$\{{nameof search}//\\\\/\\\\\\\}" $
25
- if bash_version() >= 502 {
26
- trust $ {nameof replace}="\$\{{nameof replace}//\\\\/\\\\\\\\}" $
27
- }
28
-
29
- return trust $ echo "\$\{{nameof source}/{search}/{replace}}" $
12
+ let result = ""
13
+ trust $ {nameof result}="\$\{{nameof source}/\"\$\{{nameof search}}\"/\"\$\{{nameof replace}}\"}" $
14
+ return result
30
15
}
31
16
32
17
/// Replaces all occurrences of a regex pattern in the content with the provided replace text.
You can’t perform that action at this time.
0 commit comments