@abaplint/runtime 2.10.26 → 2.10.27
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/abap_regex.js
CHANGED
|
@@ -17,6 +17,47 @@ class ABAPRegExp {
|
|
|
17
17
|
static escapeRegExp(text) {
|
|
18
18
|
return text.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
|
|
19
19
|
}
|
|
20
|
+
static getRegex(options) {
|
|
21
|
+
if (options.regex) {
|
|
22
|
+
if (typeof options.regex === "string") {
|
|
23
|
+
if (options.regex === "") {
|
|
24
|
+
throw new Error("FIND, runtime, no input, regex empty");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (options.regex.get() === "") {
|
|
28
|
+
throw new Error("FIND, runtime, no input, regex empty");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const ignoreCase = options.ignoringCase === true ? "i" : "";
|
|
32
|
+
const allOccurrences = options.all === true ? "g" : "";
|
|
33
|
+
let r = options.regex;
|
|
34
|
+
if (r === undefined) {
|
|
35
|
+
r = options.pcre;
|
|
36
|
+
}
|
|
37
|
+
if (typeof r !== "string") {
|
|
38
|
+
r = r.get();
|
|
39
|
+
}
|
|
40
|
+
if (typeof r === "string") {
|
|
41
|
+
r = ABAPRegExp.convert(r);
|
|
42
|
+
}
|
|
43
|
+
else if (r.constructor.name === "cl_abap_regex") {
|
|
44
|
+
const obj = r;
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
r = obj.mv_pattern.get();
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
if (obj.mv_ignore_case.get() === "X") {
|
|
49
|
+
options.ignoringCase = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw "getRegex(), unexpected input";
|
|
54
|
+
}
|
|
55
|
+
r = r;
|
|
56
|
+
if (r.length === 0 && options.all === true) {
|
|
57
|
+
throw "getRegex(), zero length input";
|
|
58
|
+
}
|
|
59
|
+
return new RegExp(r, "m" + ignoreCase + allOccurrences);
|
|
60
|
+
}
|
|
20
61
|
}
|
|
21
62
|
exports.ABAPRegExp = ABAPRegExp;
|
|
22
63
|
//# sourceMappingURL=abap_regex.js.map
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { ABAPObject, Structure, Table } from "../types";
|
|
2
2
|
import { ICharacter } from "../types/_character";
|
|
3
3
|
import { INumeric } from "../types/_numeric";
|
|
4
|
-
export
|
|
5
|
-
find?: ICharacter | string;
|
|
6
|
-
first?: boolean;
|
|
4
|
+
export type IRegexOptions = {
|
|
7
5
|
regex?: string | ICharacter | ABAPObject;
|
|
8
6
|
pcre?: string | ICharacter;
|
|
7
|
+
all?: boolean;
|
|
8
|
+
ignoringCase?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type IFindOptions = IRegexOptions & {
|
|
11
|
+
find?: ICharacter | string;
|
|
12
|
+
first?: boolean;
|
|
9
13
|
offset?: INumeric;
|
|
10
14
|
sectionOffset?: INumeric;
|
|
11
15
|
byteMode?: boolean;
|
|
12
16
|
length?: INumeric;
|
|
13
17
|
count?: INumeric;
|
|
14
18
|
results?: Table | Structure;
|
|
15
|
-
ignoringCase?: boolean;
|
|
16
19
|
submatches?: ICharacter[];
|
|
17
|
-
}
|
|
20
|
+
};
|
|
18
21
|
export declare function find(input: ICharacter | Table, options: IFindOptions): void;
|
|
@@ -31,39 +31,7 @@ function find(input, options) {
|
|
|
31
31
|
s = new RegExp(s, "g");
|
|
32
32
|
}
|
|
33
33
|
else if (options.regex || options.pcre) {
|
|
34
|
-
|
|
35
|
-
if (typeof options.regex === "string") {
|
|
36
|
-
if (options.regex === "") {
|
|
37
|
-
throw new Error("FIND, runtime, no input, regex empty");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else if (options.regex.get() === "") {
|
|
41
|
-
throw new Error("FIND, runtime, no input, regex empty");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
let r = options.regex;
|
|
45
|
-
if (r === undefined) {
|
|
46
|
-
r = options.pcre;
|
|
47
|
-
}
|
|
48
|
-
if (typeof r !== "string") {
|
|
49
|
-
r = r.get();
|
|
50
|
-
}
|
|
51
|
-
if (typeof r === "string") {
|
|
52
|
-
r = abap_regex_1.ABAPRegExp.convert(r);
|
|
53
|
-
}
|
|
54
|
-
else if (r.constructor.name === "cl_abap_regex") {
|
|
55
|
-
const obj = r;
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
r = obj.mv_pattern.get();
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
if (obj.mv_ignore_case.get() === "X") {
|
|
60
|
-
options.ignoringCase = true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
throw "find(), unexpected input";
|
|
65
|
-
}
|
|
66
|
-
s = new RegExp(r, "gm" + (options.ignoringCase === true ? "i" : ""));
|
|
34
|
+
s = abap_regex_1.ABAPRegExp.getRegex({ all: true, ...options });
|
|
67
35
|
}
|
|
68
36
|
else {
|
|
69
37
|
throw "FIND, runtime, no input";
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { Table } from "../types";
|
|
2
2
|
import { ICharacter } from "../types/_character";
|
|
3
3
|
import { INumeric } from "../types/_numeric";
|
|
4
|
-
|
|
4
|
+
import { IRegexOptions } from "./find";
|
|
5
|
+
export type replaceInput = IRegexOptions & {
|
|
5
6
|
target: ICharacter | Table;
|
|
6
7
|
sectionLength?: INumeric;
|
|
7
8
|
sectionOffset?: INumeric;
|
|
8
9
|
replacementLength?: INumeric;
|
|
9
10
|
replacementCount?: INumeric;
|
|
10
|
-
regex?: ICharacter;
|
|
11
|
-
pcre?: ICharacter;
|
|
12
|
-
all: boolean;
|
|
13
11
|
with: ICharacter;
|
|
14
12
|
of: ICharacter;
|
|
15
|
-
ignoringCase?: boolean;
|
|
16
13
|
};
|
|
17
14
|
export declare function replace(input: replaceInput): void;
|
|
@@ -28,22 +28,8 @@ function replace(input) {
|
|
|
28
28
|
inp = abap_regex_1.ABAPRegExp.escapeRegExp(inp);
|
|
29
29
|
search = new RegExp(inp, ignoreCase + allOccurrences);
|
|
30
30
|
}
|
|
31
|
-
else if (input.regex) {
|
|
32
|
-
|
|
33
|
-
const regex = abap_regex_1.ABAPRegExp.convert(input.regex.get());
|
|
34
|
-
if (regex.length === 0 && input.all === true) {
|
|
35
|
-
throw "REPLACE, zero length input";
|
|
36
|
-
}
|
|
37
|
-
search = new RegExp(regex, ignoreCase + allOccurrences);
|
|
38
|
-
found = temp.match(search) !== null;
|
|
39
|
-
}
|
|
40
|
-
else if (input.pcre) {
|
|
41
|
-
const str = input.pcre.get();
|
|
42
|
-
const regex = abap_regex_1.ABAPRegExp.convert(str);
|
|
43
|
-
if (regex.length === 0 && input.all === true) {
|
|
44
|
-
throw "REPLACE, zero length input";
|
|
45
|
-
}
|
|
46
|
-
search = new RegExp(regex, ignoreCase + allOccurrences);
|
|
31
|
+
else if (input.regex || input.pcre) {
|
|
32
|
+
search = abap_regex_1.ABAPRegExp.getRegex(input);
|
|
47
33
|
found = temp.match(search) !== null;
|
|
48
34
|
}
|
|
49
35
|
else if (input.sectionLength && input.sectionOffset) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/runtime",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.27",
|
|
4
4
|
"description": "Transpiler - Runtime",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"chai": "^4.5.0",
|
|
35
35
|
"mocha": "^11.1.0",
|
|
36
36
|
"source-map-support": "^0.5.21",
|
|
37
|
-
"typescript": "^5.
|
|
37
|
+
"typescript": "^5.8.2"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"temporal-polyfill": "^0.2.5"
|