コード例 #1
0
        public static DecodedChar DecodeCurrentChar(CharacterStream cs)
        {
            if (AtUnicodeEscape(cs))
            {
                // Find out how many hex chars are part of the encoded char
                int startPos = cs.Position;
                SkipUnicodeEscape(cs);

                int endPos = cs.Position;
                cs.Position = startPos;

                // Convert the hex characters into an integer
                int encodedLength = endPos - startPos;
                int decodedChar   = 0;

                for (int i = 1; i < encodedLength; i++)
                {
                    char ch = cs.Peek(i);

                    if (TextHelper.IsHexDigit(ch))
                    {
                        decodedChar *= 16;

                        if (char.IsDigit(ch))
                        {
                            decodedChar += ch - '0';
                        }
                        else
                        {
                            decodedChar += char.ToLowerInvariant(ch) - 'a' + 10;
                        }
                    }
                    else
                    {
                        Debug.Assert(char.IsWhiteSpace(ch));
                        break;
                    }
                }

                return(new DecodedChar(decodedChar, encodedLength));
            }
            else if (AtEscape(cs))
            {
                return(new DecodedChar(cs.Peek(1), 2));
            }

            return(new DecodedChar(cs.CurrentChar, 1));
        }
コード例 #2
0
        public static bool SkipWhitespaceReverse(CharacterStream cs)
        {
            int start = cs.Position;

            while (TextHelper.IsWhiteSpace(cs.Peek(-1)))
            {
                cs.Advance(-1);
            }

            return(start != cs.Position);
        }
コード例 #3
0
        public static bool AtEscapedNewLine(CharacterStream cs)
        {
            if (cs.CurrentChar == '\\')
            {
                switch (cs.Peek(1))
                {
                case '\r':
                case '\n':
                case '\f':
                    return(true);

                default:
                    return(false);
                }
            }

            return(false);
        }
コード例 #4
0
 public static bool AtUnicodeEscape(CharacterStream cs)
 {
     return(cs.CurrentChar == '\\' && TextHelper.IsHexDigit(cs.Peek(1)));
 }