Skip to content

Commit

Permalink
Fix high actor name numbering
Browse files Browse the repository at this point in the history
  • Loading branch information
AsgardXIV committed Nov 21, 2024
1 parent d2e9883 commit 4330f8b
Showing 1 changed file with 49 additions and 43 deletions.
92 changes: 49 additions & 43 deletions Brio/Core/IntExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
namespace Brio.Core;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Numerics;
using System.Text;

namespace Brio.Core;

internal static class IntExtensions
{
private static readonly string[] _units = ["Zero",
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
"Eleven",
"Twelve",
"Thirteen",
"Fourteen",
"Fifteen",
"Sixteen",
"Seventeen",
"Eighteen",
"Nineteen"];
private static readonly string[] _tens = ["",
"",
"Twenty",
"Thirty",
"Forty",
"Fifty",
"Sixty",
"Seventy",
"Eighty",
"Ninety"];

public static string ToWords(this int i, string separator = " ")
public static string ToWords(this int number, string separator = " ")
{
string output = i.ToString();
if(i < 20)
string[] ones = { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
string[] tens = { "", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };

StringBuilder result = new();

if(number < 100)
{
output = _units[i];
if(number < 20)
{
result.Append(ones[number]);
}
else
{
int tenPart = number / 10;
int onePart = number % 10;
result.Append(tens[tenPart]);

if(onePart > 0)
{
result.Append(separator);
result.Append(ones[onePart]);
}
}
}
else if(i < 100)
else
{
output = _tens[i / 10] + ((i % 10 > 0) ? separator + ToWords(i % 10, separator) : "");
result.Append(ones[number / 100]);

int remainder = number % 100;
if(remainder == 0)
{
result.Append(separator);
result.Append("Hundred");
}
else
{
result.Append("Hundred");
result.Append(separator);
result.Append(ToWords(remainder, ""));
}
}

return output;
return result.ToString();
}

public static string ToBrioName(this int i)
{
string words = ToWords(i);
if(words.Contains(' '))
return words;
string result = ToWords(i, " ");

if(!result.Contains(' '))
return "Brio " + result;

return "Brio " + words;
return result;
}
}

0 comments on commit 4330f8b

Please sign in to comment.