Esempio n. 1
0
        private bool ProcessHexString(CharReader charReader)
        {
            if (charReader.PeekChar() != '<')
            {
                return(false);
            }
            FlushTokenBuffer();
            charReader.ReadChar();
            var textBuilder = new StringBuilder();

            while (true)
            {
                var character = charReader.ReadChar();
                if (character == '>')
                {
                    OnToken?.Invoke(TokenType.HexString, textBuilder.ToString());
                    return(true);
                }
                else if (character == '\0')
                {
                    throw new Exception("Unexpected end of data.");
                }
                else if (IsBaseX(character, 16))
                {
                    textBuilder.Append(character);
                }
                else if (IsWhitespace(character))
                {
                    // Skip new line
                }
                else
                {
                    throw new Exception("Invalid hex charcter.");
                }
            }
        }
Esempio n. 2
0
        private bool ProcessXPacket(CharReader charReader)
        {
            if (!charReader.PeekLine().Equals("<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"))
            {
                return(false);
            }
            FlushTokenBuffer();
            charReader.ReadLine();
            var textBuilder = new StringBuilder();

            while (true)
            {
                var line = charReader.ReadLine();
                if (line.Equals("<?xpacket end=\"w\"?>"))
                {
                    OnToken?.Invoke(TokenType.XPacket, textBuilder.ToString());
                    return(true);
                }
                else if (!string.IsNullOrEmpty(line))
                {
                    textBuilder.AppendLine(line);
                }
            }
        }
Esempio n. 3
0
        private bool ProcessString(CharReader charReader)
        {
            if (charReader.PeekChar() != '(')
            {
                return(false);
            }
            int bracketCount = 1;

            FlushTokenBuffer();
            charReader.ReadChar();
            var textBuilder = new StringBuilder();

            while (true)
            {
                var character = charReader.ReadChar();
                if (character == '\\')
                {
                    var peekedChar = charReader.PeekChar();
                    if (IsBaseX(peekedChar, 8))
                    {
                        var octalString = GetOctalString(charReader);
                        textBuilder.Append(octalString);
                        continue;
                    }
                    if (peekedChar == '\\' || peekedChar == '(' || peekedChar == ')')
                    {
                        textBuilder.Append(charReader.ReadChar());
                        continue;
                    }
                    if (peekedChar == 'n')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\n');
                        continue;
                    }
                    if (peekedChar == 'r')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\r');
                        continue;
                    }
                    if (peekedChar == 't')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\t');
                        continue;
                    }
                    if (peekedChar == 'b')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\b');
                        continue;
                    }
                    if (peekedChar == 'f')
                    {
                        charReader.ReadChar();
                        textBuilder.Append('\f');
                        continue;
                    }
                    throw new Exception("Unexpected escape code.");
                }
                else if (character == '(')
                {
                    bracketCount++;
                }
                else if (character == ')' && bracketCount > 1)
                {
                    bracketCount--;
                }
                else if (character == ')' && bracketCount == 1)
                {
                    OnToken?.Invoke(TokenType.String, textBuilder.ToString());
                    return(true);
                }
                else if (character == '\0')
                {
                    throw new Exception("Unexpected end of data.");
                }
                textBuilder.Append(character);
            }
        }