fix printf to include trailing content

This commit is contained in:
DavidVentura
2024-01-26 17:25:17 +01:00
parent 2e1d761e28
commit 784fc27a20
+4 -1
View File
@@ -13,13 +13,16 @@ export const sprintf = (str, values) => {
// => // =>
// asd, line 20, ... // asd, line 20, ...
const matches = str.matchAll(replacy); const matches = str.matchAll(replacy);
return [...matches] let lastScanned = 0;
const s = [...matches]
.map((m, idx) => { .map((m, idx) => {
const cur = values[idx]; const cur = values[idx];
const val = m.groups.formatter == "x" ? `0x${cur.toString(16)}` : cur.toString(); const val = m.groups.formatter == "x" ? `0x${cur.toString(16)}` : cur.toString();
lastScanned = m.index + m[0].length;
return m.groups.pre + val; return m.groups.pre + val;
}) })
.join(""); .join("");
return s + str.slice(lastScanned);
}; };
export const u16_swap = (x) => ((x & 0xff00) >> 8) | ((x & 0x00ff) << 8); export const u16_swap = (x) => ((x & 0xff00) >> 8) | ((x & 0x00ff) << 8);
export const swap_endianness_u16 = (ptr) => { export const swap_endianness_u16 = (ptr) => {