public void Append(string text) { var snippet = new FastReplacerSnippet(text); RootSnippet.Append(snippet); ExtractTokens(snippet); }
public void InsertAfter(int end, FastReplacerSnippet snippet) { InnerSnippets.Add(new InnerSnippet { Snippet = snippet, Start = end, End = end, Order1 = 1, Order2 = InnerSnippets.Count }); }
public void Append(FastReplacerSnippet snippet) { InnerSnippets.Add(new InnerSnippet { Snippet = snippet, Start = this.Text.Length, End = this.Text.Length, Order1 = 1, Order2 = InnerSnippets.Count }); }
public void InsertAfter(int end, FastReplacerSnippet snippet, bool reverse) { InnerSnippets.Add(new InnerSnippet { Snippet = snippet, Start = end, End = end, Order1 = 1, Order2 = InnerSnippets.Count * (reverse ? -1 : 1) }); }
public void InsertBefore(int start, FastReplacerSnippet snippet) { InnerSnippets.Add(new InnerSnippet { Snippet = snippet, Start = start, End = start, Order1 = 2, Order2 = InnerSnippets.Count }); }
public void Replace(int start, int end, FastReplacerSnippet snippet) { InnerSnippets.Add(new InnerSnippet { Snippet = snippet, Start = start, End = end, Order1 = 0, Order2 = 0 }); }
public void AppendToFile(string text, string path) { if (!RootSnippetByFile.TryGetValue(path, out FastReplacerSnippet rootSnippet)) { rootSnippet = new FastReplacerSnippet(""); RootSnippetByFile.Add(path, rootSnippet); } var snippet = new FastReplacerSnippet(text); rootSnippet.Append(snippet); ExtractTokens(snippet); }
private void ExtractTokens(FastReplacerSnippet snippet) { int last = 0; while (last < snippet.Text.Length) { // Find next token position in snippet.Text: int start = snippet.Text.IndexOf(TokenOpen, last, StringComparison.InvariantCultureIgnoreCase); if (start == -1) { return; } int end = snippet.Text.IndexOf(TokenClose, start + TokenOpen.Length, StringComparison.InvariantCultureIgnoreCase); if (end == -1) { throw new ArgumentException(string.Format("Token is opened but not closed in text \"{0}\".", snippet.Text)); } int eol = snippet.Text.IndexOf('\n', start + TokenOpen.Length); if (eol != -1 && eol < end) { last = eol + 1; continue; } // Take the token from snippet.Text: end += TokenClose.Length; string token = snippet.Text.Substring(start, end - start); string context = snippet.Text; ValidateToken(token, context, true); // Add the token to the dictionary: var tokenOccurrence = new TokenOccurrence { Snippet = snippet, Start = start, End = end }; List <TokenOccurrence> occurrences; if (OccurrencesOfToken.TryGetValue(token, out occurrences)) { occurrences.Add(tokenOccurrence); } else { OccurrencesOfToken.Add(token, new List <TokenOccurrence> { tokenOccurrence }); } last = end; } }
/// <returns>Returns true if the token was found, false if nothing was replaced.</returns> public bool InsertBefore(string token, string text) { ValidateToken(token, text, false); List <TokenOccurrence> occurrences; if (OccurrencesOfToken.TryGetValue(token, out occurrences) && occurrences.Count > 0) { var snippet = new FastReplacerSnippet(text); foreach (var occurrence in occurrences) { occurrence.Snippet.InsertBefore(occurrence.Start, snippet); } ExtractTokens(snippet); return(true); } return(false); }
/// <returns>Returns true if the token was found, false if nothing was replaced.</returns> public bool InsertAfter(string token, string text) { ValidateToken(token, text, false); List<TokenOccurrence> occurrences; if (OccurrencesOfToken.TryGetValue(token, out occurrences) && occurrences.Count > 0) { var snippet = new FastReplacerSnippet(text); foreach (var occurrence in occurrences) occurrence.Snippet.InsertAfter(occurrence.End, snippet); ExtractTokens(snippet); return true; } return false; }
private void ExtractTokens(FastReplacerSnippet snippet) { int last = 0; while (last < snippet.Text.Length) { // Find next token position in snippet.Text: int start = snippet.Text.IndexOf(TokenOpen, last, StringComparison.InvariantCultureIgnoreCase); if (start == -1) return; int end = snippet.Text.IndexOf(TokenClose, start + TokenOpen.Length, StringComparison.InvariantCultureIgnoreCase); if (end == -1) throw new ArgumentException(string.Format("Token is opened but not closed in text \"{0}\".", snippet.Text)); int eol = snippet.Text.IndexOf('\n', start + TokenOpen.Length); if (eol != -1 && eol < end) { last = eol + 1; continue; } // Take the token from snippet.Text: end += TokenClose.Length; string token = snippet.Text.Substring(start, end - start); string context = snippet.Text; ValidateToken(token, context, true); // Add the token to the dictionary: var tokenOccurrence = new TokenOccurrence { Snippet = snippet, Start = start, End = end }; List<TokenOccurrence> occurrences; if (OccurrencesOfToken.TryGetValue(token, out occurrences)) occurrences.Add(tokenOccurrence); else OccurrencesOfToken.Add(token, new List<TokenOccurrence> { tokenOccurrence }); last = end; } }