Skip to content

Commit 5a65774

Browse files
committed
Additional changes to get correct amount of spaces
Signed-off-by: worksofliam <[email protected]>
1 parent 0b747d8 commit 5a65774

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/api/Tools.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,16 @@ export namespace Tools {
105105

106106
headers.forEach(header => {
107107
const fromPos = header.from - slideBytesBy;
108-
const strValue = line.substring(fromPos, fromPos + header.length).trimEnd();
108+
let strValue = line.substring(fromPos, fromPos + header.length);
109109

110-
let realValue: string | number | null = strValue;
110+
const extendedBytes = strValue.split(``).map(c => Buffer.byteLength(c) === 1 ? 0 : 1).reduce((a: number, b: number) => a + b, 0);
111111

112-
slideBytesBy += strValue.split(``).map(c => Buffer.byteLength(c) === 1 ? 0 : 1).reduce((a: number, b: number) => a + b, 0);
112+
slideBytesBy += extendedBytes;
113+
if (extendedBytes > 0) {
114+
strValue = strValue.substring(0, strValue.length - extendedBytes);
115+
}
116+
117+
let realValue: string | number | null = strValue.trimEnd();
113118

114119
// is value a number?
115120
if (strValue.startsWith(` `)) {

src/testing/tools.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const ToolsSuite: TestSuite = {
8585
}
8686
},
8787
{
88-
name: `JP result set test`, test: async () => {
88+
name: `JP result set test (A)`, test: async () => {
8989
const lines = [
9090
`DB2>`,
9191
` ?>`,
@@ -117,6 +117,39 @@ export const ToolsSuite: TestSuite = {
117117
assert.strictEqual(rows[0].CREATED, 1712670631000);
118118
assert.strictEqual(rows[0].CHANGED, 1712683676000);
119119
}
120+
},
121+
{
122+
name: `JP result set test (B)`, test: async () => {
123+
const lines = [
124+
`DB2>`,
125+
` ?>`,
126+
` ?>`,
127+
` ?>`,
128+
` ?>`,
129+
``,
130+
``,
131+
`LIBRARY RECORD_LENGTH ASP SOURCE_FILE NAME TYPE TEXT LINES CREATED CHANGED`,
132+
`--------- -------------------- ------ ------------ ---------- ---------- ------------------------------------------------------------------------------------------------------------------------------ -------------------- -------------------- --------------------`,
133+
`SNDLIB 112 0 QRPGLESRC TESTEDTW RPGLE 日付と時刻を先行0付きで表示-> 8桁では無理? 9 1713451802000 1713453741000`,
134+
``,
135+
` 1 RECORD(S) SELECTED.`,
136+
];
137+
138+
const rows = Tools.db2Parse(lines.join(`\n`));
139+
140+
assert.strictEqual(rows.length, 1);
141+
142+
assert.strictEqual(rows[0].LIBRARY, `SNDLIB`);
143+
assert.strictEqual(rows[0].RECORD_LENGTH, 112);
144+
assert.strictEqual(rows[0].ASP, 0);
145+
assert.strictEqual(rows[0].SOURCE_FILE, `QRPGLESRC`);
146+
assert.strictEqual(rows[0].NAME, `TESTEDTW`);
147+
assert.strictEqual(rows[0].TYPE, `RPGLE`);
148+
assert.strictEqual(rows[0].TEXT, `日付と時刻を先行0付きで表示-> 8桁では無理?`);
149+
assert.strictEqual(rows[0].LINES, 9);
150+
assert.strictEqual(rows[0].CREATED, 1713451802000);
151+
assert.strictEqual(rows[0].CHANGED, 1713453741000);
152+
}
120153
}
121154
]
122155
};

0 commit comments

Comments
 (0)