コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public LessonSpan(StringWithIndex content, string startMarker, string endMarker)
     : base(content)
 {
     StartMarker = startMarker;
     EndMarker   = endMarker;
     OverrideContent(content.TrimStart(startMarker).TrimEnd(endMarker));
 }
コード例 #6
0
 public LessonEnd(StringWithIndex content)
     : base(content, "", "")
 {
     if (content.Length != 0)
     {
         throw new ArgumentException("LessonEnd cannot contain content");
     }
 }
コード例 #7
0
        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)
            });
        }
コード例 #8
0
 public static StringWithIndex GetValueAfter(this StringWithIndex text, string lineStartMatch)
 {
     if (!text.Text.StartsWith(lineStartMatch))
     {
         return(null);
     }
     else
     {
         return(text.ReplaceStart(lineStartMatch, ""));
     }
 }
コード例 #9
0
 public static StringWithIndex ReplaceStart(this StringWithIndex text, string match, string replacement)
 {
     if (text.Text.StartsWith(match))
     {
         return(text.Substring(match.Length));
     }
     else
     {
         return(text);
     }
 }
コード例 #10
0
 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);
     }
 }
コード例 #11
0
        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));
        }
コード例 #12
0
 public LessonInstructions(StringWithIndex content) : base(content)
 {
 }
コード例 #13
0
 public static int GetIndexAfter(this StringWithIndex text)
 {
     return(text.Index + text.Length);
 }
コード例 #14
0
 public LessonGoal(StringWithIndex content) : base(content)
 {
 }
コード例 #15
0
 public LessonNode(StringWithIndex content)
 {
     Content = content;
 }
コード例 #16
0
 public LessonSummary(StringWithIndex content) : base(content)
 {
 }
コード例 #17
0
 public static List <StringWithIndex> GetLines(this StringWithIndex text)
 {
     return(Split(text, "\n").Where(l => !StringHelper.IsNullOrWhiteSpace(l.Text)).Select(l => l.TrimEnd('\r')).ToList());
 }
コード例 #18
0
 public LessonTest(StringWithIndex content) : base(content)
 {
 }
コード例 #19
0
 public LessonCodeExplanationQuote(StringWithIndex content) : base(content, "* ", "\r\n")
 {
 }
コード例 #20
0
 public LessonParagraph(StringWithIndex content) : base(content)
 {
 }
コード例 #21
0
 public static List <StringWithIndex> SplitLines(this StringWithIndex text)
 {
     return(text.Split("\r\n"));
 }
コード例 #22
0
 internal void OverrideContent(StringWithIndex content)
 {
     Content = content;
 }
コード例 #23
0
 public LessonPhrase(StringWithIndex content) : base(content, "- ", "\r\n")
 {
 }
コード例 #24
0
 public LessonCode(StringWithIndex content) : base(content, "", "")
 {
 }
コード例 #25
0
 public static StringWithIndex Trim(this StringWithIndex text, params char[] chars)
 {
     return(text.TrimStart(chars).TrimEnd(chars));
 }
コード例 #26
0
 public LessonFile(StringWithIndex content) : base(content)
 {
 }
コード例 #27
0
 public static StringWithIndex TrimEnd(this StringWithIndex text)
 {
     return(TrimEnd(text, new char[0]));
 }
コード例 #28
0
 public LessonCodeExplanation(StringWithIndex content) : base(content)
 {
 }
コード例 #29
0
 public LessonComment(StringWithIndex content) : base(content, "// ", "\r\n")
 {
 }
コード例 #30
0
 public LessonStep(StringWithIndex content) : base(content)
 {
 }