Skip to content

Commit

Permalink
update to long
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Pethick authored and Oren Novotny committed May 4, 2017
1 parent 125cb28 commit e88b07e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
13 changes: 0 additions & 13 deletions src/Humanizer.v2.ncrunchsolution

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Humanizer.Localisation.NumberToWords
{
internal class FrenchNumberToWordsConverter : FrenchNumberToWordsConverterBase
class FrenchNumberToWordsConverter : FrenchNumberToWordsConverterBase
{
protected override void CollectPartsUnderAHundred(ICollection<string> parts, ref long number, GrammaticalGender gender, bool pluralize)
protected override void CollectPartsUnderAHundred(ICollection<string> parts, ref int number, GrammaticalGender gender, bool pluralize)
{
if (number == 71)
parts.Add("soixante et onze");
Expand All @@ -15,7 +15,7 @@ protected override void CollectPartsUnderAHundred(ICollection<string> parts, ref
var @base = number < 80 ? 60 : 80;
int units = number - @base;
var tens = @base/10;
parts.Add(string.Format("{0}-{1}", GetTens(tens), GetUnits(units, gender)));
parts.Add($"{GetTens(tens)}-{GetUnits(units, gender)}");
}
else
base.CollectPartsUnderAHundred(parts, ref number, gender, pluralize);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace Humanizer.Localisation.NumberToWords
{
abstract class FrenchNumberToWordsConverterBase : GenderedNumberToWordsConverter
{
private static readonly string[] UnitsMap = new string[] { "zéro", "un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf"};
private static readonly string[] TensMap = new string[] { "zéro", "dix", "vingt", "trente", "quarante", "cinquante", "soixante", "septante", "octante", "nonante" };
static readonly string[] UnitsMap = { "zéro", "un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf"};
static readonly string[] TensMap = { "zéro", "dix", "vingt", "trente", "quarante", "cinquante", "soixante", "septante", "octante", "nonante" };

public override string Convert(int number, GrammaticalGender gender)
public override string Convert(long input, GrammaticalGender gender)
{
if (input > Int32.MaxValue || input < Int32.MinValue)
{
throw new NotImplementedException();
}
var number = (int)input;

if (number == 0)
return UnitsMap[0];
var parts = new List<string>();
Expand Down Expand Up @@ -63,7 +70,7 @@ protected static string GetUnits(int number, GrammaticalGender gender)
return UnitsMap[number];
}

private static void CollectHundreds(ICollection<string> parts, ref int number, int d, string form, bool pluralize)
static void CollectHundreds(ICollection<string> parts, ref int number, int d, string form, bool pluralize)
{
if (number < d) return;

Expand All @@ -88,7 +95,7 @@ private static void CollectHundreds(ICollection<string> parts, ref int number, i
number %= d;
}

private void CollectParts(ICollection<string> parts, ref int number, int d, string form)
void CollectParts(ICollection<string> parts, ref int number, int d, string form)
{
if (number < d) return;

Expand All @@ -108,7 +115,7 @@ private void CollectParts(ICollection<string> parts, ref int number, int d, stri
number %= d;
}

private void CollectPartsUnderAThousand(ICollection<string> parts, int number, GrammaticalGender gender, bool pluralize)
void CollectPartsUnderAThousand(ICollection<string> parts, int number, GrammaticalGender gender, bool pluralize)
{
CollectHundreds(parts, ref number, 100, "cent", pluralize);

Expand All @@ -118,7 +125,7 @@ private void CollectPartsUnderAThousand(ICollection<string> parts, int number, G
}
}

private void CollectThousands(ICollection<string> parts, ref int number, int d, string form)
void CollectThousands(ICollection<string> parts, ref int number, int d, string form)
{
if (number < d) return;

Expand Down Expand Up @@ -155,7 +162,7 @@ protected virtual void CollectPartsUnderAHundred(ICollection<string> parts, ref
}
else
{
parts.Add(string.Format("{0}-{1}", tens, GetUnits(units, gender)));
parts.Add($"{tens}-{GetUnits(units, gender)}");
}
}
}
Expand Down

0 comments on commit e88b07e

Please sign in to comment.