From 88b93fbd4d1650408eba4980a3ebc462c83c44ef Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 21 Jul 2025 22:59:46 +0200 Subject: [PATCH] Mon 21 Jul 22:43:21 CEST 2025 --- js/x11/core/xutil.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 js/x11/core/xutil.js diff --git a/js/x11/core/xutil.js b/js/x11/core/xutil.js new file mode 100644 index 0000000..d75b2b6 --- /dev/null +++ b/js/x11/core/xutil.js @@ -0,0 +1,29 @@ +function padded_length(len) +{ + return ((len + 3) >> 2) << 2; + /* + var rem = len % 4; + var pl = len; + if (rem) + return len + 4 - rem; + return len; + */ +} + +// TODO: make it return buffer? +// str += is slow +function padded_string(str) +{ + if (str.length == 0) + return ''; + + var pad = padded_length(str.length) - str.length; + var res = str; + for (var i=0; i < pad; ++i) + res += String.fromCharCode(0); + + return res; +} + +module.exports.padded_length = padded_length; +module.exports.padded_string = padded_string;