2 // PatternDataBuilder.jvm.cs
5 // Arina Itkes <arinai@mainsoft.com>
7 // Copyright (C) 2007 Mainsoft, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections.Generic;
34 using System.Collections;
36 namespace System.Text.RegularExpressions
38 sealed class PatternDataBuilder
40 private static readonly List<IConstructType> _monoConstructTypesList = new List<IConstructType>();
41 private static readonly List<IConstructType> _jvmOrderedConstructTypesList = new List<IConstructType> ();
43 static PatternDataBuilder () {
44 FillMonoConstructTypesList ();
45 FillJvmOrderedConstructTypesList ();
48 internal static PatternData GetPatternData (string pattern, RegexOptions options) {
50 foreach (IConstructType construct in _monoConstructTypesList) {
51 if (construct.HasConstruct (pattern, options)) {
56 PatternGrouping patternGrouping = new PatternGrouping ();
57 string reformattedPattern = pattern;
59 foreach (IConstructType construct in _jvmOrderedConstructTypesList) {
61 reformattedPattern = construct.Reformat (options, reformattedPattern, patternGrouping);
63 if (reformattedPattern == null)
67 return new PatternData (options, reformattedPattern, patternGrouping);
70 private static void FillMonoConstructTypesList () {
71 _monoConstructTypesList.Add (new CategoryConstruct ());
72 _monoConstructTypesList.Add (new BalancingGroupConstruct ());
73 _monoConstructTypesList.Add (new AlternationBackReferenceConstruct ());
74 _monoConstructTypesList.Add (new AlternationExpressionConstruct ());
75 _monoConstructTypesList.Add (new RightToLeftOptionConstruct ());
76 _monoConstructTypesList.Add (new InlineExplicitCaptureConstruct ());
77 _monoConstructTypesList.Add (new LookBehindWithUndefinedLength ());
78 _monoConstructTypesList.Add (new NotAllowedConstruct ());
81 private static void FillJvmOrderedConstructTypesList () {
83 //The order is meaningful
84 _jvmOrderedConstructTypesList.Add (new CommentsConstruct ());
85 _jvmOrderedConstructTypesList.Add (new NamingGroupsConstruct ());
86 _jvmOrderedConstructTypesList.Add (new ReplacedRegularCharacterConstruct ());
87 _jvmOrderedConstructTypesList.Add (new BackReferenceConstruct ());