//
using System.Net.Mail;
+using System.Globalization;
+using System.Collections.Generic;
namespace System.Net.Http.Headers
{
{
public static bool TryParse (string input, out string result)
{
- throw new NotImplementedException ();
+ if (input != null && Lexer.IsValidToken (input)) {
+ result = input;
+ return true;
+ }
+
+ result = null;
+ return false;
}
public static void Check (string s)
}
}
+ public static bool TryCheck (string s)
+ {
+ if (s == null)
+ return false;
+
+ return Lexer.IsValidToken (s);
+ }
+
public static void CheckQuotedString (string s)
{
if (s == null)
public static class DateTime
{
+ public new static readonly Func<object, string> ToString = l => ((DateTimeOffset) l).ToString ("r", CultureInfo.InvariantCulture);
+
public static bool TryParse (string input, out DateTimeOffset result)
{
- throw new NotImplementedException ();
+ return Lexer.TryGetDateValue (input, out result);
}
}
}
}
+ public static class Host
+ {
+ public static bool TryParse (string input, out string result)
+ {
+ result = input;
+
+ System.Uri dummy;
+ return System.Uri.TryCreate ("http://u@" + input + "/", UriKind.Absolute, out dummy);
+ }
+ }
+
public static class Int
{
public static bool TryParse (string input, out int result)
{
- throw new NotImplementedException ();
+ return int.TryParse (input, NumberStyles.None, CultureInfo.InvariantCulture, out result);
+ }
+ }
+
+ public static class Long
+ {
+ public static bool TryParse (string input, out long result)
+ {
+ return long.TryParse (input, NumberStyles.None, CultureInfo.InvariantCulture, out result);
+ }
+ }
+
+ public static class MD5
+ {
+ public new static readonly Func<object, string> ToString = l => Convert.ToBase64String ((byte[]) l);
+
+ public static bool TryParse (string input, out byte[] result)
+ {
+ try {
+ result = Convert.FromBase64String (input);
+ return true;
+ } catch {
+ result = null;
+ return false;
+ }
}
}
{
public static bool TryParse (string input, out TimeSpan result)
{
- throw new NotImplementedException ();
+ int value;
+ if (Int.TryParse (input, out value)) {
+ result = TimeSpan.FromSeconds (value);
+ return true;
+ }
+
+ result = TimeSpan.Zero;
+ return false;
}
}
{
public static bool TryParse (string input, out System.Uri result)
{
- return System.Uri.TryCreate ("http://" + input + "/", UriKind.Absolute, out result);
+ return System.Uri.TryCreate (input, UriKind.RelativeOrAbsolute, out result);
}
public static void Check (string s)