Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Oren Novotny committed Mar 13, 2019
1 parent 9b05dd2 commit ef68700
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Humanizer.Tests.Shared/ArticlePrefixSortTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void SortStringArrayIgnoringArticlePrefixes(string[] input, string[] expe
public void An_Empty_String_Array_Throws_ArgumentOutOfRangeException()
{
string[] items = { };
Action action = () => EnglishArticle.AppendArticlePrefix(items);
void action() => EnglishArticle.AppendArticlePrefix(items);
Assert.Throws<ArgumentOutOfRangeException>(action);
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/Humanizer/ArticlePrefixSort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ public static class EnglishArticle
public static string[] AppendArticlePrefix(string[] items)
{
if (items.Length == 0)
{
throw new ArgumentOutOfRangeException(nameof(items));
}

Regex regex = new Regex("^((The)|(the)|(a)|(A)|(An)|(an))\\s\\w+");
string[] transformed = new string[items.Length];
var regex = new Regex("^((The)|(the)|(a)|(A)|(An)|(an))\\s\\w+");
var transformed = new string[items.Length];

for (var i = 0; i < items.Length; i++)
{
if (regex.IsMatch(items[i]))
{
string article = items[i].Substring(0, items[i].IndexOf(" ", StringComparison.CurrentCulture));
string removed = items[i].Remove(0, items[i].IndexOf(" ", StringComparison.CurrentCulture));
string appended = $"{removed} {article}";
var article = items[i].Substring(0, items[i].IndexOf(" ", StringComparison.CurrentCulture));
var removed = items[i].Remove(0, items[i].IndexOf(" ", StringComparison.CurrentCulture));
var appended = $"{removed} {article}";
transformed[i] = appended.Trim();
}
else
Expand All @@ -46,9 +48,9 @@ public static string[] AppendArticlePrefix(string[] items)
/// <returns>String array</returns>
public static string[] PrependArticleSuffix(string[] appended)
{
string[] inserted = new string[appended.Length];
var inserted = new string[appended.Length];

for (int i = 0; i < appended.Length; i++)
for (var i = 0; i < appended.Length; i++)
{
string suffix;
string original;
Expand Down Expand Up @@ -98,8 +100,8 @@ public static string[] PrependArticleSuffix(string[] appended)

private static string ToOriginalFormat(string[] appended, string suffix, int i)
{
string insertion = appended[i].Remove(appended[i].IndexOf(suffix, StringComparison.CurrentCulture));
string original = $"{suffix} {insertion}";
var insertion = appended[i].Remove(appended[i].IndexOf(suffix, StringComparison.CurrentCulture));
var original = $"{suffix} {insertion}";
return original.Trim();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/Humanizer/Articles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
/// </summary>
public enum EnglishArticles
{
/// <summary>
/// A
/// </summary>
A,
/// <summary>
/// An
/// </summary>
An,
/// <summary>
/// The
/// </summary>
The
}
}

0 comments on commit ef68700

Please sign in to comment.