! Copyright (c) 2009 Samuel Tardieu. ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs combinators kernel math math.functions math.parser math.text.utils sequences splitting ; IN: math.text.french [ basic space-append ] [ drop ] if ; : basic ( n -- str ) { { [ dup literals key? ] [ literals at ] } { [ dup 0 < ] [ abs basic "moins " swap append ] } { [ dup 60 < ] [ smaller-than-60 ] } { [ dup 80 < ] [ smaller-than-80 ] } { [ dup 100 < ] [ smaller-than-100 ] } { [ dup 1000 < ] [ smaller-than-1000 ] } { [ dup 2000 < ] [ smaller-than-2000 ] } { [ dup 1000000 < ] [ smaller-than-1000000 ] } [ decompose ] } cond ; : ieme ( str -- str ) dup "ts" tail? [ but-last ] when dup "e" tail? [ but-last ] when dup "q" tail? [ CHAR: u suffix ] when "ième" append ; : divisor ( n -- str ) { { 2 [ "demi" ] } { 3 [ "tiers" ] } { 4 [ "quart" ] } [ basic ieme ] } case ; PRIVATE> GENERIC: number>text ( n -- str ) M: integer number>text dup abs 102 10^ >= [ number>string ] [ basic ] if ; M: ratio number>text >fraction [ [ number>text ] keep ] [ divisor ] bi* swap abs 1 > [ pluralize ] when space-append ;