summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2017-11-06 17:36:38 -0500
committerGitHub <noreply@github.com>2017-11-06 17:36:38 -0500
commit815012e50a80d1e6680cc691ccd31fc15ffdd59e (patch)
tree6a073dd80378b471be2033b9905289f3421132c9 /src
parente0c404ba03abd9677234f4d6e9d9e768e27245db (diff)
downloadcoreclr-815012e50a80d1e6680cc691ccd31fc15ffdd59e.tar.gz
coreclr-815012e50a80d1e6680cc691ccd31fc15ffdd59e.tar.bz2
coreclr-815012e50a80d1e6680cc691ccd31fc15ffdd59e.zip
Fix TryParse overloads using optional arguments (#14877)
When we originally added Parse and TryParse overloads for `ReadOnlySpan<char>`, we used optional arguments to minimize the number of new overloads needed. This worked decently well for Parse, but for TryParse it necessitated reordering the parameters from the string counterparts, so that the out result argument would come before the optional parameters. This makes it more difficult to port string-based calls to span-based calls, and we agreed to add the missing overloads so that we could order the parameters "correctly" to match the existing string-based overloads. This does so.
Diffstat (limited to 'src')
-rw-r--r--src/mscorlib/shared/System/Byte.cs7
-rw-r--r--src/mscorlib/shared/System/Double.cs7
-rw-r--r--src/mscorlib/shared/System/Globalization/JapaneseCalendar.Win32.cs6
-rw-r--r--src/mscorlib/shared/System/Int16.cs7
-rw-r--r--src/mscorlib/shared/System/Int32.cs7
-rw-r--r--src/mscorlib/shared/System/Int64.cs7
-rw-r--r--src/mscorlib/shared/System/SByte.cs8
-rw-r--r--src/mscorlib/shared/System/Single.cs7
-rw-r--r--src/mscorlib/shared/System/TimeSpan.cs18
-rw-r--r--src/mscorlib/shared/System/UInt16.cs8
-rw-r--r--src/mscorlib/shared/System/UInt32.cs8
-rw-r--r--src/mscorlib/shared/System/UInt64.cs8
-rw-r--r--src/mscorlib/shared/System/Version.cs2
-rw-r--r--src/mscorlib/src/System/Decimal.cs7
14 files changed, 89 insertions, 18 deletions
diff --git a/src/mscorlib/shared/System/Byte.cs b/src/mscorlib/shared/System/Byte.cs
index eaa47b6843..c16b2246a3 100644
--- a/src/mscorlib/shared/System/Byte.cs
+++ b/src/mscorlib/shared/System/Byte.cs
@@ -132,6 +132,11 @@ namespace System
return TryParse(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
}
+ public static bool TryParse(ReadOnlySpan<char> s, out byte result)
+ {
+ return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Byte result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
@@ -145,7 +150,7 @@ namespace System
return TryParse(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result);
}
- public static bool TryParse(ReadOnlySpan<char> s, out byte result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out byte result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/Double.cs b/src/mscorlib/shared/System/Double.cs
index 363c896fa8..949ac6ddd7 100644
--- a/src/mscorlib/shared/System/Double.cs
+++ b/src/mscorlib/shared/System/Double.cs
@@ -306,6 +306,11 @@ namespace System
return TryParse(s.AsReadOnlySpan(), NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result);
}
+ public static bool TryParse(ReadOnlySpan<char> s, out double result)
+ {
+ return TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result);
+ }
+
public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out double result)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
@@ -319,7 +324,7 @@ namespace System
return TryParse(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result);
}
- public static bool TryParse(ReadOnlySpan<char> s, out double result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out double result)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/Globalization/JapaneseCalendar.Win32.cs b/src/mscorlib/shared/System/Globalization/JapaneseCalendar.Win32.cs
index 94e0668de1..9ea6c21c2e 100644
--- a/src/mscorlib/shared/System/Globalization/JapaneseCalendar.Win32.cs
+++ b/src/mscorlib/shared/System/Globalization/JapaneseCalendar.Win32.cs
@@ -160,9 +160,9 @@ namespace System.Globalization
int day;
ReadOnlySpan<char> valueSpan = value.AsReadOnlySpan();
- if (!Int32.TryParse(valueSpan.Slice(0, 4), out year, style:NumberStyles.None, provider: NumberFormatInfo.InvariantInfo) ||
- !Int32.TryParse(valueSpan.Slice(5, 2), out month, style:NumberStyles.None, provider: NumberFormatInfo.InvariantInfo) ||
- !Int32.TryParse(valueSpan.Slice(8, 2), out day, style:NumberStyles.None, provider: NumberFormatInfo.InvariantInfo))
+ if (!Int32.TryParse(valueSpan.Slice(0, 4), NumberStyles.None, NumberFormatInfo.InvariantInfo, out year) ||
+ !Int32.TryParse(valueSpan.Slice(5, 2), NumberStyles.None, NumberFormatInfo.InvariantInfo, out month) ||
+ !Int32.TryParse(valueSpan.Slice(8, 2), NumberStyles.None, NumberFormatInfo.InvariantInfo, out day))
{
// Couldn't convert integer, fail
return null;
diff --git a/src/mscorlib/shared/System/Int16.cs b/src/mscorlib/shared/System/Int16.cs
index 296b3d2d40..fd567cd74d 100644
--- a/src/mscorlib/shared/System/Int16.cs
+++ b/src/mscorlib/shared/System/Int16.cs
@@ -167,6 +167,11 @@ namespace System
return TryParse(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
}
+ public static bool TryParse(ReadOnlySpan<char> s, out short result)
+ {
+ return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int16 result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
@@ -180,7 +185,7 @@ namespace System
return TryParse(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result);
}
- public static bool TryParse(ReadOnlySpan<char> s, out Int16 result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out short result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/Int32.cs b/src/mscorlib/shared/System/Int32.cs
index 690faf3f36..33061137c6 100644
--- a/src/mscorlib/shared/System/Int32.cs
+++ b/src/mscorlib/shared/System/Int32.cs
@@ -150,6 +150,11 @@ namespace System
return Number.TryParseInt32(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
}
+ public static bool TryParse(ReadOnlySpan<char> s, out int result)
+ {
+ return Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
// Parses an integer from a String in the given style. Returns false rather
// than throwing exceptin if input is invalid
//
@@ -166,7 +171,7 @@ namespace System
return Number.TryParseInt32(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result);
}
- public static bool TryParse(ReadOnlySpan<char> s, out int result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out int result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
return Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/Int64.cs b/src/mscorlib/shared/System/Int64.cs
index 1f1cf13e9c..5db9fe1929 100644
--- a/src/mscorlib/shared/System/Int64.cs
+++ b/src/mscorlib/shared/System/Int64.cs
@@ -141,6 +141,11 @@ namespace System
return Number.TryParseInt64(s.AsReadOnlySpan(), NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
}
+ public static bool TryParse(ReadOnlySpan<char> s, out long result)
+ {
+ return Number.TryParseInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out Int64 result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
@@ -154,7 +159,7 @@ namespace System
return Number.TryParseInt64(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result);
}
- public static bool TryParse(ReadOnlySpan<char> s, out long result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out long result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
return Number.TryParseInt64(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/SByte.cs b/src/mscorlib/shared/System/SByte.cs
index 5b5c031d5f..b0d32ad9cd 100644
--- a/src/mscorlib/shared/System/SByte.cs
+++ b/src/mscorlib/shared/System/SByte.cs
@@ -186,6 +186,12 @@ namespace System
}
[CLSCompliant(false)]
+ public static bool TryParse(ReadOnlySpan<char> s, out sbyte result)
+ {
+ return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ [CLSCompliant(false)]
public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out SByte result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
@@ -200,7 +206,7 @@ namespace System
}
[CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, out sbyte result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out sbyte result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/Single.cs b/src/mscorlib/shared/System/Single.cs
index 14f0ca49ff..83684770f3 100644
--- a/src/mscorlib/shared/System/Single.cs
+++ b/src/mscorlib/shared/System/Single.cs
@@ -296,6 +296,11 @@ namespace System
return TryParse(s.AsReadOnlySpan(), NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result);
}
+ public static bool TryParse(ReadOnlySpan<char> s, out float result)
+ {
+ return TryParse(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out result);
+ }
+
public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out Single result)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
@@ -309,7 +314,7 @@ namespace System
return TryParse(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result);
}
- public static Boolean TryParse(ReadOnlySpan<char> s, out Single result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out float result)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/TimeSpan.cs b/src/mscorlib/shared/System/TimeSpan.cs
index 639d24b248..180f015f1f 100644
--- a/src/mscorlib/shared/System/TimeSpan.cs
+++ b/src/mscorlib/shared/System/TimeSpan.cs
@@ -366,6 +366,10 @@ namespace System
}
return TimeSpanParse.TryParse(s.AsReadOnlySpan(), null, out result);
}
+ public static bool TryParse(ReadOnlySpan<char> s, out TimeSpan result)
+ {
+ return TimeSpanParse.TryParse(s, null, out result);
+ }
public static Boolean TryParse(String input, IFormatProvider formatProvider, out TimeSpan result)
{
if (input == null)
@@ -375,7 +379,7 @@ namespace System
}
return TimeSpanParse.TryParse(input.AsReadOnlySpan(), formatProvider, out result);
}
- public static bool TryParse(ReadOnlySpan<char> input, out TimeSpan result, IFormatProvider formatProvider = null)
+ public static bool TryParse(ReadOnlySpan<char> input, IFormatProvider formatProvider, out TimeSpan result)
{
return TimeSpanParse.TryParse(input, formatProvider, out result);
}
@@ -388,6 +392,10 @@ namespace System
}
return TimeSpanParse.TryParseExact(input.AsReadOnlySpan(), format, formatProvider, TimeSpanStyles.None, out result);
}
+ public static bool TryParseExact(ReadOnlySpan<char> input, string format, IFormatProvider formatProvider, out TimeSpan result)
+ {
+ return TimeSpanParse.TryParseExact(input, format, formatProvider, TimeSpanStyles.None, out result);
+ }
public static Boolean TryParseExact(String input, String[] formats, IFormatProvider formatProvider, out TimeSpan result)
{
if (input == null)
@@ -397,6 +405,10 @@ namespace System
}
return TimeSpanParse.TryParseExactMultiple(input.AsReadOnlySpan(), formats, formatProvider, TimeSpanStyles.None, out result);
}
+ public static bool TryParseExact(ReadOnlySpan<char> input, string[] formats, IFormatProvider formatProvider, out TimeSpan result)
+ {
+ return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, TimeSpanStyles.None, out result);
+ }
public static Boolean TryParseExact(String input, String format, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result)
{
ValidateStyles(styles, nameof(styles));
@@ -407,7 +419,7 @@ namespace System
}
return TimeSpanParse.TryParseExact(input.AsReadOnlySpan(), format, formatProvider, styles, out result);
}
- public static bool TryParseExact(ReadOnlySpan<char> input, string format, IFormatProvider formatProvider, out TimeSpan result, TimeSpanStyles styles = TimeSpanStyles.None)
+ public static bool TryParseExact(ReadOnlySpan<char> input, string format, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result)
{
ValidateStyles(styles, nameof(styles));
return TimeSpanParse.TryParseExact(input, format, formatProvider, styles, out result);
@@ -422,7 +434,7 @@ namespace System
}
return TimeSpanParse.TryParseExactMultiple(input.AsReadOnlySpan(), formats, formatProvider, styles, out result);
}
- public static bool TryParseExact(ReadOnlySpan<char> input, string[] formats, IFormatProvider formatProvider, out TimeSpan result, TimeSpanStyles styles = TimeSpanStyles.None)
+ public static bool TryParseExact(ReadOnlySpan<char> input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, out TimeSpan result)
{
ValidateStyles(styles, nameof(styles));
return TimeSpanParse.TryParseExactMultiple(input, formats, formatProvider, styles, out result);
diff --git a/src/mscorlib/shared/System/UInt16.cs b/src/mscorlib/shared/System/UInt16.cs
index d437ad95a6..e9e250e4fc 100644
--- a/src/mscorlib/shared/System/UInt16.cs
+++ b/src/mscorlib/shared/System/UInt16.cs
@@ -155,6 +155,12 @@ namespace System
}
[CLSCompliant(false)]
+ public static bool TryParse(ReadOnlySpan<char> s, out ushort result)
+ {
+ return TryParse(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ [CLSCompliant(false)]
public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt16 result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
@@ -169,7 +175,7 @@ namespace System
}
[CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, out ushort result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out ushort result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
return TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/UInt32.cs b/src/mscorlib/shared/System/UInt32.cs
index ca73b61589..9235f68ee6 100644
--- a/src/mscorlib/shared/System/UInt32.cs
+++ b/src/mscorlib/shared/System/UInt32.cs
@@ -147,6 +147,12 @@ namespace System
}
[CLSCompliant(false)]
+ public static bool TryParse(ReadOnlySpan<char> s, out uint result)
+ {
+ return Number.TryParseUInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ [CLSCompliant(false)]
public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt32 result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
@@ -161,7 +167,7 @@ namespace System
}
[CLSCompliant(false)]
- public static bool TryParse(ReadOnlySpan<char> s, out UInt32 result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out uint result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
return Number.TryParseUInt32(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/UInt64.cs b/src/mscorlib/shared/System/UInt64.cs
index 75b183ac80..ccb21e817c 100644
--- a/src/mscorlib/shared/System/UInt64.cs
+++ b/src/mscorlib/shared/System/UInt64.cs
@@ -144,6 +144,12 @@ namespace System
}
[CLSCompliant(false)]
+ public static bool TryParse(ReadOnlySpan<char> s, out ulong result)
+ {
+ return Number.TryParseUInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
+ }
+
+ [CLSCompliant(false)]
public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out UInt64 result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
@@ -158,7 +164,7 @@ namespace System
}
[CLSCompliant(false)]
- public static Boolean TryParse(ReadOnlySpan<char> s, out UInt64 result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out ulong result)
{
NumberFormatInfo.ValidateParseStyleInteger(style);
return Number.TryParseUInt64(s, style, NumberFormatInfo.GetInstance(provider), out result);
diff --git a/src/mscorlib/shared/System/Version.cs b/src/mscorlib/shared/System/Version.cs
index a084f9f5a4..da12b890d7 100644
--- a/src/mscorlib/shared/System/Version.cs
+++ b/src/mscorlib/shared/System/Version.cs
@@ -415,7 +415,7 @@ namespace System
return true;
}
- return int.TryParse(component, out parsedComponent, NumberStyles.Integer, CultureInfo.InvariantCulture) && parsedComponent >= 0;
+ return int.TryParse(component, NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedComponent) && parsedComponent >= 0;
}
public static bool operator ==(Version v1, Version v2)
diff --git a/src/mscorlib/src/System/Decimal.cs b/src/mscorlib/src/System/Decimal.cs
index e93971d1c0..c64ff59056 100644
--- a/src/mscorlib/src/System/Decimal.cs
+++ b/src/mscorlib/src/System/Decimal.cs
@@ -545,6 +545,11 @@ namespace System
return Number.TryParseDecimal(s.AsReadOnlySpan(), NumberStyles.Number, NumberFormatInfo.CurrentInfo, out result);
}
+ public static bool TryParse(ReadOnlySpan<char> s, out decimal result)
+ {
+ return Number.TryParseDecimal(s, NumberStyles.Number, NumberFormatInfo.CurrentInfo, out result);
+ }
+
public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out Decimal result)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
@@ -558,7 +563,7 @@ namespace System
return Number.TryParseDecimal(s.AsReadOnlySpan(), style, NumberFormatInfo.GetInstance(provider), out result);
}
- public static bool TryParse(ReadOnlySpan<char> s, out decimal result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
+ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out decimal result)
{
NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
return Number.TryParseDecimal(s, style, NumberFormatInfo.GetInstance(provider), out result);