private string ReplaceGroupNumber(Matcher match,
                                          string reformattedPattern,
                                          PatternGrouping patternGrouping,
                                          RegexOptions options)
        {
            int groupNumber     = int.Parse(match.group(1));
            int javaGroupNumber = groupNumber;
            int groupCount      = patternGrouping.GroupCount;

            if (groupCount == -1)
            {
                if ((options & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture)
                {
                    groupCount = 0;
                }
                else
                {
                    groupCount = JavaUtils.GroupCount(reformattedPattern);
                }
            }
            else
            {
                javaGroupNumber = patternGrouping.NetToJavaNumbersMap [groupNumber];
            }

            if (groupNumber > groupCount)
            {
                return(null);
            }

            return(match.replaceFirst(@"\\" + javaGroupNumber));
        }
        private string ReplaceGroupName(Matcher match,
                                        string reformattedPattern,
                                        PatternGrouping patternGrouping,
                                        RegexOptions options)
        {
            if (patternGrouping.GroupCount == -1)
            {
                return(null);
            }

            string  groupName = match.group(1);
            Pattern p         = Pattern.compile(NUMBER);
            Matcher m         = p.matcher((CharSequence)(object)groupName);

            if (m.matches())
            {
                return(ReplaceGroupNumber(match, reformattedPattern, patternGrouping, options));
            }

            if (!patternGrouping.GroupNameToNumberMap.Contains(groupName))
            {
                return(null);
            }

            int javaGroupNumber = patternGrouping.NetToJavaNumbersMap [(int)patternGrouping.GroupNameToNumberMap [groupName]];

            return(match.replaceFirst(@"\\" + javaGroupNumber));
        }
Exemplo n.º 3
0
        internal static PatternData GetPatternData(string pattern, RegexOptions options)
        {
            foreach (IConstructType construct in _monoConstructTypesList)
            {
                if (construct.HasConstruct(pattern, options))
                {
                    return(null);
                }
            }

            PatternGrouping patternGrouping    = new PatternGrouping();
            string          reformattedPattern = pattern;

            foreach (IConstructType construct in _jvmOrderedConstructTypesList)
            {
                reformattedPattern = construct.Reformat(options, reformattedPattern, patternGrouping);

                if (reformattedPattern == null)
                {
                    return(null);
                }
            }

            return(new PatternData(options, reformattedPattern, patternGrouping));
        }
Exemplo n.º 4
0
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			if (!HasConstruct (reformattedPattern, options)) {
				return reformattedPattern;
			}

			if (patternGrouping.GroupCount >= 0 && patternGrouping.SameGroupsFlag) {
				return null;
			}

			Matcher m = JavaUtils.Matcher (reformattedPattern, NUMBER_BACK_REFERENCE_PATTERN);
			if (m.find ()) {
				reformattedPattern = ReplaceGroupNumber (m, reformattedPattern, patternGrouping, options);
				if (reformattedPattern == null)
					return null;
			}

			m = JavaUtils.Matcher(reformattedPattern, NAME_1_BACK_REFERENCE_PATTERN);
			if (m.find ()) {
				reformattedPattern = ReplaceGroupName (m, reformattedPattern, patternGrouping, options);
				if (reformattedPattern == null)
					return null;
			}

			m = JavaUtils.Matcher(reformattedPattern, NAME_2_BACK_REFERENCE_PATTERN);
			if (m.find ()) {
				reformattedPattern = ReplaceGroupName (m, reformattedPattern, patternGrouping, options);
				if (reformattedPattern == null)
					return null;
			}

			return reformattedPattern;
		}
Exemplo n.º 5
0
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			if (!HasConstruct (reformattedPattern, options)) {
				return reformattedPattern;
			}

			UpdateGroupMapping (reformattedPattern, options, patternGrouping);

			return ReformatPattern (reformattedPattern);
		}
