@abaplint/runtime
Version:
Transpiler - Runtime
99 lines • 3.25 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.String = void 0;
const _parse_1 = require("../operators/_parse");
const throw_error_1 = require("../throw_error");
const character_1 = require("./character");
const field_symbol_1 = require("./field_symbol");
const integer_1 = require("./integer");
const packed_1 = require("./packed");
const structure_1 = require("./structure");
const float_1 = require("./float");
class String {
constructor(input) {
this.value = "";
this.qualifiedName = input?.qualifiedName;
}
clone() {
const n = new String({ qualifiedName: this.qualifiedName });
n.value = this.value;
return n;
}
getQualifiedName() {
return this.qualifiedName;
}
set(value) {
if (value instanceof field_symbol_1.FieldSymbol) {
if (value.getPointer() === undefined) {
throw new Error("GETWA_NOT_ASSIGNED");
}
return this.set(value.getPointer());
}
else if (typeof value === "string") {
this.value = value;
}
else if (typeof value === "number") {
this.value = value.toString();
}
else if (value instanceof character_1.Character) {
// replace trailing blanks if the source is a Character string
this.value = value.getTrimEnd();
}
else if (value instanceof structure_1.Structure) {
this.value = value.getCharacter().trimEnd();
}
else if (value instanceof packed_1.Packed) {
const lv_sign = value.get() >= 0 ? " " : "-";
this.value = Math.abs(value.get()).toFixed(value.getDecimals());
this.value += lv_sign;
}
else if (value instanceof integer_1.Integer) {
const lv_sign = value.get() >= 0 ? " " : "-";
this.value = Math.abs(value.get()) + "";
this.value += lv_sign;
}
else if (value instanceof float_1.Float) {
this.value = value.get() + "";
this.value = this.value.replace(",", ".");
}
else {
this.value = value.get() + "";
}
return this;
}
clear() {
this.value = "";
}
get() {
return this.value;
}
getOffset(input) {
let offset = input?.offset;
if (offset) {
offset = (0, _parse_1.parse)(offset);
}
let length = input?.length;
if (length) {
length = (0, _parse_1.parse)(length);
}
if ((offset && offset > this.value.length)
|| (length && length > this.value.length)
|| (offset && length && offset + length > this.value.length)
|| (offset && offset < 0)
|| (length && length < 0)) {
(0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
}
let ret = this.value;
if (offset) {
ret = ret.substr(offset);
}
if (length !== undefined) {
ret = ret.substr(0, length);
}
const r = new String();
r.set(ret);
return r;
}
}
exports.String = String;
//# sourceMappingURL=string.js.map