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
- MultiAsyncResult.cs
- SharedUtils.cs
- XmlArrayItemAttributes.cs
- AmbiguousMatchException.cs
- ControlOperationBehavior.cs
- OleDbTransaction.cs
- PopupRoot.cs
- EncryptedType.cs
- VisualCollection.cs
- ObjectMaterializedEventArgs.cs
- ICollection.cs
- filewebrequest.cs
- FileEnumerator.cs
- __ConsoleStream.cs
- ObjectItemCollection.cs
- Publisher.cs
- DefaultEventAttribute.cs
- DataRowChangeEvent.cs
- ExtensionElementCollection.cs
- TcpAppDomainProtocolHandler.cs
- CriticalFinalizerObject.cs
- FixedStringLookup.cs
- FixedSOMPage.cs
- HttpCachePolicyElement.cs
- StateMachineTimers.cs
- OleDbCommand.cs
- Knowncolors.cs
- SqlNamer.cs
- ServiceAuthorizationElement.cs
- XhtmlBasicPanelAdapter.cs
- QueryGeneratorBase.cs
- WindowsUpDown.cs
- UnauthorizedWebPart.cs
- WebPartConnectionsCloseVerb.cs
- EncodingDataItem.cs
- PerfCounters.cs
- LayoutUtils.cs
- DataRowChangeEvent.cs
- LifetimeServices.cs
- Win32Native.cs
- DbConnectionInternal.cs
- ReflectionPermission.cs
- ExtensionSimplifierMarkupObject.cs
- ExpandedProjectionNode.cs
- DateTimeParse.cs
- ProgressBarRenderer.cs
- AppSettingsReader.cs
- SemanticResultValue.cs
- _PooledStream.cs
- mda.cs
- ResolveNameEventArgs.cs
- DynamicPropertyHolder.cs
- ZoomPercentageConverter.cs
- OutputCacheSettingsSection.cs
- TabControlCancelEvent.cs
- ScriptModule.cs
- CollectionBuilder.cs
- QueryRelOp.cs
- PenContext.cs
- _LocalDataStore.cs
- DataTableCollection.cs
- WindowsTreeView.cs
- FrameworkContentElement.cs
- StickyNote.cs
- GridItemPatternIdentifiers.cs
- DecoderExceptionFallback.cs
- _Semaphore.cs
- DbConnectionPoolGroup.cs
- SetIterators.cs
- TableLayoutRowStyleCollection.cs
- DataGridViewColumnConverter.cs
- InstanceDataCollectionCollection.cs
- CultureInfo.cs
- DataBoundLiteralControl.cs
- FactoryId.cs
- XmlDataSource.cs
- Simplifier.cs
- EntityUtil.cs
- PriorityBinding.cs
- ActivityCodeDomReferenceService.cs
- BasicHttpSecurityMode.cs
- ContentType.cs
- WinFormsUtils.cs
- PerfCounters.cs
- SqlParameter.cs
- ObjectAnimationUsingKeyFrames.cs
- TextRangeProviderWrapper.cs
- ServiceInfo.cs
- SqlDataSourceCache.cs
- ProcessThreadCollection.cs
- SQLInt16.cs
- SortedDictionary.cs
- MyContact.cs
- VectorAnimation.cs
- OptimisticConcurrencyException.cs
- RuntimeHandles.cs
- File.cs
- GetBrowserTokenRequest.cs
- SelectedGridItemChangedEvent.cs
- OdbcPermission.cs