Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Regex / System / Text / RegularExpressions / RegexGroupCollection.cs / 1305376 / RegexGroupCollection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
// The GroupCollection lists the captured Capture numbers
// contained in a compiled Regex.
namespace System.Text.RegularExpressions {
using System.Collections;
using System.Collections.Generic;
///
///
/// Represents a sequence of capture substrings. The object is used
/// to return the set of captures done by a single capturing group.
///
///
#if !SILVERLIGHT
[ Serializable() ]
#endif
public class GroupCollection : ICollection {
internal Match _match;
#if SILVERLIGHT
internal Dictionary _captureMap;
#else
internal Hashtable _captureMap;
#endif
// cache of Group objects fed to the user
internal Group[] _groups;
/*
* Nonpublic constructor
*/
#if SILVERLIGHT
internal GroupCollection(Match match, Dictionary caps) {
#else
internal GroupCollection(Match match, Hashtable caps) {
#endif
_match = match;
_captureMap = caps;
}
/*
* The object on which to synchronize
*/
///
/// [To be supplied.]
///
public Object SyncRoot {
get {
return _match;
}
}
/*
* ICollection
*/
///
/// [To be supplied.]
///
public bool IsSynchronized {
get {
return false;
}
}
/*
* ICollection
*/
///
/// [To be supplied.]
///
public bool IsReadOnly {
get {
return true;
}
}
///
///
/// Returns the number of groups.
///
///
public int Count {
get {
return _match._matchcount.Length;
}
}
///
/// [To be supplied.]
///
public Group this[int groupnum]
{
get {
return GetGroup(groupnum);
}
}
///
/// [To be supplied.]
///
public Group this[String groupname] {
get {
if (_match._regex == null)
return Group._emptygroup;
return GetGroup(_match._regex.GroupNumberFromName(groupname));
}
}
internal Group GetGroup(int groupnum) {
if (_captureMap != null) {
Object o;
o = _captureMap[groupnum];
if (o == null)
return Group._emptygroup;
//throw new ArgumentOutOfRangeException("groupnum");
return GetGroupImpl((int)o);
}
else {
//if (groupnum >= _match._regex.CapSize || groupnum < 0)
// throw new ArgumentOutOfRangeException("groupnum");
if (groupnum >= _match._matchcount.Length || groupnum < 0)
return Group._emptygroup;
return GetGroupImpl(groupnum);
}
}
/*
* Caches the group objects
*/
internal Group GetGroupImpl(int groupnum) {
if (groupnum == 0)
return _match;
// Construct all the Group objects the first time GetGroup is called
if (_groups == null) {
_groups = new Group[_match._matchcount.Length - 1];
for (int i = 0; i < _groups.Length; i++) {
_groups[i] = new Group(_match._text, _match._matches[i + 1], _match._matchcount[i + 1]);
}
}
return _groups[groupnum - 1];
}
/*
* As required by ICollection
*/
///
///
/// Copies all the elements of the collection to the given array
/// beginning at the given index.
///
///
public void CopyTo(Array array, int arrayIndex) {
if (array == null)
throw new ArgumentNullException("array");
for (int i = arrayIndex, j = 0; j < Count; i++, j++) {
array.SetValue(this[j], i);
}
}
/*
* As required by ICollection
*/
///
///
/// Provides an enumerator in the same order as Item[].
///
///
public IEnumerator GetEnumerator() {
return new GroupEnumerator(this);
}
}
/*
* This non-public enumerator lists all the captures
* Should it be public?
*/
internal class GroupEnumerator : IEnumerator {
internal GroupCollection _rgc;
internal int _curindex;
/*
* Nonpublic constructor
*/
internal GroupEnumerator(GroupCollection rgc) {
_curindex = -1;
_rgc = rgc;
}
/*
* As required by IEnumerator
*/
public bool MoveNext() {
int size = _rgc.Count;
if (_curindex >= size)
return false;
_curindex++;
return(_curindex < size);
}
/*
* As required by IEnumerator
*/
public Object Current {
get { return Capture;}
}
/*
* Returns the current capture
*/
public Capture Capture {
get {
if (_curindex < 0 || _curindex >= _rgc.Count)
throw new InvalidOperationException(SR.GetString(SR.EnumNotStarted));
return _rgc[_curindex];
}
}
/*
* Reset to before the first item
*/
public void Reset() {
_curindex = -1;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
// The GroupCollection lists the captured Capture numbers
// contained in a compiled Regex.
namespace System.Text.RegularExpressions {
using System.Collections;
using System.Collections.Generic;
///
///
/// Represents a sequence of capture substrings. The object is used
/// to return the set of captures done by a single capturing group.
///
///
#if !SILVERLIGHT
[ Serializable() ]
#endif
public class GroupCollection : ICollection {
internal Match _match;
#if SILVERLIGHT
internal Dictionary _captureMap;
#else
internal Hashtable _captureMap;
#endif
// cache of Group objects fed to the user
internal Group[] _groups;
/*
* Nonpublic constructor
*/
#if SILVERLIGHT
internal GroupCollection(Match match, Dictionary caps) {
#else
internal GroupCollection(Match match, Hashtable caps) {
#endif
_match = match;
_captureMap = caps;
}
/*
* The object on which to synchronize
*/
///
/// [To be supplied.]
///
public Object SyncRoot {
get {
return _match;
}
}
/*
* ICollection
*/
///
/// [To be supplied.]
///
public bool IsSynchronized {
get {
return false;
}
}
/*
* ICollection
*/
///
/// [To be supplied.]
///
public bool IsReadOnly {
get {
return true;
}
}
///
///
/// Returns the number of groups.
///
///
public int Count {
get {
return _match._matchcount.Length;
}
}
///
/// [To be supplied.]
///
public Group this[int groupnum]
{
get {
return GetGroup(groupnum);
}
}
///
/// [To be supplied.]
///
public Group this[String groupname] {
get {
if (_match._regex == null)
return Group._emptygroup;
return GetGroup(_match._regex.GroupNumberFromName(groupname));
}
}
internal Group GetGroup(int groupnum) {
if (_captureMap != null) {
Object o;
o = _captureMap[groupnum];
if (o == null)
return Group._emptygroup;
//throw new ArgumentOutOfRangeException("groupnum");
return GetGroupImpl((int)o);
}
else {
//if (groupnum >= _match._regex.CapSize || groupnum < 0)
// throw new ArgumentOutOfRangeException("groupnum");
if (groupnum >= _match._matchcount.Length || groupnum < 0)
return Group._emptygroup;
return GetGroupImpl(groupnum);
}
}
/*
* Caches the group objects
*/
internal Group GetGroupImpl(int groupnum) {
if (groupnum == 0)
return _match;
// Construct all the Group objects the first time GetGroup is called
if (_groups == null) {
_groups = new Group[_match._matchcount.Length - 1];
for (int i = 0; i < _groups.Length; i++) {
_groups[i] = new Group(_match._text, _match._matches[i + 1], _match._matchcount[i + 1]);
}
}
return _groups[groupnum - 1];
}
/*
* As required by ICollection
*/
///
///
/// Copies all the elements of the collection to the given array
/// beginning at the given index.
///
///
public void CopyTo(Array array, int arrayIndex) {
if (array == null)
throw new ArgumentNullException("array");
for (int i = arrayIndex, j = 0; j < Count; i++, j++) {
array.SetValue(this[j], i);
}
}
/*
* As required by ICollection
*/
///
///
/// Provides an enumerator in the same order as Item[].
///
///
public IEnumerator GetEnumerator() {
return new GroupEnumerator(this);
}
}
/*
* This non-public enumerator lists all the captures
* Should it be public?
*/
internal class GroupEnumerator : IEnumerator {
internal GroupCollection _rgc;
internal int _curindex;
/*
* Nonpublic constructor
*/
internal GroupEnumerator(GroupCollection rgc) {
_curindex = -1;
_rgc = rgc;
}
/*
* As required by IEnumerator
*/
public bool MoveNext() {
int size = _rgc.Count;
if (_curindex >= size)
return false;
_curindex++;
return(_curindex < size);
}
/*
* As required by IEnumerator
*/
public Object Current {
get { return Capture;}
}
/*
* Returns the current capture
*/
public Capture Capture {
get {
if (_curindex < 0 || _curindex >= _rgc.Count)
throw new InvalidOperationException(SR.GetString(SR.EnumNotStarted));
return _rgc[_curindex];
}
}
/*
* Reset to before the first item
*/
public void Reset() {
_curindex = -1;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HyperLinkField.cs
- TypeExtensionConverter.cs
- InheritanceAttribute.cs
- Compiler.cs
- brushes.cs
- VerificationAttribute.cs
- ExecutionEngineException.cs
- ProxyWebPartConnectionCollection.cs
- DataControlFieldCell.cs
- DispatchOperation.cs
- DescendantBaseQuery.cs
- XmlSchemaSimpleTypeList.cs
- HashCodeCombiner.cs
- PeerToPeerException.cs
- ParameterBuilder.cs
- DataGridViewRowCancelEventArgs.cs
- PerformanceCounterPermission.cs
- ValidationRule.cs
- DiagnosticStrings.cs
- MatcherBuilder.cs
- SHA1Managed.cs
- BitmapEffectDrawingContextState.cs
- SqlXmlStorage.cs
- iisPickupDirectory.cs
- ToolStripItemImageRenderEventArgs.cs
- TypeUtil.cs
- xdrvalidator.cs
- ComplexBindingPropertiesAttribute.cs
- Int32CollectionConverter.cs
- Query.cs
- IdentifierService.cs
- ListViewTableRow.cs
- BookmarkTable.cs
- WebPartHeaderCloseVerb.cs
- CacheOutputQuery.cs
- ListViewInsertionMark.cs
- BrowserTree.cs
- RubberbandSelector.cs
- CheckBox.cs
- HotCommands.cs
- DropDownList.cs
- DefaultParameterValueAttribute.cs
- ScriptServiceAttribute.cs
- DataControlField.cs
- MetadataException.cs
- MetadataCache.cs
- Inline.cs
- HandoffBehavior.cs
- XmlSchemaAnnotated.cs
- TreeIterator.cs
- XmlEntity.cs
- UserControlParser.cs
- Crc32Helper.cs
- Int16.cs
- FunctionCommandText.cs
- HyperLinkField.cs
- Documentation.cs
- SystemWebCachingSectionGroup.cs
- _DisconnectOverlappedAsyncResult.cs
- Marshal.cs
- InsufficientMemoryException.cs
- AuthenticationConfig.cs
- ScaleTransform3D.cs
- TextClipboardData.cs
- RemotingSurrogateSelector.cs
- RequestCacheValidator.cs
- HtmlListAdapter.cs
- Renderer.cs
- TreeViewCancelEvent.cs
- _StreamFramer.cs
- CompiledIdentityConstraint.cs
- WebPartHeaderCloseVerb.cs
- CharEntityEncoderFallback.cs
- DataGridViewUtilities.cs
- XPathDocument.cs
- HttpServerVarsCollection.cs
- UserValidatedEventArgs.cs
- SelectionBorderGlyph.cs
- IndexedWhereQueryOperator.cs
- DiscoveryMessageSequence11.cs
- ButtonPopupAdapter.cs
- VBCodeProvider.cs
- WorkflowViewStateService.cs
- DrawingImage.cs
- New.cs
- BuildManager.cs
- TransformerInfo.cs
- ErrorProvider.cs
- CommentEmitter.cs
- XmlAnyElementAttribute.cs
- DetailsViewUpdateEventArgs.cs
- SqlDependencyListener.cs
- XMLSchema.cs
- complextypematerializer.cs
- ExtendLockCommand.cs
- BoundColumn.cs
- PolicyLevel.cs
- SafeThemeHandle.cs
- FirewallWrapper.cs
- ButtonBase.cs