MCPcopy Index your code
hub / github.com/OneNoteDev/WebClipper / hexWrite

Function hexWrite

lib/sanitize-html.js:1379–1404  ·  view source on GitHub ↗
(buf, string, offset, length)

Source from the content-addressed store, hash-verified

1377}
1378
1379function hexWrite (buf, string, offset, length) {
1380 offset = Number(offset) || 0
1381 var remaining = buf.length - offset
1382 if (!length) {
1383 length = remaining
1384 } else {
1385 length = Number(length)
1386 if (length > remaining) {
1387 length = remaining
1388 }
1389 }
1390
1391 // must be an even number of digits
1392 var strLen = string.length
1393 if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
1394
1395 if (length > strLen / 2) {
1396 length = strLen / 2
1397 }
1398 for (var i = 0; i < length; ++i) {
1399 var parsed = parseInt(string.substr(i * 2, 2), 16)
1400 if (isNaN(parsed)) return i
1401 buf[offset + i] = parsed
1402 }
1403 return i
1404}
1405
1406function utf8Write (buf, string, offset, length) {
1407 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)

Callers 1

sanitize-html.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected