Nullable: String (#23450)
authorSantiago Fernandez Madero <safern@microsoft.com>
Tue, 26 Mar 2019 16:27:32 +0000 (09:27 -0700)
committerSantiago Fernandez Madero <safern@microsoft.com>
Thu, 28 Mar 2019 00:31:48 +0000 (17:31 -0700)
src/System.Private.CoreLib/shared/System/String.Comparison.cs
src/System.Private.CoreLib/shared/System/String.Manipulation.cs
src/System.Private.CoreLib/shared/System/String.Searching.cs
src/System.Private.CoreLib/shared/System/String.cs
src/System.Private.CoreLib/src/System/String.CoreCLR.cs

index dde5cad..826848a 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Diagnostics;
 using System.Globalization;
 using System.Numerics;
@@ -178,7 +179,7 @@ namespace System
         // to determine whether it is lexicographically less, equal, or greater, and then returns
         // either a negative integer, 0, or a positive integer; respectively.
         //
-        public static int Compare(string strA, string strB)
+        public static int Compare(string? strA, string? strB)
         {
             return Compare(strA, strB, StringComparison.CurrentCulture);
         }
@@ -189,7 +190,7 @@ namespace System
         // negative integer, 0, or a positive integer is returned; respectively.
         // The case-sensitive option is set by ignoreCase
         //
-        public static int Compare(string strA, string strB, bool ignoreCase)
+        public static int Compare(string? strA, string? strB, bool ignoreCase)
         {
             var comparisonType = ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
             return Compare(strA, strB, comparisonType);
@@ -198,7 +199,7 @@ namespace System
 
         // Provides a more flexible function for string comparison. See StringComparison 
         // for meaning of different comparisonType.
-        public static int Compare(string strA, string strB, StringComparison comparisonType)
+        public static int Compare(string? strA, string? strB, StringComparison comparisonType)
         {
             if (object.ReferenceEquals(strA, strB))
             {
@@ -251,7 +252,7 @@ namespace System
         // to determine whether it is lexicographically less, equal, or greater, and then a
         // negative integer, 0, or a positive integer is returned; respectively.
         //
-        public static int Compare(string strA, string strB, CultureInfo culture, CompareOptions options)
+        public static int Compare(string? strA, string? strB, CultureInfo culture, CompareOptions options)
         {
             if (culture == null)
             {
@@ -269,7 +270,7 @@ namespace System
         // The case-sensitive option is set by ignoreCase, and the culture is set
         // by culture
         //
-        public static int Compare(string strA, string strB, bool ignoreCase, CultureInfo culture)
+        public static int Compare(string? strA, string? strB, bool ignoreCase, CultureInfo culture)
         {
             var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
             return Compare(strA, strB, culture, options);
@@ -279,7 +280,7 @@ namespace System
         // at indexA of given length is compared with the substring of strB
         // beginning at indexB of the same length.
         //
-        public static int Compare(string strA, int indexA, string strB, int indexB, int length)
+        public static int Compare(string? strA, int indexA, string? strB, int indexB, int length)
         {
             // NOTE: It's important we call the boolean overload, and not the StringComparison
             // one. The two have some subtly different behavior (see notes in the former).
@@ -290,7 +291,7 @@ namespace System
         // at indexA of given length is compared with the substring of strB
         // beginning at indexB of the same length.  Case sensitivity is determined by the ignoreCase boolean.
         //
-        public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase)
+        public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, bool ignoreCase)
         {
             // Ideally we would just forward to the string.Compare overload that takes
             // a StringComparison parameter, and just pass in CurrentCulture/CurrentCultureIgnoreCase.
@@ -328,7 +329,7 @@ namespace System
         // beginning at indexB of the same length.  Case sensitivity is determined by the ignoreCase boolean,
         // and the culture is set by culture.
         //
-        public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase, CultureInfo culture)
+        public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, bool ignoreCase, CultureInfo culture)
         {
             var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
             return Compare(strA, indexA, strB, indexB, length, culture, options);
@@ -339,7 +340,7 @@ namespace System
         // at indexA of length length is compared with the substring of strB
         // beginning at indexB of the same length.
         //
-        public static int Compare(string strA, int indexA, string strB, int indexB, int length, CultureInfo culture, CompareOptions options)
+        public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, CultureInfo culture, CompareOptions options)
         {
             if (culture == null)
             {
@@ -362,7 +363,7 @@ namespace System
             return culture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, options);
         }
 
-        public static int Compare(string strA, int indexA, string strB, int indexB, int length, StringComparison comparisonType)
+        public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, StringComparison comparisonType)
         {
             CheckStringComparison(comparisonType);
 
@@ -424,7 +425,7 @@ namespace System
 
         // Compares strA and strB using an ordinal (code-point) comparison.
         //
-        public static int CompareOrdinal(string strA, string strB)
+        public static int CompareOrdinal(string? strA, string? strB)
         {
             if (object.ReferenceEquals(strA, strB))
             {
@@ -457,7 +458,7 @@ namespace System
 
         // Compares strA and strB using an ordinal (code-point) comparison.
         //
-        public static int CompareOrdinal(string strA, int indexA, string strB, int indexB, int length)
+        public static int CompareOrdinal(string? strA, int indexA, string? strB, int indexB, int length)
         {
             if (strA == null || strB == null)
             {
@@ -505,7 +506,7 @@ namespace System
         // indicates the relationship. This method returns a value less than 0 if this is less than value, 0
         // if this is equal to value, or a value greater than 0 if this is greater than value.
         //
-        public int CompareTo(object value)
+        public int CompareTo(object? value)
         {
             if (value == null)
             {
@@ -522,7 +523,7 @@ namespace System
 
         // Determines the sorting relation of StrB to the current instance.
         //
-        public int CompareTo(string strB)
+        public int CompareTo(string? strB)
         {
             return string.Compare(this, strB, StringComparison.CurrentCulture);
         }
@@ -578,7 +579,7 @@ namespace System
             }
         }
 
-        public bool EndsWith(string value, bool ignoreCase, CultureInfo culture)
+        public bool EndsWith(string value, bool ignoreCase, CultureInfo? culture)
         {
             if (null == value)
             {
@@ -601,7 +602,7 @@ namespace System
         }
 
         // Determines whether two strings match.
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             if (object.ReferenceEquals(this, obj))
                 return true;
@@ -616,7 +617,7 @@ namespace System
         }
 
         // Determines whether two strings match.
-        public bool Equals(string value)
+        public bool Equals(string? value)
         {
             if (object.ReferenceEquals(this, value))
                 return true;
@@ -634,15 +635,15 @@ namespace System
             return EqualsHelper(this, value);
         }
 
-        public bool Equals(string value, StringComparison comparisonType)
+        public bool Equals(string? value, StringComparison comparisonType)
         {
-            if ((object)this == (object)value)
+            if (object.ReferenceEquals(this, value))
             {
                 CheckStringComparison(comparisonType);
                 return true;
             }
 
-            if ((object)value == null)
+            if (value is null)
             {
                 CheckStringComparison(comparisonType);
                 return false;
@@ -676,14 +677,14 @@ namespace System
 
 
         // Determines whether two Strings match.
-        public static bool Equals(string a, string b)
+        public static bool Equals(string? a, string? b)
         {
-            if ((object)a == (object)b)
+            if (object.ReferenceEquals(a,b))
             {
                 return true;
             }
 
-            if ((object)a == null || (object)b == null || a.Length != b.Length)
+            if (a is null || b is null || a.Length != b.Length)
             {
                 return false;
             }
@@ -691,15 +692,15 @@ namespace System
             return EqualsHelper(a, b);
         }
 
-        public static bool Equals(string a, string b, StringComparison comparisonType)
+        public static bool Equals(string? a, string? b, StringComparison comparisonType)
         {
-            if ((object)a == (object)b)
+            if (object.ReferenceEquals(a, b))
             {
                 CheckStringComparison(comparisonType);
                 return true;
             }
 
-            if ((object)a == null || (object)b == null)
+            if (a is null || b is null)
             {
                 CheckStringComparison(comparisonType);
                 return false;
@@ -731,12 +732,12 @@ namespace System
             }
         }
 
-        public static bool operator ==(string a, string b)
+        public static bool operator ==(string? a, string? b)
         {
             return string.Equals(a, b);
         }
 
-        public static bool operator !=(string a, string b)
+        public static bool operator !=(string? a, string? b)
         {
             return !string.Equals(a, b);
         }
@@ -840,7 +841,7 @@ namespace System
         //
         public bool StartsWith(string value)
         {
-            if ((object)value == null)
+            if (value is null)
             {
                 throw new ArgumentNullException(nameof(value));
             }
@@ -849,7 +850,7 @@ namespace System
 
         public bool StartsWith(string value, StringComparison comparisonType)
         {
-            if ((object)value == null)
+            if (value is null)
             {
                 throw new ArgumentNullException(nameof(value));
             }
@@ -900,7 +901,7 @@ namespace System
             }
         }
 
-        public bool StartsWith(string value, bool ignoreCase, CultureInfo culture)
+        public bool StartsWith(string value, bool ignoreCase, CultureInfo? culture)
         {
             if (null == value)
             {
index 82d7422..bd56d0c 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Buffers;
 using System.Collections.Generic;
 using System.Diagnostics;
@@ -33,7 +34,7 @@ namespace System
             }
         }
 
-        public static string Concat(object arg0)
+        public static string Concat(object? arg0)
         {
             if (arg0 == null)
             {
@@ -42,7 +43,7 @@ namespace System
             return arg0.ToString();
         }
 
-        public static string Concat(object arg0, object arg1)
+        public static string Concat(object? arg0, object? arg1)
         {
             if (arg0 == null)
             {
@@ -56,7 +57,7 @@ namespace System
             return Concat(arg0.ToString(), arg1.ToString());
         }
 
-        public static string Concat(object arg0, object arg1, object arg2)
+        public static string Concat(object? arg0, object? arg1, object? arg2)
         {
             if (arg0 == null)
             {
@@ -76,7 +77,7 @@ namespace System
             return Concat(arg0.ToString(), arg1.ToString(), arg2.ToString());
         }
 
-        public static string Concat(params object[] args)
+        public static string Concat(params object?[] args)
         {
             if (args == null)
             {
@@ -105,7 +106,7 @@ namespace System
 
             for (int i = 0; i < args.Length; i++)
             {
-                object value = args[i];
+                object? value = args[i];
 
                 string toString = value?.ToString() ?? string.Empty; // We need to handle both the cases when value or value.ToString() is null
                 strings[i] = toString;
@@ -195,7 +196,7 @@ namespace System
                     // Everything should be called in the order
                     // MoveNext-Current-ToString, unless further optimizations
                     // can be made, to avoid breaking changes
-                    string firstString = currentValue?.ToString();
+                    string? firstString = currentValue?.ToString();
 
                     // If there's only 1 item, simply call ToString on that
                     if (!en.MoveNext())
@@ -225,17 +226,17 @@ namespace System
             }
         }
 
-        public static string Concat(IEnumerable<string> values)
+        public static string Concat(IEnumerable<string?> values)
         {
             if (values == null)
                 throw new ArgumentNullException(nameof(values));
 
-            using (IEnumerator<string> en = values.GetEnumerator())
+            using (IEnumerator<string?> en = values.GetEnumerator())
             {
                 if (!en.MoveNext())
                     return string.Empty;
 
-                string firstValue = en.Current;
+                string? firstValue = en.Current;
 
                 if (!en.MoveNext())
                 {
@@ -255,7 +256,7 @@ namespace System
             }
         }
 
-        public static string Concat(string str0, string str1)
+        public static string Concat(string? str0, string? str1)
         {
             if (IsNullOrEmpty(str0))
             {
@@ -281,7 +282,7 @@ namespace System
             return result;
         }
 
-        public static string Concat(string str0, string str1, string str2)
+        public static string Concat(string? str0, string? str1, string? str2)
         {
             if (IsNullOrEmpty(str0))
             {
@@ -308,7 +309,7 @@ namespace System
             return result;
         }
 
-        public static string Concat(string str0, string str1, string str2, string str3)
+        public static string Concat(string? str0, string? str1, string? str2, string? str3)
         {
             if (IsNullOrEmpty(str0))
             {
@@ -405,7 +406,7 @@ namespace System
             return result;
         }
 
-        public static string Concat(params string[] values)
+        public static string Concat(params string?[] values)
         {
             if (values == null)
                 throw new ArgumentNullException(nameof(values));
@@ -428,7 +429,7 @@ namespace System
             long totalLengthLong = 0;
             for (int i = 0; i < values.Length; i++)
             {
-                string value = values[i];
+                string? value = values[i];
                 if (value != null)
                 {
                     totalLengthLong += value.Length;
@@ -451,7 +452,7 @@ namespace System
             int copiedLength = 0;
             for (int i = 0; i < values.Length; i++)
             {
-                string value = values[i];
+                string? value = values[i];
                 if (!string.IsNullOrEmpty(value))
                 {
                     int valueLen = value.Length;
@@ -470,25 +471,25 @@ namespace System
             // something changed concurrently to mutate the input array: fall back to
             // doing the concatenation again, but this time with a defensive copy. This
             // fall back should be extremely rare.
-            return copiedLength == totalLength ? result : Concat((string[])values.Clone());
+            return copiedLength == totalLength ? result : Concat((string?[])values.Clone());
         }
 
-        public static string Format(string format, object arg0)
+        public static string Format(string format, object? arg0)
         {
             return FormatHelper(null, format, new ParamsArray(arg0));
         }
 
-        public static string Format(string format, object arg0, object arg1)
+        public static string Format(string format, object? arg0, object? arg1)
         {
             return FormatHelper(null, format, new ParamsArray(arg0, arg1));
         }
 
-        public static string Format(string format, object arg0, object arg1, object arg2)
+        public static string Format(string format, object? arg0, object? arg1, object? arg2)
         {
             return FormatHelper(null, format, new ParamsArray(arg0, arg1, arg2));
         }
 
-        public static string Format(string format, params object[] args)
+        public static string Format(string format, params object?[] args)
         {
             if (args == null)
             {
@@ -500,22 +501,22 @@ namespace System
             return FormatHelper(null, format, new ParamsArray(args));
         }
 
-        public static string Format(IFormatProvider provider, string format, object arg0)
+        public static string Format(IFormatProvider? provider, string format, object? arg0)
         {
             return FormatHelper(provider, format, new ParamsArray(arg0));
         }
 
-        public static string Format(IFormatProvider provider, string format, object arg0, object arg1)
+        public static string Format(IFormatProvider? provider, string format, object? arg0, object? arg1)
         {
             return FormatHelper(provider, format, new ParamsArray(arg0, arg1));
         }
 
-        public static string Format(IFormatProvider provider, string format, object arg0, object arg1, object arg2)
+        public static string Format(IFormatProvider? provider, string format, object? arg0, object? arg1, object? arg2)
         {
             return FormatHelper(provider, format, new ParamsArray(arg0, arg1, arg2));
         }
 
-        public static string Format(IFormatProvider provider, string format, params object[] args)
+        public static string Format(IFormatProvider? provider, string format, params object?[] args)
         {
             if (args == null)
             {
@@ -527,7 +528,7 @@ namespace System
             return FormatHelper(provider, format, new ParamsArray(args));
         }
 
-        private static string FormatHelper(IFormatProvider provider, string format, ParamsArray args)
+        private static string FormatHelper(IFormatProvider? provider, string format, ParamsArray args)
         {
             if (format == null)
                 throw new ArgumentNullException(nameof(format));
@@ -574,7 +575,7 @@ namespace System
             return result;
         }
 
-        public static string Join(char separator, params string[] value)
+        public static string Join(char separator, params string?[] value)
         {
             if (value == null)
             {
@@ -584,7 +585,7 @@ namespace System
             return Join(separator, value, 0, value.Length);
         }
 
-        public static unsafe string Join(char separator, params object[] values)
+        public static unsafe string Join(char separator, params object?[] values)
         {
             // Defer argument validation to the internal function
             return JoinCore(&separator, 1, values);
@@ -596,7 +597,7 @@ namespace System
             return JoinCore(&separator, 1, values);
         }
 
-        public static unsafe string Join(char separator, string[] value, int startIndex, int count)
+        public static unsafe string Join(char separator, string?[] value, int startIndex, int count)
         {
             // Defer argument validation to the internal function
             return JoinCore(&separator, 1, value, startIndex, count);
@@ -604,7 +605,7 @@ namespace System
 
         // Joins an array of strings together as one string with a separator between each original string.
         //
-        public static string Join(string separator, params string[] value)
+        public static string Join(string? separator, params string?[] value)
         {
             if (value == null)
             {
@@ -613,7 +614,7 @@ namespace System
             return Join(separator, value, 0, value.Length);
         }
 
-        public static unsafe string Join(string separator, params object[] values)
+        public static unsafe string Join(string? separator, params object?[] values)
         {
             separator = separator ?? string.Empty;
             fixed (char* pSeparator = &separator._firstChar)
@@ -623,7 +624,7 @@ namespace System
             }
         }
 
-        public static unsafe string Join<T>(string separator, IEnumerable<T> values)
+        public static unsafe string Join<T>(string? separator, IEnumerable<T> values)
         {
             separator = separator ?? string.Empty;
             fixed (char* pSeparator = &separator._firstChar)
@@ -633,7 +634,7 @@ namespace System
             }
         }
 
-        public static string Join(string separator, IEnumerable<string> values)
+        public static string Join(string? separator, IEnumerable<string> values)
         {
             if (values == null)
             {
@@ -672,7 +673,7 @@ namespace System
 
         // Joins an array of strings together as one string with a separator between each original string.
         //
-        public static unsafe string Join(string separator, string[] value, int startIndex, int count)
+        public static unsafe string Join(string? separator, string?[] value, int startIndex, int count)
         {
             separator = separator ?? string.Empty;
             fixed (char* pSeparator = &separator._firstChar)
@@ -682,7 +683,7 @@ namespace System
             }
         }
 
-        private static unsafe string JoinCore(char* separator, int separatorLength, object[] values)
+        private static unsafe string JoinCore(char* separator, int separatorLength, object?[] values)
         {
             if (values == null)
             {
@@ -694,7 +695,7 @@ namespace System
                 return string.Empty;
             }
 
-            string firstString = values[0]?.ToString();
+            string? firstString = values[0]?.ToString();
 
             if (values.Length == 1)
             {
@@ -707,7 +708,7 @@ namespace System
             for (int i = 1; i < values.Length; i++)
             {
                 result.Append(separator, separatorLength);
-                object value = values[i];
+                object? value = values[i];
                 if (value != null)
                 {
                     result.Append(value.ToString());
@@ -739,7 +740,7 @@ namespace System
                 // Everything should be called in the order
                 // MoveNext-Current-ToString, unless further optimizations
                 // can be made, to avoid breaking changes
-                string firstString = currentValue?.ToString();
+                string? firstString = currentValue?.ToString();
 
                 // If there's only 1 item, simply call ToString on that
                 if (!en.MoveNext())
@@ -769,7 +770,7 @@ namespace System
             }
         }
 
-        private static unsafe string JoinCore(char* separator, int separatorLength, string[] value, int startIndex, int count)
+        private static unsafe string JoinCore(char* separator, int separatorLength, string?[] value, int startIndex, int count)
         {
             // If the separator is null, it is converted to an empty string before entering this function.
             // Even for empty strings, fixed should never return null (it should return a pointer to a null char).
@@ -810,7 +811,7 @@ namespace System
             // Calculate the length of the resultant string so we know how much space to allocate.
             for (int i = startIndex, end = startIndex + count; i < end; i++)
             {
-                string currentValue = value[i];
+                string? currentValue = value[i];
                 if (currentValue != null)
                 {
                     totalLength += currentValue.Length;
@@ -833,7 +834,7 @@ namespace System
 
                 // We range check again to avoid buffer overflows if this happens.
 
-                string currentValue = value[i];
+                string? currentValue = value[i];
                 if (currentValue != null)
                 {
                     int valueLen = currentValue.Length;
@@ -875,7 +876,7 @@ namespace System
             // fall back should be extremely rare.
             return copiedLength == totalLength ?
                 result :
-                JoinCore(separator, separatorLength, (string[])value.Clone(), startIndex, count);
+                JoinCore(separator, separatorLength, (string?[])value.Clone(), startIndex, count);
         }
 
         public string PadLeft(int totalWidth) => PadLeft(totalWidth, ' ');
@@ -973,12 +974,12 @@ namespace System
             return Substring(0, startIndex);
         }
 
-        public string Replace(string oldValue, string newValue, bool ignoreCase, CultureInfo culture)
+        public string Replace(string oldValue, string? newValue, bool ignoreCase, CultureInfo? culture)
         {
             return ReplaceCore(oldValue, newValue, culture, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
         }
 
-        public string Replace(string oldValue, string newValue, StringComparison comparisonType)
+        public string Replace(string oldValue, string? newValue, StringComparison comparisonType)
         {
             switch (comparisonType)
             {
@@ -1001,7 +1002,7 @@ namespace System
             }
         }
 
-        private unsafe string ReplaceCore(string oldValue, string newValue, CultureInfo culture, CompareOptions options)
+        private unsafe string ReplaceCore(string oldValue, string? newValue, CultureInfo? culture, CompareOptions options)
         {
             if (oldValue == null)
                 throw new ArgumentNullException(nameof(oldValue));
@@ -1121,7 +1122,7 @@ namespace System
             }
         }
 
-        public string Replace(string oldValue, string newValue)
+        public string Replace(string oldValue, string? newValue)
         {
             if (oldValue == null)
                 throw new ArgumentNullException(nameof(oldValue));
@@ -1232,7 +1233,7 @@ namespace System
         // If the separator is null
         // whitespace (i.e., Character.IsWhitespace) is used as the separator.
         //
-        public string[] Split(params char[] separator)
+        public string[] Split(params char[]? separator)
         {
             return SplitInternal(separator, int.MaxValue, StringSplitOptions.None);
         }
@@ -1248,17 +1249,17 @@ namespace System
         // If there are more than count different strings, the last n-(count-1)
         // elements are concatenated and added as the last string.
         //
-        public string[] Split(char[] separator, int count)
+        public string[] Split(char[]? separator, int count)
         {
             return SplitInternal(separator, count, StringSplitOptions.None);
         }
 
-        public string[] Split(char[] separator, StringSplitOptions options)
+        public string[] Split(char[]? separator, StringSplitOptions options)
         {
             return SplitInternal(separator, int.MaxValue, options);
         }
 
-        public string[] Split(char[] separator, int count, StringSplitOptions options)
+        public string[] Split(char[]? separator, int count, StringSplitOptions options)
         {
             return SplitInternal(separator, count, options);
         }
@@ -1305,27 +1306,27 @@ namespace System
             return result;
         }
 
-        public string[] Split(string separator, StringSplitOptions options = StringSplitOptions.None)
+        public string[] Split(string? separator, StringSplitOptions options = StringSplitOptions.None)
         {
             return SplitInternal(separator ?? string.Empty, null, int.MaxValue, options);
         }
 
-        public string[] Split(string separator, int count, StringSplitOptions options = StringSplitOptions.None)
+        public string[] Split(string? separator, int count, StringSplitOptions options = StringSplitOptions.None)
         {
             return SplitInternal(separator ?? string.Empty, null, count, options);
         }
 
-        public string[] Split(string[] separator, StringSplitOptions options)
+        public string[] Split(string[]? separator, StringSplitOptions options)
         {
             return SplitInternal(null, separator, int.MaxValue, options);
         }
 
-        public string[] Split(string[] separator, int count, StringSplitOptions options)
+        public string[] Split(string[]? separator, int count, StringSplitOptions options)
         {
             return SplitInternal(null, separator, count, options);
         }
 
-        private string[] SplitInternal(string separator, string[] separators, int count, StringSplitOptions options)
+        private string[] SplitInternal(string? separator, string?[]? separators, int count, StringSplitOptions options)
         {
             if (count < 0)
             {
@@ -1344,7 +1345,7 @@ namespace System
 
             if (!singleSeparator && (separators == null || separators.Length == 0))
             {
-                return SplitInternal((char[])null, count, options);
+                return SplitInternal(default(ReadOnlySpan<char>), count, options);
             }
 
             if ((count == 0) || (omitEmptyEntries && Length == 0))
@@ -1352,14 +1353,14 @@ namespace System
                 return Array.Empty<string>();
             }
 
-            if (count == 1 || (singleSeparator && separator.Length == 0))
+            if (count == 1 || (singleSeparator && separator!.Length == 0))
             {
                 return new string[] { this };
             }
 
             if (singleSeparator)
             {
-                return SplitInternal(separator, count, options);
+                return SplitInternal(separator!, count, options);
             }
 
             Span<int> sepListInitialSpan = stackalloc int[StackallocIntBufferSizeLimit];
@@ -1368,7 +1369,7 @@ namespace System
             Span<int> lengthListInitialSpan = stackalloc int[StackallocIntBufferSizeLimit];
             var lengthListBuilder = new ValueListBuilder<int>(lengthListInitialSpan);
 
-            MakeSeparatorList(separators, ref sepListBuilder, ref lengthListBuilder);
+            MakeSeparatorList(separators!, ref sepListBuilder, ref lengthListBuilder);
             ReadOnlySpan<int> sepList = sepListBuilder.AsSpan();
             ReadOnlySpan<int> lengthList = lengthListBuilder.AsSpan();
 
@@ -1616,7 +1617,7 @@ namespace System
         /// <param name="separators">separator strngs</param>
         /// <param name="sepListBuilder"><see cref="ValueListBuilder{T}"/> for separator indexes</param>
         /// <param name="lengthListBuilder"><see cref="ValueListBuilder{T}"/> for separator length values</param>
-        private void MakeSeparatorList(string[] separators, ref ValueListBuilder<int> sepListBuilder, ref ValueListBuilder<int> lengthListBuilder)
+        private void MakeSeparatorList(string?[] separators, ref ValueListBuilder<int> sepListBuilder, ref ValueListBuilder<int> lengthListBuilder)
         {
             Debug.Assert(separators != null && separators.Length > 0, "separators != null && separators.Length > 0");
 
@@ -1626,7 +1627,7 @@ namespace System
             {
                 for (int j = 0; j < separators.Length; j++)
                 {
-                    string separator = separators[j];
+                    string? separator = separators[j];
                     if (IsNullOrEmpty(separator))
                     {
                         continue;
@@ -1768,7 +1769,7 @@ namespace System
         public unsafe string Trim(char trimChar) => TrimHelper(&trimChar, 1, TrimType.Both);
 
         // Removes a set of characters from the beginning and end of this string.
-        public unsafe string Trim(params char[] trimChars)
+        public unsafe string Trim(params char[]? trimChars)
         {
             if (trimChars == null || trimChars.Length == 0)
             {
@@ -1787,7 +1788,7 @@ namespace System
         public unsafe string TrimStart(char trimChar) => TrimHelper(&trimChar, 1, TrimType.Head);
 
         // Removes a set of characters from the beginning of this string.
-        public unsafe string TrimStart(params char[] trimChars)
+        public unsafe string TrimStart(params char[]? trimChars)
         {
             if (trimChars == null || trimChars.Length == 0)
             {
@@ -1806,7 +1807,7 @@ namespace System
         public unsafe string TrimEnd(char trimChar) => TrimHelper(&trimChar, 1, TrimType.Tail);
 
         // Removes a set of characters from the end of this string.
-        public unsafe string TrimEnd(params char[] trimChars)
+        public unsafe string TrimEnd(params char[]? trimChars)
         {
             if (trimChars == null || trimChars.Length == 0)
             {
index cce119b..49c0654 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Globalization;
 using System.Runtime.InteropServices;
 using Internal.Runtime.CompilerServices;
index 10f7522..1a1b80c 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Buffers;
 using System.Collections;
 using System.Collections.Generic;
@@ -22,7 +23,7 @@ namespace System
 
     [Serializable]
     [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
-    public sealed partial class String : IComparable, IEnumerable, IConvertible, IEnumerable<char>, IComparable<string>, IEquatable<string>, ICloneable
+    public sealed partial class String : IComparable, IEnumerable, IConvertible, IEnumerable<char>, IComparable<string?>, IEquatable<string?>, ICloneable
     {
         /*
          * CONSTRUCTORS
@@ -41,7 +42,7 @@ namespace System
 #if !CORECLR
         static
 #endif
-        private string Ctor(char[] value)
+        private string Ctor(char[]? value)
         {
             if (value == null || value.Length == 0)
                 return Empty;
@@ -244,7 +245,7 @@ namespace System
 #if !CORECLR
         static
 #endif
-        private unsafe string Ctor(sbyte* value, int startIndex, int length, Encoding enc)
+        private unsafe string Ctor(sbyte* value, int startIndex, int length, Encoding? enc)
         {
             if (enc == null)
                 return new string(value, startIndex, length);
@@ -361,7 +362,7 @@ namespace System
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static implicit operator ReadOnlySpan<char>(string value) =>
+        public static implicit operator ReadOnlySpan<char>(string? value) =>
             value != null ? new ReadOnlySpan<char>(ref value.GetRawStringData(), value.Length) : default;
 
         public object Clone()
@@ -436,7 +437,7 @@ namespace System
         }
 
         [NonVersionable]
-        public static bool IsNullOrEmpty(string value)
+        public static bool IsNullOrEmpty(string? value)
         {
             // Using 0u >= (uint)value.Length rather than
             // value.Length == 0 as it will elide the bounds check to
@@ -460,7 +461,7 @@ namespace System
         [System.Runtime.CompilerServices.IndexerName("Chars")]
         public string this[Range range] => Substring(range);
 
-        public static bool IsNullOrWhiteSpace(string value)
+        public static bool IsNullOrWhiteSpace(string? value)
         {
             if (value == null) return true;
 
@@ -533,7 +534,7 @@ namespace System
         }
 
         // Returns this string.
-        public string ToString(IFormatProvider provider)
+        public string ToString(IFormatProvider? provider)
         {
             return this;
         }
@@ -695,77 +696,77 @@ namespace System
             return TypeCode.String;
         }
 
-        bool IConvertible.ToBoolean(IFormatProvider provider)
+        bool IConvertible.ToBoolean(IFormatProvider? provider)
         {
             return Convert.ToBoolean(this, provider);
         }
 
-        char IConvertible.ToChar(IFormatProvider provider)
+        char IConvertible.ToChar(IFormatProvider? provider)
         {
             return Convert.ToChar(this, provider);
         }
 
-        sbyte IConvertible.ToSByte(IFormatProvider provider)
+        sbyte IConvertible.ToSByte(IFormatProvider? provider)
         {
             return Convert.ToSByte(this, provider);
         }
 
-        byte IConvertible.ToByte(IFormatProvider provider)
+        byte IConvertible.ToByte(IFormatProvider? provider)
         {
             return Convert.ToByte(this, provider);
         }
 
-        short IConvertible.ToInt16(IFormatProvider provider)
+        short IConvertible.ToInt16(IFormatProvider? provider)
         {
             return Convert.ToInt16(this, provider);
         }
 
-        ushort IConvertible.ToUInt16(IFormatProvider provider)
+        ushort IConvertible.ToUInt16(IFormatProvider? provider)
         {
             return Convert.ToUInt16(this, provider);
         }
 
-        int IConvertible.ToInt32(IFormatProvider provider)
+        int IConvertible.ToInt32(IFormatProvider? provider)
         {
             return Convert.ToInt32(this, provider);
         }
 
-        uint IConvertible.ToUInt32(IFormatProvider provider)
+        uint IConvertible.ToUInt32(IFormatProvider? provider)
         {
             return Convert.ToUInt32(this, provider);
         }
 
-        long IConvertible.ToInt64(IFormatProvider provider)
+        long IConvertible.ToInt64(IFormatProvider? provider)
         {
             return Convert.ToInt64(this, provider);
         }
 
-        ulong IConvertible.ToUInt64(IFormatProvider provider)
+        ulong IConvertible.ToUInt64(IFormatProvider? provider)
         {
             return Convert.ToUInt64(this, provider);
         }
 
-        float IConvertible.ToSingle(IFormatProvider provider)
+        float IConvertible.ToSingle(IFormatProvider? provider)
         {
             return Convert.ToSingle(this, provider);
         }
 
-        double IConvertible.ToDouble(IFormatProvider provider)
+        double IConvertible.ToDouble(IFormatProvider? provider)
         {
             return Convert.ToDouble(this, provider);
         }
 
-        decimal IConvertible.ToDecimal(IFormatProvider provider)
+        decimal IConvertible.ToDecimal(IFormatProvider? provider)
         {
             return Convert.ToDecimal(this, provider);
         }
 
-        DateTime IConvertible.ToDateTime(IFormatProvider provider)
+        DateTime IConvertible.ToDateTime(IFormatProvider? provider)
         {
             return Convert.ToDateTime(this, provider);
         }
 
-        object IConvertible.ToType(Type type, IFormatProvider provider)
+        object IConvertible.ToType(Type type, IFormatProvider? provider)
         {
             return Convert.DefaultToType((IConvertible)this, type, provider);
         }
index 0695f46..fe6de4a 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using Microsoft.Win32;
 using System.Diagnostics;
 using System.Runtime.CompilerServices;
@@ -77,7 +78,7 @@ namespace System
         [MethodImpl(MethodImplOptions.InternalCall)]
         private extern string Intern();
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private extern string IsInterned();
+        private extern string? IsInterned();
 
         public static string Intern(string str)
         {
@@ -89,7 +90,7 @@ namespace System
             return str.Intern();
         }
 
-        public static string IsInterned(string str)
+        public static string? IsInterned(string str)
         {
             if (str == null)
             {