--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-07-23 14:58:42 -07:00
parent e2425945ee
commit 860c53bafa

View File

@@ -5,9 +5,16 @@ namespace Orchard.ContentTypes.Extensions {
public static class StrinExtensions {
private static readonly Regex humps = new Regex("[A-Z][^A-Z]*");
public static string CamelFriendly(this string camel) {
return camel != null
? humps.Matches(camel).OfType<Match>().Select(m => m.Value).Aggregate((a, b) => a + " " + b).TrimStart(' ')
: null;
if (camel == null)
return null;
var matches = humps.Matches(camel).OfType<Match>().Select(m => m.Value);
if (matches.Any()) {
return matches.Aggregate((a, b) => a + " " + b).TrimStart(' ');
}
else {
return camel;
}
}
public static string TrimEnd(this string rough, string trim = "") {
@@ -15,7 +22,7 @@ namespace Orchard.ContentTypes.Extensions {
return null;
return rough.EndsWith(trim)
? rough.Substring(0, rough.Length - 4)
? rough.Substring(0, rough.Length - trim.Length)
: rough;
}
}