From 626633d6c52cbc91c187def2e547e3ffdbe7e095 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Tue, 26 Mar 2019 09:23:00 -0700 Subject: nullable: number (#23454) --- .../shared/System/Number.BigInteger.cs | 1 + .../shared/System/Number.DiyFp.cs | 1 + .../shared/System/Number.Dragon4.cs | 1 + .../shared/System/Number.Formatting.cs | 42 +++++++++++----------- .../shared/System/Number.Grisu3.cs | 1 + .../shared/System/Number.NumberBuffer.cs | 1 + .../System/Number.NumberToFloatingPointBits.cs | 1 + .../shared/System/Number.Parsing.cs | 15 ++++---- 8 files changed, 36 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/System.Private.CoreLib/shared/System/Number.BigInteger.cs b/src/System.Private.CoreLib/shared/System/Number.BigInteger.cs index 06ae1e7668..33ac49e625 100644 --- a/src/System.Private.CoreLib/shared/System/Number.BigInteger.cs +++ b/src/System.Private.CoreLib/shared/System/Number.BigInteger.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; using System.Numerics; using System.Runtime.InteropServices; diff --git a/src/System.Private.CoreLib/shared/System/Number.DiyFp.cs b/src/System.Private.CoreLib/shared/System/Number.DiyFp.cs index bb9fc092bc..5daf2f5d6a 100644 --- a/src/System.Private.CoreLib/shared/System/Number.DiyFp.cs +++ b/src/System.Private.CoreLib/shared/System/Number.DiyFp.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; using System.Numerics; diff --git a/src/System.Private.CoreLib/shared/System/Number.Dragon4.cs b/src/System.Private.CoreLib/shared/System/Number.Dragon4.cs index 30704975fb..0dc6c90858 100644 --- a/src/System.Private.CoreLib/shared/System/Number.Dragon4.cs +++ b/src/System.Private.CoreLib/shared/System/Number.Dragon4.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; using System.Numerics; using Internal.Runtime.CompilerServices; diff --git a/src/System.Private.CoreLib/shared/System/Number.Formatting.cs b/src/System.Private.CoreLib/shared/System/Number.Formatting.cs index 1ae5b65d24..6f2fb50119 100644 --- a/src/System.Private.CoreLib/shared/System/Number.Formatting.cs +++ b/src/System.Private.CoreLib/shared/System/Number.Formatting.cs @@ -1,7 +1,8 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // 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.Globalization; @@ -129,7 +130,7 @@ namespace System // user-defined format strings. The following table describes the formatting // characters that are supported in user defined format strings. // - // + // // 0 - Digit placeholder. If the value being // formatted has a digit in the position where the '0' appears in the format // string, then that digit is copied to the output string. Otherwise, a '0' is @@ -377,7 +378,7 @@ namespace System number.CheckConsistency(); } - public static string FormatDouble(double value, string format, NumberFormatInfo info) + public static string FormatDouble(double value, string? format, NumberFormatInfo info) { Span stackBuffer = stackalloc char[CharStackBufferSize]; var sb = new ValueStringBuilder(stackBuffer); @@ -388,7 +389,7 @@ namespace System { Span stackBuffer = stackalloc char[CharStackBufferSize]; var sb = new ValueStringBuilder(stackBuffer); - string s = FormatDouble(ref sb, value, format, info); + string? s = FormatDouble(ref sb, value, format, info); return s != null ? TryCopyTo(s, destination, out charsWritten) : sb.TryCopyTo(destination, out charsWritten); @@ -445,7 +446,7 @@ namespace System case 'N': case 'n': { - // The fixed-point and number formats use the precision specifier to indicate the number + // The fixed-point and number formats use the precision specifier to indicate the number // of decimal digits to format. This defaults to NumberFormatInfo.NumberDecimalDigits. if (precision == -1) @@ -519,7 +520,7 @@ namespace System /// Non-null if an existing string can be returned, in which case the builder will be unmodified. /// Null if no existing string was returned, in which case the formatted output is in the builder. /// - private static unsafe string FormatDouble(ref ValueStringBuilder sb, double value, ReadOnlySpan format, NumberFormatInfo info) + private static unsafe string? FormatDouble(ref ValueStringBuilder sb, double value, ReadOnlySpan format, NumberFormatInfo info) { if (!double.IsFinite(value)) { @@ -544,7 +545,7 @@ namespace System NumberBuffer number = new NumberBuffer(NumberBufferKind.FloatingPoint, pDigits, DoubleNumberBufferLength); number.IsNegative = double.IsNegative(value); - // We need to track the original precision requested since some formats + // We need to track the original precision requested since some formats // accept values like 0 and others may require additional fixups. int nMaxDigits = GetFloatingPointMaxDigitsAndPrecision(fmt, ref precision, info, out bool isSignificantDigits); @@ -585,7 +586,7 @@ namespace System return null; } - public static string FormatSingle(float value, string format, NumberFormatInfo info) + public static string FormatSingle(float value, string? format, NumberFormatInfo info) { Span stackBuffer = stackalloc char[CharStackBufferSize]; var sb = new ValueStringBuilder(stackBuffer); @@ -596,7 +597,7 @@ namespace System { Span stackBuffer = stackalloc char[CharStackBufferSize]; var sb = new ValueStringBuilder(stackBuffer); - string s = FormatSingle(ref sb, value, format, info); + string? s = FormatSingle(ref sb, value, format, info); return s != null ? TryCopyTo(s, destination, out charsWritten) : sb.TryCopyTo(destination, out charsWritten); @@ -607,7 +608,7 @@ namespace System /// Non-null if an existing string can be returned, in which case the builder will be unmodified. /// Null if no existing string was returned, in which case the formatted output is in the builder. /// - private static unsafe string FormatSingle(ref ValueStringBuilder sb, float value, ReadOnlySpan format, NumberFormatInfo info) + private static unsafe string? FormatSingle(ref ValueStringBuilder sb, float value, ReadOnlySpan format, NumberFormatInfo info) { if (!float.IsFinite(value)) { @@ -632,7 +633,7 @@ namespace System NumberBuffer number = new NumberBuffer(NumberBufferKind.FloatingPoint, pDigits, SingleNumberBufferLength); number.IsNegative = float.IsNegative(value); - // We need to track the original precision requested since some formats + // We need to track the original precision requested since some formats // accept values like 0 and others may require additional fixups. int nMaxDigits = GetFloatingPointMaxDigitsAndPrecision(fmt, ref precision, info, out bool isSignificantDigits); @@ -687,7 +688,7 @@ namespace System return false; } - public static unsafe string FormatInt32(int value, ReadOnlySpan format, IFormatProvider provider) + public static unsafe string FormatInt32(int value, ReadOnlySpan format, IFormatProvider? provider) { // Fast path for default format with a non-negative value if (value >= 0 && format.Length == 0) @@ -733,7 +734,7 @@ namespace System } } - public static unsafe bool TryFormatInt32(int value, ReadOnlySpan format, IFormatProvider provider, Span destination, out int charsWritten) + public static unsafe bool TryFormatInt32(int value, ReadOnlySpan format, IFormatProvider? provider, Span destination, out int charsWritten) { // Fast path for default format with a non-negative value if (value >= 0 && format.Length == 0) @@ -779,7 +780,7 @@ namespace System } } - public static unsafe string FormatUInt32(uint value, ReadOnlySpan format, IFormatProvider provider) + public static unsafe string FormatUInt32(uint value, ReadOnlySpan format, IFormatProvider? provider) { // Fast path for default format if (format.Length == 0) @@ -823,7 +824,7 @@ namespace System } } - public static unsafe bool TryFormatUInt32(uint value, ReadOnlySpan format, IFormatProvider provider, Span destination, out int charsWritten) + public static unsafe bool TryFormatUInt32(uint value, ReadOnlySpan format, IFormatProvider? provider, Span destination, out int charsWritten) { // Fast path for default format if (format.Length == 0) @@ -867,7 +868,7 @@ namespace System } } - public static unsafe string FormatInt64(long value, ReadOnlySpan format, IFormatProvider provider) + public static unsafe string FormatInt64(long value, ReadOnlySpan format, IFormatProvider? provider) { // Fast path for default format with a non-negative value if (value >= 0 && format.Length == 0) @@ -914,7 +915,7 @@ namespace System } } - public static unsafe bool TryFormatInt64(long value, ReadOnlySpan format, IFormatProvider provider, Span destination, out int charsWritten) + public static unsafe bool TryFormatInt64(long value, ReadOnlySpan format, IFormatProvider? provider, Span destination, out int charsWritten) { // Fast path for default format with a non-negative value if (value >= 0 && format.Length == 0) @@ -961,7 +962,7 @@ namespace System } } - public static unsafe string FormatUInt64(ulong value, ReadOnlySpan format, IFormatProvider provider) + public static unsafe string FormatUInt64(ulong value, ReadOnlySpan format, IFormatProvider? provider) { // Fast path for default format if (format.Length == 0) @@ -1006,7 +1007,7 @@ namespace System } } - public static unsafe bool TryFormatUInt64(ulong value, ReadOnlySpan format, IFormatProvider provider, Span destination, out int charsWritten) + public static unsafe bool TryFormatUInt64(ulong value, ReadOnlySpan format, IFormatProvider? provider, Span destination, out int charsWritten) { // Fast path for default format if (format.Length == 0) @@ -2131,7 +2132,7 @@ namespace System } } - private static unsafe void FormatFixed(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info, int[] groupDigits, string sDecimal, string sGroup) + private static unsafe void FormatFixed(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo? info, int[]? groupDigits, string? sDecimal, string? sGroup) { int digPos = number.Scale; byte* dig = number.GetDigitsPointer(); @@ -2140,6 +2141,7 @@ namespace System { if (groupDigits != null) { + Debug.Assert(sGroup != null, "Must be nulll when groupDigits != null"); int groupSizeIndex = 0; // Index into the groupDigits array. int bufferSize = digPos; // The length of the result buffer string. int groupSize = 0; // The current group size. diff --git a/src/System.Private.CoreLib/shared/System/Number.Grisu3.cs b/src/System.Private.CoreLib/shared/System/Number.Grisu3.cs index 96ec7af2f8..5ff8d466a3 100644 --- a/src/System.Private.CoreLib/shared/System/Number.Grisu3.cs +++ b/src/System.Private.CoreLib/shared/System/Number.Grisu3.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 diff --git a/src/System.Private.CoreLib/shared/System/Number.NumberBuffer.cs b/src/System.Private.CoreLib/shared/System/Number.NumberBuffer.cs index 268bdc78b6..ccedf417aa 100644 --- a/src/System.Private.CoreLib/shared/System/Number.NumberBuffer.cs +++ b/src/System.Private.CoreLib/shared/System/Number.NumberBuffer.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; using System.Text; using Internal.Runtime.CompilerServices; diff --git a/src/System.Private.CoreLib/shared/System/Number.NumberToFloatingPointBits.cs b/src/System.Private.CoreLib/shared/System/Number.NumberToFloatingPointBits.cs index ac4c7727f3..cfe8ce5201 100644 --- a/src/System.Private.CoreLib/shared/System/Number.NumberToFloatingPointBits.cs +++ b/src/System.Private.CoreLib/shared/System/Number.NumberToFloatingPointBits.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 diff --git a/src/System.Private.CoreLib/shared/System/Number.Parsing.cs b/src/System.Private.CoreLib/shared/System/Number.Parsing.cs index fc845a1ea8..3f9f5c1283 100644 --- a/src/System.Private.CoreLib/shared/System/Number.Parsing.cs +++ b/src/System.Private.CoreLib/shared/System/Number.Parsing.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; using System.Globalization; using System.Runtime.CompilerServices; @@ -274,7 +275,7 @@ namespace System string decSep; // decimal separator from NumberFormatInfo. string groupSep; // group separator from NumberFormatInfo. - string currSymbol = null; // currency symbol from NumberFormatInfo. + string? currSymbol = null; // currency symbol from NumberFormatInfo. bool parsingCurrency = false; if ((styles & NumberStyles.AllowCurrencySymbol) != 0) @@ -529,7 +530,7 @@ namespace System int index = 0; int num = value[0]; - // Skip past any whitespace at the beginning. + // Skip past any whitespace at the beginning. if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num)) { do @@ -700,7 +701,7 @@ namespace System int index = 0; int num = value[0]; - // Skip past any whitespace at the beginning. + // Skip past any whitespace at the beginning. if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num)) { do @@ -944,7 +945,7 @@ namespace System int index = 0; int num = value[0]; - // Skip past any whitespace at the beginning. + // Skip past any whitespace at the beginning. if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num)) { do @@ -1116,7 +1117,7 @@ namespace System int num = value[0]; uint numValue; - // Skip past any whitespace at the beginning. + // Skip past any whitespace at the beginning. if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num)) { do @@ -1272,7 +1273,7 @@ namespace System int index = 0; int num = value[0]; - // Skip past any whitespace at the beginning. + // Skip past any whitespace at the beginning. if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num)) { do @@ -1444,7 +1445,7 @@ namespace System int num = value[0]; uint numValue; - // Skip past any whitespace at the beginning. + // Skip past any whitespace at the beginning. if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num)) { do -- cgit v1.2.3