src/Markdig/Helpers/HtmlHelper.cs
/// <summary>
/// Scans an entity.
/// Returns number of chars matched.
/// </summary>
Scans an entity.
Returns number of chars matched.
Scans an entity . Returns number of chars matched .
public static int ScanEntity<T>(T slice, out int numericEntity, out int namedEntityStart,  out int namedEntityLength) where T : ICharIterator
        {
            numericEntity = 0;
            namedEntityStart = 0;
            namedEntityLength = 0;
            if (slice.CurrentChar != '&' || slice.PeekChar(3) == '\0')
            {
                return 0;
            }
            var start = slice.Start;
            char c = slice.NextChar();
            int counter = 0;
            if (c == '#')
            {
                c = slice.PeekChar();
                if ((c | 0x20) == 'x')
                {
                    c = slice.NextChar(); 
                    while (c != '\0')
                    {
                        c = slice.NextChar();
                        if (c.IsDigit())
                        {
                            if (++counter == 7) return 0;
                            numericEntity = numericEntity * 16 + (c - '0');
                            continue;
                        }
                        else if ((uint)((c - 'A') & ~0x20) <= ('F' - 'A'))
                        {
                            if (++counter == 7) return 0;
                            numericEntity = numericEntity * 16 + ((c | 0x20) - 'a' + 10);
                            continue;
                        }
                        if (c == ';')
                            return counter == 0 ? 0 : slice.Start - start + 1;
                        return 0;
                    }
                }
                else
                {
                    while (c != '\0')
                    {
                        c = slice.NextChar();
                        if (c.IsDigit())
                        {
                            if (++counter == 8) return 0;
                            numericEntity = numericEntity * 10 + (c - '0');
                            continue;
                        }
                        if (c == ';')
                            return counter == 0 ? 0 : slice.Start - start + 1;
                        return 0;
                    }
                }
            }
            else
            {
                if (!c.IsAlpha())
                    return 0;
                namedEntityStart = slice.Start;
                namedEntityLength++;
                while (c != '\0')
                {
                    c = slice.NextChar();
                    if (c.IsAlphaNumeric())
                    {
                        if (++counter == 32)
                            return 0;
                        namedEntityLength++;
                        continue;
                    }
                    if (c == ';')
                    {
                        return counter == 0 ? 0 : slice.Start - start + 1;
                    }
                    return 0;
                }
            }
            return 0;
        }
public static int ScanEntity < T > ( T slice , out int numericEntity , out int namedEntityStart , out int namedEntityLength ) where T : ICharIterator { numericEntity = 0 ; namedEntityStart = 0 ; namedEntityLength = 0 ; if ( slice . CurrentChar != ' ' || slice . PeekChar ( 3 ) == ' \0 ' ) { return 0 ; } var start = slice . Start ; char c = slice . NextChar ( ) ; int counter = 0 ; if ( c == ' ' ) { c = slice . PeekChar ( ) ; if ( ( c | 0x20 ) == ' ' ) { c = slice . NextChar ( ) ; while ( c != ' \0 ' ) { c = slice . NextChar ( ) ; if ( c . IsDigit ( ) ) { if ( ++ counter == 7 ) return 0 ; numericEntity = numericEntity * 16 + ( c - ' ' ) ; continue ; } else if ( ( uint ) ( ( c - ' ' ) & ~ 0x20 ) <= ( ' ' - ' ' ) ) { if ( ++ counter == 7 ) return 0 ; numericEntity = numericEntity * 16 + ( ( c | 0x20 ) - ' ' + 10 ) ; continue ; } if ( c == ' ' ) return counter == 0 ? 0 : slice . Start - start + 1 ; return 0 ; } } else { while ( c != ' \0 ' ) { c = slice . NextChar ( ) ; if ( c . IsDigit ( ) ) { if ( ++ counter == 8 ) return 0 ; numericEntity = numericEntity * 10 + ( c - ' ' ) ; continue ; } if ( c == ' ' ) return counter == 0 ? 0 : slice . Start - start + 1 ; return 0 ; } } } else { if ( ! c . IsAlpha ( ) ) return 0 ; namedEntityStart = slice . Start ; namedEntityLength ++ ; while ( c != ' \0 ' ) { c = slice . NextChar ( ) ; if ( c . IsAlphaNumeric ( ) ) { if ( ++ counter == 32 ) return 0 ; namedEntityLength ++ ; continue ; } if ( c == ' ' ) { return counter == 0 ? 0 : slice . Start - start + 1 ; } return 0 ; } } return 0 ; }
Scans an entity.
Scans an entity .
// Credits: code from CommonMark.NET // Copyright (c) 2014, Kārlis Gaņģis All rights reserved.  // See license for details:  https://github.com/Knagis/CommonMark.NET/blob/master/LICENSE.md // skip # // expect 1-6 hex digits starting from pos+3 // expect 1-7 digits starting from pos+2 // expect a letter and 1-31 letters or digits
slice
T
int
out