Ejemplo n.º 1
0
 public string ToString(bool includeLine, IGuidFormatter formatter = null, bool upcase = false)
 {
     if (includeLine && formatter != null) return string.Format("Ln: {0} Col: {1}\t{2}\t{3}", Line, Column, formatter.ToString(Guid, upcase, false), Match);
     else if (includeLine) return string.Format("Ln: {0} Col: {1}", Line, Column, Match);
     else if (formatter != null) return string.Format("{0}\t{1}", formatter.ToString(Guid, upcase, false), Match);
     return Match;
 }
 public override string Replace(string input, Guider guider, IGuidFormatter formatter=null, bool upcase = false, Action<Replacement> onReplacement = null, int lineNumber = -1)
 {
     string output = (input != null)?input:"";
     return s_B64.Replace(input, (m)=> {
         string s = s_SpaceStripper.Replace(m.Value, "");
         StringBuilder replacementText = new StringBuilder();
         List<Guid> guids = new List<Guid>();
         foreach(Guid g in ToGuid(s))
         {
             if (guider.MoveNext(g))
             {
                 Guid replacementGuid = guider.Current;
                 guids.Add(replacementGuid);
                 string currentText = (formatter != null)?formatter.ToString(replacementGuid, upcase, false):replacementGuid.ToString("D");
                 if (formatter != null)
                 {
                     if (replacementText.Length > 0) replacementText.Append("\r\n");
                     replacementText.Append(currentText);
                 }
                 if (onReplacement != null) onReplacement(new Replacement() { Line=lineNumber, Column = m.Index, FoundText=g.ToString("D"), FoundGuid=g,  ReplacedByText=currentText, ReplacedByGuid=replacementGuid });
             }
         }
         if (guids.Count > 0 && replacementText.Length == 0) replacementText.Append(ToString(guids, upcase, false));
         else if (guids.Count == 0) return m.Value;
         return replacementText.ToString();
     });
 }
 public virtual string Replace(string input, Guider guider, IGuidFormatter formatter=null, bool upcase = false, Action<Replacement> onReplacement = null, int lineNumber = -1)
 {
     if (!string.IsNullOrEmpty(input))
     {
         return Matcher.Replace(input, (m) => {
             Guid foundGuid = MatchToGuid(m);
             if (guider.MoveNext(foundGuid))
             {
                 Guid replacementGuid = guider.Current;
                 string replacementText = formatter==null?Replace(m.Value, m.Index, m, foundGuid, replacementGuid, upcase):formatter.ToString(replacementGuid, upcase, false);
                 if (onReplacement != null) onReplacement(new Replacement() { Line=lineNumber, Column = m.Index, FoundText=m.Value, FoundGuid=foundGuid,  ReplacedByText=replacementText, ReplacedByGuid=replacementGuid });
                 return replacementText;
             }
             return m.Value;
         });
     }
     return input;
 }