private int GetHexCharEntity(int offset, int length)
        {
            byte[] buffer = this.buffer;
            int    num    = 0;

            for (int i = 3; i < (length - 1); i++)
            {
                byte num3 = buffer[offset + i];
                int  num4 = 0;
                if ((num3 >= 0x30) && (num3 <= 0x39))
                {
                    num4 = num3 - 0x30;
                }
                else if ((num3 >= 0x61) && (num3 <= 0x66))
                {
                    num4 = 10 + (num3 - 0x61);
                }
                else if ((num3 >= 0x41) && (num3 <= 70))
                {
                    num4 = 10 + (num3 - 0x41);
                }
                else
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(this.reader);
                }
                num = (num * 0x10) + num4;
                if (num > 0x10ffff)
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(this.reader);
                }
            }
            return(num);
        }
示例#2
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 = HexConverter.FromChar(ch);
                if (digit == 0xFF)
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(_reader);
                }
                DiagnosticUtility.DebugAssert(digit >= 0 && digit < 16, "");
                value = value * 16 + digit;
                if (value > SurrogateChar.MaxValue)
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(_reader);
                }
            }
            return(value);
        }
        public int GetCharEntity(int offset, int length)
        {
            if (length < 3)
            {
                XmlExceptionHelper.ThrowInvalidCharRef(this.reader);
            }
            byte[] buffer = this.buffer;
            switch (buffer[offset + 1])
            {
            case 0x67:
                return(this.GetGreaterThanCharEntity(offset, length));

            case 0x6c:
                return(this.GetLessThanCharEntity(offset, length));

            case 0x71:
                return(this.GetQuoteCharEntity(offset, length));

            case 0x23:
                if (buffer[offset + 2] == 120)
                {
                    return(this.GetHexCharEntity(offset, length));
                }
                return(this.GetDecimalCharEntity(offset, length));

            case 0x61:
                if (buffer[offset + 2] == 0x6d)
                {
                    return(this.GetAmpersandCharEntity(offset, length));
                }
                return(this.GetApostropheCharEntity(offset, length));
            }
            XmlExceptionHelper.ThrowInvalidCharRef(this.reader);
            return(0);
        }
 private int GetQuoteCharEntity(int offset, int length)
 {
     byte[] buffer = this.buffer;
     if (((length != 6) || (buffer[offset + 1] != 0x71)) || (((buffer[offset + 2] != 0x75) || (buffer[offset + 3] != 0x6f)) || (buffer[offset + 4] != 0x74)))
     {
         XmlExceptionHelper.ThrowInvalidCharRef(this.reader);
     }
     return(0x22);
 }
 private int GetLessThanCharEntity(int offset, int length)
 {
     byte[] buffer = this.buffer;
     if (((length != 4) || (buffer[offset + 1] != 0x6c)) || (buffer[offset + 2] != 0x74))
     {
         XmlExceptionHelper.ThrowInvalidCharRef(this.reader);
     }
     return(60);
 }
 private int GetAmpersandCharEntity(int offset, int length)
 {
     byte[] buffer = this.buffer;
     if (((length != 5) || (buffer[offset + 1] != 0x61)) || ((buffer[offset + 2] != 0x6d) || (buffer[offset + 3] != 0x70)))
     {
         XmlExceptionHelper.ThrowInvalidCharRef(this.reader);
     }
     return(0x26);
 }
示例#7
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)'>');
 }
示例#8
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)'&');
 }
示例#9
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)'\'');
 }
示例#10
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)'"');
 }
示例#11
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);
            }
        }
        private int GetDecimalCharEntity(int offset, int length)
        {
            byte[] buffer = this.buffer;
            int    num    = 0;

            for (int i = 2; i < (length - 1); i++)
            {
                byte num3 = buffer[offset + i];
                if ((num3 < 0x30) || (num3 > 0x39))
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(this.reader);
                }
                num = (num * 10) + (num3 - 0x30);
                if (num > 0x10ffff)
                {
                    XmlExceptionHelper.ThrowInvalidCharRef(this.reader);
                }
            }
            return(num);
        }
示例#13
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);
        }
示例#14
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);
        }