Exemplo n.º 6
0
		internal PatternData (
			RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {

			this._patternGrouping = patternGrouping;

			_javaPattern = Pattern.compile (reformattedPattern, GetJavaFlags (options));

			FillGroups (options);
		}
Exemplo n.º 7
0
        internal PatternData(
            RegexOptions options,
            string reformattedPattern,
            PatternGrouping patternGrouping)
        {
            this._patternGrouping = patternGrouping;

            _javaPattern = Pattern.compile(reformattedPattern, GetJavaFlags(options));

            FillGroups(options);
        }
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			reformattedPattern = JavaUtils.ReplaceWithLookBehind (reformattedPattern, BACKSLASH_PATTERN, BACKSLASH_BEHIND_PATTERN, BACKSLASH);
			reformattedPattern = JavaUtils.ReplaceAllAdvanced (reformattedPattern, LEFT_FIGURE_PAREN, ESC_LEFT_FIGURE);
			reformattedPattern = JavaUtils.ReplaceAllAdvanced (reformattedPattern, RIGHT_FIGURE_PAREN, ESC_RIGHT_FIGURE);
			reformattedPattern = JavaUtils.ReplaceWithLookBehind (reformattedPattern, BRACKET_PATTERN, BRACKET_BEHIND_PATTERN, BRACKET);
			reformattedPattern = JavaUtils.ReplaceAllAdvanced (reformattedPattern, NULL_PATTERN, JAVA_NULL);

			return reformattedPattern;
		}
Exemplo n.º 9
0
        public string Reformat(RegexOptions options,
                               string reformattedPattern,
                               PatternGrouping patternGrouping)
        {
            reformattedPattern = JavaUtils.ReplaceWithLookBehind(reformattedPattern, BACKSLASH_PATTERN, BACKSLASH_BEHIND_PATTERN, BACKSLASH);
            reformattedPattern = JavaUtils.ReplaceAllAdvanced(reformattedPattern, LEFT_FIGURE_PAREN, ESC_LEFT_FIGURE);
            reformattedPattern = JavaUtils.ReplaceAllAdvanced(reformattedPattern, RIGHT_FIGURE_PAREN, ESC_RIGHT_FIGURE);
            reformattedPattern = JavaUtils.ReplaceWithLookBehind(reformattedPattern, BRACKET_PATTERN, BRACKET_BEHIND_PATTERN, BRACKET);
            reformattedPattern = JavaUtils.ReplaceAllAdvanced(reformattedPattern, NULL_PATTERN, JAVA_NULL);

            return(reformattedPattern);
        }
Exemplo n.º 10
0
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			
			reformattedPattern = JavaUtils.ReplaceAll (reformattedPattern, INLINE_COMMENT_PATTERN, String.Empty);

			if ((options & RegexOptions.IgnorePatternWhitespace) == 0) 
				return reformattedPattern;
			
			reformattedPattern = JavaUtils.ReplaceAll (reformattedPattern, COMMENT_PATTERN, String.Empty);

			return reformattedPattern;
		}
Exemplo n.º 11
0
        public string Reformat(RegexOptions options,
                               string reformattedPattern,
                               PatternGrouping patternGrouping)
        {
            if (!HasConstruct(reformattedPattern, options))
            {
                return(reformattedPattern);
            }

            UpdateGroupMapping(reformattedPattern, options, patternGrouping);

            return(ReformatPattern(reformattedPattern));
        }
Exemplo n.º 12
0
        public string Reformat(RegexOptions options,
                               string reformattedPattern,
                               PatternGrouping patternGrouping)
        {
            reformattedPattern = JavaUtils.ReplaceAll(reformattedPattern, INLINE_COMMENT_PATTERN, String.Empty);

            if ((options & RegexOptions.IgnorePatternWhitespace) == 0)
            {
                return(reformattedPattern);
            }

            reformattedPattern = JavaUtils.ReplaceAll(reformattedPattern, COMMENT_PATTERN, String.Empty);

            return(reformattedPattern);
        }
Exemplo n.º 13
0
        public string Reformat(RegexOptions options,
                               string reformattedPattern,
                               PatternGrouping patternGrouping)
        {
            if (!HasConstruct(reformattedPattern, options))
            {
                return(reformattedPattern);
            }

            if (patternGrouping.GroupCount >= 0 && patternGrouping.SameGroupsFlag)
            {
                return(null);
            }

            Matcher m = JavaUtils.Matcher(reformattedPattern, NUMBER_BACK_REFERENCE_PATTERN);

            if (m.find())
            {
                reformattedPattern = ReplaceGroupNumber(m, reformattedPattern, patternGrouping, options);
                if (reformattedPattern == null)
                {
                    return(null);
                }
            }

            m = JavaUtils.Matcher(reformattedPattern, NAME_1_BACK_REFERENCE_PATTERN);
            if (m.find())
            {
                reformattedPattern = ReplaceGroupName(m, reformattedPattern, patternGrouping, options);
                if (reformattedPattern == null)
                {
                    return(null);
                }
            }

            m = JavaUtils.Matcher(reformattedPattern, NAME_2_BACK_REFERENCE_PATTERN);
            if (m.find())
            {
                reformattedPattern = ReplaceGroupName(m, reformattedPattern, patternGrouping, options);
                if (reformattedPattern == null)
                {
                    return(null);
                }
            }

            return(reformattedPattern);
        }
