Example #1
0
 private int GetGreaterThanCharEntity(int offset, int length)
 {
     byte[] buffer = _buffer;
     if (length != 4 ||
         buffer[offset + 1] != (byte)'g' ||
         buffer[offset + 2] != (byte)'t')
     {
         XmlExceptionHelper.ThrowInvalidCharRef(_reader);
     }
     return((int)'>');
 }
Example #2
0
 private int GetAmpersandCharEntity(int offset, int length)
 {
     byte[] buffer = _buffer;
     if (length != 5 ||
         buffer[offset + 1] != (byte)'a' ||
         buffer[offset + 2] != (byte)'m' ||
         buffer[offset + 3] != (byte)'p')
     {
         XmlExceptionHelper.ThrowInvalidCharRef(_reader);
     }
     return((int)'&');
 }
Example #3
0
 private int GetApostropheCharEntity(int offset, int length)
 {
     byte[] buffer = _buffer;
     if (length != 6 ||
         buffer[offset + 1] != (byte)'a' ||
         buffer[offset + 2] != (byte)'p' ||
         buffer[offset + 3] != (byte)'o' ||
         buffer[offset + 4] != (byte)'s')
     {
         XmlExceptionHelper.ThrowInvalidCharRef(_reader);
     }
     return((int)'\'');
 }
Example #4
0
 private int GetQuoteCharEntity(int offset, int length)
 {
     byte[] buffer = _buffer;
     if (length != 6 ||
         buffer[offset + 1] != (byte)'q' ||
         buffer[offset + 2] != (byte)'u' ||
         buffer[offset + 3] != (byte)'o' ||
         buffer[offset + 4] != (byte)'t')
     {
         XmlExceptionHelper.ThrowInvalidCharRef(_reader);
     }
     return((int)'"');
 }
Example #5
0
        public int GetCharEntity(int offset, int length)
        {
            if (length < 3)
            {
                XmlExceptionHelper.ThrowInvalidCharRef(_reader);
            }
            byte[] buffer = _buffer;
            DiagnosticUtility.DebugAssert(buffer[offset] == '&', "");
            DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', "");
            switch (buffer[offset + 1])
            {
            case (byte)'l':
                return(GetLessThanCharEntity(offset, length));

            case (byte)'g':
                return(GetGreaterThanCharEntity(offset, length));

            case (byte)'a':
                if (buffer[offset + 2] == (byte)'m')
                {
                    return(GetAmpersandCharEntity(offset, length));
                }
                else
                {
                    return(GetApostropheCharEntity(offset, length));
                }

            case (byte)'q':
                return(GetQuoteCharEntity(offset, length));

            case (byte)'#':
                if (buffer[offset + 2] == (byte)'x')
                {
                    return(GetHexCharEntity(offset, length));
                }
                else
                {
                    return(GetDecimalCharEntity(offset, length));
                }

            default:
                XmlExceptionHelper.ThrowInvalidCharRef(_reader);
                return(0);
            }
        }
Example #6
0
        private int GetHexCharEntity(int offset, int length)
        {
            byte[] buffer = _buffer;
            DiagnosticUtility.DebugAssert(buffer[offset + 0] == '&', "");
            DiagnosticUtility.DebugAssert(buffer[offset + 1] == '#', "");
            DiagnosticUtility.DebugAssert(buffer[offset + 2] == 'x', "");
            DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', "");
            int value = 0;

            for (int i = 3; i < length - 1; i++)
            {
                byte ch    = buffer[offset + i];
                int  digit = 0;
                if (ch >= '0' && ch <= '9')
                {
                    digit = (ch - '0');
                }
                else if (ch >= 'a' && ch <= 'f')
                {
                    digit = 10 + (ch - 'a');
                }
                else if (ch >= 'A' && ch <= 'F')
                {
                    digit = 10 + (ch - 'A');
                }
                else
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(_reader);
                }
                DiagnosticUtility.DebugAssert(digit >= 0 && digit < 16, "");
                value = value * 16 + digit;
                if (value > SurrogateChar.MaxValue)
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(_reader);
                }
            }
            return(value);
        }
Example #7
0
        private int GetDecimalCharEntity(int offset, int length)
        {
            byte[] buffer = _buffer;
            DiagnosticUtility.DebugAssert(buffer[offset + 0] == '&', "");
            DiagnosticUtility.DebugAssert(buffer[offset + 1] == '#', "");
            DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', "");
            int value = 0;

            for (int i = 2; i < length - 1; i++)
            {
                byte ch = buffer[offset + i];
                if (ch < (byte)'0' || ch > (byte)'9')
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(_reader);
                }
                value = value * 10 + (ch - '0');
                if (value > SurrogateChar.MaxValue)
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(_reader);
                }
            }
            return(value);
        }