MCPcopy Index your code
hub / github.com/stemkoski/stemkoski.github.com / _hexWrite

Function _hexWrite

MathBox/mathbox-core.js:1129–1155  ·  view source on GitHub ↗
(buf, string, offset, length)

Source from the content-addressed store, hash-verified

1127// =======================
1128
1129function _hexWrite (buf, string, offset, length) {
1130 offset = Number(offset) || 0
1131 var remaining = buf.length - offset
1132 if (!length) {
1133 length = remaining
1134 } else {
1135 length = Number(length)
1136 if (length > remaining) {
1137 length = remaining
1138 }
1139 }
1140
1141 // must be an even number of digits
1142 var strLen = string.length
1143 assert(strLen % 2 === 0, 'Invalid hex string')
1144
1145 if (length > strLen / 2) {
1146 length = strLen / 2
1147 }
1148 for (var i = 0; i < length; i++) {
1149 var byte = parseInt(string.substr(i * 2, 2), 16)
1150 assert(!isNaN(byte), 'Invalid hex string')
1151 buf[offset + i] = byte
1152 }
1153 Buffer._charsWritten = i * 2
1154 return i
1155}
1156
1157function _utf8Write (buf, string, offset, length) {
1158 var charsWritten = Buffer._charsWritten =

Callers 1

mathbox-core.jsFile · 0.70

Calls 2

isNaNFunction · 0.85
assertFunction · 0.70

Tested by

no test coverage detected