private static byte[] _ParseText
        (
            TextReader reader
        )
        {
            List <byte> table = new List <byte>(182);

            string        text      = reader.ReadToEnd();
            TextNavigator navigator = new TextNavigator(text);

            while (true)
            {
                if (!navigator.SkipWhitespace())
                {
                    break;
                }

                string s = navigator.ReadInteger();
                if (string.IsNullOrEmpty(s))
                {
                    throw new IrbisException("Bad Alphabet table");
                }

                byte value = byte.Parse(s);
                table.Add(value);
            }

            if (table.Count < 1)
            {
                throw new IrbisException("Bad alphabet table");
            }

            return(table.ToArray());
        }
Пример #2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public TextPosition
 (
     [NotNull] TextNavigator navigator
 )
 {
     Column   = navigator.Column;
     Line     = navigator.Line;
     Position = navigator.Position;
 }
Пример #3
0
        public static TextNavigator FromFile
        (
            [NotNull] string fileName
        )
        {
            string        text   = File.ReadAllText(fileName);
            TextNavigator result = new TextNavigator(text);

            return(result);
        }
Пример #4
0
        public TextNavigator Clone()
        {
            TextNavigator result = new TextNavigator(_text)
            {
                _column   = _column,
                _length   = _length,
                _line     = _line,
                _position = _position
            };

            return(result);
        }
Пример #5
0
        public static string RemoveComments
        (
            [CanBeNull] string text
        )
        {
            const char ZERO = '\0';

            if (string.IsNullOrEmpty(text))
            {
                return(text);
            }

            if (!text.Contains("/*"))
            {
                return(text);
            }

            StringBuilder result    = new StringBuilder(text.Length);
            TextNavigator navigator = new TextNavigator(text);
            char          state     = ZERO;

            while (!navigator.IsEOF)
            {
                char c = navigator.ReadChar();

                switch (state)
                {
                case '\'':
                    if (c == '\'')
                    {
                        state = ZERO;
                    }
                    result.Append(c);
                    break;

                case '"':
                    if (c == '"')
                    {
                        state = ZERO;
                    }
                    result.Append(c);
                    break;

                case '|':
                    if (c == '|')
                    {
                        state = ZERO;
                    }
                    result.Append(c);
                    break;

                default:
                    if (c == '/')
                    {
                        if (navigator.PeekChar() == '*')
                        {
                            navigator.ReadTo('\r', '\n');
                        }
                        else
                        {
                            result.Append(c);
                        }
                    }
                    else if (c == '\'' || c == '"' || c == '|')
                    {
                        state = c;
                        result.Append(c);
                    }
                    else
                    {
                        result.Append(c);
                    }
                    break;
                }
            }

            return(result.ToString());
        }