Exemplo n.º 14
0
		internal static PatternData GetPatternData (string pattern, RegexOptions options) {

			foreach (IConstructType construct in _monoConstructTypesList) {
				if (construct.HasConstruct (pattern, options)) {
					return null;
				}
			}

			PatternGrouping patternGrouping = new PatternGrouping ();
			string reformattedPattern = pattern;

			foreach (IConstructType construct in _jvmOrderedConstructTypesList) {
				
				reformattedPattern = construct.Reformat (options, reformattedPattern, patternGrouping);
				
				if (reformattedPattern == null) 
					return null;
			}

			return new PatternData (options, reformattedPattern, patternGrouping);
		}
Exemplo n.º 15
0
 public string Reformat(RegexOptions options,
                        string reformattedPattern,
                        PatternGrouping patternGrouping)
 {
     throw new NotImplementedException("Reformat for not allowed constructs is not implemented.");
 }
Exemplo n.º 16
0
		private static void UpdateGroupMapping (string reformattedPattern,
			RegexOptions options,
			PatternGrouping patternGrouping) {
		
			CharSequence workString = (CharSequence) (object) JavaUtils.ReplaceAll (reformattedPattern, ESCAPED_LEFT_PAREN_TEMPL, String.Empty);

			//Split pattern by left parenthesis
			Pattern p = Pattern.compile (LEFT_PAREN);
			string [] parts = p.split (workString);

			Pattern nonCapturedGroupPattern = Pattern.compile (NON_CAPTURED_GROUP_PATTERN);
			Pattern groupNamePattern1 = Pattern.compile (NAMED_GROUP_PATTERN1);
			Pattern groupNamePattern2 = Pattern.compile (NAMED_GROUP_PATTERN2);
			Pattern groupNumPattern1 = Pattern.compile (NUMBERED_GROUP_PATTERN1);
			Pattern groupNumPattern2 = Pattern.compile (NUMBERED_GROUP_PATTERN2);

			int enoughLength = parts.Length;
			string [] namedGroups = new string [enoughLength];
			int [] javaGroupNumberToNetGroupNumber = new int [enoughLength];
			int capturedGroupsCount = 0;
			int namedGroupsCount = 0;
			int nonamedGroupsCount = 0;
			int sameGroupsCounter = 0;

			//Scan of groups
			for (int i = 1; i < parts.Length; ++i) {
				//nonamed group            
				if (parts [i].StartsWith (QUESTION) == false) {
					javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = ++nonamedGroupsCount;
					continue;
				}

				//Skip non captured groups
				Matcher partMatcher =
						nonCapturedGroupPattern.matcher ((CharSequence) (object) parts [i]);
				if (partMatcher.find ()) {
					continue;
				}

				//Find named groups by 2 patterns
				partMatcher = groupNamePattern1.matcher ((CharSequence) (object) parts [i]);
				if (partMatcher.find ()) {
					namedGroups [namedGroupsCount++] = partMatcher.group (1);
					javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = -1;
					continue;
				}
				partMatcher = groupNamePattern2.matcher ((CharSequence) (object) parts [i]);
				if (partMatcher.find ()) {
					namedGroups [namedGroupsCount++] = partMatcher.group (1);
					javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = -1;
					continue;
				}

				//Find explicitly numbered groups by 2 patterns
				partMatcher = groupNumPattern1.matcher ((CharSequence) (object) parts [i]);
				if (partMatcher.find ()) {
					int netGroupNumber = int.Parse (partMatcher.group (1));
					if ((options & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture) {
						namedGroups [namedGroupsCount++] = partMatcher.group (1);
						javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = -1;						
					}
					else {
						javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = netGroupNumber;
						if (javaGroupNumberToNetGroupNumber [capturedGroupsCount] != netGroupNumber) {
							++sameGroupsCounter;
						}
					}
					continue;
				}
				partMatcher = groupNumPattern2.matcher ((CharSequence) (object) parts [i]);
				if (partMatcher.find ()) {
					int netGroupNumber = int.Parse (partMatcher.group (1));
					if ((options & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture) {
						namedGroups [namedGroupsCount++] = partMatcher.group (1);
						javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = -1;
					}
					else {
						javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = netGroupNumber;
						if (javaGroupNumberToNetGroupNumber [capturedGroupsCount] != netGroupNumber) {
							++sameGroupsCounter;
						}
					}
					continue;
				}
			}

			//Filling grouping
			patternGrouping.SetGroups (namedGroups,
				javaGroupNumberToNetGroupNumber,
				nonamedGroupsCount,
				capturedGroupsCount,
				sameGroupsCounter,
				options);

			return;
		}
 public string Reformat(RegexOptions options,
                        string reformattedPattern,
                        PatternGrouping patternGrouping)
 {
     throw new NotImplementedException("Reformat for look ahead with undefined length construct is not implemented.");
 }
 public string Reformat(RegexOptions options,
                        string reformattedPattern,
                        PatternGrouping patternGrouping)
 {
     throw new NotImplementedException("Reformat for balancing group is not implemented.");
 }
Exemplo n.º 19
0
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			throw new NotImplementedException ("Reformat for not allowed constructs is not implemented.");
		}
Exemplo n.º 20
0
 public string Reformat(RegexOptions options,
                        string reformattedPattern,
                        PatternGrouping patternGrouping)
 {
     return(JavaUtils.ReplaceAll(reformattedPattern, DEFINITION, IS_CATEGORY));
 }
Exemplo n.º 21
0
        private static void UpdateGroupMapping(string reformattedPattern,
                                               RegexOptions options,
                                               PatternGrouping patternGrouping)
        {
            CharSequence workString = (CharSequence)(object)JavaUtils.ReplaceAll(reformattedPattern, ESCAPED_LEFT_PAREN_TEMPL, String.Empty);

            //Split pattern by left parenthesis
            Pattern p = Pattern.compile(LEFT_PAREN);

            string [] parts = p.split(workString);

            Pattern nonCapturedGroupPattern = Pattern.compile(NON_CAPTURED_GROUP_PATTERN);
            Pattern groupNamePattern1       = Pattern.compile(NAMED_GROUP_PATTERN1);
            Pattern groupNamePattern2       = Pattern.compile(NAMED_GROUP_PATTERN2);
            Pattern groupNumPattern1        = Pattern.compile(NUMBERED_GROUP_PATTERN1);
            Pattern groupNumPattern2        = Pattern.compile(NUMBERED_GROUP_PATTERN2);

            int enoughLength = parts.Length;

            string [] namedGroups = new string [enoughLength];
            int []    javaGroupNumberToNetGroupNumber = new int [enoughLength];
            int       capturedGroupsCount             = 0;
            int       namedGroupsCount   = 0;
            int       nonamedGroupsCount = 0;
            int       sameGroupsCounter  = 0;

            //Scan of groups
            for (int i = 1; i < parts.Length; ++i)
            {
                //nonamed group
                if (parts [i].StartsWith(QUESTION) == false)
                {
                    javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = ++nonamedGroupsCount;
                    continue;
                }

                //Skip non captured groups
                Matcher partMatcher =
                    nonCapturedGroupPattern.matcher((CharSequence)(object)parts [i]);
                if (partMatcher.find())
                {
                    continue;
                }

                //Find named groups by 2 patterns
                partMatcher = groupNamePattern1.matcher((CharSequence)(object)parts [i]);
                if (partMatcher.find())
                {
                    namedGroups [namedGroupsCount++] = partMatcher.group(1);
                    javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = -1;
                    continue;
                }
                partMatcher = groupNamePattern2.matcher((CharSequence)(object)parts [i]);
                if (partMatcher.find())
                {
                    namedGroups [namedGroupsCount++] = partMatcher.group(1);
                    javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = -1;
                    continue;
                }

                //Find explicitly numbered groups by 2 patterns
                partMatcher = groupNumPattern1.matcher((CharSequence)(object)parts [i]);
                if (partMatcher.find())
                {
                    int netGroupNumber = int.Parse(partMatcher.group(1));
                    if ((options & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture)
                    {
                        namedGroups [namedGroupsCount++] = partMatcher.group(1);
                        javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = -1;
                    }
                    else
                    {
                        javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = netGroupNumber;
                        if (javaGroupNumberToNetGroupNumber [capturedGroupsCount] != netGroupNumber)
                        {
                            ++sameGroupsCounter;
                        }
                    }
                    continue;
                }
                partMatcher = groupNumPattern2.matcher((CharSequence)(object)parts [i]);
                if (partMatcher.find())
                {
                    int netGroupNumber = int.Parse(partMatcher.group(1));
                    if ((options & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture)
                    {
                        namedGroups [namedGroupsCount++] = partMatcher.group(1);
                        javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = -1;
                    }
                    else
                    {
                        javaGroupNumberToNetGroupNumber [++capturedGroupsCount] = netGroupNumber;
                        if (javaGroupNumberToNetGroupNumber [capturedGroupsCount] != netGroupNumber)
                        {
                            ++sameGroupsCounter;
                        }
                    }
                    continue;
                }
            }

            //Filling grouping
            patternGrouping.SetGroups(namedGroups,
                                      javaGroupNumberToNetGroupNumber,
                                      nonamedGroupsCount,
                                      capturedGroupsCount,
                                      sameGroupsCounter,
                                      options);

            return;
        }
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			throw new NotImplementedException ("Reformat for alternation construct with back reference is not implemented.");
		}
Exemplo n.º 23
0
		private string ReplaceGroupNumber (Matcher match,
			string reformattedPattern,
			PatternGrouping patternGrouping,
			RegexOptions options) {
			int groupNumber = int.Parse (match.group (1));
			int javaGroupNumber = groupNumber;
			int groupCount = patternGrouping.GroupCount;

			if (groupCount == -1) {
				if ((options & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture) {
					groupCount = 0;
				}
				else {
					groupCount = JavaUtils.GroupCount (reformattedPattern);
				}
			}
			else {
				javaGroupNumber = patternGrouping.NetToJavaNumbersMap [groupNumber];
			}

			if (groupNumber > groupCount) {
				return null;
			}

			return match.replaceFirst (@"\\" + javaGroupNumber);
		}
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			throw new NotImplementedException ("RightToLeftOptions Reformat is not implemented");
		}
Exemplo n.º 25
0
		private string ReplaceGroupName (Matcher match,
			string reformattedPattern,
			PatternGrouping patternGrouping,
			RegexOptions options) {

			if (patternGrouping.GroupCount == -1){
				return null;
			}

			string groupName = match.group (1);
			Pattern p = Pattern.compile (NUMBER);
			Matcher m = p.matcher ((CharSequence) (object) groupName);
			if (m.matches ()) {
				return ReplaceGroupNumber (match, reformattedPattern, patternGrouping, options);
			}

			if (!patternGrouping.GroupNameToNumberMap.Contains (groupName)) {
				return null;
			}

			int javaGroupNumber = patternGrouping.NetToJavaNumbersMap [(int) patternGrouping.GroupNameToNumberMap [groupName]];
			return match.replaceFirst (@"\\" + javaGroupNumber);
		}
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			throw new NotImplementedException("Reformat for inline explicit capture construct is not implemented.");
		}
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			throw new NotImplementedException ("Reformat for look ahead with undefined length construct is not implemented.");
		}
Exemplo n.º 28
0
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {
			throw new NotImplementedException ("Reformat for balancing group is not implemented.");
		}
Exemplo n.º 29
0
 public string Reformat(RegexOptions options,
                        string reformattedPattern,
                        PatternGrouping patternGrouping)
 {
     throw new NotImplementedException("Reformat for alternation construct with back reference is not implemented.");
 }
Exemplo n.º 30
0
 public string Reformat(RegexOptions options,
                        string reformattedPattern,
                        PatternGrouping patternGrouping)
 {
     throw new NotImplementedException("RightToLeftOptions Reformat is not implemented");
 }
 public string Reformat(RegexOptions options,
                        string reformattedPattern,
                        PatternGrouping patternGrouping)
 {
     throw new NotImplementedException("Reformat for inline explicit capture construct is not implemented.");
 }
Exemplo n.º 32
0
		public string Reformat (RegexOptions options,
			string reformattedPattern,
			PatternGrouping patternGrouping) {

			return JavaUtils.ReplaceAll (reformattedPattern, DEFINITION, IS_CATEGORY);
		}