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); }
public LessonSpan(StringWithIndex content, string startMarker, string endMarker) : base(content) { StartMarker = startMarker; EndMarker = endMarker; OverrideContent(content.TrimStart(startMarker).TrimEnd(endMarker)); }
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)); }
public LessonInstructions(StringWithIndex content) : base(content) { }
public static int GetIndexAfter(this StringWithIndex text) { return(text.Index + text.Length); }
public LessonGoal(StringWithIndex content) : base(content) { }
public LessonNode(StringWithIndex content) { Content = content; }
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()); }
public LessonTest(StringWithIndex content) : base(content) { }
public LessonCodeExplanationQuote(StringWithIndex content) : base(content, "* ", "\r\n") { }
public LessonParagraph(StringWithIndex content) : base(content) { }
public static List <StringWithIndex> SplitLines(this StringWithIndex text) { return(text.Split("\r\n")); }
internal void OverrideContent(StringWithIndex content) { Content = content; }
public LessonPhrase(StringWithIndex content) : base(content, "- ", "\r\n") { }
public LessonCode(StringWithIndex content) : base(content, "", "") { }
public static StringWithIndex Trim(this StringWithIndex text, params char[] chars) { return(text.TrimStart(chars).TrimEnd(chars)); }
public LessonFile(StringWithIndex content) : base(content) { }
public static StringWithIndex TrimEnd(this StringWithIndex text) { return(TrimEnd(text, new char[0])); }
public LessonCodeExplanation(StringWithIndex content) : base(content) { }
public LessonComment(StringWithIndex content) : base(content, "// ", "\r\n") { }
public LessonStep(StringWithIndex content) : base(content) { }