1(function () { 2 window.wflsi18n = { 3 __: function(text) { 4 if (window.WordfenceLSI18nStrings && text in window.WordfenceLSI18nStrings) { 5 return window.WordfenceLSI18nStrings[text]; 6 } 7 return text; 8 }, 9 _n: function(singular, plural, count) { 10 if (count === 1) { 11 return window.wflsi18n.__(singular); 12 } 13 return window.wflsi18n.__(plural); 14 } 15 }; 16 17 if (typeof wp === 'object' && wp.i18n) { 18 window.wflsi18n.sprintf = wp.i18n.sprintf; 19 return; 20 } 21 22 /** 23 * Code has been adapted from WordPress' i18n.js functions and is being used as a polyfill for WordPress 24 * versions before 5.0. 25 */ 26 var re = { 27 not_string: /[^s]/, 28 not_bool: /[^t]/, 29 not_type: /[^T]/, 30 not_primitive: /[^v]/, 31 number: /[diefg]/, 32 numeric_arg: /[bcdiefguxX]/, 33 json: /[j]/, 34 not_json: /[^j]/, 35 text: /^[^\x25]+/, 36 modulo: /^\x25{2}/, 37 placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/, 38 key: /^([a-z_][a-z_\d]*)/i, 39 key_access: /^\.([a-z_][a-z_\d]*)/i, 40 index_access: /^\[(\d+)\]/, 41 sign: /^[+-]/ 42 }; 43 44 function sprintf(key) { 45 // `arguments` is not an array, but should be fine for this call 46 return sprintf_format(sprintf_parse(key), arguments) 47 } 48 49 function vsprintf(fmt, argv) { 50 return sprintf.apply(null, [fmt].concat(argv || [])) 51 } 52 53 function sprintf_format(parse_tree, argv) { 54 var cursor = 1, tree_length = parse_tree.length, arg, output = '', i, k, ph, pad, pad_character, pad_length, is_positive, sign 55 for (i = 0; i < tree_length; i++) { 56 if (typeof parse_tree[i] === 'string') { 57 output += parse_tree[i] 58 } 59 else if (typeof parse_tree[i] === 'object') { 60 ph = parse_tree[i] // convenience purposes only 61 if (ph.keys) { // keyword argument 62 arg = argv[cursor] 63 for (k = 0; k < ph.keys.length; k++) { 64 if (arg == undefined) { 65 throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k-1])) 66 } 67 arg = arg[ph.keys[k]] 68 } 69 } 70 else if (ph.param_no) { // positional argument (explicit) 71 arg = argv[ph.param_no] 72 } 73 else { // positional argument (implicit) 74 arg = argv[cursor++] 75 } 76 77 if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) { 78 arg = arg() 79 } 80 81 if (re.numeric_arg.test(ph.type) && (typeof arg !== 'number' && isNaN(arg))) { 82 throw new TypeError(sprintf('[sprintf] expecting number but found %T', arg)) 83 } 84 85 if (re.number.test(ph.type)) { 86 is_positive = arg >= 0 87 } 88 89 switch (ph.type) { 90 case 'b': 91 arg = parseInt(arg, 10).toString(2) 92 break 93 case 'c': 94 arg = String.fromCharCode(parseInt(arg, 10)) 95 break 96 case 'd': 97 case 'i': 98 arg = parseInt(arg, 10) 99 break 100 case 'j': 101 arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0) 102 break 103 case 'e': 104 arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential() 105 break 106 case 'f': 107 arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg) 108 break 109 case 'g': 110 arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg) 111 break 112 case 'o': 113 arg = (parseInt(arg, 10) >>> 0).toString(8) 114 break 115 case 's': 116 arg = String(arg) 117 arg = (ph.precision ? arg.substring(0, ph.precision) : arg) 118 break 119 case 't': 120 arg = String(!!arg) 121 arg = (ph.precision ? arg.substring(0, ph.precision) : arg) 122 break 123 case 'T': 124 arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase() 125 arg = (ph.precision ? arg.substring(0, ph.precision) : arg) 126 break 127 case 'u': 128 arg = parseInt(arg, 10) >>> 0 129 break 130 case 'v': 131 arg = arg.valueOf() 132 arg = (ph.precision ? arg.substring(0, ph.precision) : arg) 133 break 134 case 'x': 135 arg = (parseInt(arg, 10) >>> 0).toString(16) 136 break 137 case 'X': 138 arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase() 139 break 140 } 141 if (re.json.test(ph.type)) { 142 output += arg 143 } 144 else { 145 if (re.number.test(ph.type) && (!is_positive || ph.sign)) { 146 sign = is_positive ? '+' : '-' 147 arg = arg.toString().replace(re.sign, '') 148 } 149 else { 150 sign = '' 151 } 152 pad_character = ph.pad_char ? ph.pad_char === '0' ? '0' : ph.pad_char.charAt(1) : ' ' 153 pad_length = ph.width - (sign + arg).length 154 pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : '' 155 output += ph.align ? sign + arg + pad : (pad_character === '0' ? sign + pad + arg : pad + sign + arg) 156 } 157 } 158 } 159 return output 160 } 161 162 var sprintf_cache = Object.create(null) 163 164 function sprintf_parse(fmt) { 165 if (sprintf_cache[fmt]) { 166 return sprintf_cache[fmt] 167 } 168 169 var _fmt = fmt, match, parse_tree = [], arg_names = 0 170 while (_fmt) { 171 if ((match = re.text.exec(_fmt)) !== null) { 172 parse_tree.push(match[0]) 173 } 174 else if ((match = re.modulo.exec(_fmt)) !== null) { 175 parse_tree.push('%') 176 } 177 else if ((match = re.placeholder.exec(_fmt)) !== null) { 178 if (match[2]) { 179 arg_names |= 1 180 var field_list = [], replacement_field = match[2], field_match = [] 181 if ((field_match = re.key.exec(replacement_field)) !== null) { 182 field_list.push(field_match[1]) 183 while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { 184 if ((field_match = re.key_access.exec(replacement_field)) !== null) { 185 field_list.push(field_match[1]) 186 } 187 else if ((field_match = re.index_access.exec(replacement_field)) !== null) { 188 field_list.push(field_match[1]) 189 } 190 else { 191 throw new SyntaxError('[sprintf] failed to parse named argument key') 192 } 193 } 194 } 195 else { 196 throw new SyntaxError('[sprintf] failed to parse named argument key') 197 } 198 match[2] = field_list 199 } 200 else { 201 arg_names |= 2 202 } 203 if (arg_names === 3) { 204 throw new Error('[sprintf] mixing positional and named placeholders is not (yet) supported') 205 } 206 207 parse_tree.push( 208 { 209 placeholder: match[0], 210 param_no: match[1], 211 keys: match[2], 212 sign: match[3], 213 pad_char: match[4], 214 align: match[5], 215 width: match[6], 216 precision: match[7], 217 type: match[8] 218 } 219 ) 220 } 221 else { 222 throw new SyntaxError('[sprintf] unexpected placeholder') 223 } 224 _fmt = _fmt.substring(match[0].length) 225 } 226 return sprintf_cache[fmt] = parse_tree 227 } 228 229 window.wflsi18n.sprintf = sprintf; 230})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.