public static StringWithIndex TrimStart(this StringWithIndex text, params char[] chars)
        {
            var trimmed    = text.Text.TrimStart(chars);
            var lengthDiff = text.Length - trimmed.Length;

            return(text.Substring(lengthDiff, text.Length - lengthDiff));
        }
        public static List <StringWithIndex> SplitWithoutModification(this StringWithIndex text, params string[] separatorStarts)
        {
            var parts = new List <StringWithIndex>();

            var area = text.Text;

            var prevIndex = 0;
            var nextIndex = -1;

            nextIndex = area.IndexOfAny(separatorStarts);

            while (nextIndex >= 0)
            {
                // Add previous part
                parts.Add(new StringWithIndex(text.Source, text.Index + prevIndex, nextIndex - prevIndex));

                prevIndex = nextIndex;
                nextIndex = area.IndexOfAny(separatorStarts, nextIndex + 1);
            }

            // Add last part
            parts.Add(new StringWithIndex(text.Source, text.Index + prevIndex, text.Length - prevIndex));

            return(parts);
        }
        public static List <StringWithIndex> Split(this StringWithIndex text, params string[] separators)
        {
            var parts   = SplitWithoutModification(text, separators);
            var trimmed = parts.Select(p => p.TrimStart(separators)).ToList();

            return(trimmed);
        }
        public static List <StringWithIndex> SplitWithoutModificationRegex(this StringWithIndex text, string regexStr)
        {
            var parts = new List <StringWithIndex>();

            var regex = new Regex(regexStr);
            var area  = text.Text;

            var prevIndex = 0;
            var m         = regex.Match(area);

            while (m.Success)
            {
                var index = m.Index;

                parts.Add(text.Substring(prevIndex, index - prevIndex));

                prevIndex = index;
                m         = regex.Match(area, index + 1);
            }

            // Add last part
            parts.Add(text.Substring(prevIndex, area.Length - prevIndex));

            return(parts);
        }
Beispiel #5
0
 public LessonSpan(StringWithIndex content, string startMarker, string endMarker)
     : base(content)
 {
     StartMarker = startMarker;
     EndMarker   = endMarker;
     OverrideContent(content.TrimStart(startMarker).TrimEnd(endMarker));
 }
Beispiel #6
0
 public LessonEnd(StringWithIndex content)
     : base(content, "", "")
 {
     if (content.Length != 0)
     {
         throw new ArgumentException("LessonEnd cannot contain content");
     }
 }
        public static List <StringWithIndex> SplitAfterFirstLine(this StringWithIndex text)
        {
            var area           = text.Text;
            var lineBreakIndex = area.IndexOf("\r\n");

            return(new List <StringWithIndex>()
            {
                text.Substring(0, lineBreakIndex),
                text.Substring(lineBreakIndex + 2)
            });
        }
 public static StringWithIndex GetValueAfter(this StringWithIndex text, string lineStartMatch)
 {
     if (!text.Text.StartsWith(lineStartMatch))
     {
         return(null);
     }
     else
     {
         return(text.ReplaceStart(lineStartMatch, ""));
     }
 }
 public static StringWithIndex ReplaceStart(this StringWithIndex text, string match, string replacement)
 {
     if (text.Text.StartsWith(match))
     {
         return(text.Substring(match.Length));
     }
     else
     {
         return(text);
     }
 }
 public static StringWithIndex ReplaceEnd(this StringWithIndex text, string match, string replacement)
 {
     if (text.Text.EndsWith(match))
     {
         return(text.Substring(0, text.Text.Length - match.Length));
     }
     else
     {
         return(text);
     }
 }
        public static StringWithIndex TrimStart(this StringWithIndex text, params string[] starts)
        {
            var trimmed = text.Text;

            foreach (var s in starts.OrderByDescending(s => s.Length))
            {
                if (trimmed.StartsWith(s))
                {
                    trimmed = trimmed.ReplaceStart(s, "");
                    break;
                }
            }

            var lengthDiff = text.Length - trimmed.Length;

            return(text.Substring(lengthDiff, text.Length - lengthDiff));
        }
Beispiel #12
0
 public LessonInstructions(StringWithIndex content) : base(content)
 {
 }
 public static int GetIndexAfter(this StringWithIndex text)
 {
     return(text.Index + text.Length);
 }
Beispiel #14
0
 public LessonGoal(StringWithIndex content) : base(content)
 {
 }
Beispiel #15
0
 public LessonNode(StringWithIndex content)
 {
     Content = content;
 }
Beispiel #16
0
 public LessonSummary(StringWithIndex content) : base(content)
 {
 }
 public static List <StringWithIndex> GetLines(this StringWithIndex text)
 {
     return(Split(text, "\n").Where(l => !StringHelper.IsNullOrWhiteSpace(l.Text)).Select(l => l.TrimEnd('\r')).ToList());
 }
Beispiel #18
0
 public LessonTest(StringWithIndex content) : base(content)
 {
 }
Beispiel #19
0
 public LessonCodeExplanationQuote(StringWithIndex content) : base(content, "* ", "\r\n")
 {
 }
Beispiel #20
0
 public LessonParagraph(StringWithIndex content) : base(content)
 {
 }
 public static List <StringWithIndex> SplitLines(this StringWithIndex text)
 {
     return(text.Split("\r\n"));
 }
Beispiel #22
0
 internal void OverrideContent(StringWithIndex content)
 {
     Content = content;
 }
Beispiel #23
0
 public LessonPhrase(StringWithIndex content) : base(content, "- ", "\r\n")
 {
 }
Beispiel #24
0
 public LessonCode(StringWithIndex content) : base(content, "", "")
 {
 }
 public static StringWithIndex Trim(this StringWithIndex text, params char[] chars)
 {
     return(text.TrimStart(chars).TrimEnd(chars));
 }
Beispiel #26
0
 public LessonFile(StringWithIndex content) : base(content)
 {
 }
 public static StringWithIndex TrimEnd(this StringWithIndex text)
 {
     return(TrimEnd(text, new char[0]));
 }
Beispiel #28
0
 public LessonCodeExplanation(StringWithIndex content) : base(content)
 {
 }
Beispiel #29
0
 public LessonComment(StringWithIndex content) : base(content, "// ", "\r\n")
 {
 }
Beispiel #30
0
 public LessonStep(StringWithIndex content) : base(content)
 {
 }