(input: {offset?: number | INumeric | Hex | Integer8, length?: number | INumeric | Hex | Integer8})
| 65 | public get(): string { |
| 66 | return this.value; |
| 67 | } |
| 68 | |
| 69 | public getOffset(input: {offset?: number | INumeric | Hex | Integer8, length?: number | INumeric | Hex | Integer8}) { |
| 70 | let offset = input?.offset; |
| 71 | if (offset) { |
| 72 | if (offset instanceof Integer8) { |
| 73 | offset = Number(offset.get()); |
| 74 | } else { |
| 75 | offset = parse(offset); |
| 76 | } |
| 77 | if (offset * 2 > this.value.length |
| 78 | || offset < 0) { |
| 79 | throwError("CX_SY_RANGE_OUT_OF_BOUNDS"); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | let length = input?.length; |
| 84 | if (length) { |
| 85 | if (length instanceof Integer8) { |
| 86 | length = Number(length.get()); |
| 87 | } else { |
| 88 | length = parse(length); |
| 89 | } |
| 90 | if (length * 2 > this.value.length |
| 91 | || length < 0) { |
| 92 | throwError("CX_SY_RANGE_OUT_OF_BOUNDS"); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // NOTE: this only copies the minimal length of the string, |
| 97 | if (offset !== undefined && length !== undefined) { |
| 98 | if (offset * 2 + length * 2 > this.value.length) { |
| 99 | throwError("CX_SY_RANGE_OUT_OF_BOUNDS"); |
| 100 | } |
| 101 | return new XString().set(this.value.substr(offset * 2, length * 2)); |
| 102 | } else if (offset !== undefined) { |
| 103 | return new XString().set(this.value.substr(offset * 2)); |
| 104 | } else if (length !== undefined) { |
| 105 | return new XString().set(this.value.substr(0, length * 2)); |
| 106 | } else { |
| 107 | throw new Error("xstring: getOffset, unexpected"); |
| 108 | } |
| 109 | } |
| 110 | } |
nothing calls this directly
no test coverage detected