Esempio n. 1
0
        public IContent Splice(int offset)
        {
            var right = new ContentString(_content.GetRange(offset, _content.Count - offset));

            _content.RemoveRange(offset, _content.Count - offset);

            // Prevent encoding invalid documents because of splitting of surrogate pairs.
            var firstCharCode = (char)_content[offset - 1];

            if (firstCharCode >= 0xD800 && firstCharCode <= 0xDBFF)
            {
                // Last character of the left split is the start of a surrogate utf16/ucs2 pair.
                // We don't support splitting of surrogate pairs because this may lead to invalid documents.
                // Replace the invalid character with a unicode replacement character U+FFFD.
                _content[offset - 1] = '\uFFFD';

                // Replace right as well.
                right._content[0] = '\uFFFD';
            }

            return(right);
        }
Esempio n. 2
0
        public static IContent ReadItemContent(IUpdateDecoder decoder, byte info)
        {
            switch (info & Bits.Bits5)
            {
            case 0:     // GC
                throw new Exception("GC is not ItemContent");

            case 1:     // Deleted
                return(ContentDeleted.Read(decoder));

            case 2:     // JSON
                return(ContentJson.Read(decoder));

            case 3:     // Binary
                return(ContentBinary.Read(decoder));

            case 4:     // String
                return(ContentString.Read(decoder));

            case 5:     // Embed
                return(ContentEmbed.Read(decoder));

            case 6:     // Format
                return(ContentFormat.Read(decoder));

            case 7:     // Type
                return(ContentType.Read(decoder));

            case 8:     // Any
                return(ContentAny.Read(decoder));

            case 9:     // Doc
                return(ContentDoc.Read(decoder));

            default:
                throw new InvalidOperationException($"Content type not recognized: {info}");
            }
        }