New test.
[mono.git] / mcs / class / System / System.Text.RegularExpressions / Match.jvm.cs
1 //
2 // Match.jvm.cs
3 //
4 // Author:
5 //      Arina Itkes  <arinai@mainsoft.com>
6 //
7 // Copyright (C) 2007 Mainsoft, Inc.
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31
32
33 using System;
34 using System.Collections.Generic;
35 using System.Text;
36 using java.util.regex;
37 using java.lang;
38
39 namespace System.Text.RegularExpressions
40 {
41
42         public partial class Match : Group
43         {
44                 #region Fields
45
46                 GroupCollection _monoGroups;
47                 readonly object _monoGroupsLock = new object ();
48
49                 #endregion Fields
50
51                 #region Ctors
52
53                 internal Match (Regex regex, IMachine machine, string text, int text_length, int n_groups,
54                  int index, int length, int n_caps)
55                         : this (regex, machine, new GroupCollection (n_groups), text,
56                         text_length, index, length, n_caps) { }
57
58                 internal Match (Regex regex, IMachine machine,
59                         GroupCollection groups,
60                         string text, int text_length,
61                         int index, int length)
62                         : this (regex, machine, groups, text, text_length, index, length, 1) { }
63
64                 private Match (Regex regex, IMachine machine,
65                                                 GroupCollection groups,
66                                                 string text, int text_length,
67                                                 int index, int length, int n_caps)
68                         : base (text, index, length, n_caps) {
69                         this.regex = regex;
70                         this.machine = machine;
71                         this.text_length = text_length;
72
73                         this.groups = groups;
74                         groups.SetValue (this, 0);
75                 }
76
77                 #endregion Ctors
78
79                 #region Properties
80                 private GroupCollection MonoGroups {
81                         get {
82                                 lock (_monoGroupsLock) {
83                                         if (_monoGroups != null)
84                                                 return _monoGroups;
85
86                                         Match monoMatch = regex.GetMonoMachine ().Scan (regex, text, index, index + length);
87                                         _monoGroups = monoMatch.Groups;
88                                 }
89
90                                 return _monoGroups;
91                         }
92                 }
93
94                 #endregion Properties
95
96                 internal void FillMonoCaptures (Group group) {
97                         group.Captures = MonoGroups [group.GroupNumber].Captures;
98                 }
99         }
100 }