Exemple #1
0
        public void Append(string text)
        {
            FastReplacerSnippet s = new FastReplacerSnippet(text);

            RootSnippet.Append(s);
            ExtractTokens(s);
        }
 public void InsertAfter(int end, FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start = end,
         End = end,
         Order1 = 1,
         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 InsertBefore(int start, FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start = start,
         End = start,
         Order1 = 2,
         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)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start   = end,
         End     = end,
         Order1  = 1,
         Order2  = InnerSnippets.Count
     });
 }
 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 Append(FastReplacerSnippet snippet)
 {
     InnerSnippets.Add(new InnerSnippet
     {
         Snippet = snippet,
         Start   = this.Text.Length,
         End     = this.Text.Length,
         Order1  = 1,
         Order2  = InnerSnippets.Count
     });
 }
 /// <returns>Returns true if the token was found, false if nothing was replaced.</returns>
 public bool Replace(string token, string text)
 {
     ValidateToken(token, text, false);
     List<TokenOccurrence> occurrences;
     if (OccurrencesOfToken.TryGetValue(token, out occurrences))
     {
         OccurrencesOfToken.Remove(token);
         FastReplacerSnippet s = new FastReplacerSnippet(text);
         foreach (var occurrence in occurrences)
             occurrence.Snippet.Replace(occurrence.Start, occurrence.End, s);
         ExtractTokens(s);
         return occurrences.Count > 0;
     }
     return false;
 }
Exemple #11
0
        private void ExtractTokens(FastReplacerSnippet snippet)
        {
            int last = 0;

            while (last < snippet.Text.Length)
            {
                //TokenOpen的位置
                int start = snippet.Text.IndexOf(TokenOpen, last);
                //未找到tokenopen
                if (start == -1)
                {
                    return;
                }
                //TokenClose的位置
                int end = snippet.Text.IndexOf(TokenClose, start + TokenOpen.Length);
                //未找到TokenClose,表明没有正确闭合
                if (end == -1)
                {
                    throw new ArgumentException(string.Format("Token is opened but not closed in text \"{0}\".", snippet.Text));
                }
                end += TokenClose.Length;

                //截取token
                string token   = snippet.Text.Substring(start, end - start);
                string context = snippet.Text;

                ValidateToken(token, context, true);

                //组织token数据到字典上 以token为key TokenOccurrence包含token的起始位置与结束位置
                TokenOccurrence 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;
            }
        }
Exemple #12
0
        /// <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))
            {
                FastReplacerSnippet s = new FastReplacerSnippet(text);
                foreach (var occurrence in occurrences)
                {
                    occurrence.Snippet.InsertAfter(occurrence.End, s);
                }
                ExtractTokens(s);
                return(occurrences.Count > 0);
            }
            return(false);
        }
 public void Append(string text)
 {
     FastReplacerSnippet s = new FastReplacerSnippet(text);
     RootSnippet.Append(s);
     ExtractTokens(s);
 }
        private void ExtractTokens(FastReplacerSnippet snippet)
        {
            int last = 0;
            while (last < snippet.Text.Length)
            {
                //TokenOpen的位置
                int start = snippet.Text.IndexOf(TokenOpen, last);
                //未找到tokenopen
                if (start == -1)
                    return;
                //TokenClose的位置
                int end = snippet.Text.IndexOf(TokenClose, start + TokenOpen.Length);
                //未找到TokenClose,表明没有正确闭合
                if (end == -1)
                    throw new ArgumentException(string.Format("Token is opened but not closed in text \"{0}\".", snippet.Text));
                end += TokenClose.Length;

                //截取token
                string token = snippet.Text.Substring(start, end - start);
                string context = snippet.Text;
                
                ValidateToken(token, context, true);

                //组织token数据到字典上 以token为key TokenOccurrence包含token的起始位置与结束位置
                TokenOccurrence 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;
            }
        }