Debian Codegraph @

mcs/class/referencesource/System/regex/system/text/regularexpressions/RegexGroup.cs

raw
1 //------------------------------------------------------------------------------
2 // <copyright file="RegexGroup.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6
7 // Group represents the substring or substrings that
8 // are captured by a single capturing group after one
9 // regular expression match.
10
11 namespace System.Text.RegularExpressions {
12 using System.Security.Permissions;
13 using System.Runtime.Serialization;
14
15 /// <devdoc>
16 /// Group
17 /// represents the results from a single capturing group. A capturing group can
18 /// capture zero, one, or more strings in a single match because of quantifiers, so
19 /// Group supplies a collection of Capture objects.
20 /// </devdoc>
21 #if !SILVERLIGHT
22 [ Serializable() ]
23 #endif
24 public class Group : Capture {
25 // the empty group object
26 internal static Group _emptygroup = new Group(String.Empty, new int[0], 0, string.Empty);
27
28 internal int[] _caps;
29 internal int _capcount;
30 internal CaptureCollection _capcoll;
31 #if !SILVERLIGHT
32 [OptionalField]
33 #endif
34 internal string _name;
35
36 internal Group(String text, int[] caps, int capcount, string name)
37
38 : base(text, capcount == 0 ? 0 : caps[(capcount - 1) * 2],
39 capcount == 0 ? 0 : caps[(capcount * 2) - 1]) {
40
41 _caps = caps;
42 _capcount = capcount;
43 _name = name;
44 }
45
46 /*
47 * True if the match was successful
48 */
49 /// <devdoc>
50 /// <para>Indicates whether the match is successful.</para>
51 /// </devdoc>
52 public bool Success {
53 get {
54 return _capcount != 0;
55 }
56 }
57
58 /// <summary>
59 /// Provides the name of the group.
60 /// </summary>
61 public string Name
62 {
63 get
64 {
65 return _name;
66 }
67 }
68
69 /*
70 * The collection of all captures for this group
71 */
72 /// <devdoc>
73 /// <para>
74 /// Returns a collection of all the captures matched by the capturing
75 /// group, in innermost-leftmost-first order (or innermost-rightmost-first order if
76 /// compiled with the "r" option). The collection may have zero or more items.
77 /// </para>
78 /// </devdoc>
79 public CaptureCollection Captures {
80 get {
81 if (_capcoll == null)
82 _capcoll = new CaptureCollection(this);
83
84 return _capcoll;
85 }
86 }
87
88 /*
89 * Convert to a thread-safe object by precomputing cache contents
90 */
91 /// <devdoc>
92 /// <para>Returns
93 /// a Group object equivalent to the one supplied that is safe to share between
94 /// multiple threads.</para>
95 /// </devdoc>
96 #if !SILVERLIGHT
97 #if MONO_FEATURE_CAS
98 [HostProtection(Synchronization=true)]
99 #endif
100 static public Group Synchronized(Group inner) {
101 #else
102 static internal Group Synchronized(Group inner) {
103 #endif
104 if (inner == null)
105 throw new ArgumentNullException("inner");
106
107 // force Captures to be computed.
108
109 CaptureCollection capcoll;
110 Capture dummy;
111
112 capcoll = inner.Captures;
113
114 if (inner._capcount > 0)
115 dummy = capcoll[0];
116
117 return inner;
118 }
119 }
120
121
122 }