Exemple #1
0
        public RelabelNode(TsurgeonPattern child, string newLabel) :
            base("relabel", new TsurgeonPattern[] {child})
        {
            var m1 = SubstPattern.Match(newLabel);
            if (m1.Success)
            {
                mode = RelabelMode.Regex;
                this.labelRegex = new Regex(m1.Groups[1].Value);
                this.replacementString = m1.Groups[2].Value;
                replacementPieces = new List<string>();
                var generalMatcher =
                    OneGeneralReplacementPattern.Match(m1.Groups[2].Value);
                int lastPosition = 0;
                var nextMatch = generalMatcher.NextMatch();
                while (nextMatch.Success)
                {
                    if (nextMatch.Index > lastPosition)
                    {
                        replacementPieces.Add(replacementString.Substring(lastPosition, nextMatch.Index));
                    }
                    lastPosition = nextMatch.Index + nextMatch.Length;
                    string piece = nextMatch.Value;
                    if (piece.Equals(""))
                    {
                        nextMatch = generalMatcher.NextMatch();
                        continue;
                    }
                    replacementPieces.Add(nextMatch.Value);
                    nextMatch = generalMatcher.NextMatch();
                }
                if (lastPosition < replacementString.Length)
                {
                    replacementPieces.Add(replacementString.Substring(lastPosition));
                }
                this.newLabel = null;
            }
            else
            {
                mode = RelabelMode.Fixed;
                var m2 = RegexPattern.Match(newLabel);
                if (m2.Success)
                {
                    // fixed relabel but surrounded by regex slashes
                    string unescapedLabel = m2.Groups[1].Value;
                    this.newLabel = RemoveEscapeSlashes(unescapedLabel);
                }
                else
                {
                    // just a node name to relabel to
                    this.newLabel = newLabel;
                }
                this.replacementString = null;
                this.replacementPieces = null;
                this.labelRegex = null;

            }
        }
Exemple #2
0
        public RelabelNode(TsurgeonPattern child, string newLabel) :
            base("relabel", new TsurgeonPattern[] { child })
        {
            var m1 = SubstPattern.Match(newLabel);

            if (m1.Success)
            {
                mode                   = RelabelMode.Regex;
                this.labelRegex        = new Regex(m1.Groups[1].Value);
                this.replacementString = m1.Groups[2].Value;
                replacementPieces      = new List <string>();
                var generalMatcher =
                    OneGeneralReplacementPattern.Match(m1.Groups[2].Value);
                int lastPosition = 0;
                var nextMatch    = generalMatcher.NextMatch();
                while (nextMatch.Success)
                {
                    if (nextMatch.Index > lastPosition)
                    {
                        replacementPieces.Add(replacementString.Substring(lastPosition, nextMatch.Index));
                    }
                    lastPosition = nextMatch.Index + nextMatch.Length;
                    string piece = nextMatch.Value;
                    if (piece.Equals(""))
                    {
                        nextMatch = generalMatcher.NextMatch();
                        continue;
                    }
                    replacementPieces.Add(nextMatch.Value);
                    nextMatch = generalMatcher.NextMatch();
                }
                if (lastPosition < replacementString.Length)
                {
                    replacementPieces.Add(replacementString.Substring(lastPosition));
                }
                this.newLabel = null;
            }
            else
            {
                mode = RelabelMode.Fixed;
                var m2 = RegexPattern.Match(newLabel);
                if (m2.Success)
                {
                    // fixed relabel but surrounded by regex slashes
                    string unescapedLabel = m2.Groups[1].Value;
                    this.newLabel = RemoveEscapeSlashes(unescapedLabel);
                }
                else
                {
                    // just a node name to relabel to
                    this.newLabel = newLabel;
                }
                this.replacementString = null;
                this.replacementPieces = null;
                this.labelRegex        = null;
            }
        }