Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Design / system / Data / Common / Utils / StringUtil.cs / 1305376 / StringUtil.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- namespace System.Data.Common.Utils { // This class provides some useful string utilities, e.g., converting a // list to string. internal static class StringUtil { ////// This private static method checks a string to make sure that it is not empty. /// Comparing with String.Empty is not sufficient since a string with nothing /// but white space isn't considered "empty" by that rationale. /// internal static bool IsNullOrEmptyOrWhiteSpace(string value) { return IsNullOrEmptyOrWhiteSpace(value, 0); } internal static bool IsNullOrEmptyOrWhiteSpace(string value, int offset) { // don't use Trim(), which will copy the string, which may be large, just to test for emptyness //return String.IsNullOrEmpty(value) || String.IsNullOrEmpty(value.Trim()); if (null != value) { for(int i = offset; i < value.Length; ++i) { if (!Char.IsWhiteSpace(value[i])) { return false; } } } return true; } // separate implementation from IsNullOrEmptyOrWhiteSpace(string, int) because that one will // pick up the jit optimization to avoid boundary checks and the this won't is unknown (most likely not) internal static bool IsNullOrEmptyOrWhiteSpace(string value, int offset, int length) { // don't use Trim(), which will copy the string, which may be large, just to test for emptyness //return String.IsNullOrEmpty(value) || String.IsNullOrEmpty(value.Trim()); if (null != value) { length = Math.Min(value.Length, length); for(int i = offset; i < length; ++i) { if (!Char.IsWhiteSpace(value[i])) { return false; } } } return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- namespace System.Data.Common.Utils { // This class provides some useful string utilities, e.g., converting a // list to string. internal static class StringUtil { ////// This private static method checks a string to make sure that it is not empty. /// Comparing with String.Empty is not sufficient since a string with nothing /// but white space isn't considered "empty" by that rationale. /// internal static bool IsNullOrEmptyOrWhiteSpace(string value) { return IsNullOrEmptyOrWhiteSpace(value, 0); } internal static bool IsNullOrEmptyOrWhiteSpace(string value, int offset) { // don't use Trim(), which will copy the string, which may be large, just to test for emptyness //return String.IsNullOrEmpty(value) || String.IsNullOrEmpty(value.Trim()); if (null != value) { for(int i = offset; i < value.Length; ++i) { if (!Char.IsWhiteSpace(value[i])) { return false; } } } return true; } // separate implementation from IsNullOrEmptyOrWhiteSpace(string, int) because that one will // pick up the jit optimization to avoid boundary checks and the this won't is unknown (most likely not) internal static bool IsNullOrEmptyOrWhiteSpace(string value, int offset, int length) { // don't use Trim(), which will copy the string, which may be large, just to test for emptyness //return String.IsNullOrEmpty(value) || String.IsNullOrEmpty(value.Trim()); if (null != value) { length = Math.Min(value.Length, length); for(int i = offset; i < length; ++i) { if (!Char.IsWhiteSpace(value[i])) { return false; } } } 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
- InkCanvasSelectionAdorner.cs
- GenericsInstances.cs
- NativeActivityContext.cs
- MediaCommands.cs
- HtmlButton.cs
- DataPager.cs
- IncrementalReadDecoders.cs
- ReadWriteSpinLock.cs
- TypeHelper.cs
- DesignerActionKeyboardBehavior.cs
- CertificateElement.cs
- TrustVersion.cs
- compensatingcollection.cs
- LineProperties.cs
- PrintDocument.cs
- FlagsAttribute.cs
- Section.cs
- PriorityBinding.cs
- Geometry3D.cs
- ObjectHandle.cs
- DataPagerFieldCommandEventArgs.cs
- DeclarativeCatalogPartDesigner.cs
- LexicalChunk.cs
- ControlIdConverter.cs
- Trace.cs
- FileDetails.cs
- Vector3DAnimationBase.cs
- WCFServiceClientProxyGenerator.cs
- CompositeKey.cs
- CommentEmitter.cs
- XmlWrappingReader.cs
- Debug.cs
- AsymmetricKeyExchangeFormatter.cs
- ButtonFieldBase.cs
- DependencyObjectType.cs
- DispatcherHookEventArgs.cs
- COM2PictureConverter.cs
- ShapingEngine.cs
- FormsIdentity.cs
- ServiceOperationViewControl.cs
- XPathNodeIterator.cs
- QualificationDataItem.cs
- ActivationArguments.cs
- CurrentTimeZone.cs
- Registry.cs
- HandleRef.cs
- PackWebRequestFactory.cs
- InheritedPropertyChangedEventArgs.cs
- DataGridViewButtonColumn.cs
- CatalogZoneBase.cs
- SizeF.cs
- Unit.cs
- HttpRequestCacheValidator.cs
- SqlDataSourceCache.cs
- TargetParameterCountException.cs
- SerializableAttribute.cs
- TrackingWorkflowEventArgs.cs
- DispatcherOperation.cs
- ConfigXmlReader.cs
- PerfCounters.cs
- NetworkStream.cs
- CFStream.cs
- XPathNavigatorKeyComparer.cs
- Image.cs
- Freezable.cs
- XmlTextEncoder.cs
- OdbcConnectionPoolProviderInfo.cs
- AssemblyFilter.cs
- TypeConverterHelper.cs
- TextEditorTables.cs
- QilTernary.cs
- datacache.cs
- DrawingContextDrawingContextWalker.cs
- SessionParameter.cs
- DbConnectionPoolCounters.cs
- XmlNavigatorFilter.cs
- SafeHGlobalHandleCritical.cs
- GeometryDrawing.cs
- ISAPIWorkerRequest.cs
- ReferencedAssembly.cs
- SecurityHelper.cs
- DrawingState.cs
- GridViewPageEventArgs.cs
- GeneratedCodeAttribute.cs
- VariantWrapper.cs
- DnsEndpointIdentity.cs
- DataGrid.cs
- FastEncoderWindow.cs
- MetadataArtifactLoaderComposite.cs
- RedistVersionInfo.cs
- DataGridViewTextBoxCell.cs
- ListSourceHelper.cs
- MenuCommand.cs
- WindowVisualStateTracker.cs
- SchemaComplexType.cs
- VersionedStream.cs
- PersistenceTypeAttribute.cs
- WarningException.cs
- InstanceCompleteException.cs
- BuildManagerHost.cs