<commit_before>﻿using System;
using System.Diagnostics.CodeAnalysis;

namespace SF.Strings
{
    /// <summary>
    ///     Useful class for string parsing
    /// </summary>
    [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
    public class StringParser : ICloneable
    {
        private int _index;
        private readonly string _text;
        private int _length;

        public StringParser(string text)
        {
            if (text == null)
                throw new ArgumentNullException(nameof(text));
            _text = text;
            _length = text.Length;
        }

        private StringParser(string text, int length)
        {
            _text = text;
            _length = length;
        }

        public int Length => _length;

        public string Text => _text;

        public int Index
        {
            get { return _index; }
            set { _index = Math.Max(0, Math.Min(value, _length)); }
        }

        public bool End => _index == _length;

        public bool Start => _index == 0;

        public string View => _text.Substring(0, _length);
        
        public string Right => End ? string.Empty : _text.Substring(_index, _length - _index);

        public string Left => Start ? string.Empty : _text.Left(_index);

        public int CharactersLeft => _length - _index;

        object ICloneable.Clone()
        {
            return Clone();
        }

        public void Reset()
        {
            _index = 0;
        }

        public StringParser Skip(int count)
        {
            _index = (_index + count).Clip(0, _length);
            return this;
        }

        public StringParser Back(int count)
        {
            return Skip(-count);
        }

        public StringParser SkipTo(string str)
        {
            if (str == null)
                throw new ArgumentNullException(nameof(str));
            if (End)
                return this;
            var pos = _text.IndexOf(str, _index, CharactersLeft, StringComparison.Ordinal);
            _index = pos < 0 ? _length : pos;
            return this;
        }

        public StringParser SkipTo(char c)
        {
            if (End)
                return this;
            var pos = _text.IndexOf(c, _index, CharactersLeft);<commit_msg>Fixed reset<commit_after>﻿using System;
using System.Diagnostics.CodeAnalysis;

namespace SF.Strings
{
    /// <summary>
    ///     Useful class for string parsing
    /// </summary>
    [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
    public class StringParser : ICloneable
    {
        private int _index;
        private readonly string _text;
        private int _length;

        public StringParser(string text)
        {
            if (text == null)
                throw new ArgumentNullException(nameof(text));
            _text = text;
            _length = text.Length;
        }

        private StringParser(string text, int length)
        {
            _text = text;
            _length = length;
        }

        public int Length => _length;

        public string Text => _text;

        public int Index
        {
            get { return _index; }
            set { _index = Math.Max(0, Math.Min(value, _length)); }
        }

        public bool End => _index == _length;

        public bool Start => _index == 0;

        public string View => _text.Substring(0, _length);
        
        public string Right => End ? string.Empty : _text.Substring(_index, _length - _index);

        public string Left => Start ? string.Empty : _text.Left(_index);

        public int CharactersLeft => _length - _index;

        object ICloneable.Clone()
        {
            return Clone();
        }

        public void Reset()
        {
            _index = 0;
            _length = _text.Length;
        }

        public StringParser Skip(int count)
        {
            _index = (_index + count).Clip(0, _length);
            return this;
        }

        public StringParser Back(int count)
        {
            return Skip(-count);
        }

        public StringParser SkipTo(string str)
        {
            if (str == null)
                throw new ArgumentNullException(nameof(str));
            if (End)
                return this;
            var pos = _text.IndexOf(str, _index, CharactersLeft, StringComparison.Ordinal);
            _index = pos < 0 ? _length : pos;
            return this;
        }

        public StringParser SkipTo(char c)
        {
            if (End)
                return this;
            var pos = _text.IndexOf(c, _index, CharactersLeft);
{'fraction_non_alphanumeric': 0.09163778162911612, 'fraction_numerical': 0.0025996533795493936, 'mean_word_length': 1.5424008810572687, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '657502', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1203, 'n_words': 340}