Пример #1
0
        private ITokenV2[] CreateInner(string s)
        {
            var innerRemaining = this.InnerString;
            var innerTokens    = new List <ITokenV2>();

            while (innerRemaining.Length > 0)
            {
                if (!MarkerTokenV2.AtBeginningOf(innerRemaining))
                {
                    var normal = new NormalTokenV2(innerRemaining);
                    innerTokens.Add(normal);

                    innerRemaining = normal.Remaining;
                }
                else
                {
                    var marker = new MarkerTokenV2(innerRemaining);
                    innerTokens.Add(marker);

                    innerRemaining = marker.Remaining;
                }
            }

            return(innerTokens.ToArray());
        }
Пример #2
0
        private ITokenV2 CreateNextToken(string s)
        {
            if (MarkerTokenV2.AtBeginningOf(s))
            {
                return(new MarkerTokenV2(s));
            }

            return(new NormalTokenV2(s));
        }
Пример #3
0
        public NormalTokenV2(string s)
        {
            var index = MarkerTokenV2.FirstMarkerIndex(s);

            if (index == -1)
            {
                this.Count     = s.Length;
                this.Remaining = string.Empty;
            }
            else
            {
                this.Count     = index;
                this.Remaining = s.Substring(index, s.Length - index);
            }
        }
Пример #4
0
        public MarkerTokenV2(string s)
        {
            if (!MarkerTokenV2.AtBeginningOf(s))
            {
                throw new ArgumentException("Marker must be at the beginning of the string");
            }

            var marker = markerPattern.Match(s);

            var parts = marker.Value.Replace("(", "").Replace(")", "").Split(new string[] { "x" }, StringSplitOptions.RemoveEmptyEntries);

            this.Take   = Int32.Parse(parts[0]);
            this.Repeat = Int32.Parse(parts[1]);

            this.InnerString = s.Substring(marker.Length, this.Take);

            this.Remaining = s.Substring(marker.Index + marker.Length + this.Take,
                                         s.Length - (marker.Index + marker.Length + this.Take));
        }