System.Xml.XmlTextReaderImpl.ParseNamedCharRefInline C# (CSharp) Méthode

ParseNamedCharRefInline() private méthode

private ParseNamedCharRefInline ( int startPos, bool expand, StringBuilder internalSubsetBuilder ) : int
startPos int
expand bool
internalSubsetBuilder StringBuilder
Résultat int
        private int ParseNamedCharRefInline(int startPos, bool expand, StringBuilder internalSubsetBuilder)
        {
            Debug.Assert(startPos < _ps.charsUsed);
            Debug.Assert(_ps.chars[startPos] == '&');
            Debug.Assert(_ps.chars[startPos + 1] != '#');

            int pos = startPos + 1;
            char[] chars = _ps.chars;
            char ch;

            switch (chars[pos])
            {
                // &apos; or &amp; 
                case 'a':
                    pos++;
                    // &amp;
                    if (chars[pos] == 'm')
                    {
                        if (_ps.charsUsed - pos >= 3)
                        {
                            if (chars[pos + 1] == 'p' && chars[pos + 2] == ';')
                            {
                                pos += 3;
                                ch = '&';
                                goto FoundCharRef;
                            }
                            else
                            {
                                return -1;
                            }
                        }
                    }
                    // &apos;
                    else if (chars[pos] == 'p')
                    {
                        if (_ps.charsUsed - pos >= 4)
                        {
                            if (chars[pos + 1] == 'o' && chars[pos + 2] == 's' &&
                                    chars[pos + 3] == ';')
                            {
                                pos += 4;
                                ch = '\'';
                                goto FoundCharRef;
                            }
                            else
                            {
                                return -1;
                            }
                        }
                    }
                    else if (pos < _ps.charsUsed)
                    {
                        return -1;
                    }
                    break;
                // &guot;
                case 'q':
                    if (_ps.charsUsed - pos >= 5)
                    {
                        if (chars[pos + 1] == 'u' && chars[pos + 2] == 'o' &&
                                chars[pos + 3] == 't' && chars[pos + 4] == ';')
                        {
                            pos += 5;
                            ch = '"';
                            goto FoundCharRef;
                        }
                        else
                        {
                            return -1;
                        }
                    }
                    break;
                // &lt;
                case 'l':
                    if (_ps.charsUsed - pos >= 3)
                    {
                        if (chars[pos + 1] == 't' && chars[pos + 2] == ';')
                        {
                            pos += 3;
                            ch = '<';
                            goto FoundCharRef;
                        }
                        else
                        {
                            return -1;
                        }
                    }
                    break;
                // &gt;
                case 'g':
                    if (_ps.charsUsed - pos >= 3)
                    {
                        if (chars[pos + 1] == 't' && chars[pos + 2] == ';')
                        {
                            pos += 3;
                            ch = '>';
                            goto FoundCharRef;
                        }
                        else
                        {
                            return -1;
                        }
                    }
                    break;
                default:
                    return -1;
            }

            // need more data in the buffer
            return -2;

        FoundCharRef:
            Debug.Assert(pos > 0);
            if (expand)
            {
                if (internalSubsetBuilder != null)
                {
                    internalSubsetBuilder.Append(_ps.chars, _ps.charPos, pos - _ps.charPos);
                }
                _ps.chars[pos - 1] = ch;
            }
            return pos;
        }
XmlTextReaderImpl