Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Configuration / RegexWorker.cs / 1305376 / RegexWorker.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Base class for browser capabilities object: just a read-only dictionary * holder that supports Init() * * */ using System.Web.UI; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Globalization; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Web.RegularExpressions; using System.Web.Util; namespace System.Web.Configuration { // public class RegexWorker { internal static readonly Regex RefPat = new BrowserCapsRefRegex(); private Hashtable _groups; private HttpBrowserCapabilities _browserCaps; public RegexWorker(HttpBrowserCapabilities browserCaps) { _browserCaps = browserCaps; } private string Lookup(string from) { MatchCollection matches = RefPat.Matches(from); // shortcut for no reference case if (matches.Count == 0) { return from; } StringBuilder sb = new StringBuilder(); int startIndex = 0; foreach (Match match in matches) { int length = match.Index - startIndex; sb.Append(from.Substring(startIndex, length)); startIndex = match.Index + match.Length; string groupName = match.Groups["name"].Value; string result = null; if (_groups != null) { result = (String)_groups[groupName]; } if (result == null) { result = _browserCaps[groupName]; } sb.Append(result); } sb.Append(from, startIndex, from.Length - startIndex); string output = sb.ToString(); // Return null instead of empty string since empty string is used to override values. if (output.Length == 0) { return null; } return output; } public string this[string key] { get { return Lookup(key); } } public bool ProcessRegex(string target, string regexExpression) { if(target == null) { target = String.Empty; } Regex regex = new Regex(regexExpression, RegexOptions.ExplicitCapture); Match match = regex.Match(target); if(match.Success == false) { return false; } string[] groups = regex.GetGroupNames(); if (groups.Length > 0) { if (_groups == null) { _groups = new Hashtable(); } for (int i = 0; i < groups.Length; i++) { _groups[groups[i]] = match.Groups[i].Value; } } return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Base class for browser capabilities object: just a read-only dictionary * holder that supports Init() * * */ using System.Web.UI; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Globalization; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Web.RegularExpressions; using System.Web.Util; namespace System.Web.Configuration { // public class RegexWorker { internal static readonly Regex RefPat = new BrowserCapsRefRegex(); private Hashtable _groups; private HttpBrowserCapabilities _browserCaps; public RegexWorker(HttpBrowserCapabilities browserCaps) { _browserCaps = browserCaps; } private string Lookup(string from) { MatchCollection matches = RefPat.Matches(from); // shortcut for no reference case if (matches.Count == 0) { return from; } StringBuilder sb = new StringBuilder(); int startIndex = 0; foreach (Match match in matches) { int length = match.Index - startIndex; sb.Append(from.Substring(startIndex, length)); startIndex = match.Index + match.Length; string groupName = match.Groups["name"].Value; string result = null; if (_groups != null) { result = (String)_groups[groupName]; } if (result == null) { result = _browserCaps[groupName]; } sb.Append(result); } sb.Append(from, startIndex, from.Length - startIndex); string output = sb.ToString(); // Return null instead of empty string since empty string is used to override values. if (output.Length == 0) { return null; } return output; } public string this[string key] { get { return Lookup(key); } } public bool ProcessRegex(string target, string regexExpression) { if(target == null) { target = String.Empty; } Regex regex = new Regex(regexExpression, RegexOptions.ExplicitCapture); Match match = regex.Match(target); if(match.Success == false) { return false; } string[] groups = regex.GetGroupNames(); if (groups.Length > 0) { if (_groups == null) { _groups = new Hashtable(); } for (int i = 0; i < groups.Length; i++) { _groups[groups[i]] = match.Groups[i].Value; } } return true; } } } // 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
- DrawListViewItemEventArgs.cs
- KnownTypes.cs
- SequenceNumber.cs
- CompareInfo.cs
- TableFieldsEditor.cs
- Accessible.cs
- Typography.cs
- XmlSchemaDatatype.cs
- ConnectionInterfaceCollection.cs
- ViewSimplifier.cs
- CookieProtection.cs
- HttpCacheParams.cs
- CustomErrorsSectionWrapper.cs
- SHA512.cs
- PerfCounters.cs
- EditorPartChrome.cs
- SourceLineInfo.cs
- CompModHelpers.cs
- ClaimSet.cs
- TypeTypeConverter.cs
- Ports.cs
- CharacterBufferReference.cs
- WebControlAdapter.cs
- OleDbConnectionInternal.cs
- SmiEventSink_DeferedProcessing.cs
- FederatedMessageSecurityOverHttp.cs
- SqlBulkCopyColumnMapping.cs
- TreeViewEvent.cs
- IndexerNameAttribute.cs
- PaintValueEventArgs.cs
- MenuBase.cs
- RenamedEventArgs.cs
- CompoundFileDeflateTransform.cs
- BufferedGraphicsContext.cs
- CopyAction.cs
- ServiceRoute.cs
- OdbcConnectionOpen.cs
- Stacktrace.cs
- TextTreeFixupNode.cs
- RenderCapability.cs
- updatecommandorderer.cs
- HttpHeaderCollection.cs
- MetadataArtifactLoaderComposite.cs
- EventlogProvider.cs
- MouseBinding.cs
- ViewRendering.cs
- CollectionContainer.cs
- XmlNamespaceDeclarationsAttribute.cs
- KerberosSecurityTokenAuthenticator.cs
- SizeConverter.cs
- WSTransactionSection.cs
- Decoder.cs
- ComplexObject.cs
- FieldMetadata.cs
- GenerateDerivedKeyRequest.cs
- SafeLibraryHandle.cs
- CellNormalizer.cs
- StructuralType.cs
- UIElement3DAutomationPeer.cs
- DbDataSourceEnumerator.cs
- ListViewGroupItemCollection.cs
- PageCatalogPart.cs
- WmlMobileTextWriter.cs
- BindMarkupExtensionSerializer.cs
- ToolStripSettings.cs
- InnerItemCollectionView.cs
- SqlServer2KCompatibilityCheck.cs
- PaperSize.cs
- SerializerWriterEventHandlers.cs
- SHA512.cs
- WindowsAltTab.cs
- DrawingVisual.cs
- RangeContentEnumerator.cs
- FontSource.cs
- CertificateElement.cs
- designeractionbehavior.cs
- TimestampInformation.cs
- MimeXmlReflector.cs
- SpeechRecognitionEngine.cs
- SchemeSettingElement.cs
- LineServicesCallbacks.cs
- ProxyWebPartConnectionCollection.cs
- DirectoryInfo.cs
- SecurityDescriptor.cs
- PresentationSource.cs
- TabItemAutomationPeer.cs
- UnmanagedMemoryStream.cs
- CodeNamespaceImport.cs
- AsymmetricAlgorithm.cs
- DescendentsWalker.cs
- ColumnClickEvent.cs
- JavaScriptString.cs
- UdpDuplexChannel.cs
- SocketElement.cs
- CriticalFinalizerObject.cs
- XmlSchemaSimpleContentRestriction.cs
- ConfigUtil.cs
- AspNetRouteServiceHttpHandler.cs
- GenericTypeParameterBuilder.cs
- PointAnimationBase.cs