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
- ListBoxAutomationPeer.cs
- ItemsPanelTemplate.cs
- LocationSectionRecord.cs
- Typography.cs
- MultiPropertyDescriptorGridEntry.cs
- FixUpCollection.cs
- DrawingContext.cs
- ArgumentOutOfRangeException.cs
- SafeEventLogWriteHandle.cs
- PageFunction.cs
- XmlSchemaComplexContent.cs
- XmlArrayAttribute.cs
- MouseDevice.cs
- ToolStripMenuItem.cs
- ProviderConnectionPoint.cs
- UserNamePasswordClientCredential.cs
- CustomAttributeSerializer.cs
- FieldToken.cs
- File.cs
- GridLengthConverter.cs
- DecimalFormatter.cs
- LinkedList.cs
- SpellerInterop.cs
- QfeChecker.cs
- TimeoutValidationAttribute.cs
- DefaultMemberAttribute.cs
- followingquery.cs
- MessageDecoder.cs
- AssemblyAttributesGoHere.cs
- CacheVirtualItemsEvent.cs
- PassportAuthenticationEventArgs.cs
- DataAccessor.cs
- CultureInfoConverter.cs
- templategroup.cs
- DataColumnCollection.cs
- DataControlFieldCell.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- SmiTypedGetterSetter.cs
- EditorServiceContext.cs
- DesignerMetadata.cs
- WindowsRichEditRange.cs
- MethodCallTranslator.cs
- TabletDeviceInfo.cs
- DocumentPaginator.cs
- SerializationSectionGroup.cs
- CompositeScriptReference.cs
- WindowInteractionStateTracker.cs
- XmlObjectSerializerReadContextComplexJson.cs
- OperationGenerator.cs
- datacache.cs
- ConfigXmlSignificantWhitespace.cs
- TabletDevice.cs
- ContextProperty.cs
- XmlTextReaderImplHelpers.cs
- InputDevice.cs
- LinkLabelLinkClickedEvent.cs
- UnsafeNativeMethods.cs
- XmlStreamedByteStreamReader.cs
- Int16Animation.cs
- Size.cs
- MessageBox.cs
- DispatcherExceptionEventArgs.cs
- SubMenuStyleCollection.cs
- DbQueryCommandTree.cs
- TreeNodeBinding.cs
- DisplayNameAttribute.cs
- DetailsViewPageEventArgs.cs
- UserControlAutomationPeer.cs
- DynamicRendererThreadManager.cs
- StandardRuntimeEnumValidator.cs
- SQLDouble.cs
- TripleDESCryptoServiceProvider.cs
- AssociatedControlConverter.cs
- EntityClientCacheEntry.cs
- AutoScrollHelper.cs
- SimpleMailWebEventProvider.cs
- DecimalConstantAttribute.cs
- Guid.cs
- Scene3D.cs
- BrowserCapabilitiesCodeGenerator.cs
- ResourceIDHelper.cs
- XmlQualifiedName.cs
- SeverityFilter.cs
- RuntimeIdentifierPropertyAttribute.cs
- ImageKeyConverter.cs
- WebPartConnectionsCancelEventArgs.cs
- TransportConfigurationTypeElementCollection.cs
- CaseDesigner.xaml.cs
- SafeArrayRankMismatchException.cs
- SelectorItemAutomationPeer.cs
- StrokeNodeData.cs
- XomlCompilerHelpers.cs
- lengthconverter.cs
- RegexRunnerFactory.cs
- HyperLinkColumn.cs
- Label.cs
- StylusLogic.cs
- MemberBinding.cs
- EncryptedPackage.cs
- ClipboardData.cs