System.Xml.XmlUtf8RawTextWriter.WriteCDataSection C# (CSharp) Méthode

WriteCDataSection() protected méthode

protected WriteCDataSection ( string text ) : void
text string
Résultat void
        protected unsafe void WriteCDataSection( string text ) {
            // write text
            fixed ( char * pSrcBegin = text )
            fixed ( byte * pDstBegin = bufBytes ) {
                char * pSrc = pSrcBegin;
                char * pSrcEnd = pSrcBegin + text.Length;
                byte * pDst = pDstBegin + bufPos;

                int ch = 0;
                for (;;) {
                    byte * pDstEnd = pDst + ( pSrcEnd - pSrc );
                    if ( pDstEnd > pDstBegin + bufLen ) {
                        pDstEnd = pDstBegin + bufLen;
                    }


                    while ( pDst < pDstEnd && ( ( ( xmlCharType.charProperties[( ch = *pSrc )] & XmlCharType.fAttrValue ) != 0 ) && ch != ']' && ch <= 0x7F ) ) {



                        *pDst = (byte)ch;
                        pDst++;
                        pSrc++;
                    }

                    Debug.Assert( pSrc <= pSrcEnd );

                    // end of value
                    if ( pSrc >= pSrcEnd ) {
                        break;
                    }

                    // end of buffer
                    if ( pDst >= pDstEnd ) {
                        bufPos = (int)(pDst - pDstBegin);
                        FlushBuffer();
                        pDst = pDstBegin + 1;
                        continue;
                    }

                    // handle special characters
                    switch ( ch ) {
                        case '>':
                            if ( hadDoubleBracket && pDst[-1] == (byte) ']') {   // pDst[-1] will always correct - there is a padding character at _BUFFER[0]
                                // The characters "]]>" were found within the CData text
                                pDst = RawEndCData( pDst );
                                pDst = RawStartCData( pDst );
                            }
                            *pDst = (byte) '>';
                            pDst++;
                            break;
                        case ']':
                            if ( pDst[-1] == (byte)']' ) {   // pDst[-1] will always correct - there is a padding character at _BUFFER[0]
                                hadDoubleBracket = true;
                            }
                            else {
                                hadDoubleBracket = false;
                            }
                            *pDst = (byte)']';
                            pDst++;
                            break;
                        case (char)0xD:
                            if ( newLineHandling == NewLineHandling.Replace ) {
                                // Normalize "\r\n", or "\r" to NewLineChars
                                if ( pSrc[1] == '\n' ) {
                                    pSrc++;
                                }
                                pDst = WriteNewLine( pDst );
                            }
                            else {
                                *pDst = (byte)ch;
                                pDst++;
                            }
                            break;
                        case (char)0xA:
                            if ( newLineHandling == NewLineHandling.Replace ) {
                                pDst = WriteNewLine( pDst );
                            }
                            else {
                                *pDst = (byte)ch;
                                pDst++;
                            }
                            break;
                        case '&':
                        case '<':
                        case '"':
                        case '\'':
                        case (char)0x9:
                            *pDst = (byte)ch;
                            pDst++;
                            break;
                        default:
                            if ( InRange( ch, SurHighStart, SurLowEnd ) ) { pDst = EncodeSurrogate( pSrc, pSrcEnd, pDst ); pSrc += 2; } else if ( ch <= 0x7F || ch >= 0xFFFE ) { pDst = InvalidXmlChar( ch, pDst, false ); pSrc++; } else { pDst = EncodeMultibyteUTF8( ch, pDst ); pSrc++; };
                            continue;
                    }
                    pSrc++;
                }
                bufPos = (int)(pDst - pDstBegin);
            }
        }