summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib/shared/System
diff options
context:
space:
mode:
authorKrzysztof Wicher <mordotymoja@gmail.com>2019-03-28 16:58:31 -0700
committerGitHub <noreply@github.com>2019-03-28 16:58:31 -0700
commit7a28c47bbf9570929d3b4fd8f6358f48cc6b5a37 (patch)
tree2629184b64d8d8cff09ca125ebbd3a4968276c69 /src/System.Private.CoreLib/shared/System
parentf414bbdebcd361a653191dc2465f7f7d63223ca0 (diff)
downloadcoreclr-7a28c47bbf9570929d3b4fd8f6358f48cc6b5a37.tar.gz
coreclr-7a28c47bbf9570929d3b4fd8f6358f48cc6b5a37.tar.bz2
coreclr-7a28c47bbf9570929d3b4fd8f6358f48cc6b5a37.zip
Nullable: DateTimeFormat, DateTimeFormatInfoScanner, SortKey, StringInfo, TextElementEnumerator, TimeSpanFormat, TimeSpanParse (#23486)
* nullable: DateTimeFormat, DateTimeFormatInfoScanner, SortKey, StringInfo, TextElementEnumerator, TimeSpanFormat, TimeSpanParse * prefix workaround comment with TODO-NULLABLE * add TODO-NULLABLE
Diffstat (limited to 'src/System.Private.CoreLib/shared/System')
-rw-r--r--src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs29
-rw-r--r--src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs67
-rw-r--r--src/System.Private.CoreLib/shared/System/Globalization/SortKey.cs3
-rw-r--r--src/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs23
-rw-r--r--src/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs1
-rw-r--r--src/System.Private.CoreLib/shared/System/Globalization/TimeSpanFormat.cs18
-rw-r--r--src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs22
7 files changed, 87 insertions, 76 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs
index 5bf9f4ef25..c2b20c46bf 100644
--- a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs
+++ b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs
@@ -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.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@@ -220,7 +221,7 @@ namespace System
{
index++;
}
- return (index - pos);
+ return index - pos;
}
private static string FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
@@ -232,7 +233,7 @@ namespace System
}
// Call dtfi.GetDayName() here, instead of accessing DayNames property, because we don't
// want a clone of DayNames, which will hurt perf.
- return (dtfi.GetDayName((DayOfWeek)dayOfWeek));
+ return dtfi.GetDayName((DayOfWeek)dayOfWeek);
}
private static string FormatMonth(int month, int repeatCount, DateTimeFormatInfo dtfi)
@@ -240,11 +241,11 @@ namespace System
Debug.Assert(month >= 1 && month <= 12, "month >=1 && month <= 12");
if (repeatCount == 3)
{
- return (dtfi.GetAbbreviatedMonthName(month));
+ return dtfi.GetAbbreviatedMonthName(month);
}
// Call GetMonthName() here, instead of accessing MonthNames property, because we don't
// want a clone of MonthNames, which will hurt perf.
- return (dtfi.GetMonthName(month));
+ return dtfi.GetMonthName(month);
}
//
@@ -446,7 +447,7 @@ namespace System
// Actions: Format the DateTime instance using the specified format.
//
private static StringBuilder FormatCustomized(
- DateTime dateTime, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, TimeSpan offset, StringBuilder result)
+ DateTime dateTime, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, TimeSpan offset, StringBuilder? result)
{
Calendar cal = dtfi.Calendar;
@@ -878,7 +879,7 @@ namespace System
internal static string GetRealFormat(ReadOnlySpan<char> format, DateTimeFormatInfo dtfi)
{
- string realFormat = null;
+ string realFormat;
switch (format[0])
{
@@ -934,7 +935,7 @@ namespace System
default:
throw new FormatException(SR.Format_InvalidString);
}
- return (realFormat);
+ return realFormat;
}
@@ -1000,12 +1001,12 @@ namespace System
return GetRealFormat(format, dtfi);
}
- internal static string Format(DateTime dateTime, string format, IFormatProvider provider)
+ internal static string Format(DateTime dateTime, string? format, IFormatProvider? provider)
{
return Format(dateTime, format, provider, NullOffset);
}
- internal static string Format(DateTime dateTime, string format, IFormatProvider provider, TimeSpan offset)
+ internal static string Format(DateTime dateTime, string? format, IFormatProvider? provider, TimeSpan offset)
{
if (format != null && format.Length == 1)
{
@@ -1036,10 +1037,10 @@ namespace System
return StringBuilderCache.GetStringAndRelease(FormatStringBuilder(dateTime, format, dtfi, offset));
}
- internal static bool TryFormat(DateTime dateTime, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider provider) =>
+ internal static bool TryFormat(DateTime dateTime, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
TryFormat(dateTime, destination, out charsWritten, format, provider, NullOffset);
- internal static bool TryFormat(DateTime dateTime, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider provider, TimeSpan offset)
+ internal static bool TryFormat(DateTime dateTime, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider, TimeSpan offset)
{
if (format.Length == 1)
{
@@ -1328,8 +1329,8 @@ namespace System
internal static string[] GetAllDateTimes(DateTime dateTime, char format, DateTimeFormatInfo dtfi)
{
Debug.Assert(dtfi != null);
- string[] allFormats = null;
- string[] results = null;
+ string[] allFormats;
+ string[] results;
switch (format)
{
@@ -1376,7 +1377,7 @@ namespace System
default:
throw new FormatException(SR.Format_InvalidString);
}
- return (results);
+ return results;
}
internal static string[] GetAllDateTimes(DateTime dateTime, DateTimeFormatInfo dtfi)
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
index d18bd3e4a8..a43bfe777b 100644
--- a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
+++ b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormatInfoScanner.cs
@@ -19,6 +19,7 @@
//
////////////////////////////////////////////////////////////////////////////
+#nullable enable
using System.Collections.Generic;
using System.Text;
@@ -37,7 +38,7 @@ namespace System.Globalization
UseSpacesInMonthNames = 0x00000004,
UseHebrewParsing = 0x00000008,
UseSpacesInDayNames = 0x00000010, // Has spaces or non-breaking space in the day names.
- UseDigitPrefixInTokens = 0x00000020, // Has token starting with numbers.
+ UseDigitPrefixInTokens = 0x00000020, // Has token starting with numbers.
}
internal enum CalendarId : ushort
@@ -47,7 +48,7 @@ namespace System.Globalization
GREGORIAN_US = 2, // Gregorian (U.S.) calendar
JAPAN = 3, // Japanese Emperor Era calendar
/* SSS_WARNINGS_OFF */
- TAIWAN = 4, // Taiwan Era calendar /* SSS_WARNINGS_ON */
+ TAIWAN = 4, // Taiwan Era calendar /* SSS_WARNINGS_ON */
KOREA = 5, // Korean Tangun Era calendar
HIJRI = 6, // Hijri (Arabic Lunar) calendar
THAI = 7, // Thai calendar
@@ -126,7 +127,7 @@ namespace System.Globalization
Dictionary<string, string> temp = new Dictionary<string, string>();
// Add known words into the hash table.
- // Skip these special symbols.
+ // Skip these special symbols.
temp.Add("/", string.Empty);
temp.Add("-", string.Empty);
temp.Add(".", string.Empty);
@@ -204,14 +205,14 @@ namespace System.Globalization
// A helper to add the found date word or month postfix into ArrayList for date words.
//
// Parameters:
- // formatPostfix: What kind of postfix this is.
+ // formatPostfix: What kind of postfix this is.
// Possible values:
// null: This is a regular date word
// "MMMM": month postfix
// word: The date word or postfix to be added.
//
////////////////////////////////////////////////////////////////////////////
- internal void AddDateWordOrPostfix(string formatPostfix, string str)
+ internal void AddDateWordOrPostfix(string? formatPostfix, string str)
{
if (str.Length > 0)
{
@@ -269,10 +270,10 @@ namespace System.Globalization
// Possible values:
// null: This is a regular date word
// "MMMM": month postfix
- //
+ //
//
////////////////////////////////////////////////////////////////////////////
- internal int AddDateWords(string pattern, int index, string formatPostfix)
+ internal int AddDateWords(string pattern, int index, string? formatPostfix)
{
// Skip any whitespaces so we will start from a letter.
int newIndex = SkipWhiteSpacesAndNonLetter(pattern, index);
@@ -283,10 +284,10 @@ namespace System.Globalization
}
index = newIndex;
- // This is the first char added into dateWord.
+ // This is the first char added into dateWord.
// Skip all non-letter character. We will add the first letter into DateWord.
StringBuilder dateWord = new StringBuilder();
- // We assume that date words should start with a letter.
+ // We assume that date words should start with a letter.
// Skip anything until we see a letter.
while (index < pattern.Length)
@@ -294,8 +295,8 @@ namespace System.Globalization
char ch = pattern[index];
if (ch == '\'')
{
- // We have seen the end of quote. Add the word if we do not see it before,
- // and break the while loop.
+ // We have seen the end of quote. Add the word if we do not see it before,
+ // and break the while loop.
AddDateWordOrPostfix(formatPostfix, dateWord.ToString());
index++;
break;
@@ -367,7 +368,7 @@ namespace System.Globalization
//
////////////////////////////////////////////////////////////////////////////
- internal void AddIgnorableSymbols(string text)
+ internal void AddIgnorableSymbols(string? text)
{
if (m_dateWords == null)
{
@@ -412,7 +413,7 @@ namespace System.Globalization
// "\x0443." in bg-BG: dd.M.yyyy '\x0433.'
//
// Example of postfix:
- // month postfix:
+ // month postfix:
// "ta" in fi-FI: d. MMMM'ta 'yyyy
// Currently, only month postfix is supported.
//
@@ -420,7 +421,7 @@ namespace System.Globalization
// Always call this with Framework-style pattern, instead of Windows style pattern.
// Windows style pattern uses '' for single quote, while .NET uses \'
//
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
internal void ScanDateWord(string pattern)
{
// Check if we have found all of the year/month/day pattern.
@@ -497,7 +498,7 @@ namespace System.Globalization
//
////////////////////////////////////////////////////////////////////////////
- internal string[] GetDateWordsOfDTFI(DateTimeFormatInfo dtfi)
+ internal string[]? GetDateWordsOfDTFI(DateTimeFormatInfo dtfi)
{
// Enumarate all LongDatePatterns, and get the DateWords and scan for month postfix.
string[] datePatterns = dtfi.GetAllDateTimePatterns('D');
@@ -539,7 +540,7 @@ namespace System.Globalization
ScanDateWord(datePatterns[i]);
}
- string[] result = null;
+ string[]? result = null;
if (m_dateWords != null && m_dateWords.Count > 0)
{
result = new string[m_dateWords.Count];
@@ -548,16 +549,16 @@ namespace System.Globalization
result[i] = m_dateWords[i];
}
}
- return (result);
+ return result;
}
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
//
// Scan the month names to see if genitive month names are used, and return
// the format flag.
//
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
internal static FORMATFLAGS GetFormatFlagGenitiveMonth(string[] monthNames, string[] genitveMonthNames, string[] abbrevMonthNames, string[] genetiveAbbrevMonthNames)
{
// If we have different names in regular and genitive month names, use genitive month flag.
@@ -565,11 +566,11 @@ namespace System.Globalization
? FORMATFLAGS.UseGenitiveMonth : 0);
}
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
//
// Scan the month names to see if spaces are used or start with a digit, and return the format flag
//
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
internal static FORMATFLAGS GetFormatFlagUseSpaceInMonthNames(string[] monthNames, string[] genitveMonthNames, string[] abbrevMonthNames, string[] genetiveAbbrevMonthNames)
{
FORMATFLAGS formatFlags = 0;
@@ -587,11 +588,11 @@ namespace System.Globalization
return (formatFlags);
}
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
//
// Scan the day names and set the correct format flag.
//
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
internal static FORMATFLAGS GetFormatFlagUseSpaceInDayNames(string[] dayNames, string[] abbrevDayNames)
{
return ((ArrayElementsHaveSpace(dayNames) ||
@@ -599,11 +600,11 @@ namespace System.Globalization
? FORMATFLAGS.UseSpacesInDayNames : 0);
}
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
//
// Check the calendar to see if it is HebrewCalendar and set the Hebrew format flag if necessary.
//
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
internal static FORMATFLAGS GetFormatFlagUseHebrewCalendar(int calID)
{
return (calID == (int)CalendarId.HEBREW ?
@@ -612,9 +613,9 @@ namespace System.Globalization
//-----------------------------------------------------------------------------
- // EqualStringArrays
- // compares two string arrays and return true if all elements of the first
- // array equals to all elmentsof the second array.
+ // EqualStringArrays
+ // compares two string arrays and return true if all elements of the first
+ // array equals to all elmentsof the second array.
// otherwise it returns false.
//-----------------------------------------------------------------------------
@@ -632,7 +633,7 @@ namespace System.Globalization
return false;
}
- // Check each string
+ // Check each string
for (int i = 0; i < array1.Length; i++)
{
if (array1[i] != array2[i])
@@ -645,7 +646,7 @@ namespace System.Globalization
}
//-----------------------------------------------------------------------------
- // ArrayElementsHaveSpace
+ // ArrayElementsHaveSpace
// It checks all input array elements if any of them has space character
// returns true if found space character in one of the array elements.
// otherwise returns false.
@@ -670,11 +671,11 @@ namespace System.Globalization
}
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
//
// Check if any element of the array start with a digit.
//
- ////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////
private static bool ArrayElementsBeginWithDigit(string[] array)
{
for (int i = 0; i < array.Length; i++)
@@ -711,7 +712,7 @@ namespace System.Globalization
if (index == array[i].Length - 4)
{
// Skip known CJK month suffix.
- // Starting with Windows 8, the CJK months for some cultures looks like: "1' \x6708'"
+ // Starting with Windows 8, the CJK months for some cultures looks like: "1' \x6708'"
// instead of just "1\x6708"
if (array[i][index] == '\'' && array[i][index + 1] == ' ' &&
array[i][index + 2] == '\x6708' && array[i][index + 3] == '\'')
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/SortKey.cs b/src/System.Private.CoreLib/shared/System/Globalization/SortKey.cs
index b00f34b814..f75b4f74ab 100644
--- a/src/System.Private.CoreLib/shared/System/Globalization/SortKey.cs
+++ b/src/System.Private.CoreLib/shared/System/Globalization/SortKey.cs
@@ -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;
namespace System.Globalization
@@ -92,7 +93,7 @@ namespace System.Globalization
return 0;
}
- public override bool Equals(object value)
+ public override bool Equals(object? value)
{
return value is SortKey otherSortKey && Compare(this, otherSortKey) == 0;
}
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs b/src/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs
index 2c9b4da5cc..af03dda16b 100644
--- a/src/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs
+++ b/src/System.Private.CoreLib/shared/System/Globalization/StringInfo.cs
@@ -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;
namespace System.Globalization
@@ -15,7 +16,7 @@ namespace System.Globalization
{
private string _str;
- private int[] _indexes;
+ private int[]? _indexes;
public StringInfo() : this(string.Empty)
{
@@ -24,9 +25,11 @@ namespace System.Globalization
public StringInfo(string value)
{
this.String = value;
+ // TODO-NULLABLE: compiler doesn't see this field being initialized through property
+ _str = _str!;
}
- public override bool Equals(object value)
+ public override bool Equals(object? value)
{
return value is StringInfo otherStringInfo
&& _str.Equals(otherStringInfo._str);
@@ -35,10 +38,10 @@ namespace System.Globalization
public override int GetHashCode() => _str.GetHashCode();
/// <summary>
- /// Our zero-based array of index values into the string. Initialize if
+ /// Our zero-based array of index values into the string. Initialize if
/// our private array is not yet, in fact, initialized.
/// </summary>
- private int[] Indexes
+ private int[]? Indexes
{
get
{
@@ -65,7 +68,7 @@ namespace System.Globalization
public string SubstringByTextElements(int startingTextElement)
{
- // If the string is empty, no sense going further.
+ // If the string is empty, no sense going further.
if (Indexes == null)
{
if (startingTextElement < 0)
@@ -87,7 +90,7 @@ namespace System.Globalization
{
throw new ArgumentOutOfRangeException(nameof(startingTextElement), startingTextElement, SR.ArgumentOutOfRange_NeedPosNum);
}
- if (String.Length == 0 || startingTextElement >= Indexes.Length)
+ if (String.Length == 0 || startingTextElement >= Indexes!.Length)
{
throw new ArgumentOutOfRangeException(nameof(startingTextElement), startingTextElement, SR.Arg_ArgumentOutOfRangeException);
}
@@ -126,7 +129,7 @@ namespace System.Globalization
/// * EnclosingMark (e.g. U+20DD COMBINING ENCLOSING CIRCLE)
///
/// In the context of GetNextTextElement() and ParseCombiningCharacters(), a text element is defined as:
- /// 1. If a character/surrogate is in the following category, it is a text element.
+ /// 1. If a character/surrogate is in the following category, it is a text element.
/// It can NOT further combine with characters in the combinging class to form a text element.
/// * one of the Unicode category in the combinging class
/// * UnicodeCategory.Format
@@ -196,9 +199,9 @@ namespace System.Globalization
}
/// <summary>
- /// Returns the str containing the next text element in str starting at
- /// index index. If index is not supplied, then it will start at the beginning
- /// of str. It recognizes a base character plus one or more combining
+ /// Returns the str containing the next text element in str starting at
+ /// index index. If index is not supplied, then it will start at the beginning
+ /// of str. It recognizes a base character plus one or more combining
/// characters or a properly formed surrogate pair as a text element.
/// See also the ParseCombiningCharacters() and the ParseSurrogates() methods.
/// </summary>
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs b/src/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs
index 60d2a1055a..7b0136b808 100644
--- a/src/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs
+++ b/src/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs
@@ -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.Collections;
using System.Diagnostics;
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanFormat.cs b/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanFormat.cs
index ccb42ad87c..376827e6fd 100644
--- a/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanFormat.cs
+++ b/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanFormat.cs
@@ -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.Text;
using System.Diagnostics;
using System.Runtime.CompilerServices;
@@ -39,7 +40,7 @@ namespace System.Globalization
/// <summary>Main method called from TimeSpan.ToString.</summary>
- internal static string Format(TimeSpan value, string format, IFormatProvider formatProvider)
+ internal static string Format(TimeSpan value, string? format, IFormatProvider? formatProvider)
{
if (string.IsNullOrEmpty(format))
{
@@ -67,7 +68,7 @@ namespace System.Globalization
}
/// <summary>Main method called from TimeSpan.TryFormat.</summary>
- internal static bool TryFormat(TimeSpan value, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider formatProvider)
+ internal static bool TryFormat(TimeSpan value, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? formatProvider)
{
if (format.Length == 0)
{
@@ -126,7 +127,7 @@ namespace System.Globalization
private enum StandardFormat { C, G, g }
- private static bool TryFormatStandard(TimeSpan value, StandardFormat format, string decimalSeparator, Span<char> destination, out int charsWritten)
+ private static bool TryFormatStandard(TimeSpan value, StandardFormat format, string? decimalSeparator, Span<char> destination, out int charsWritten)
{
Debug.Assert(format == StandardFormat.C || format == StandardFormat.G || format == StandardFormat.g);
@@ -281,11 +282,12 @@ namespace System.Globalization
// Write fraction and separator, if necessary
if (fractionDigits != 0)
{
+ Debug.Assert(format == StandardFormat.C || decimalSeparator != null);
if (format == StandardFormat.C)
{
destination[idx++] = '.';
}
- else if (decimalSeparator.Length == 1)
+ else if (decimalSeparator!.Length == 1)
{
destination[idx++] = decimalSeparator[0];
}
@@ -330,7 +332,7 @@ namespace System.Globalization
}
/// <summary>Format the TimeSpan instance using the specified format.</summary>
- private static StringBuilder FormatCustomized(TimeSpan value, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, StringBuilder result = null)
+ private static StringBuilder FormatCustomized(TimeSpan value, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, StringBuilder? result = null)
{
Debug.Assert(dtfi != null);
@@ -390,7 +392,7 @@ namespace System.Globalization
break;
case 'f':
//
- // The fraction of a second in single-digit precision. The remaining digits are truncated.
+ // The fraction of a second in single-digit precision. The remaining digits are truncated.
//
tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
if (tokenLen > DateTimeFormat.MaxSecondsFractionDigits)
@@ -451,7 +453,7 @@ namespace System.Globalization
break;
case '%':
// Optional format character.
- // For example, format string "%d" will print day
+ // For example, format string "%d" will print day
// Most of the cases, "%" can be ignored.
nextChar = DateTimeFormat.ParseNextChar(format, i);
// nextChar will be -1 if we already reach the end of the format string.
@@ -532,7 +534,7 @@ namespace System.Globalization
x._literals[3] = ":";
x._literals[4] = ".";
x._literals[5] = string.Empty;
- x.AppCompatLiteral = ":."; // MinuteSecondSep+SecondFractionSep;
+ x.AppCompatLiteral = ":."; // MinuteSecondSep+SecondFractionSep;
x.dd = 2;
x.hh = 2;
x.mm = 2;
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs b/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs
index a9172e2802..24a3cdf4e0 100644
--- a/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs
+++ b/src/System.Private.CoreLib/shared/System/Globalization/TimeSpanParse.cs
@@ -48,6 +48,7 @@
//
////////////////////////////////////////////////////////////////////////////
+#nullable enable
using System.Diagnostics;
using System.Text;
@@ -611,7 +612,7 @@ namespace System.Globalization
return true;
}
- internal static TimeSpan Parse(ReadOnlySpan<char> input, IFormatProvider formatProvider)
+ internal static TimeSpan Parse(ReadOnlySpan<char> input, IFormatProvider? formatProvider)
{
var parseResult = new TimeSpanResult(throwOnFailure: true, originalTimeSpanString: input);
bool success = TryParseTimeSpan(input, TimeSpanStandardStyles.Any, formatProvider, ref parseResult);
@@ -619,7 +620,7 @@ namespace System.Globalization
return parseResult.parsedTimeSpan;
}
- internal static bool TryParse(ReadOnlySpan<char> input, IFormatProvider formatProvider, out TimeSpan result)
+ internal static bool TryParse(ReadOnlySpan<char> input, IFormatProvider? formatProvider, out TimeSpan result)
{
var parseResult = new TimeSpanResult(throwOnFailure: false, originalTimeSpanString: input);
@@ -633,7 +634,7 @@ namespace System.Globalization
return false;
}
- internal static TimeSpan ParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider formatProvider, TimeSpanStyles styles)
+ internal static TimeSpan ParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, TimeSpanStyles styles)
{
var parseResult = new TimeSpanResult(throwOnFailure: true, originalTimeSpanString: input);
bool success = TryParseExactTimeSpan(input, format, formatProvider, styles, ref parseResult);
@@ -641,7 +642,7 @@ namespace System.Globalization
return parseResult.parsedTimeSpan;
}
- internal static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result)
+ internal static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result)
{
var parseResult = new TimeSpanResult(throwOnFailure: false, originalTimeSpanString: input);
@@ -655,7 +656,7 @@ namespace System.Globalization
return false;
}
- internal static TimeSpan ParseExactMultiple(ReadOnlySpan<char> input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles)
+ internal static TimeSpan ParseExactMultiple(ReadOnlySpan<char> input, string?[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles)
{
var parseResult = new TimeSpanResult(throwOnFailure: true, originalTimeSpanString: input);
bool success = TryParseExactMultipleTimeSpan(input, formats, formatProvider, styles, ref parseResult);
@@ -663,7 +664,7 @@ namespace System.Globalization
return parseResult.parsedTimeSpan;
}
- internal static bool TryParseExactMultiple(ReadOnlySpan<char> input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result)
+ internal static bool TryParseExactMultiple(ReadOnlySpan<char> input, string?[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, out TimeSpan result)
{
var parseResult = new TimeSpanResult(throwOnFailure: false, originalTimeSpanString: input);
@@ -678,7 +679,7 @@ namespace System.Globalization
}
/// <summary>Common private Parse method called by both Parse and TryParse.</summary>
- private static bool TryParseTimeSpan(ReadOnlySpan<char> input, TimeSpanStandardStyles style, IFormatProvider formatProvider, ref TimeSpanResult result)
+ private static bool TryParseTimeSpan(ReadOnlySpan<char> input, TimeSpanStandardStyles style, IFormatProvider? formatProvider, ref TimeSpanResult result)
{
input = input.Trim();
if (input.IsEmpty)
@@ -1215,7 +1216,7 @@ namespace System.Globalization
}
/// <summary>Common private ParseExact method called by both ParseExact and TryParseExact.</summary>
- private static bool TryParseExactTimeSpan(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result)
+ private static bool TryParseExactTimeSpan(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, TimeSpanStyles styles, ref TimeSpanResult result)
{
if (format.Length == 0)
{
@@ -1669,7 +1670,7 @@ namespace System.Globalization
}
/// <summary>Common private ParseExactMultiple method called by both ParseExactMultiple and TryParseExactMultiple.</summary>
- private static bool TryParseExactMultipleTimeSpan(ReadOnlySpan<char> input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result)
+ private static bool TryParseExactMultipleTimeSpan(ReadOnlySpan<char> input, string?[] formats, IFormatProvider? formatProvider, TimeSpanStyles styles, ref TimeSpanResult result)
{
if (formats == null)
{
@@ -1690,7 +1691,8 @@ namespace System.Globalization
// one of the formats.
for (int i = 0; i < formats.Length; i++)
{
- if (formats[i] == null || formats[i].Length == 0)
+ // TODO-NULLABLE: ! below should not be required
+ if (formats[i] == null || formats[i]!.Length == 0)
{
return result.SetBadFormatSpecifierFailure();
}