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
- PassportPrincipal.cs
- DataServiceEntityAttribute.cs
- WebPartsPersonalizationAuthorization.cs
- HtmlInputSubmit.cs
- BoolExpression.cs
- ImageFormatConverter.cs
- Funcletizer.cs
- ConfigXmlText.cs
- AutomationPatternInfo.cs
- ClockGroup.cs
- SafeFileMappingHandle.cs
- WebPartTransformer.cs
- ZipFileInfoCollection.cs
- XsltQilFactory.cs
- FtpCachePolicyElement.cs
- InstanceCreationEditor.cs
- PreviewPrintController.cs
- ValidationException.cs
- TextEffectCollection.cs
- StringReader.cs
- ProfileModule.cs
- ConnectionsZone.cs
- XamlReader.cs
- ObjectTag.cs
- X509Certificate.cs
- _CommandStream.cs
- Panel.cs
- NetworkInformationException.cs
- CodeRegionDirective.cs
- PropertyCondition.cs
- URLIdentityPermission.cs
- Variable.cs
- dtdvalidator.cs
- SchemaCollectionPreprocessor.cs
- AssociatedControlConverter.cs
- UpDownBase.cs
- ButtonFlatAdapter.cs
- safex509handles.cs
- SharedStatics.cs
- DataGridViewLinkCell.cs
- GeneralTransform3D.cs
- GenericAuthenticationEventArgs.cs
- FacetDescription.cs
- Pen.cs
- UIElement3DAutomationPeer.cs
- SystemSounds.cs
- FontFamilyValueSerializer.cs
- UIElementPropertyUndoUnit.cs
- CheckBox.cs
- CryptoApi.cs
- IndicShape.cs
- WebPartConnection.cs
- ObjectQuery.cs
- AutomationProperty.cs
- URLIdentityPermission.cs
- Int16Storage.cs
- XmlCharType.cs
- MultiTouchSystemGestureLogic.cs
- SafeRightsManagementPubHandle.cs
- ToolStripPanelCell.cs
- NopReturnReader.cs
- ContentPropertyAttribute.cs
- TextTreeNode.cs
- WCFBuildProvider.cs
- StyleSheetRefUrlEditor.cs
- TemplateControlBuildProvider.cs
- TextAnchor.cs
- JournalEntryStack.cs
- HGlobalSafeHandle.cs
- DataRecordObjectView.cs
- ComponentCodeDomSerializer.cs
- XmlNamespaceMapping.cs
- EntityDataSourceMemberPath.cs
- TabletDevice.cs
- ExceptionDetail.cs
- Merger.cs
- SynchronizedDispatch.cs
- CollectionViewSource.cs
- Border.cs
- ManagementObjectCollection.cs
- ToolStripKeyboardHandlingService.cs
- TabletDeviceInfo.cs
- MethodBody.cs
- SystemDropShadowChrome.cs
- BitmapEffectInput.cs
- SizeKeyFrameCollection.cs
- ProviderCollection.cs
- CorrelationTokenInvalidatedHandler.cs
- XPathNavigatorKeyComparer.cs
- Directory.cs
- ConfigurationLockCollection.cs
- GrammarBuilder.cs
- SrgsItemList.cs
- ResourceDisplayNameAttribute.cs
- GetLedgerRequest.cs
- EventListener.cs
- XmlNamedNodeMap.cs
- DataSourceSelectArguments.cs
- MenuItem.cs
- CollectionChangeEventArgs.cs