MCPcopy Create free account
hub / github.com/GNOME/gjs / getEncodingFromLabel

Function getEncodingFromLabel

modules/esm/_encoding/encodingMap.js:271–305  ·  view source on GitHub ↗
(label)

Source from the content-addressed store, hash-verified

269 * @returns {Encoding | null}
270 */
271export function getEncodingFromLabel(label) {
272 const formattedLabel = trimAsciiWhitespace(label.toLowerCase());
273
274 let canonicalLabel = encodings.get(formattedLabel);
275
276 // Lookup an internal mapping using the canonical name, if found, or
277 // the formatted label otherwise.
278 //
279 // x-mac-ukrainian > x-mac-cyrillic > MacCyrillic
280 // (canonical label) (internal label)
281 //
282 // big5-hkscs > undefined > big5-hkscs
283 // (canonical label) (internal label)
284 //
285 let internalLabel = internalEncodings.get(
286 canonicalLabel ?? formattedLabel
287 );
288
289 // If both the canonical label and the internal encoding
290 // are not found, this encoding is unsupported.
291 if (!canonicalLabel && !internalLabel)
292 return null;
293
294 if (internalLabel) {
295 return {
296 label: canonicalLabel ?? formattedLabel,
297 internalLabel,
298 };
299 }
300
301 return {
302 label: canonicalLabel,
303 internalLabel: canonicalLabel,
304 };
305}

Callers 1

constructorMethod · 0.90

Calls 2

trimAsciiWhitespaceFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected