This commit is contained in:
jow-
2026-05-28 08:43:18 +00:00
parent ae193a3a04
commit 9f73a4d57d
3 changed files with 127 additions and 95 deletions
File diff suppressed because one or more lines are too long
+39 -7
View File
@@ -677,25 +677,58 @@ String.prototype.format = function()
return s;
}
const dicts = [];
for (let i = 0; i < arguments.length; i++)
if (arguments[i] !== null && typeof(arguments[i]) === 'object' && !Array.isArray(arguments[i]))
dicts.push(arguments[i]);
let str = this;
let subst, n, pad;
let out = '';
const re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t|m))/;
const re_named = /^(([^%]*)%\{([^}:]+)(?::('.|0|\x20)?(-)?(\d+)?(\.\d+)?(b|c|d|u|f|o|s|x|X|q|h|j|t|m))?\})/;
let a = [], numSubstitutions = 0;
while ((a = re.exec(str)) !== null) {
while (true) {
const an = re_named.exec(str);
a = an || re.exec(str);
if (!a)
break;
const m = a[1];
let leftpart = a[2], pPad = a[3], pJustify = a[4], pMinLength = a[5];
let pPrecision = a[6], pType = a[7];
let leftpart = a[2], pPad, pJustify, pMinLength, pPrecision, pType;
let precision;
let param;
if (an) {
pPad = a[4]; pJustify = a[5]; pMinLength = a[6];
pPrecision = a[7]; pType = a[8] || 's';
param = '';
for (let i = 0; i < dicts.length; i++) {
if (Object.prototype.hasOwnProperty.call(dicts[i], a[3])) {
param = dicts[i][a[3]];
break;
}
}
}
else {
pPad = a[3]; pJustify = a[4]; pMinLength = a[5];
pPrecision = a[6]; pType = a[7];
if (pType == '%') {
subst = '%';
out += leftpart + subst;
str = str.substr(m.length);
continue;
}
else {
if (numSubstitutions < arguments.length) {
let param = arguments[numSubstitutions++];
if (numSubstitutions < arguments.length)
param = arguments[numSubstitutions++];
}
if (param !== undefined) {
pad = '';
if (pPad && pPad.substr(0,1) == "'")
pad = pPad.substr(1,1);
@@ -805,7 +838,6 @@ String.prototype.format = function()
break;
}
}
}
if (pMinLength) {
subst = subst.toString();
File diff suppressed because one or more lines are too long