We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
-
Expand
Microsoft.Win32
-
Expand
Microsoft.Win32.SafeHandles
-
Expand
System
-
Expand
System.Runtime.Hosting
-
Expand
System.Runtime.InteropServices
-
Expand
System.Runtime.CompilerServices
-
Expand
System.Collections
-
Expand
System.Collections.Generic
-
Expand
System.Collections.ObjectModel
-
Expand
System.Configuration.Assemblies
-
Expand
System.Diagnostics
-
Expand
System.Diagnostics.CodeAnalysis
-
Expand
System.Diagnostics.SymbolStore
-
Expand
System.Globalization
-
Expand
System.IO
-
Expand
System.IO.IsolatedStorage
-
Expand
System.Reflection
-
Expand
System.Reflection.Cache
-
Expand
System.Reflection.Emit
-
Expand
System.Resources
-
Expand
System.Runtime
-
Expand
System.Runtime.InteropServices.Expando
-
Expand
System.Runtime.ConstrainedExecution
-
Expand
System.Runtime.Remoting.Activation
-
Expand
System.Runtime.Remoting.Messaging
-
Expand
System.Runtime.Remoting.Channels
-
Expand
System.Runtime.Remoting.Lifetime
-
Expand
System.Runtime.Remoting
-
Expand
System.Runtime.Remoting.Contexts
-
Expand
System.Runtime.Remoting.Proxies
-
Expand
System.Runtime.Remoting.Metadata
-
Expand
System.Runtime.Remoting.Metadata.W3cXsd2001
-
Expand
System.Runtime.Remoting.Services
-
Expand
System.Runtime.Serialization
-
Expand
System.Runtime.Serialization.Formatters
-
Expand
System.Runtime.Serialization.Formatters.Binary
-
Expand
System.Runtime.Versioning
-
Expand
System.Security
-
Expand
System.Security.Cryptography
-
Expand
System.Security.Cryptography.X509Certificates
-
Expand
System.Security.Permissions
-
Expand
System.Security.Policy
-
Expand
System.Security.Principal
-
Expand
System.Security.Util
-
Expand
System.Text
-
Expand
ASCIIEncoding
-
Expand
BaseCodePageEncoding
-
Expand
CodePageDataFileHeader
-
Expand
CodePageEncoding
-
Expand
CodePageHeader
-
Expand
CodePageIndex
-
Expand
DBCSCodePageEncoding
-
Expand
DBCSDecoder
-
Expand
Decoder
-
Expand
Decoder
-
Expand
Decoder
-
Expand
Decoder
-
Expand
DecoderExceptionFallback
-
Expand
DecoderExceptionFallbackBuffer
-
Expand
DecoderFallback
-
Expand
DecoderFallbackBuffer
-
Expand
DecoderFallbackException
-
Expand
DecoderNLS
-
Expand
DecoderReplacementFallback
-
Expand
DecoderReplacementFallbackBuffer
-
Expand
DecoderUTF7Fallback
-
Expand
DecoderUTF7FallbackBuffer
-
Expand
DefaultDecoder
-
Expand
DefaultEncoder
-
Expand
Encoder
-
Expand
Encoder
-
Expand
EncoderExceptionFallback
-
Expand
EncoderExceptionFallbackBuffer
-
Expand
EncoderFallback
-
Expand
EncoderFallbackBuffer
-
Expand
EncoderFallbackException
-
Expand
EncoderNLS
-
Expand
EncoderReplacementFallback
-
Expand
EncoderReplacementFallbackBuffer
-
Expand
Encoding
-
Expand
EncodingByteBuffer
-
Expand
EncodingCharBuffer
-
Expand
EncodingInfo
-
Expand
EncodingNLS
-
Expand
EUCJPEncoding
-
Expand
ExtendedNormalizationForms
-
Expand
GB18030Decoder
-
Expand
GB18030Encoding
-
Expand
InternalDecoderBestFitFallback
-
Expand
InternalDecoderBestFitFallbackBuffer
-
Expand
InternalEncoderBestFitFallback
-
Expand
InternalEncoderBestFitFallbackBuffer
-
Expand
ISCIIDecoder
-
Expand
ISCIIEncoder
-
Expand
ISCIIEncoding
-
Expand
ISO2022Decoder
-
Expand
ISO2022Encoder
-
Expand
ISO2022Encoding
-
Expand
ISO2022Modes
-
Expand
Latin1Encoding
-
Expand
MLangCodePageEncoding
-
Expand
MLangDecoder
-
Expand
MLangEncoder
-
Expand
Normalization
-
Expand
NormalizationForm
-
Expand
SBCSCodePageEncoding
-
Expand
StringBuilder
-
Append(bool)
-
Append(byte)
-
Append(char)
-
Append(char)
-
Append(char, int)
-
Append(char, int)
-
Append(char, int, int)
-
Append(decimal)
-
Append(double)
-
Append(float)
-
Append(int)
-
Append(long)
-
Append(object)
-
Append(sbyte)
-
Append(short)
-
Append(string)
-
Append(string, int, int)
-
Append(uint)
-
Append(ulong)
-
Append(ushort)
-
AppendFormat(IFormatProvider, string, object)
-
AppendFormat(string, object)
-
AppendFormat(string, object)
-
AppendFormat(string, object, object)
-
AppendFormat(string, object, object, object)
-
AppendLine()
-
AppendLine(string)
-
Capacity()
-
CopyTo(int, char, int, int)
-
EnsureCapacity(int)
-
Equals(StringBuilder)
-
FormatError()
-
GetNewString(string, int)
-
GetObjectData(SerializationInfo, StreamingContext)
-
GetThreadSafeString(IntPtr)
-
Insert(int, bool)
-
Insert(int, byte)
-
Insert(int, char)
-
Insert(int, char)
-
Insert(int, char, int, int)
-
Insert(int, decimal)
-
Insert(int, double)
-
Insert(int, float)
-
Insert(int, int)
-
Insert(int, long)
-
Insert(int, object)
-
Insert(int, sbyte)
-
Insert(int, short)
-
Insert(int, string)
-
Insert(int, string, int)
-
Insert(int, uint)
-
Insert(int, ulong)
-
Insert(int, ushort)
-
Length()
-
MaxCapacity()
-
NeedsAllocation(string, int)
-
Remove(int, int)
-
Replace(char, char)
-
Replace(char, char, int, int)
-
Replace(string, string)
-
Replace(string, string, int, int)
-
ReplaceString(IntPtr, string)
-
StringBuilder()
-
StringBuilder(int)
-
StringBuilder(int, int)
-
StringBuilder(SerializationInfo, StreamingContext)
-
StringBuilder(string)
-
StringBuilder(string, int)
-
StringBuilder(string, int, int, int)
-
ToString()
-
ToString(int, int)
-
VerifyClassInvariant()
-
Expand
SurrogateEncoder
-
Expand
UnicodeEncoding
-
Expand
UTF32Decoder
-
Expand
UTF32Encoding
-
Expand
UTF7Encoding
-
Expand
UTF8Decoder
-
Expand
UTF8Encoder
-
Expand
UTF8Encoding
-
Expand
System.Threading
-
Expand
System.Runtime.Remoting.Channels.Http
-
Expand
System.Runtime.Remoting.Channels.Tcp
-
Expand
System.Runtime.Remoting.MetadataServices
-
Expand
System.Runtime.Serialization.Formatters.Soap.Xml
-
Expand
System.Runtime.Serialization.Formatters.Soap
-
Expand
Microsoft.Tools.Caspol
-
Expand
Microsoft.Tools.Build
-
Expand
Microsoft.CSharp
-
Expand
System.CodeDom
-
Expand
System.CodeDom.Compiler
-
Expand
System.Collections.Specialized
-
Expand
System.ComponentModel
-
Expand
System.ComponentModel.Design
-
Expand
System.ComponentModel.Design.Serialization
-
Expand
System.Configuration
-
Expand
System.Web
-
Expand
System.Configuration.Provider
-
Expand
System.Configuration.Internal
-
Expand
System.Internal
-
Expand
System.Windows.Forms
-
Expand
System.Net
-
Expand
System.Net.Sockets
-
Expand
System.Net.NetworkInformation
-
Expand
System.Net.ComImports
-
Expand
System.Net.Security
-
Expand
System.Net.Cache
-
Expand
System.Net.Configuration
-
Expand
System.Text.RegularExpressions
-
Expand
System.Tools
-
Expand
System.IO.Compression
-
Expand
System.IO.Ports
-
Expand
System.Security.AccessControl
-
Expand
System.Xml
-
Expand
System.Xml.XPath.DataBinding
-
Expand
System.Xml.Schema
-
Expand
System.Xml.Serialization
-
Expand
System.Xml.Serialization.Advanced
-
Expand
System.Xml.Serialization.Configuration
-
Expand
System.Xml.XPath
-
Expand
System.Xml.Xsl
-
Expand
System.Xml.Xsl.IlGen
-
Expand
System.Xml.Xsl.Qil
-
Expand
System.Xml.Xsl.Runtime
-
Expand
System.Xml.Xsl.XPath
-
Expand
System.Xml.Xsl.Xslt
-
Expand
System.Xml.Xsl.XsltOld
-
Expand
System.Xml.Xsl.XsltOld.Debugger
-
Expand
Microsoft.JScript
-
Expand
Microsoft.Vsa
-
Expand
Microsoft.JScript.Vsa
- namespace System.Text
- {
- using System.Text;
- using System.Runtime.Serialization;
- using System;
- using System.Runtime.CompilerServices;
- using System.Threading;
- using System.Globalization;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [System.Runtime.InteropServices.ComVisible(true)]
- [Serializable()]
- public sealed class StringBuilder : ISerializable
- {
-
-
-
-
-
-
-
- internal IntPtr m_currentThread = Thread.InternalGetCurrentThread();
- internal int m_MaxCapacity = 0;
-
-
-
- internal volatile string m_StringValue = null;
-
-
-
-
-
-
-
- internal const int DefaultCapacity = 16;
- private const string CapacityField = "Capacity";
- private const string MaxCapacityField = "m_MaxCapacity";
- private const string StringValueField = "m_StringValue";
- private const string ThreadIDField = "m_currentThread";
-
-
-
-
-
-
-
-
-
- public StringBuilder() : this(DefaultCapacity)
- {
- }
-
-
-
- public StringBuilder(int capacity) : this(String.Empty, capacity)
- {
- }
-
-
-
-
-
-
-
- public StringBuilder(string value) : this(value, DefaultCapacity)
- {
- }
-
-
-
-
-
-
-
- public StringBuilder(string value, int capacity) : this(value, 0, ((value != null) ? value.Length : 0), capacity)
- {
- }
-
-
-
-
-
- public StringBuilder(string value, int startIndex, int length, int capacity)
- {
- if (capacity < 0) {
- throw new ArgumentOutOfRangeException("capacity", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_MustBePositive"), "capacity"));
- }
- if (length < 0) {
- throw new ArgumentOutOfRangeException("length", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegNum"), "length"));
- }
-
- if (startIndex < 0) {
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
- }
-
- if (value == null) {
- value = String.Empty;
- }
-
- if (startIndex > value.Length - length) {
- throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_IndexLength"));
- }
-
- m_MaxCapacity = Int32.MaxValue;
-
- if (capacity == 0) {
- capacity = DefaultCapacity;
- }
-
- while (capacity < length) {
- capacity *= 2;
-
-
-
- if (capacity < 0) {
- capacity = length;
- break;
- }
- }
-
- m_StringValue = String.GetStringForStringBuilder(value, startIndex, length, capacity);
- }
-
-
-
- public StringBuilder(int capacity, int maxCapacity)
- {
- if (capacity > maxCapacity) {
- throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_Capacity"));
- }
- if (maxCapacity < 1) {
- throw new ArgumentOutOfRangeException("maxCapacity", Environment.GetResourceString("ArgumentOutOfRange_SmallMaxCapacity"));
- }
-
- if (capacity < 0) {
- throw new ArgumentOutOfRangeException("capacity", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_MustBePositive"), "capacity"));
- }
- if (capacity == 0) {
- capacity = Math.Min(DefaultCapacity, maxCapacity);
- }
-
- m_StringValue = String.GetStringForStringBuilder(String.Empty, capacity);
- m_MaxCapacity = maxCapacity;
-
- }
-
- private StringBuilder(SerializationInfo info, StreamingContext context)
- {
- if (info == null)
- throw new ArgumentNullException("info");
-
- int persistedCapacity = 0;
- string persistedString = null;
- int persistedMaxCapacity = Int32.MaxValue;
- bool capacityPresent = false;
-
-
- SerializationInfoEnumerator enumerator = info.GetEnumerator();
- while (enumerator.MoveNext()) {
- switch (enumerator.Name) {
- case MaxCapacityField:
- persistedMaxCapacity = info.GetInt32(MaxCapacityField);
- break;
- case StringValueField:
- persistedString = info.GetString(StringValueField);
- break;
- case CapacityField:
- persistedCapacity = info.GetInt32(CapacityField);
- capacityPresent = true;
- break;
- default:
-
-
-
- break;
- }
-
- }
-
-
- if (persistedString == null) {
- persistedString = String.Empty;
- }
- if (persistedMaxCapacity < 1 || persistedString.Length > persistedMaxCapacity) {
- throw new SerializationException(Environment.GetResourceString("Serialization_StringBuilderMaxCapacity"));
- }
-
- if (!capacityPresent) {
-
- persistedCapacity = DefaultCapacity;
- if (persistedCapacity < persistedString.Length) {
- persistedCapacity = persistedString.Length;
- }
- if (persistedCapacity > persistedMaxCapacity) {
- persistedCapacity = persistedMaxCapacity;
- }
- }
- if (persistedCapacity < 0 || persistedCapacity < persistedString.Length || persistedCapacity > persistedMaxCapacity) {
- throw new SerializationException(Environment.GetResourceString("Serialization_StringBuilderCapacity"));
- }
-
-
- m_MaxCapacity = persistedMaxCapacity;
- m_StringValue = String.GetStringForStringBuilder(persistedString, 0, persistedString.Length, persistedCapacity);
- VerifyClassInvariant();
- }
-
- void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null) {
- throw new ArgumentNullException("info");
- }
-
- VerifyClassInvariant();
-
- info.AddValue(MaxCapacityField, m_MaxCapacity);
- info.AddValue(CapacityField, Capacity);
- info.AddValue(StringValueField, m_StringValue);
-
- info.AddValue(ThreadIDField, 0);
- }
-
- [System.Diagnostics.Conditional("_DEBUG")]
- private void VerifyClassInvariant()
- {
- BCLDebug.Assert(m_MaxCapacity >= 1, "Invalid StringBuilder");
- BCLDebug.Assert(Capacity >= 0 && Capacity <= m_MaxCapacity, "Invalid StringBuilder");
- BCLDebug.Assert(m_StringValue != null && Capacity >= m_StringValue.Length, "Invalid StringBuilder");
- }
-
- private string GetThreadSafeString(out IntPtr tid)
- {
-
-
-
-
- string temp = m_StringValue;
- tid = Thread.InternalGetCurrentThread();
- if (m_currentThread == tid)
- return temp;
- return String.GetStringForStringBuilder(temp, temp.Capacity);
- }
-
- public int Capacity {
- get { return m_StringValue.Capacity; }
-
- set {
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
-
- if (value < 0) {
- throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity"));
- }
-
- if (value < currentString.Length) {
- throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity"));
- }
-
- if (value > MaxCapacity) {
- throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_Capacity"));
- }
-
- int currCapacity = currentString.Capacity;
-
- if (value != currCapacity) {
-
-
-
- string newString = String.GetStringForStringBuilder(currentString, value);
- ReplaceString(tid, newString);
- }
- }
- }
-
- public int MaxCapacity {
- get { return m_MaxCapacity; }
- }
-
-
-
-
-
-
-
- public int EnsureCapacity(int capacity)
- {
- if (capacity < 0) {
- throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_NeedPosCapacity"));
- }
-
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
-
-
- if (!NeedsAllocation(currentString, capacity)) {
- return currentString.Capacity;
- }
-
- string newString = GetNewString(currentString, capacity);
- ReplaceString(tid, newString);
- return newString.Capacity;
- }
-
- public override string ToString()
- {
-
-
-
-
-
-
- string currentString = m_StringValue;
- IntPtr currentThread = m_currentThread;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (currentThread != Thread.InternalGetCurrentThread()) {
- return String.InternalCopy(currentString);
- }
-
- if ((2 * currentString.Length) < currentString.ArrayLength) {
- return String.InternalCopy(currentString);
- }
-
- currentString.ClearPostNullChar();
- m_currentThread = IntPtr.Zero;
- return currentString;
- }
-
-
- public string ToString(int startIndex, int length)
- {
-
-
- return m_StringValue.InternalSubStringWithChecks(startIndex, length, true);
- }
-
-
-
-
-
- public int Length {
- get { return m_StringValue.Length; }
- set {
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
-
- if (value == 0) {
-
- currentString.SetLength(0);
- ReplaceString(tid, currentString);
- return;
- }
-
- int currentLength = currentString.Length;
- int newlength = value;
-
- if (newlength < 0) {
- throw new ArgumentOutOfRangeException("newlength", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength"));
- }
-
- if (newlength > MaxCapacity) {
- throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity"));
- }
-
-
-
- if (newlength == currentLength) {
- return;
- }
-
-
-
-
- if (newlength <= currentString.Capacity) {
- if (newlength > currentLength) {
- for (int i = currentLength; i < newlength; i++)
-
- currentString.InternalSetCharNoBoundsCheck(i, '\0');
- }
-
- currentString.InternalSetCharNoBoundsCheck(newlength, '\0');
-
- currentString.SetLength(newlength);
- ReplaceString(tid, currentString);
-
- return;
- }
-
-
- int newCapacity = (newlength > currentString.Capacity) ? newlength : currentString.Capacity;
- string newString = String.GetStringForStringBuilder(currentString, newCapacity);
-
-
- newString.SetLength(newlength);
- ReplaceString(tid, newString);
- }
- }
-
- [System.Runtime.CompilerServices.IndexerName("Chars")]
- public char this[int index]
- {
- get { return m_StringValue[index]; }
- set {
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
- currentString.SetChar(index, value);
- ReplaceString(tid, currentString);
- }
- }
-
-
- public StringBuilder Append(char value, int repeatCount)
- {
- if (repeatCount == 0) {
- return this;
- }
- if (repeatCount < 0) {
- throw new ArgumentOutOfRangeException("repeatCount", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount"));
- }
-
-
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
-
- int currentLength = currentString.Length;
- int requiredLength = currentLength + repeatCount;
-
- if (requiredLength < 0)
- throw new OutOfMemoryException();
-
- if (!NeedsAllocation(currentString, requiredLength)) {
- currentString.AppendInPlace(value, repeatCount, currentLength);
- ReplaceString(tid, currentString);
- return this;
- }
-
- string newString = GetNewString(currentString, requiredLength);
- newString.AppendInPlace(value, repeatCount, currentLength);
- ReplaceString(tid, newString);
- return this;
- }
-
-
- public StringBuilder Append(char[] value, int startIndex, int charCount)
- {
- int requiredLength;
-
- if (value == null) {
- if (startIndex == 0 && charCount == 0) {
- return this;
- }
- throw new ArgumentNullException("value");
- }
-
- if (charCount == 0) {
- return this;
- }
-
- if (startIndex < 0) {
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
- }
- if (charCount < 0) {
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
- }
- if (charCount > value.Length - startIndex) {
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
-
- int currentLength = currentString.Length;
- requiredLength = currentLength + charCount;
- if (NeedsAllocation(currentString, requiredLength)) {
- string newString = GetNewString(currentString, requiredLength);
- newString.AppendInPlace(value, startIndex, charCount, currentLength);
- ReplaceString(tid, newString);
- }
- else {
- currentString.AppendInPlace(value, startIndex, charCount, currentLength);
- ReplaceString(tid, currentString);
- }
-
- return this;
- }
-
-
- public StringBuilder Append(string value)
- {
-
-
- if (value == null) {
- return this;
- }
-
- IntPtr tid;
-
- string currentString = m_StringValue;
- tid = Thread.InternalGetCurrentThread();
- if (m_currentThread != tid)
- currentString = String.GetStringForStringBuilder(currentString, currentString.Capacity);
-
- int currentLength = currentString.Length;
-
- int requiredLength = currentLength + value.Length;
-
- if (NeedsAllocation(currentString, requiredLength)) {
- string newString = GetNewString(currentString, requiredLength);
- newString.AppendInPlace(value, currentLength);
- ReplaceString(tid, newString);
- }
- else {
- currentString.AppendInPlace(value, currentLength);
- ReplaceString(tid, currentString);
- }
-
- return this;
- }
-
- unsafe internal StringBuilder Append(char* value, int count)
- {
-
-
- if (value == null) {
- return this;
- }
-
-
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
- int currentLength = currentString.Length;
-
- int requiredLength = currentLength + count;
-
- if (NeedsAllocation(currentString, requiredLength)) {
- string newString = GetNewString(currentString, requiredLength);
- newString.AppendInPlace(value, count, currentLength);
- ReplaceString(tid, newString);
- }
- else {
- currentString.AppendInPlace(value, count, currentLength);
- ReplaceString(tid, currentString);
- }
-
- return this;
- }
-
-
- private bool NeedsAllocation(string currentString, int requiredLength)
- {
-
- return (currentString.ArrayLength <= requiredLength);
- }
-
- private string GetNewString(string currentString, int requiredLength)
- {
- int newCapacity;
- int maxCapacity = m_MaxCapacity;
-
- if (requiredLength < 0) {
- throw new OutOfMemoryException();
- }
-
- if (requiredLength > maxCapacity) {
- throw new ArgumentOutOfRangeException("requiredLength", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity"));
- }
-
- newCapacity = (currentString.Capacity)*2;
-
- if (newCapacity < requiredLength) {
- newCapacity = requiredLength;
- }
-
- if (newCapacity > maxCapacity) {
- newCapacity = maxCapacity;
- }
-
- if (newCapacity <= 0) {
- throw new ArgumentOutOfRangeException("newCapacity", Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity"));
- }
-
- return String.GetStringForStringBuilder(currentString, newCapacity);
- }
-
- private void ReplaceString(IntPtr tid, string value)
- {
- BCLDebug.Assert(value != null, "[StringBuilder.ReplaceString]value!=null");
-
-
-
-
-
-
-
-
-
-
- m_currentThread = tid;
-
- m_StringValue = value;
- }
-
-
-
- public StringBuilder Append(string value, int startIndex, int count)
- {
-
-
- if (value == null) {
- if (startIndex == 0 && count == 0) {
- return this;
- }
- throw new ArgumentNullException("value");
- }
-
- if (count <= 0) {
- if (count == 0) {
- return this;
- }
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
- }
-
- if (startIndex < 0 || (startIndex > value.Length - count)) {
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
- int currentLength = currentString.Length;
-
- int requiredLength = currentLength + count;
-
- if (NeedsAllocation(currentString, requiredLength)) {
- string newString = GetNewString(currentString, requiredLength);
- newString.AppendInPlace(value, startIndex, count, currentLength);
- ReplaceString(tid, newString);
- }
- else {
- currentString.AppendInPlace(value, startIndex, count, currentLength);
- ReplaceString(tid, currentString);
- }
-
- return this;
- }
-
- [System.Runtime.InteropServices.ComVisible(false)]
- public StringBuilder AppendLine()
- {
- return Append(Environment.NewLine);
- }
-
- [System.Runtime.InteropServices.ComVisible(false)]
- public StringBuilder AppendLine(string value)
- {
- Append(value);
- return Append(Environment.NewLine);
- }
-
- [System.Runtime.InteropServices.ComVisible(false)]
- public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
- {
- if (destination == null) {
- throw new ArgumentNullException("destination");
- }
-
- if (count < 0) {
- throw new ArgumentOutOfRangeException(Environment.GetResourceString("Arg_NegativeArgCount"), "count");
- }
-
- if (destinationIndex < 0) {
- throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegNum", "destinationIndex"), "destinationIndex");
- }
-
- if (destinationIndex > destination.Length - count) {
- throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_OffsetOut"));
- }
-
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
- int currentLength = currentString.Length;
-
- if (sourceIndex < 0 || sourceIndex > currentLength) {
- throw new ArgumentOutOfRangeException(Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- if (sourceIndex > currentLength - count) {
- throw new ArgumentException(Environment.GetResourceString("Arg_LongerThanSrcString"));
- }
-
-
- if (count == 0) {
- return;
- }
-
- unsafe {
- fixed (char* dest = &destination[destinationIndex], tsrc = currentString) {
- char* src = tsrc + sourceIndex;
- Buffer.memcpyimpl((byte*)src, (byte*)dest, count * 2);
- }
- }
- }
-
-
-
-
-
-
- unsafe public StringBuilder Insert(int index, string value, int count)
- {
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
- int currentLength = currentString.Length;
-
-
- if (index < 0 || index > currentLength) {
- throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- if (count < 0) {
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
- }
-
-
- if (value == null || value.Length == 0 || count == 0) {
- return this;
- }
-
-
- int requiredLength;
- try {
- requiredLength = checked(currentLength + (value.Length * count));
- }
- catch (OverflowException) {
- throw new OutOfMemoryException();
- }
-
- if (NeedsAllocation(currentString, requiredLength)) {
- string newString = GetNewString(currentString, requiredLength);
- newString.InsertInPlace(index, value, count, currentLength, requiredLength);
- ReplaceString(tid, newString);
- }
- else {
- currentString.InsertInPlace(index, value, count, currentLength, requiredLength);
- ReplaceString(tid, currentString);
- }
- return this;
- }
-
-
-
-
-
-
-
-
- public StringBuilder Remove(int startIndex, int length)
- {
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
- int currentLength = currentString.Length;
-
- if (length < 0) {
- throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength"));
- }
-
- if (startIndex < 0) {
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
- }
-
- if (length > currentLength - startIndex) {
- throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- currentString.RemoveInPlace(startIndex, length, currentLength);
- ReplaceString(tid, currentString);
-
- return this;
- }
-
-
-
-
-
-
-
-
-
-
-
- public StringBuilder Append(bool value)
- {
- return Append(value.ToString());
- }
-
-
-
- [CLSCompliant(false)]
- public StringBuilder Append(sbyte value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
-
- public StringBuilder Append(byte value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
- public StringBuilder Append(char value)
- {
- IntPtr tid;
-
-
- string currentString = m_StringValue;
- tid = Thread.InternalGetCurrentThread();
- if (m_currentThread != tid)
- currentString = String.GetStringForStringBuilder(currentString, currentString.Capacity);
-
- int currentLength = currentString.Length;
- if (!NeedsAllocation(currentString, currentLength + 1)) {
- currentString.AppendInPlace(value, currentLength);
- ReplaceString(tid, currentString);
- return this;
- }
-
- string newString = GetNewString(currentString, currentLength + 1);
- newString.AppendInPlace(value, currentLength);
- ReplaceString(tid, newString);
- return this;
- }
-
-
-
- public StringBuilder Append(short value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
-
- public StringBuilder Append(int value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
-
- public StringBuilder Append(long value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
-
- public StringBuilder Append(float value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
-
- public StringBuilder Append(double value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
- public StringBuilder Append(decimal value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
-
- [CLSCompliant(false)]
- public StringBuilder Append(ushort value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
-
- [CLSCompliant(false)]
- public StringBuilder Append(uint value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
-
-
- [CLSCompliant(false)]
- public StringBuilder Append(ulong value)
- {
- return Append(value.ToString(CultureInfo.CurrentCulture));
- }
-
-
-
- public StringBuilder Append(object value)
- {
- if (null == value) {
-
- return this;
- }
- return Append(value.ToString());
- }
-
-
- public StringBuilder Append(char[] value)
- {
- if (null == value) {
- return this;
- }
-
- int valueLength = value.Length;
-
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
-
- int currentLength = currentString.Length;
- int requiredLength = currentLength + value.Length;
- if (NeedsAllocation(currentString, requiredLength)) {
- string newString = GetNewString(currentString, requiredLength);
- newString.AppendInPlace(value, 0, valueLength, currentLength);
- ReplaceString(tid, newString);
- }
- else {
- currentString.AppendInPlace(value, 0, valueLength, currentLength);
- ReplaceString(tid, currentString);
- }
- return this;
- }
-
-
-
-
-
-
-
-
- public StringBuilder Insert(int index, string value)
- {
- if (value == null)
- return Insert(index, value, 0);
- else
-
- return Insert(index, value, 1);
- }
-
-
-
-
-
-
- public StringBuilder Insert(int index, bool value)
- {
- return Insert(index, value.ToString(), 1);
- }
-
-
-
-
-
-
- [CLSCompliant(false)]
- public StringBuilder Insert(int index, sbyte value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
-
- public StringBuilder Insert(int index, byte value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
-
- public StringBuilder Insert(int index, short value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
-
- public StringBuilder Insert(int index, char value)
- {
- return Insert(index, Char.ToString(value), 1);
- }
-
-
-
-
-
-
- public StringBuilder Insert(int index, char[] value)
- {
- if (null == value) {
- return Insert(index, value, 0, 0);
- }
- return Insert(index, value, 0, value.Length);
- }
-
-
-
-
-
- public StringBuilder Insert(int index, char[] value, int startIndex, int charCount)
- {
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
- int currentLength = currentString.Length;
-
-
- if (index < 0 || index > currentLength) {
- throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
-
- if (value == null) {
- if (startIndex == 0 && charCount == 0) {
- return this;
- }
- throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_String"));
- }
-
-
-
- if (startIndex < 0) {
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
- }
-
- if (charCount < 0) {
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
- }
-
- if (startIndex > value.Length - charCount) {
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- if (charCount == 0) {
-
- return this;
- }
-
- int requiredLength = currentLength + charCount;
- if (NeedsAllocation(currentString, requiredLength)) {
- string newString = GetNewString(currentString, requiredLength);
- newString.InsertInPlace(index, value, startIndex, charCount, currentLength, requiredLength);
- ReplaceString(tid, newString);
- }
- else {
- currentString.InsertInPlace(index, value, startIndex, charCount, currentLength, requiredLength);
- ReplaceString(tid, currentString);
- }
- return this;
- }
-
-
-
-
-
-
- public StringBuilder Insert(int index, int value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
-
- public StringBuilder Insert(int index, long value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
-
- public StringBuilder Insert(int index, float value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
-
-
- public StringBuilder Insert(int index, double value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
- public StringBuilder Insert(int index, decimal value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
- [CLSCompliant(false)]
- public StringBuilder Insert(int index, ushort value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
-
- [CLSCompliant(false)]
- public StringBuilder Insert(int index, uint value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
- [CLSCompliant(false)]
- public StringBuilder Insert(int index, ulong value)
- {
- return Insert(index, value.ToString(CultureInfo.CurrentCulture), 1);
- }
-
-
-
-
-
-
- public StringBuilder Insert(int index, object value)
- {
-
- if (null == value) {
- return this;
- }
- return Insert(index, value.ToString(), 1);
- }
-
- public StringBuilder AppendFormat(string format, object arg0)
- {
- return AppendFormat(null, format, new object[] {arg0});
- }
-
- public StringBuilder AppendFormat(string format, object arg0, object arg1)
- {
- return AppendFormat(null, format, new object[] {arg0, arg1});
- }
-
- public StringBuilder AppendFormat(string format, object arg0, object arg1, object arg2)
- {
- return AppendFormat(null, format, new object[] {arg0, arg1, arg2});
- }
-
- public StringBuilder AppendFormat(string format, params object[] args)
- {
- return AppendFormat(null, format, args);
- }
-
- private static void FormatError()
- {
- throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
- }
-
- public StringBuilder AppendFormat(IFormatProvider provider, string format, params object[] args)
- {
- if (format == null || args == null) {
- throw new ArgumentNullException((format == null) ? "format" : "args");
- }
- char[] chars = format.ToCharArray(0, format.Length);
- int pos = 0;
- int len = chars.Length;
- char ch = '\0';
-
- ICustomFormatter cf = null;
- if (provider != null) {
- cf = (ICustomFormatter)provider.GetFormat(typeof(ICustomFormatter));
- }
-
- while (true) {
- int p = pos;
- int i = pos;
- while (pos < len) {
- ch = chars[pos];
-
- pos++;
- if (ch == '}') {
- if (pos < len && chars[pos] == '}')
- pos++;
- else
-
- FormatError();
- }
-
- if (ch == '{') {
- if (pos < len && chars[pos] == '{')
- pos++;
-
- else {
- pos--;
- break;
- }
- }
-
- chars[i++] = ch;
- }
- if (i > p)
- Append(chars, p, i - p);
- if (pos == len)
- break;
- pos++;
- if (pos == len || (ch = chars[pos]) < '0' || ch > '9')
- FormatError();
- int index = 0;
- do {
- index = index * 10 + ch - '0';
- pos++;
- if (pos == len)
- FormatError();
- ch = chars[pos];
- }
- while (ch >= '0' && ch <= '9' && index < 1000000);
- if (index >= args.Length)
- throw new FormatException(Environment.GetResourceString("Format_IndexOutOfRange"));
- while (pos < len && (ch = chars[pos]) == ' ')
- pos++;
- bool leftJustify = false;
- int width = 0;
- if (ch == ',') {
- pos++;
- while (pos < len && chars[pos] == ' ')
- pos++;
-
- if (pos == len)
- FormatError();
- ch = chars[pos];
- if (ch == '-') {
- leftJustify = true;
- pos++;
- if (pos == len)
- FormatError();
- ch = chars[pos];
- }
- if (ch < '0' || ch > '9')
- FormatError();
- do {
- width = width * 10 + ch - '0';
- pos++;
- if (pos == len)
- FormatError();
- ch = chars[pos];
- }
- while (ch >= '0' && ch <= '9' && width < 1000000);
- }
-
- while (pos < len && (ch = chars[pos]) == ' ')
- pos++;
- object arg = args[index];
- string fmt = null;
- if (ch == ':') {
- pos++;
- p = pos;
- i = pos;
- while (true) {
- if (pos == len)
- FormatError();
- ch = chars[pos];
- pos++;
- if (ch == '{') {
- if (pos < len && chars[pos] == '{')
- pos++;
- else
-
- FormatError();
- }
- else if (ch == '}') {
- if (pos < len && chars[pos] == '}')
- pos++;
-
- else {
- pos--;
- break;
- }
- }
-
- chars[i++] = ch;
- }
- if (i > p)
- fmt = new string(chars, p, i - p);
- }
- if (ch != '}')
- FormatError();
- pos++;
- string s = null;
- if (cf != null) {
- s = cf.Format(fmt, arg, provider);
- }
-
- if (s == null) {
- if (arg is IFormattable) {
- s = ((IFormattable)arg).ToString(fmt, provider);
- }
- else if (arg != null) {
- s = arg.ToString();
- }
- }
-
- if (s == null)
- s = String.Empty;
- int pad = width - s.Length;
- if (!leftJustify && pad > 0)
- Append(' ', pad);
- Append(s);
- if (leftJustify && pad > 0)
- Append(' ', pad);
- }
- return this;
- }
-
-
-
-
-
-
-
- public StringBuilder Replace(string oldValue, string newValue)
- {
- return Replace(oldValue, newValue, 0, Length);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- public extern StringBuilder Replace(string oldValue, string newValue, int startIndex, int count);
-
- public bool Equals(StringBuilder sb)
- {
- if (sb == null)
- return false;
- return ((this.Capacity == sb.Capacity) && (this.MaxCapacity == sb.MaxCapacity) && (this.m_StringValue.Equals(sb.m_StringValue)));
- }
-
-
-
-
-
-
- public StringBuilder Replace(char oldChar, char newChar)
- {
- return Replace(oldChar, newChar, 0, Length);
- }
- public StringBuilder Replace(char oldChar, char newChar, int startIndex, int count)
- {
- IntPtr tid;
- string currentString = GetThreadSafeString(out tid);
- int currentLength = currentString.Length;
-
- if ((uint)startIndex > (uint)currentLength) {
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- if (count < 0 || startIndex > currentLength - count) {
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Index"));
- }
-
- BCLDebug.Assert(!NeedsAllocation(currentString, currentLength), "New allocation should not happen!");
- currentString.ReplaceCharInPlace(oldChar, newChar, startIndex, count, currentLength);
- ReplaceString(tid, currentString);
- return this;
- }
- }
- }