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
- ContainerVisual.cs
- WebPartAuthorizationEventArgs.cs
- CodeSnippetCompileUnit.cs
- WebPartConnectionsCloseVerb.cs
- BamlRecordHelper.cs
- KnownTypesHelper.cs
- MethodCallConverter.cs
- Decimal.cs
- OdbcStatementHandle.cs
- SystemBrushes.cs
- ConnectionStringSettingsCollection.cs
- DBSchemaTable.cs
- XomlCompilerHelpers.cs
- PopupEventArgs.cs
- HierarchicalDataBoundControlAdapter.cs
- FileLevelControlBuilderAttribute.cs
- AppDomainManager.cs
- ChameleonKey.cs
- SplineQuaternionKeyFrame.cs
- CachedFontFamily.cs
- RSAOAEPKeyExchangeDeformatter.cs
- AnnotationHelper.cs
- HostingMessageProperty.cs
- SettingsBindableAttribute.cs
- CultureTable.cs
- ParameterBuilder.cs
- WinInet.cs
- TTSVoice.cs
- ConfigurationSectionGroup.cs
- GroupLabel.cs
- StoreContentChangedEventArgs.cs
- DesignTimeVisibleAttribute.cs
- ContractHandle.cs
- RuleConditionDialog.Designer.cs
- FillRuleValidation.cs
- SessionEndedEventArgs.cs
- JsonWriter.cs
- URIFormatException.cs
- LinkClickEvent.cs
- LightweightEntityWrapper.cs
- NamespaceCollection.cs
- XPathSingletonIterator.cs
- PermissionSetEnumerator.cs
- XmlCodeExporter.cs
- AssemblyAttributesGoHere.cs
- TextElementCollectionHelper.cs
- JsonQueryStringConverter.cs
- TemplateControlBuildProvider.cs
- ImageMetadata.cs
- FormClosedEvent.cs
- ImageButton.cs
- MailAddressParser.cs
- ActivityDesignerAccessibleObject.cs
- LinqDataSource.cs
- Pair.cs
- UrlMappingCollection.cs
- FrameDimension.cs
- TreeNodeStyle.cs
- AssemblyNameUtility.cs
- NonVisualControlAttribute.cs
- DummyDataSource.cs
- SqlRetyper.cs
- SimpleTypesSurrogate.cs
- RoutedUICommand.cs
- columnmapfactory.cs
- GridViewAutomationPeer.cs
- SiteMapNodeItem.cs
- DetailsViewPagerRow.cs
- itemelement.cs
- TeredoHelper.cs
- StaticTextPointer.cs
- RecognizerBase.cs
- cookieexception.cs
- ModifierKeysValueSerializer.cs
- ThreadInterruptedException.cs
- InvalidPrinterException.cs
- GeometryGroup.cs
- ExtractedStateEntry.cs
- SplashScreen.cs
- HostedTransportConfigurationManager.cs
- UnmanagedMemoryStreamWrapper.cs
- EncryptedData.cs
- SQLMoney.cs
- PropertyInformation.cs
- FolderNameEditor.cs
- XamlTypeMapperSchemaContext.cs
- DataGridTextBox.cs
- BamlVersionHeader.cs
- Vector3DAnimation.cs
- UserControl.cs
- PointCollectionConverter.cs
- NamespaceMapping.cs
- ExtendedProtectionPolicyTypeConverter.cs
- ConstructorBuilder.cs
- ReadWriteSpinLock.cs
- LinkUtilities.cs
- UInt16Storage.cs
- ColumnHeader.cs
- ExtensionWindowHeader.cs
- SpeechDetectedEventArgs.cs