MCPcopy
hub / github.com/yjs/yjs / splice

Method splice

src/structs/ContentString.js:51–66  ·  view source on GitHub ↗

* @param {number} offset * @return {ContentString}

(offset)

Source from the content-addressed store, hash-verified

49 * @return {ContentString}
50 */
51 splice (offset) {
52 const right = new ContentString(this.str.slice(offset))
53 this.str = this.str.slice(0, offset)
54
55 // Prevent encoding invalid documents because of splitting of surrogate pairs: https://github.com/yjs/yjs/issues/248
56 const firstCharCode = this.str.charCodeAt(offset - 1)
57 if (firstCharCode >= 0xD800 && firstCharCode <= 0xDBFF) {
58 // Last character of the left split is the start of a surrogate utf16/ucs2 pair.
59 // We don't support splitting of surrogate pairs because this may lead to invalid documents.
60 // Replace the invalid character with a unicode replacement character (� / U+FFFD)
61 this.str = this.str.slice(0, offset - 1) + '�'
62 // replace right as well
63 right.str = '�' + right.str.slice(1)
64 }
65 return right
66 }
67
68 /**
69 * @param {ContentString} right

Callers

nothing calls this directly

Calls 1

sliceMethod · 0.45

Tested by

no test coverage detected