* @param {number} offset * @return {ContentString}
(offset)
| 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 |