Tidy.Core.Lexer.ParseEntity C# (CSharp) Method

ParseEntity() public method

public ParseEntity ( short mode ) : void
mode short
return void
        public virtual void ParseEntity(short mode)
        {
            int start;
            bool first = true;
            bool semicolon = false;
            bool numeric = false;
            int c, ch, startcol;

            start = Lexsize - 1; /* to start at "&" */
            startcol = Input.CursorColumn - 1;

            while (true)
            {
                c = Input.ReadChar();
                if (c == StreamIn.END_OF_STREAM)
                {
                    break;
                }
                if (c == ';')
                {
                    semicolon = true;
                    break;
                }

                if (first && c == '#')
                {
                    AddCharToLexer(c);
                    first = false;
                    numeric = true;
                    continue;
                }

                first = false;
                short map = Map((char) c);

                /* AQ: Added flag for numeric entities so that numeric entities
                with missing semi-colons are recognized.
                Eg. "&#114ep..." is recognized as "rep"
                */
                if (numeric && ((c == 'x') || ((map & DIGIT) != 0)))
                {
                    AddCharToLexer(c);
                    continue;
                }
                if (!numeric && ((map & NAMECHAR) != 0))
                {
                    AddCharToLexer(c);
                    continue;
                }

                /* otherwise put it back */

                Input.UngetChar(c);
                break;
            }

            string str = GetString(Lexbuf, start, Lexsize - start);
            ch = EntityTable.DefaultEntityTable.EntityCode(str);

            /* deal with unrecognized entities */
            if (ch <= 0)
            {
                /* set error position just before offending chararcter */
                Lines = Input.CursorLine;
                Columns = startcol;

                if (Lexsize > start + 1)
                {
                    Report.EntityError(this, Report.UNKNOWN_ENTITY, str, ch);

                    if (semicolon)
                        AddCharToLexer(';');
                }
                    /* naked & */
                else
                {
                    Report.EntityError(this, Report.UNESCAPED_AMPERSAND, str, ch);
                }
            }
            else
            {
                if (c != ';')
                    /* issue warning if not terminated by ';' */
                {
                    /* set error position just before offending chararcter */
                    Lines = Input.CursorLine;
                    Columns = startcol;
                    Report.EntityError(this, Report.MISSING_SEMICOLON, str, c);
                }

                Lexsize = start;

                if (ch == 160 && (mode & PREFORMATTED) != 0)
                    ch = ' ';

                AddCharToLexer(ch);

                if (ch == '&' && !Options.QuoteAmpersand)
                {
                    AddCharToLexer('a');
                    AddCharToLexer('m');
                    AddCharToLexer('p');
                    AddCharToLexer(';');
                }
            }
        }