Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Regex / System / Text / RegularExpressions / RegexMatchCollection.cs / 1305376 / RegexMatchCollection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- // The MatchCollection lists the successful matches that // result when searching a string for a regular expression. namespace System.Text.RegularExpressions { using System.Collections; using System.Collections.Generic; /* * This collection returns a sequence of successful match results, either * from GetMatchCollection() or GetExecuteCollection(). It stops when the * first failure is encountered (it does not return the failed match). */ ////// #if !SILVERLIGHT [ Serializable() ] #endif public class MatchCollection : ICollection { internal Regex _regex; #if SILVERLIGHT internal List/// Represents the set of names appearing as capturing group /// names in a regular expression. /// ///_matches; #else internal ArrayList _matches; #endif internal bool _done; internal String _input; internal int _beginning; internal int _length; internal int _startat; internal int _prevlen; private static int infinite = 0x7FFFFFFF; /* * Nonpublic constructor */ internal MatchCollection(Regex regex, String input, int beginning, int length, int startat) { if (startat < 0 || startat > input.Length) throw new ArgumentOutOfRangeException("startat", SR.GetString(SR.BeginIndexNotNegative)); _regex = regex; _input = input; _beginning = beginning; _length = length; _startat = startat; _prevlen = -1; #if SILVERLIGHT _matches = new List (); #else _matches = new ArrayList(); #endif _done = false; } internal Match GetMatch(int i) { if (i < 0) return null; if (_matches.Count > i) return (Match)_matches[i]; if (_done) return null; Match match; do { match = _regex.Run(false, _prevlen, _input, _beginning, _length, _startat); if (!match.Success) { _done = true; return null; } _matches.Add(match); _prevlen = match._length; _startat = match._textpos; } while (_matches.Count <= i); return match; } /// /// public int Count { get { if (_done) return _matches.Count; GetMatch(infinite); return _matches.Count; } } ////// Returns the number of captures. /// ////// public Object SyncRoot { get { return this; } } ///[To be supplied.] ////// public bool IsSynchronized { get { return false; } } ///[To be supplied.] ////// public bool IsReadOnly { get { return true; } } ///[To be supplied.] ////// public virtual Match this[int i] { get { Match match; match = GetMatch(i); if (match == null) throw new ArgumentOutOfRangeException("i"); return match; } } ////// Returns the ith Match in the collection. /// ////// public void CopyTo(Array array, int arrayIndex) { if ((array != null) && (array.Rank != 1)) { throw new ArgumentException(SR.GetString(SR.Arg_RankMultiDimNotSupported)); } // property access to force computation of whole array int count = Count; try { #if SILVERLIGHT // Array.Copy will check for null. Array.Copy(_matches.ToArray(), 0, array, arrayIndex, count); #else _matches.CopyTo(array, arrayIndex); #endif } catch (ArrayTypeMismatchException) { throw new ArgumentException(SR.GetString(SR.Arg_InvalidArrayType)); } } ////// Copies all the elements of the collection to the given array /// starting at the given index. /// ////// public IEnumerator GetEnumerator() { return new MatchEnumerator(this); } } /* * This non-public enumerator lists all the group matches. * Should it be public? */ #if !SILVERLIGHT [ Serializable() ] #endif internal class MatchEnumerator : IEnumerator { internal MatchCollection _matchcoll; internal Match _match = null; internal int _curindex; internal bool _done; /* * Nonpublic constructor */ internal MatchEnumerator(MatchCollection matchcoll) { _matchcoll = matchcoll; } /* * Advance to the next match */ public bool MoveNext() { if (_done) return false; _match = _matchcoll.GetMatch(_curindex++); if (_match == null) { _done = true; return false; } return true; } /* * The current match */ public Object Current { get { if (_match == null) throw new InvalidOperationException(SR.GetString(SR.EnumNotStarted)); return _match; } } /* * Position before the first item */ public void Reset() { _curindex = 0; _done = false; _match = null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ ///// Provides an enumerator in the same order as Item[i]. /// ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- // The MatchCollection lists the successful matches that // result when searching a string for a regular expression. namespace System.Text.RegularExpressions { using System.Collections; using System.Collections.Generic; /* * This collection returns a sequence of successful match results, either * from GetMatchCollection() or GetExecuteCollection(). It stops when the * first failure is encountered (it does not return the failed match). */ ////// #if !SILVERLIGHT [ Serializable() ] #endif public class MatchCollection : ICollection { internal Regex _regex; #if SILVERLIGHT internal List/// Represents the set of names appearing as capturing group /// names in a regular expression. /// ///_matches; #else internal ArrayList _matches; #endif internal bool _done; internal String _input; internal int _beginning; internal int _length; internal int _startat; internal int _prevlen; private static int infinite = 0x7FFFFFFF; /* * Nonpublic constructor */ internal MatchCollection(Regex regex, String input, int beginning, int length, int startat) { if (startat < 0 || startat > input.Length) throw new ArgumentOutOfRangeException("startat", SR.GetString(SR.BeginIndexNotNegative)); _regex = regex; _input = input; _beginning = beginning; _length = length; _startat = startat; _prevlen = -1; #if SILVERLIGHT _matches = new List (); #else _matches = new ArrayList(); #endif _done = false; } internal Match GetMatch(int i) { if (i < 0) return null; if (_matches.Count > i) return (Match)_matches[i]; if (_done) return null; Match match; do { match = _regex.Run(false, _prevlen, _input, _beginning, _length, _startat); if (!match.Success) { _done = true; return null; } _matches.Add(match); _prevlen = match._length; _startat = match._textpos; } while (_matches.Count <= i); return match; } /// /// public int Count { get { if (_done) return _matches.Count; GetMatch(infinite); return _matches.Count; } } ////// Returns the number of captures. /// ////// public Object SyncRoot { get { return this; } } ///[To be supplied.] ////// public bool IsSynchronized { get { return false; } } ///[To be supplied.] ////// public bool IsReadOnly { get { return true; } } ///[To be supplied.] ////// public virtual Match this[int i] { get { Match match; match = GetMatch(i); if (match == null) throw new ArgumentOutOfRangeException("i"); return match; } } ////// Returns the ith Match in the collection. /// ////// public void CopyTo(Array array, int arrayIndex) { if ((array != null) && (array.Rank != 1)) { throw new ArgumentException(SR.GetString(SR.Arg_RankMultiDimNotSupported)); } // property access to force computation of whole array int count = Count; try { #if SILVERLIGHT // Array.Copy will check for null. Array.Copy(_matches.ToArray(), 0, array, arrayIndex, count); #else _matches.CopyTo(array, arrayIndex); #endif } catch (ArrayTypeMismatchException) { throw new ArgumentException(SR.GetString(SR.Arg_InvalidArrayType)); } } ////// Copies all the elements of the collection to the given array /// starting at the given index. /// ////// public IEnumerator GetEnumerator() { return new MatchEnumerator(this); } } /* * This non-public enumerator lists all the group matches. * Should it be public? */ #if !SILVERLIGHT [ Serializable() ] #endif internal class MatchEnumerator : IEnumerator { internal MatchCollection _matchcoll; internal Match _match = null; internal int _curindex; internal bool _done; /* * Nonpublic constructor */ internal MatchEnumerator(MatchCollection matchcoll) { _matchcoll = matchcoll; } /* * Advance to the next match */ public bool MoveNext() { if (_done) return false; _match = _matchcoll.GetMatch(_curindex++); if (_match == null) { _done = true; return false; } return true; } /* * The current match */ public Object Current { get { if (_match == null) throw new InvalidOperationException(SR.GetString(SR.EnumNotStarted)); return _match; } } /* * Position before the first item */ public void Reset() { _curindex = 0; _done = false; _match = null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007./// Provides an enumerator in the same order as Item[i]. /// ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IApplicationTrustManager.cs
- PixelFormats.cs
- SessionState.cs
- PackageStore.cs
- FieldToken.cs
- SqlWriter.cs
- WebPartZone.cs
- WindowsSpinner.cs
- XmlSerializerOperationBehavior.cs
- SoapCodeExporter.cs
- MultiDataTrigger.cs
- IssuedSecurityTokenProvider.cs
- metadatamappinghashervisitor.cs
- ViewBase.cs
- DownloadProgressEventArgs.cs
- DatatypeImplementation.cs
- URLIdentityPermission.cs
- BamlWriter.cs
- XmlMemberMapping.cs
- HwndAppCommandInputProvider.cs
- X509CertificateCollection.cs
- VBIdentifierName.cs
- DelegateSerializationHolder.cs
- MachineKeySection.cs
- Section.cs
- PeerNameRecord.cs
- ObjectQueryExecutionPlan.cs
- SqlXmlStorage.cs
- WindowsIdentity.cs
- DropShadowEffect.cs
- EditorPart.cs
- PriorityRange.cs
- SecurityAppliedMessage.cs
- ServiceXNameTypeConverter.cs
- Panel.cs
- PackagingUtilities.cs
- ButtonDesigner.cs
- InstanceLockException.cs
- Comparer.cs
- Pens.cs
- MetaTableHelper.cs
- TextDpi.cs
- MsmqIntegrationBindingCollectionElement.cs
- UpdateProgress.cs
- SQLInt16.cs
- GenericTypeParameterConverter.cs
- XmlSignatureProperties.cs
- SizeLimitedCache.cs
- SAPICategories.cs
- MissingFieldException.cs
- MetaChildrenColumn.cs
- GroupQuery.cs
- RangeValidator.cs
- securestring.cs
- SchemeSettingElementCollection.cs
- SchemaConstraints.cs
- BigInt.cs
- ManagementException.cs
- MetadataCache.cs
- Timer.cs
- NullNotAllowedCollection.cs
- TransformProviderWrapper.cs
- MappingItemCollection.cs
- ReliabilityContractAttribute.cs
- WebBrowserNavigatedEventHandler.cs
- ToggleButton.cs
- HttpUnhandledOperationInvoker.cs
- TabOrder.cs
- TextDecorationCollectionConverter.cs
- XmlSerializerFactory.cs
- ImmutableCommunicationTimeouts.cs
- ListCollectionView.cs
- GenericUriParser.cs
- BaseValidator.cs
- SqlRemoveConstantOrderBy.cs
- DetailsViewDeletedEventArgs.cs
- WinInet.cs
- PermissionListSet.cs
- KeyGesture.cs
- HttpMethodConstraint.cs
- Vector3dCollection.cs
- Triangle.cs
- Shared.cs
- HtmlElement.cs
- XmlCharCheckingReader.cs
- EndpointDispatcher.cs
- ByteStack.cs
- CssTextWriter.cs
- EpmTargetTree.cs
- FixedSchema.cs
- RightsDocument.cs
- GestureRecognizer.cs
- JsonReader.cs
- DbXmlEnabledProviderManifest.cs
- SoapObjectReader.cs
- ToolStripDropDownButton.cs
- TailCallAnalyzer.cs
- XmlLanguage.cs
- SqlReferenceCollection.cs
- CompilerWrapper.cs