Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / XmlUtils / System / Xml / Xsl / Runtime / StringConcat.cs / 1 / StringConcat.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.ComponentModel; namespace System.Xml.Xsl.Runtime { ////// Efficiently concatenates strings when the number of string is not known beforehand, and /// yet it is common for only one string to be concatenated. StringBuilder is not good for /// this purpose, since it *always* allocates objects, even if only one string is appended. /// [EditorBrowsable(EditorBrowsableState.Never)] public struct StringConcat { private string s1, s2, s3, s4; private string delimiter; private ListstrList; int idxStr; /// /// Clear the result string. /// public void Clear() { this.idxStr = 0; this.delimiter = null; } ////// Gets or sets the string that delimits concatenated strings. /// public string Delimiter { get { return this.delimiter; } set { this.delimiter = value; } } ////// Return the number of concatenated strings, including delimiters. /// internal int Count { get { return this.idxStr; } } ////// Concatenate a new string to the result. /// public void Concat(string value) { Debug.Assert(value != null); if (this.delimiter != null && this.idxStr != 0) { // Add delimiter ConcatNoDelimiter(this.delimiter); } ConcatNoDelimiter(value); } ////// Get the result string. /// public string GetResult() { switch (this.idxStr) { case 0: return string.Empty; case 1: return this.s1; case 2: return string.Concat(this.s1, this.s2); case 3: return string.Concat(this.s1, this.s2, this.s3); case 4: return string.Concat(this.s1, this.s2, this.s3, this.s4); } return string.Concat(this.strList.ToArray()); } ////// Concatenate a new string to the result without adding a delimiter. /// internal void ConcatNoDelimiter(string s) { switch (this.idxStr) { case 0: this.s1 = s; break; case 1: this.s2 = s; break; case 2: this.s3 = s; break; case 3: this.s4 = s; break; case 4: // Calling Clear() is expensive, allocate a new List instead int capacity = (this.strList == null) ? 8 : this.strList.Count; ListstrList = this.strList = new List (capacity); strList.Add(this.s1); strList.Add(this.s2); strList.Add(this.s3); strList.Add(this.s4); goto default; default: this.strList.Add(s); break; } this.idxStr++; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Diagnostics; using System.ComponentModel; namespace System.Xml.Xsl.Runtime { ////// Efficiently concatenates strings when the number of string is not known beforehand, and /// yet it is common for only one string to be concatenated. StringBuilder is not good for /// this purpose, since it *always* allocates objects, even if only one string is appended. /// [EditorBrowsable(EditorBrowsableState.Never)] public struct StringConcat { private string s1, s2, s3, s4; private string delimiter; private ListstrList; int idxStr; /// /// Clear the result string. /// public void Clear() { this.idxStr = 0; this.delimiter = null; } ////// Gets or sets the string that delimits concatenated strings. /// public string Delimiter { get { return this.delimiter; } set { this.delimiter = value; } } ////// Return the number of concatenated strings, including delimiters. /// internal int Count { get { return this.idxStr; } } ////// Concatenate a new string to the result. /// public void Concat(string value) { Debug.Assert(value != null); if (this.delimiter != null && this.idxStr != 0) { // Add delimiter ConcatNoDelimiter(this.delimiter); } ConcatNoDelimiter(value); } ////// Get the result string. /// public string GetResult() { switch (this.idxStr) { case 0: return string.Empty; case 1: return this.s1; case 2: return string.Concat(this.s1, this.s2); case 3: return string.Concat(this.s1, this.s2, this.s3); case 4: return string.Concat(this.s1, this.s2, this.s3, this.s4); } return string.Concat(this.strList.ToArray()); } ////// Concatenate a new string to the result without adding a delimiter. /// internal void ConcatNoDelimiter(string s) { switch (this.idxStr) { case 0: this.s1 = s; break; case 1: this.s2 = s; break; case 2: this.s3 = s; break; case 3: this.s4 = s; break; case 4: // Calling Clear() is expensive, allocate a new List instead int capacity = (this.strList == null) ? 8 : this.strList.Count; ListstrList = this.strList = new List (capacity); strList.Add(this.s1); strList.Add(this.s2); strList.Add(this.s3); strList.Add(this.s4); goto default; default: this.strList.Add(s); break; } this.idxStr++; } } } // 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
- XmlChildEnumerator.cs
- OpCopier.cs
- XmlAggregates.cs
- DragStartedEventArgs.cs
- BitmapVisualManager.cs
- TlsSspiNegotiation.cs
- ThreadAttributes.cs
- MenuDesigner.cs
- SignatureHelper.cs
- SpecialFolderEnumConverter.cs
- LocalServiceSecuritySettingsElement.cs
- Trace.cs
- FormViewUpdatedEventArgs.cs
- CultureInfoConverter.cs
- SerialPort.cs
- RadioButton.cs
- Configuration.cs
- GACMembershipCondition.cs
- ClientTargetSection.cs
- IisTraceListener.cs
- ExtenderControl.cs
- RecordManager.cs
- CommonRemoteMemoryBlock.cs
- EncoderParameter.cs
- RelOps.cs
- CommentAction.cs
- AttributeCollection.cs
- TableProviderWrapper.cs
- XmlQueryOutput.cs
- DispatcherFrame.cs
- Simplifier.cs
- TextEncodedRawTextWriter.cs
- Executor.cs
- Constraint.cs
- WebServiceFault.cs
- MetadataSerializer.cs
- DataGridViewBindingCompleteEventArgs.cs
- Quad.cs
- UserMapPath.cs
- CngProperty.cs
- ToolStripDropDown.cs
- MultiTrigger.cs
- EntityContainer.cs
- AQNBuilder.cs
- TextBox.cs
- VersionedStreamOwner.cs
- StaticContext.cs
- RemoteEndpointMessageProperty.cs
- Parser.cs
- HtmlLink.cs
- HtmlInputControl.cs
- XmlSignificantWhitespace.cs
- SizeLimitedCache.cs
- _BufferOffsetSize.cs
- ParallelTimeline.cs
- StreamUpdate.cs
- BindingSource.cs
- DbConnectionHelper.cs
- Selection.cs
- AlternateView.cs
- ThreadStartException.cs
- BooleanProjectedSlot.cs
- TypeUtils.cs
- SafeRightsManagementEnvironmentHandle.cs
- ExtentKey.cs
- SqlServer2KCompatibilityAnnotation.cs
- DataGridViewButtonColumn.cs
- PopupEventArgs.cs
- FontStretches.cs
- MetadataItemEmitter.cs
- Context.cs
- RadialGradientBrush.cs
- MetadataImporter.cs
- DataBoundControlAdapter.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- QueryCoreOp.cs
- FontDriver.cs
- FocusWithinProperty.cs
- MarkupProperty.cs
- ValidationVisibilityAttribute.cs
- RuleSetReference.cs
- XmlIlTypeHelper.cs
- SpellerHighlightLayer.cs
- Literal.cs
- MimeFormReflector.cs
- IndicCharClassifier.cs
- WindowsIPAddress.cs
- CodeSubDirectory.cs
- MarkupExtensionParser.cs
- GiveFeedbackEvent.cs
- _FtpDataStream.cs
- HuffmanTree.cs
- TrustManagerPromptUI.cs
- GCHandleCookieTable.cs
- ListViewItemEventArgs.cs
- ToolStripDropDownClosedEventArgs.cs
- IfElseDesigner.xaml.cs
- FileDetails.cs
- SafeNativeMethods.cs
- RemoteWebConfigurationHost.cs