@abaplint/runtime
Version:
Transpiler - Runtime
104 lines • 3.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.concatenate = concatenate;
const types_1 = require("../types");
function concatenate(input) {
if (input.byteMode === true) {
concatenateByteMode(input);
return;
}
let sep = "";
if (input.separatedBy) {
if (typeof input.separatedBy === "string" || typeof input.separatedBy === "number") {
sep = input.separatedBy.toString();
}
else {
sep = input.separatedBy.get().toString();
}
}
if (input.lines === true) {
let result = "";
const tab = input.source[0];
if (tab instanceof types_1.Table) {
const array = tab.array();
const length = array.length;
const respectingBlanks = input.respectingBlanks === true;
const hasSeparator = sep.length > 0;
for (let i = 0; i < length; i++) {
if (hasSeparator === true && i > 0) {
result += sep;
}
const value = array[i].get();
result += respectingBlanks === true ? value : value.trimEnd();
}
}
input.target.set(result);
}
else {
let result = "";
for (const source of input.source) {
let val = "";
if (source instanceof types_1.Table) {
throw new Error("concatenate, error: input is table");
}
else if (typeof source === "string" || typeof source === "number") {
val = source.toString();
}
else if (source instanceof types_1.Character) {
if (input.respectingBlanks !== true) {
val = source.getTrimEnd();
}
else {
val = source.get();
}
}
else {
val = source.get().toString();
}
result += val + sep;
}
if (sep.length > 0 && result.length > 0) {
result = result.slice(0, result.length - sep.length);
}
input.target.set(result);
}
}
function rawByteValue(source) {
if (typeof source === "string") {
return source;
}
else if (typeof source === "number") {
return source.toString();
}
else {
return source.get().toString();
}
}
function concatenateByteMode(input) {
let sep = "";
if (input.separatedBy !== undefined) {
sep = rawByteValue(input.separatedBy);
}
let result = "";
if (input.lines === true) {
const tab = input.source[0];
if (tab instanceof types_1.Table) {
for (const l of tab.array()) {
result += l.get().toString() + sep;
}
}
}
else {
for (const source of input.source) {
if (source instanceof types_1.Table) {
throw new Error("concatenate, error: input is table");
}
result += rawByteValue(source) + sep;
}
}
if (sep.length > 0 && result.length > 0) {
result = result.slice(0, result.length - sep.length);
}
input.target.set(result);
}
//# sourceMappingURL=concatenate.js.map