Browse Source

Make TryReadInt32 not throw too.

And simplify the code.
pull/1534/head
Steven Kirk 8 years ago
parent
commit
a3f1c0d621
  1. 29
      src/Avalonia.Base/Utilities/StringTokenizer.cs

29
src/Avalonia.Base/Utilities/StringTokenizer.cs

@ -52,9 +52,16 @@ namespace Avalonia.Utilities
public bool TryReadInt32(out Int32 result, char? separator = null)
{
var success = TryReadString(out var stringResult, separator);
result = success ? int.Parse(stringResult, _formatProvider) : 0;
return success;
if (TryReadString(out var stringResult, separator) &&
int.TryParse(stringResult, NumberStyles.Integer, _formatProvider, out result))
{
return true;
}
else
{
result = default(Int32);
return false;
}
}
public int ReadInt32(char? separator = null)
@ -69,16 +76,16 @@ namespace Avalonia.Utilities
public bool TryReadDouble(out double result, char? separator = null)
{
var success = TryReadString(out var stringResult, separator);
if (success)
if (TryReadString(out var stringResult, separator) &&
double.TryParse(stringResult, NumberStyles.Float, _formatProvider, out result))
{
success = double.TryParse(stringResult, NumberStyles.Float, _formatProvider, out result);
return success;
return true;
}
else
{
result = default(double);
return false;
}
result = default(double);
return false;
}
public double ReadDouble(char? separator = null)

Loading…
Cancel
Save