Ejemplo n.º 1
0
 public StateHolder(TextNavigator navigator)
     : this()
 {
     _navigator = navigator;
     _column    = navigator._column;
     _line      = navigator._line;
     Position   = navigator._position;
 }
Ejemplo n.º 2
0
        public static string Decode
        (
            [CanBeNull] string text
        )
        {
            if (ReferenceEquals(text, null) || text.Length == 0)
            {
                return(text);
            }

            int length = text.Length;

            StringBuilder result    = new StringBuilder(length);
            TextNavigator navigator = new TextNavigator(text);

            while (!navigator.IsEOF)
            {
                string chunk = navigator.ReadUntil('\\');
                result.Append(chunk);
                char prefix = navigator.ReadChar();
                if (prefix != '\\')
                {
                    break;
                }
                char c = navigator.ReadChar();
                if (c == '\0')
                {
                    result.Append(prefix);
                    break;
                }
                if (c != 'u')
                {
                    result.Append(prefix);
                    result.Append(c);
                    continue;
                }
                StringBuilder buffer = new StringBuilder();
                while (!navigator.IsEOF)
                {
                    c = navigator.ReadChar();
                    if (!char.IsDigit(c))
                    {
                        break;
                    }
                    buffer.Append(c);
                }
                if (buffer.Length != 0)
                {
                    c = (char)int.Parse(buffer.ToString());
                    result.Append(c);
                }
            }

            return(result.ToString());
        }
Ejemplo n.º 3
0
        public TextNavigator Clone()
        {
            var result = new TextNavigator(_text)
            {
                _column   = _column,
                _line     = _line,
                _position = _position
            };

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public TextPosition
        (
            [NotNull] TextNavigator navigator
        )
        {
            Sure.NotNull(navigator, nameof(navigator));

            Column   = navigator.Column;
            Line     = navigator.Line;
            Position = navigator.Position;
        }
Ejemplo n.º 5
0
        public static TextNavigator FromFile
        (
            [NotNull] string fileName
        )
        {
            Sure.FileExists(fileName, nameof(fileName));

            string        text   = File.ReadAllText(fileName, Encoding.UTF8);
            TextNavigator result = new TextNavigator(text);

            return(result);
        }
Ejemplo n.º 6
0
        public static TextNavigator FromFile
        (
            string fileName,
            Encoding?encoding = default
        )
        {
            // Sure.FileExists(fileName, nameof(fileName));

            encoding ??= Encoding.UTF8;
            var text   = File.ReadAllText(fileName, encoding);
            var result = new TextNavigator(text);

            return(result);
        }