@abaplint/runtime 2.3.107 → 2.3.108

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.
@@ -5,6 +5,7 @@ export interface IFindInput {
5
5
  val: ICharacter | string;
6
6
  sub?: ICharacter | string;
7
7
  off?: INumeric | number;
8
+ occ?: INumeric | number;
8
9
  regex?: ICharacter | string;
9
10
  case?: ICharacter | string;
10
11
  }
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.find = void 0;
4
+ const throw_error_1 = require("../throw_error");
4
5
  const types_1 = require("../types");
5
6
  function find(input) {
6
- var _a, _b, _c, _d;
7
- const val = typeof input.val === "string" ? input.val : input.val.get();
7
+ var _a, _b, _c, _d, _e;
8
+ let val = typeof input.val === "string" ? input.val : input.val.get();
8
9
  if (input.regex) {
9
10
  const caseInput = typeof input.case === "string" ? input.case : (_a = input.case) === null || _a === void 0 ? void 0 : _a.get();
10
11
  const regex = typeof input.regex === "string" ? input.regex : input.regex.get();
@@ -20,8 +21,30 @@ function find(input) {
20
21
  }
21
22
  else {
22
23
  const sub = typeof input.sub === "string" ? input.sub : (_c = input.sub) === null || _c === void 0 ? void 0 : _c.get();
23
- const off = typeof input.off === "number" ? input.off : (_d = input.off) === null || _d === void 0 ? void 0 : _d.get();
24
- const found = val.indexOf(sub || "", off);
24
+ let off = typeof input.off === "number" ? input.off : ((_d = input.off) === null || _d === void 0 ? void 0 : _d.get()) || 0;
25
+ let occ = typeof input.occ === "number" ? input.occ : (_e = input.occ) === null || _e === void 0 ? void 0 : _e.get();
26
+ if (occ === 0) {
27
+ (0, throw_error_1.throwError)("CX_SY_STRG_PAR_VAL");
28
+ }
29
+ else if (occ === undefined) {
30
+ occ = 1;
31
+ }
32
+ let negative = false;
33
+ if (occ < 0) {
34
+ negative = true;
35
+ val = val.split("").reverse().join("");
36
+ occ = Math.abs(occ);
37
+ }
38
+ let found = -1;
39
+ for (let i = 0; i < occ; i++) {
40
+ found = val.indexOf(sub || "", off);
41
+ if (found > 0) {
42
+ off = off + found + 1;
43
+ }
44
+ }
45
+ if (negative === true && found > 0) {
46
+ found = val.length - found - 1;
47
+ }
25
48
  return new types_1.Integer().set(found);
26
49
  }
27
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.3.107",
3
+ "version": "2.3.108",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",