diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs index da35b451e5d..7c94fa97b69 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/KnownStrings.cs @@ -35,7 +35,7 @@ internal static class KnownStrings public const string DefaultPrefix = "p"; public const string ReferenceName = "__ReferenceID"; - public static ReadOnlySpan WhitespaceChars => [' ', '\t', '\n', '\r', '\f']; + public static readonly char[] WhitespaceChars = [' ', '\t', '\n', '\r', '\f']; public const char SpaceChar = ' '; public const char TabChar = '\t'; public const char NewlineChar = '\n'; diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs index 0e8071404cc..b46b1c5a53b 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/ContentType.cs @@ -287,9 +287,9 @@ public override string ToString() { foreach (string paramterKey in _parameterDictionary.Keys) { - stringBuilder.Append(LinearWhiteSpaceChars[0]); + stringBuilder.Append(_linearWhiteSpaceChars[0]); stringBuilder.Append(_semicolonSeparator); - stringBuilder.Append(LinearWhiteSpaceChars[0]); + stringBuilder.Append(_linearWhiteSpaceChars[0]); stringBuilder.Append(paramterKey); stringBuilder.Append(_equalSeparator); stringBuilder.Append(_parameterDictionary[paramterKey]); @@ -399,13 +399,13 @@ private static void ValidateCarriageReturns(string contentType) //character of the content type are not Linear White Spaces. So its safe to //assume that the index will be greater than 0 and less that length-2. - int index = contentType.IndexOf(LinearWhiteSpaceChars[2]); + int index = contentType.IndexOf(_linearWhiteSpaceChars[2]); while (index != -1) { - if (contentType[index - 1] == LinearWhiteSpaceChars[1] || contentType[index + 1] == LinearWhiteSpaceChars[1]) + if (contentType[index - 1] == _linearWhiteSpaceChars[1] || contentType[index + 1] == _linearWhiteSpaceChars[1]) { - index = contentType.IndexOf(LinearWhiteSpaceChars[2], ++index); + index = contentType.IndexOf(_linearWhiteSpaceChars[2], ++index); } else throw new ArgumentException(SR.InvalidLinearWhiteSpaceCharacter); @@ -421,7 +421,7 @@ private static void ValidateCarriageReturns(string contentType) private void ParseTypeAndSubType(ReadOnlySpan typeAndSubType) { //okay to trim at this point the end of the string as Linear White Spaces(LWS) chars are allowed here. - typeAndSubType = typeAndSubType.TrimEnd(LinearWhiteSpaceChars); + typeAndSubType = typeAndSubType.TrimEnd(_linearWhiteSpaceChars); int forwardSlashPos = typeAndSubType.IndexOf('/'); if (forwardSlashPos < 0 || // no slashes @@ -460,7 +460,7 @@ private void ParseParameterAndValue(ReadOnlySpan parameterAndValue) //okay to trim start as there can be spaces before the begining //of the parameter name. - parameterAndValue = parameterAndValue.TrimStart(LinearWhiteSpaceChars); + parameterAndValue = parameterAndValue.TrimStart(_linearWhiteSpaceChars); int equalSignIndex = parameterAndValue.IndexOf(_equalSeparator); @@ -478,7 +478,7 @@ private void ParseParameterAndValue(ReadOnlySpan parameterAndValue) ValidateToken(parameterAndValue.Slice(0, equalSignIndex).ToString()), ValidateQuotedStringOrToken(parameterAndValue.Slice(parameterStartIndex, parameterValueLength).ToString())); - parameterAndValue = parameterAndValue.Slice(parameterStartIndex + parameterValueLength).TrimStart(LinearWhiteSpaceChars); + parameterAndValue = parameterAndValue.Slice(parameterStartIndex + parameterValueLength).TrimStart(_linearWhiteSpaceChars); } } @@ -501,7 +501,7 @@ private static int GetLengthOfParameterValue(ReadOnlySpan s, int startInde if (semicolonIndex != -1) { - int lwsIndex = s.Slice(startIndex).IndexOfAny(LinearWhiteSpaceChars); + int lwsIndex = s.Slice(startIndex).IndexOfAny(_linearWhiteSpaceChars); length = lwsIndex != -1 && lwsIndex < semicolonIndex ? lwsIndex : semicolonIndex; length += startIndex; // the indexes from IndexOf{Any} are based on slicing from startIndex } @@ -635,7 +635,7 @@ private static bool IsAsciiLetterOrDigit(char character) => /// /// input character /// - private static bool IsLinearWhiteSpaceChar(char ch) => LinearWhiteSpaceChars.Contains(ch); + private static bool IsLinearWhiteSpaceChar(char ch) => new ReadOnlySpan(_linearWhiteSpaceChars).Contains(ch); /// /// Lazy initialization for the ParameterDictionary @@ -678,7 +678,7 @@ private void EnsureParameterDictionary() ]; //Linear White Space characters - private static ReadOnlySpan LinearWhiteSpaceChars => [ + private static readonly char[] _linearWhiteSpaceChars = [ ' ', // space - \x20 '\n', // new line - \x0A '\r', // carriage return - \x0D