Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Pär Björklund committed Aug 7, 2017
1 parent 7ef44ae commit 0b98780
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/System.Net.Primitives/src/System/Net/IPAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,29 @@ internal IPAddress(int newAddress)
/// </devdoc>
public static bool TryParse(string ipString, out IPAddress address)
{
if (ipString == null)
{
address = null;
return false;
}

var tempBuffer = ipString.ToCharArray();
address = IPAddressParser.Parse(ipString, true);
return (address != null);
}

public static bool TryParse(ReadOnlySpan<char> ipSpan, out IPAddress address)
{
address = IPAddressParser.Parse(ipSpan, true);
return (address != null);
}

public static IPAddress Parse(string ipString)
{
if (ipString == null)
throw new ArgumentNullException(nameof(ipString));

var tempBuffer = ipString.ToCharArray();
return IPAddressParser.Parse(ipString, false);
}

Expand Down
5 changes: 5 additions & 0 deletions src/System.Net.Primitives/src/System/Net/IPAddressParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace System.Net
{
internal class IPAddressParser
{
internal static unsafe IPAddress Parse(ReadOnlySpan<char> ipSpan, bool tryParse)
{
return Parse(ipSpan.ToString(), tryParse);
}

internal static unsafe IPAddress Parse(string ipString, bool tryParse)
{
if (ipString == null)
Expand Down

0 comments on commit 0b98780

Please sign in to comment.