Mon 21 Jul 22:43:21 CEST 2025
This commit is contained in:
parent
3515d21d27
commit
88b93fbd4d
29
js/x11/core/xutil.js
Normal file
29
js/x11/core/xutil.js
Normal file
|
@ -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;
|
Loading…
Reference in New Issue
Block a user