Skip to content

Commit

Permalink
minor formatting cleanup after #417
Browse files Browse the repository at this point in the history
  • Loading branch information
MehdiK committed May 24, 2015
1 parent 309ccef commit 7a703a9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 52 deletions.
7 changes: 4 additions & 3 deletions src/Humanizer/Configuration/NumberToWordsConverterRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace Humanizer.Configuration
{
internal class NumberToWordsConverterRegistry : LocaliserRegistry<INumberToWordsConverter>
{
public NumberToWordsConverterRegistry() : base((culture) => new DefaultNumberToWordsConverter(culture))
public NumberToWordsConverterRegistry()
: base((culture) => new DefaultNumberToWordsConverter(culture))
{
Register("en", new EnglishNumberToWordsConverter());
Register("ar", new ArabicNumberToWordsConverter());
Expand All @@ -24,8 +25,8 @@ internal class NumberToWordsConverterRegistry : LocaliserRegistry<INumberToWords
Register("uk", new UkrainianNumberToWordsConverter());
Register("uz-Latn-UZ", new UzbekLatnNumberToWordConverter());
Register("uz-Cyrl-UZ", new UzbekCyrlNumberToWordConverter());
Register("sr", (culture) => new SerbianCyrlNumberToWordsConverter(culture));
Register("sr-Latn", (culture) => new SerbianNumberToWordsConverter(culture));
Register("sr", (culture) => new SerbianCyrlNumberToWordsConverter(culture));
Register("sr-Latn", (culture) => new SerbianNumberToWordsConverter(culture));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,100 +6,83 @@

namespace Humanizer.Localisation.NumberToWords
{
internal class SerbianCyrlNumberToWordsConverter : GenderlessNumberToWordsConverter
internal class SerbianCyrlNumberToWordsConverter : GenderlessNumberToWordsConverter
{
private static readonly string[] UnitsMap = { "нула", "један", "два", "три", "четири", "пет", "шест", "седам", "осам", "девет", "десет", "једанест", "дванаест", "тринаест", "четрнаест", "петнаест", "шестнаест", "седамнаест", "осамнаест", "деветнаест" };
private static readonly string[] TensMap = { "нула", "десет", "двадесет", "тридесет", "четрдесет", "петдесет", "шестдесет", "седамдесет", "осамдесет", "деветдесет" };

private readonly CultureInfo _culture;

public SerbianCyrlNumberToWordsConverter(CultureInfo culture)
public SerbianCyrlNumberToWordsConverter(CultureInfo culture)
{
_culture = culture;
}

public override string Convert(int number)
{
if (number == 0)
{
return "нула";
}

if (number < 0)
{
return string.Format("- {0}", Convert(-number));
}

var parts = new List<string>();
var billions = number / 1000000000;

if (billions > 0)
{
parts.Add(Part("милијарда", "две милијарде", "{0} милијарде", "{0} милијарда", billions));
parts.Add(Part("милијарда", "две милијарде", "{0} милијарде", "{0} милијарда", billions));
number %= 1000000000;

if (number > 0)
{
parts.Add(" ");
}
}

var millions = number / 1000000;

if (millions > 0)
{
parts.Add(Part("милион", "два милиона", "{0} милиона", "{0} милиона", millions));
parts.Add(Part("милион", "два милиона", "{0} милиона", "{0} милиона", millions));
number %= 1000000;

if (number > 0)
{
parts.Add(" ");
}
}

var thousands = number / 1000;

if (thousands > 0)
{
parts.Add(Part("хиљаду", "две хиљаде", "{0} хиљаде", "{0} хиљада", thousands));
number %= 1000;

if (number > 0)
{
parts.Add(" ");
}
}

var hundreds = number / 100;

if (hundreds > 0)
{

parts.Add(Part("сто", "двесто", "{0}сто", "{0}сто", hundreds));
number %= 100;

if (number > 0)
{
parts.Add(" ");
}
}

if (number > 0)
{
if (number < 20)
{
parts.Add(UnitsMap[number]);
}
else
{
{
parts.Add(TensMap[number / 10]);

var units = number % 10;

if (units > 0)
{
parts.Add(string.Format(" {0}", UnitsMap[units]));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,84 +21,67 @@ public SerbianNumberToWordsConverter(CultureInfo culture)
public override string Convert(int number)
{
if (number == 0)
{
return "nula";
}

if (number < 0)
{
return string.Format("- {0}", Convert(-number));
}

var parts = new List<string>();
var billions = number / 1000000000;

if (billions > 0)
{
parts.Add(Part("milijarda", "dve milijarde", "{0} milijarde", "{0} milijarda", billions));
parts.Add(Part("milijarda", "dve milijarde", "{0} milijarde", "{0} milijarda", billions));
number %= 1000000000;

if (number > 0)
{
parts.Add(" ");
}
}

var millions = number / 1000000;

if (millions > 0)
{
parts.Add(Part("milion", "dva miliona", "{0} miliona", "{0} miliona", millions));
parts.Add(Part("milion", "dva miliona", "{0} miliona", "{0} miliona", millions));
number %= 1000000;

if (number > 0)
{
parts.Add(" ");
}
}

var thousands = number / 1000;

if (thousands > 0)
{
parts.Add(Part("hiljadu", "dve hiljade", "{0} hiljade", "{0} hiljada", thousands));
parts.Add(Part("hiljadu", "dve hiljade", "{0} hiljade", "{0} hiljada", thousands));
number %= 1000;

if (number > 0)
{
parts.Add(" ");
}
}

var hundreds = number / 100;

if (hundreds > 0)
{
parts.Add(Part("sto", "dvesto", "{0}sto", "{0}sto", hundreds));
parts.Add(Part("sto", "dvesto", "{0}sto", "{0}sto", hundreds));
number %= 100;

if (number > 0)
{
parts.Add(" ");
}
}

if (number > 0)
{
if (number < 20)
{
parts.Add(UnitsMap[number]);
}
else
{
{
parts.Add(TensMap[number / 10]);

var units = number % 10;

if (units > 0)
{
parts.Add(string.Format(" {0}", UnitsMap[units]));
}
}
}

Expand Down Expand Up @@ -127,5 +110,4 @@ private string Part(string singular, string dual, string trialQuadral, string pl
}
}
}

}

0 comments on commit 7a703a9

Please sign in to comment.