MCPcopy Create free account
hub / github.com/Code-Bullet/Jump-King / getMacEncodingTable

Function getMacEncodingTable

libraries/p5.js:7032–7075  ·  view source on GitHub ↗
(encoding)

Source from the content-addressed store, hash-verified

7030var macEncodingTableCache = typeof WeakMap === 'function' && new WeakMap();
7031var macEncodingCacheKeys;
7032var getMacEncodingTable = function(encoding) {
7033 // Since we use encoding as a cache key for WeakMap, it has to be
7034 // a String object and not a literal. And at least on NodeJS 2.10.1,
7035 // WeakMap requires that the same String instance is passed for cache hits.
7036 if (!macEncodingCacheKeys) {
7037 macEncodingCacheKeys = {};
7038 for (var e in eightBitMacEncodings) {
7039 /*jshint -W053 */ // Suppress "Do not use String as a constructor."
7040 macEncodingCacheKeys[e] = new String(e);
7041 }
7042 }
7043
7044 var cacheKey = macEncodingCacheKeys[encoding];
7045 if (cacheKey === undefined) {
7046 return undefined;
7047 }
7048
7049 // We can't do "if (cache.has(key)) {return cache.get(key)}" here:
7050 // since garbage collection may run at any time, it could also kick in
7051 // between the calls to cache.has() and cache.get(). In that case,
7052 // we would return 'undefined' even though we do support the encoding.
7053 if (macEncodingTableCache) {
7054 var cachedTable = macEncodingTableCache.get(cacheKey);
7055 if (cachedTable !== undefined) {
7056 return cachedTable;
7057 }
7058 }
7059
7060 var decodingTable = eightBitMacEncodings[encoding];
7061 if (decodingTable === undefined) {
7062 return undefined;
7063 }
7064
7065 var encodingTable = {};
7066 for (var i = 0; i < decodingTable.length; i++) {
7067 encodingTable[decodingTable.charCodeAt(i)] = i + 0x80;
7068 }
7069
7070 if (macEncodingTableCache) {
7071 macEncodingTableCache.set(cacheKey, encodingTable);
7072 }
7073
7074 return encodingTable;
7075};
7076
7077// Encodes an old-style Macintosh string. Returns a byte array upon success.
7078// If the requested encoding is unsupported, or if the input string contains

Callers 1

p5.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected