Exemplo n.º 1
0
        // Read from in-memory string as UTF8 characters.
        public HZincReader(string instr)
        {
            MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(instr));

            m_instrm    = mStrm;
            m_tokenizer = new HaystackTokenizer(new StreamReader(mStrm));
            init();
        }
Exemplo n.º 2
0
        //////////////////////////////////////////////////////////////////////////
        // Construction
        //////////////////////////////////////////////////////////////////////////

        // Read from UTF-8 input stream.
        public HZincReader(Stream instrm)
        {
            try
            {
                m_instrm    = instrm;
                m_tokenizer = new HaystackTokenizer(new StreamReader(instrm, Encoding.UTF8));
                init();
            }
            catch (IOException e)
            {
                err("init failed", e);
            }
        }
Exemplo n.º 3
0
        private HaystackToken ReadNumber()
        {
            string strDecNumSep = _numberFormat.NumberDecimalSeparator;
            char   cNumSep      = '.';

            if (strDecNumSep.Length == 1)
            {
                cNumSep = strDecNumSep[0];
            }
            bool bHex = false;

            if (_currentChar < 0)
            {
                err("unexpected eof in num");
            }
            if (!(_currentChar < 0 || _peekChar < 0))
            {
                // hex number (no unit allowed)
                bHex = (char)_currentChar == '0' && (char)_peekChar == 'x';
            }
            bool bExit = false;

            if (bHex)
            {
                consume('0');
                consume('x');
                StringBuilder sb01 = new StringBuilder();
                bExit = false;
                while (!bExit)
                {
                    if (HaystackTokenizer.isHex(_currentChar))
                    {
                        sb01.Append((char)_currentChar);
                        consume();
                    }
                    else if (_currentChar == '_')
                    {
                        consume();
                    }
                    else
                    {
                        bExit = true;
                    }
                }
                _currentValue = new HaystackNumber(long.Parse(sb01.ToString(), NumberStyles.AllowHexSpecifier));
                return(HaystackToken.num);
            }
            // consume all things that might be part of this number token
            var builder = new StringBuilder().Append((char)_currentChar);

            consume();
            int  colons    = 0;
            int  dashes    = 0;
            int  unitIndex = 0;
            bool exp       = false;

            bExit = false;
            while (!bExit)
            {
                if (_currentChar >= 0) // Check for eof
                {
                    if (!char.IsDigit((char)_currentChar))
                    {
                        if (exp && (_currentChar == '+' || _currentChar == '-'))
                        {
                        }
                        else if (_currentChar == '-')
                        {
                            ++dashes;
                        }
                        else if ((_peekChar >= 0) && (_currentChar == ':') && (char.IsDigit((char)_peekChar)))
                        {
                            ++colons;
                        }
                        else if ((exp || colons >= 1) && _currentChar == '+')
                        {
                        }
                        else if (_currentChar == cNumSep)
                        {
                            if (_peekChar >= 0)
                            {
                                if (!char.IsDigit((char)_peekChar))
                                {
                                    break;
                                }
                            }
                        }
                        else if ((_peekChar >= 0) && (((char)_currentChar == 'e' || (char)_currentChar == 'E') && ((char)_peekChar == '-' || (char)_peekChar == '+' || char.IsDigit((char)_peekChar))))
                        {
                            exp = true;
                        }
                        else if (char.IsLetter((char)_currentChar) || _currentChar == '%' || _currentChar == '$' || _currentChar == '/' || _currentChar > 128)
                        {
                            if (unitIndex == 0)
                            {
                                unitIndex = builder.Length;
                            }
                        }
                        else if ((_peekChar >= 0) && (_currentChar == '_'))
                        {
                            if (unitIndex == 0 && char.IsDigit((char)_peekChar))
                            {
                                consume();
                                continue;
                            }
                            else
                            {
                                if (unitIndex == 0)
                                {
                                    unitIndex = builder.Length;
                                }
                            }
                        }
                        else
                        {
                            bExit = true;
                        }
                    }
                }
                else
                {
                    bExit = true;
                }
                if (!bExit)
                {
                    builder.Append((char)_currentChar);
                    consume();
                }
            }

            if (dashes == 2 && colons == 0)
            {
                return(date(builder.ToString()));
            }
            if (dashes == 0 && colons >= 1)
            {
                return(time(builder, colons == 1));
            }
            if (dashes >= 2)
            {
                return(dateTime(builder));
            }
            return(number(builder.ToString(), unitIndex));
        }
 public ZincReader(Stream stream)
 {
     _tokenizer = new HaystackTokenizer(new StreamReader(stream, Encoding.UTF8));
     Init();
 }
Exemplo n.º 5
0
        private HaystackToken num()
        {
            string strDecNumSep = m_numberFormat.NumberDecimalSeparator;
            char   cNumSep      = '.';

            if (strDecNumSep.Length == 1)
            {
                cNumSep = strDecNumSep[0];
            }
            bool bHex = false;

            if (m_cCur < 0)
            {
                err("unexpected eof in num");
            }
            if (!(m_cCur < 0 || m_cPeek < 0))
            {
                // hex number (no unit allowed)
                bHex = (char)m_cCur == '0' && (char)m_cPeek == 'x';
            }
            bool bExit = false;

            if (bHex)
            {
                consume('0');
                consume('x');
                StringBuilder sb01 = new StringBuilder();
                bExit = false;
                while (!bExit)
                {
                    if (HaystackTokenizer.isHex(m_cCur))
                    {
                        sb01.Append((char)m_cCur);
                        consume();
                    }
                    else if (m_cCur == '_')
                    {
                        consume();
                    }
                    else
                    {
                        bExit = true;
                    }
                }
                m_val = HNum.make(Int64.Parse(sb01.ToString(), System.Globalization.NumberStyles.AllowHexSpecifier));
                return(HaystackToken.num);
            }
            // consume all things that might be part of this number token
            StringBuilder s = new StringBuilder().Append((char)m_cCur);

            consume();
            int  colons    = 0;
            int  dashes    = 0;
            int  unitIndex = 0;
            bool exp       = false;

            bExit = false;
            while (!bExit)
            {
                if (m_cCur >= 0) // Check for eof
                {
                    if (!char.IsDigit((char)m_cCur))
                    {
                        if (exp && (m_cCur == '+' || m_cCur == '-'))
                        {
                        }
                        else if (m_cCur == '-')
                        {
                            ++dashes;
                        }
                        else if ((m_cPeek >= 0) && (m_cCur == ':') && (char.IsDigit((char)m_cPeek)))
                        {
                            ++colons;
                        }
                        else if ((exp || colons >= 1) && m_cCur == '+')
                        {
                        }
                        else if (m_cCur == cNumSep)
                        {
                            if (m_cPeek >= 0)
                            {
                                if (!char.IsDigit((char)m_cPeek))
                                {
                                    break;
                                }
                            }
                        }
                        else if ((m_cPeek >= 0) && (((char)m_cCur == 'e' || (char)m_cCur == 'E') && ((char)m_cPeek == '-' || (char)m_cPeek == '+' || char.IsDigit((char)m_cPeek))))
                        {
                            exp = true;
                        }
                        else if (char.IsLetter((char)m_cCur) || m_cCur == '%' || m_cCur == '$' || m_cCur == '/' || m_cCur > 128)
                        {
                            if (unitIndex == 0)
                            {
                                unitIndex = s.Length;
                            }
                        }
                        else if ((m_cPeek >= 0) && (m_cCur == '_'))
                        {
                            if (unitIndex == 0 && char.IsDigit((char)m_cPeek))
                            {
                                consume();
                                continue;
                            }
                            else
                            {
                                if (unitIndex == 0)
                                {
                                    unitIndex = s.Length;
                                }
                            }
                        }
                        else
                        {
                            bExit = true;
                        }
                    }
                }
                else
                {
                    bExit = true;
                }
                if (!bExit)
                {
                    s.Append((char)m_cCur);
                    consume();
                }
            }

            if (dashes == 2 && colons == 0)
            {
                return(date(s.ToString()));
            }
            if (dashes == 0 && colons >= 1)
            {
                return(time(s, colons == 1));
            }
            if (dashes >= 2)
            {
                return(dateTime(s));
            }
            return(number(s.ToString(), unitIndex));
        }