/// <summary> /// Replaces all line breaks in the text with the specied value. /// </summary> public EditString ReplaceLineBreaks(string newValue) { var text = this.CurrentText; List <StringEdit> edits = null; for (int i = 0; i < text.Length; i++) { if (TextFacts.IsLineBreakStart(text[i])) { var len = TextFacts.GetLineBreakLength(text, i); // only make the edit if the newValue is different than the existing line break if (len != newValue.Length || string.Compare(text, i, newValue, 0, len) != 0) { if (edits == null) { edits = new List <StringEdit>(); } edits.Add(StringEdit.Replacement(i, len, newValue)); } // add one less because for-loop will add one back i += len - 1; } } return(this.ApplyAll(edits)); }
private static void GetTriviaClassifications(SyntaxToken token, Action <ClassifiedRange> action) { if (token.TriviaWidth > 0) { var trivia = token.Trivia; for (int i = 0; i < trivia.Length; i++) { // Tag anything that is not whitespace as the start of comment! // if it wasn't the start of a comment, it wouldn't be in the trivia! // TODO: if we ever get more kinds of trivia, this will need updating. if (!TextFacts.IsWhitespace(trivia[i])) { var start = i; for (; i < trivia.Length; i++) { if (TextFacts.IsLineBreakStart(trivia[i])) { break; } } action(new ClassifiedRange(ClassificationKind.Comment, token.TriviaStart + start, i - start)); } } } }
private static int SkipWhitespace(string text, int start) { int p = start; while (p < text.Length && TextFacts.IsWhitespace(text[p]) && !TextFacts.IsLineBreakStart(text[p])) { p++; } return(p); }