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

Function utf8border

static/word2md/mammoth.browser.js:13827–13846  ·  view source on GitHub ↗
(buf, max)

Source from the content-addressed store, hash-verified

13825// buf[] - utf8 bytes array
13826// max - length limit (mandatory);
13827var utf8border = function(buf, max) {
13828 var pos;
13829
13830 max = max || buf.length;
13831 if (max > buf.length) { max = buf.length; }
13832
13833 // go back from last position, until start of sequence found
13834 pos = max-1;
13835 while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
13836
13837 // Fuckup - very small and broken sequence,
13838 // return max, because we should return something anyway.
13839 if (pos < 0) { return max; }
13840
13841 // If we came to start of buffer - that means vuffer is too small,
13842 // return max too.
13843 if (pos === 0) { return max; }
13844
13845 return (pos + _utf8len[buf[pos]] > max) ? pos : max;
13846};
13847
13848// convert array to string
13849var buf2string = function (buf) {

Callers 1

mammoth.browser.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected