Import FuelLog
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
@@ -21,6 +22,12 @@ namespace MileageTraker.Web.Utility
|
||||
current + (Char.IsUpper(c) ? " " + c : c.ToString()));
|
||||
}
|
||||
|
||||
public static string ToTitleCase(this string str)
|
||||
{
|
||||
// http://stackoverflow.com/q/1943273/99492
|
||||
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str);
|
||||
}
|
||||
|
||||
private static T GetAttribute<T>(this Enum enumeration) where T : Attribute
|
||||
{
|
||||
var type = enumeration.GetType();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MileageTraker.Web.Utility
|
||||
{
|
||||
public static class NameNormalizer
|
||||
{
|
||||
private const string NamePattern = @"(?<Last>\w+),\s*(?<First>\w+)(?:\s*)?(?<Suffix>(jr|sr|iii))?";
|
||||
private static readonly Regex NameRegex = new Regex(NamePattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
|
||||
|
||||
public static string Normalize(string name)
|
||||
{
|
||||
var match = NameRegex.Match(name);
|
||||
if (!match.Success)
|
||||
return name;
|
||||
return string.Format("{0} {1} {2}",
|
||||
match.Groups["First"], match.Groups["Last"], match.Groups["Suffix"]).TrimEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace MileageTraker.Web.Utility
|
||||
{
|
||||
protected override string FormatValueCore(string value)
|
||||
{
|
||||
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value);
|
||||
return value.ToTitleCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user