MCPcopy Create free account
hub / github.com/bitpay/bitcore-message / slowToString

Function slowToString

bitcore-message.js:742–810  ·  view source on GitHub ↗
(encoding, start, end)

Source from the content-addressed store, hash-verified

740Buffer.byteLength = byteLength
741
742function slowToString (encoding, start, end) {
743 var loweredCase = false
744
745 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
746 // property of a typed array.
747
748 // This behaves neither like String nor Uint8Array in that we set start/end
749 // to their upper/lower bounds if the value passed is out of range.
750 // undefined is handled specially as per ECMA-262 6th Edition,
751 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
752 if (start === undefined || start < 0) {
753 start = 0
754 }
755 // Return early if start > this.length. Done here to prevent potential uint32
756 // coercion fail below.
757 if (start > this.length) {
758 return ''
759 }
760
761 if (end === undefined || end > this.length) {
762 end = this.length
763 }
764
765 if (end <= 0) {
766 return ''
767 }
768
769 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
770 end >>>= 0
771 start >>>= 0
772
773 if (end <= start) {
774 return ''
775 }
776
777 if (!encoding) encoding = 'utf8'
778
779 while (true) {
780 switch (encoding) {
781 case 'hex':
782 return hexSlice(this, start, end)
783
784 case 'utf8':
785 case 'utf-8':
786 return utf8Slice(this, start, end)
787
788 case 'ascii':
789 return asciiSlice(this, start, end)
790
791 case 'latin1':
792 case 'binary':
793 return latin1Slice(this, start, end)
794
795 case 'base64':
796 return base64Slice(this, start, end)
797
798 case 'ucs2':
799 case 'ucs-2':

Callers

nothing calls this directly

Calls 6

hexSliceFunction · 0.85
utf8SliceFunction · 0.85
asciiSliceFunction · 0.85
latin1SliceFunction · 0.85
base64SliceFunction · 0.85
utf16leSliceFunction · 0.85

Tested by

no test coverage detected