MCPcopy Index your code
hub / github.com/nodejs/node / getEncodingOps

Function getEncodingOps

lib/buffer.js:787–835  ·  view source on GitHub ↗
(encoding)

Source from the content-addressed store, hash-verified

785 },
786};
787function getEncodingOps(encoding) {
788 encoding += '';
789 switch (encoding.length) {
790 case 4:
791 if (encoding === 'utf8') return encodingOps.utf8;
792 if (encoding === 'ucs2') return encodingOps.ucs2;
793 encoding = StringPrototypeToLowerCase(encoding);
794 if (encoding === 'utf8') return encodingOps.utf8;
795 if (encoding === 'ucs2') return encodingOps.ucs2;
796 break;
797 case 5:
798 if (encoding === 'utf-8') return encodingOps.utf8;
799 if (encoding === 'ascii') return encodingOps.ascii;
800 if (encoding === 'ucs-2') return encodingOps.ucs2;
801 encoding = StringPrototypeToLowerCase(encoding);
802 if (encoding === 'utf-8') return encodingOps.utf8;
803 if (encoding === 'ascii') return encodingOps.ascii;
804 if (encoding === 'ucs-2') return encodingOps.ucs2;
805 break;
806 case 7:
807 if (encoding === 'utf16le' ||
808 StringPrototypeToLowerCase(encoding) === 'utf16le')
809 return encodingOps.utf16le;
810 break;
811 case 8:
812 if (encoding === 'utf-16le' ||
813 StringPrototypeToLowerCase(encoding) === 'utf-16le')
814 return encodingOps.utf16le;
815 break;
816 case 6:
817 if (encoding === 'latin1' || encoding === 'binary')
818 return encodingOps.latin1;
819 if (encoding === 'base64') return encodingOps.base64;
820 encoding = StringPrototypeToLowerCase(encoding);
821 if (encoding === 'latin1' || encoding === 'binary')
822 return encodingOps.latin1;
823 if (encoding === 'base64') return encodingOps.base64;
824 break;
825 case 3:
826 if (encoding === 'hex' || StringPrototypeToLowerCase(encoding) === 'hex')
827 return encodingOps.hex;
828 break;
829 case 9:
830 if (encoding === 'base64url' ||
831 StringPrototypeToLowerCase(encoding) === 'base64url')
832 return encodingOps.base64url;
833 break;
834 }
835}
836
837function byteLength(string, encoding) {
838 if (typeof string !== 'string') {

Callers 4

fromStringFunction · 0.85
byteLengthFunction · 0.85
buffer.jsFile · 0.85
bidirectionalIndexOfFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…