MCPcopy Create free account
hub / github.com/TruthHun/BookStack / hexWrite

Function hexWrite

static/word2md/mammoth.browser.js:10475–10500  ·  view source on GitHub ↗
(buf, string, offset, length)

Source from the content-addressed store, hash-verified

10473}
10474
10475function hexWrite (buf, string, offset, length) {
10476 offset = Number(offset) || 0
10477 var remaining = buf.length - offset
10478 if (!length) {
10479 length = remaining
10480 } else {
10481 length = Number(length)
10482 if (length > remaining) {
10483 length = remaining
10484 }
10485 }
10486
10487 // must be an even number of digits
10488 var strLen = string.length
10489 if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
10490
10491 if (length > strLen / 2) {
10492 length = strLen / 2
10493 }
10494 for (var i = 0; i < length; ++i) {
10495 var parsed = parseInt(string.substr(i * 2, 2), 16)
10496 if (isNaN(parsed)) return i
10497 buf[offset + i] = parsed
10498 }
10499 return i
10500}
10501
10502function utf8Write (buf, string, offset, length) {
10503 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)

Callers 1

mammoth.browser.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected