@abaplint/runtime 2.1.55 → 2.1.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/statements/replace.js +16 -22
- package/package.json +1 -1
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.replace = void 0;
|
|
4
|
+
function escapeRegExp(text) {
|
|
5
|
+
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
6
|
+
}
|
|
4
7
|
function replace(input) {
|
|
5
8
|
let temp = input.target.get();
|
|
6
9
|
const ignoreCase = input.ignoringCase === true ? "i" : "";
|
|
7
|
-
|
|
10
|
+
const allOccurrences = input.all === true ? "g" : "";
|
|
11
|
+
let search = undefined;
|
|
8
12
|
let found = false;
|
|
9
13
|
if (input.of) {
|
|
10
|
-
|
|
11
|
-
if (
|
|
14
|
+
let inp = input.of.get();
|
|
15
|
+
if (inp.length === 0 && input.all === true) {
|
|
12
16
|
throw "REPLACE, zero length input";
|
|
13
17
|
}
|
|
14
|
-
found = temp.indexOf(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
+
found = temp.indexOf(inp) >= 0;
|
|
19
|
+
inp = escapeRegExp(inp);
|
|
20
|
+
search = new RegExp(inp, ignoreCase + allOccurrences);
|
|
18
21
|
}
|
|
19
22
|
else if (input.regex) {
|
|
20
23
|
if (input.regex.get().length === 0 && input.all === true) {
|
|
21
24
|
throw "REPLACE, zero length input";
|
|
22
25
|
}
|
|
23
|
-
found = temp.match(
|
|
24
|
-
search = new RegExp(input.regex.get(), ignoreCase);
|
|
26
|
+
found = temp.match(input.regex.get()) !== null;
|
|
27
|
+
search = new RegExp(input.regex.get(), ignoreCase + allOccurrences);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw "REPLACE, unexpected input";
|
|
25
31
|
}
|
|
26
32
|
let replace = "";
|
|
27
33
|
if (typeof input.with === "string") {
|
|
@@ -33,19 +39,7 @@ function replace(input) {
|
|
|
33
39
|
replace = replace.replace(/\\\{/g, "{");
|
|
34
40
|
replace = replace.replace(/\\\}/g, "}");
|
|
35
41
|
}
|
|
36
|
-
|
|
37
|
-
if (input.regex) {
|
|
38
|
-
temp = temp.replace(new RegExp(input.regex.get(), "g" + ignoreCase), replace);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
while (temp.replace(search, replace) !== temp) {
|
|
42
|
-
temp = temp.replace(search, replace);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
temp = temp.replace(search, replace);
|
|
48
|
-
}
|
|
42
|
+
temp = temp.replace(search, replace);
|
|
49
43
|
const subrc = found ? 0 : 4;
|
|
50
44
|
// @ts-ignore
|
|
51
45
|
abap.builtin.sy.get().subrc.set(subrc);
|