コード例 #1
0
ファイル: GenericSpeller.cs プロジェクト: sahwar/Slovom
        public override SpelledNumber SpellOrdinal(ulong number, Gender gender = Gender.Neutral)
        {
            if (number < _settings.Magnitude)
            {
                return(InnerSpeller.SpellOrdinal(number, gender));
            }

            ulong numberOfUnits = number / _settings.Magnitude;
            ulong reminder      = number % _settings.Magnitude;

            if (reminder == 0)
            {
                string result = GetOrdinal(numberOfUnits, gender);

                SpelledNumber unitsOrdinalSpelled = new SpelledNumber(result, false);
                return(unitsOrdinalSpelled);
            }

            SpelledNumber unitsSpelled;

            if (numberOfUnits == 1)
            {
                unitsSpelled = new SpelledNumber(_settings.Singular, false);
            }
            else
            {
                SpelledNumber spelled = InnerSpeller.Spell(numberOfUnits, _settings.SpellingGender);

                unitsSpelled = new SpelledNumber(spelled.Spelled + _settings.PluralSuffix, spelled.ContainsAnd);
            }

            return(unitsSpelled.Concat(InnerSpeller.SpellOrdinal(reminder, gender)));
        }
コード例 #2
0
        public override SpelledNumber Spell(ulong number, Gender gender = Gender.Neutral)
        {
            if (number > 0)
            {
                return(InnerSpeller.Spell(number, gender));
            }

            return(new SpelledNumber("нула", false));
        }
コード例 #3
0
ファイル: GenericSpeller.cs プロジェクト: sahwar/Slovom
        private string GetOrdinal(ulong numberOfUnits, Gender gender)
        {
            if (numberOfUnits == 1)
            {
                return(_settings.GetOrdinalSuffix(gender));
            }

            return(InnerSpeller.Spell(numberOfUnits, _settings.SpellingGender) + " " + _settings.GetOrdinalSuffix(gender));
        }
コード例 #4
0
        public override SpelledNumber Spell(ulong number, Gender gender = Gender.Neutral)
        {
            if (number < 100)
            {
                return(InnerSpeller.Spell(number, gender));
            }

            ulong hundreds = (number / 100) * 100;

            SpelledNumber hundredsInWords = new SpelledNumber(GetHundreds(hundreds), false);

            ulong reminder = number % 100;

            if (reminder == 0)
            {
                return(hundredsInWords);
            }

            return(hundredsInWords.Concat(InnerSpeller.Spell(reminder, gender)));
        }
コード例 #5
0
        public override SpelledNumber Spell(ulong number, Gender gender = Gender.Neutral)
        {
            if (number < 20)
            {
                return(InnerSpeller.Spell(number, gender));
            }

            ulong tens = (number / 10) * 10;

            string tensInWords = GetTens(tens);
            var    tensSpelled = new SpelledNumber(tensInWords, false);

            ulong reminder = number % 10;

            if (reminder == 0)
            {
                return(tensSpelled);
            }

            return(tensSpelled.Concat(InnerSpeller.Spell(reminder, gender)));
        }
コード例 #6
0
ファイル: NumbersTo19Speller.cs プロジェクト: sahwar/Slovom
        public override SpelledNumber Spell(ulong number, Gender gender = Gender.Neutral)
        {
            if (number < 10)
            {
                return(InnerSpeller.Spell(number, gender));
            }

            string result;

            switch (number)
            {
            case 10: result = "десет"; break;

            case 11: result = "единадесет"; break;

            case 12: result = "дванадесет"; break;

            case 13: result = "тринадесет"; break;

            case 14: result = "четиринадесет"; break;

            case 15: result = "петнадесет"; break;

            case 16: result = "шестнадесет"; break;

            case 17: result = "седемнадесет"; break;

            case 18: result = "осемнадесет"; break;

            case 19: result = "деветнадесет"; break;

            default:
                throw new ArgumentOutOfRangeException(nameof(number), $"'{nameof(NumbersTo19Speller)}' is can't spell number {number}!");
            }

            return(new SpelledNumber(result, false));
        }