コード例 #1
0
        public void Append(string text)
        {
            var snippet = new FastReplacerSnippet(text);

            RootSnippet.Append(snippet);
            ExtractTokens(snippet);
        }
コード例 #2
0
ファイル: FastReplacerSnippet.cs プロジェクト: koav/Rhetos
 public void InsertAfter(int end, FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start = end,
         End = end,
         Order1 = 1,
         Order2 = InnerSnippets.Count
     });
 }
コード例 #3
0
ファイル: FastReplacerSnippet.cs プロジェクト: koav/Rhetos
 public void Append(FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start = this.Text.Length,
         End = this.Text.Length,
         Order1 = 1,
         Order2 = InnerSnippets.Count
     });
 }
コード例 #4
0
 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)
     });
 }
コード例 #5
0
 public void InsertBefore(int start, FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start   = start,
         End     = start,
         Order1  = 2,
         Order2  = InnerSnippets.Count
     });
 }
コード例 #6
0
 public void Replace(int start, int end, FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start   = start,
         End     = end,
         Order1  = 0,
         Order2  = 0
     });
 }
コード例 #7
0
 public void Append(FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start   = this.Text.Length,
         End     = this.Text.Length,
         Order1  = 1,
         Order2  = InnerSnippets.Count
     });
 }
コード例 #8
0
 public void InsertAfter(int end, FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start   = end,
         End     = end,
         Order1  = 1,
         Order2  = InnerSnippets.Count
     });
 }
コード例 #9
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);
        }
コード例 #10
0
        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;
            }
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
ファイル: FastReplacerSnippet.cs プロジェクト: koav/Rhetos
 public void Replace(int start, int end, FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start = start,
         End = end,
         Order1 = 0,
         Order2 = 0
     });
 }
コード例 #13
0
ファイル: FastReplacerSnippet.cs プロジェクト: koav/Rhetos
 public void InsertBefore(int start, FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start = start,
         End = start,
         Order1 = 2,
         Order2 = InnerSnippets.Count
     });
 }
コード例 #14
0
ファイル: FastReplacer.cs プロジェクト: davorpr1/Rhetos
 /// <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;
 }
コード例 #15
0
ファイル: FastReplacer.cs プロジェクト: davorpr1/Rhetos
 public void Append(string text)
 {
     var snippet = new FastReplacerSnippet(text);
     RootSnippet.Append(snippet);
     ExtractTokens(snippet);
 }
コード例 #16
0
ファイル: FastReplacer.cs プロジェクト: davorpr1/Rhetos
        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;
            }
        }