For more information... RTFM!
NAVIGATION
RECENTLY VIEWED
ACCOUNT LOGIN

You are not logged in

Powered by Interchange version 5.7.0

roman

Expect the body text to consist of a string of numbers and convert the value into Roman numerals.  If the body text contains any non-numeric values then they will be stripped.

Availability

Availability

This filter was introduced in version 5.4.0, and is therefore not available for use with any earlier Interchange version.

Example

[filter roman]1968[/filter]

Results in:

MCMLXVIII

Source code

sub {
    my $val = shift;

    $val =~ s/\D+//g;
    return '' unless $val;

    $val =~ m/(\d*?)(\d{1,3})$/ or return '';

    my $buf = 'M' x ($1 || 0);
    my @digits = reverse(split('',$2));

    my @numerals = (
        [ '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', ],
        [ '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', ],
        [ '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', ],
    );

    for (my $i = $#digits; $i >= 0; $i--) {
        $buf .= $numerals[$i]->[$digits[$i]];
    }
    return $buf;
}

Category:  Filters
Last modified by: Kevin Walsh
Modification date: Friday 23 February 2007 at 6:50 PM (EST)
Home  |  Legal nonsense  |  Privacy policy  |  Contact us