develooper Front page | perl.perl6.language | Postings from December 2005

Transliteration preferring longest match

Thread Next
From:
Brad Bowman
Date:
December 15, 2005 09:51
Subject:
Transliteration preferring longest match
Message ID:
43A1ACDB.2060603@bereft.net

Hi,

S05 describes an array version of trans for transliteration:
  ( http://dev.perl.org/perl6/doc/design/syn/S05.html#Transliteration )

   The array version can map one-or-more characters to one-or-more characters:

      $str.=trans( [' ',      '<',    '>',    '&'    ] =>
                   ['&nbsp;', '&lt;', '&gt;', '&amp;' ]);

   In the case that more than one sequence of input characters matches,
   the longest one wins. In the case of two identical sequences the first
   in order wins.

Why does the longest input sequence win? 
   Is it for some consistency that that I'm not seeing? Some exceedingly
common use case?  The rule seems unnecessarily restrictive.

The "first in order" rule is more flexible, the user can sort their
arrays to produce the longest input rule, or use another order if that is
preferred.  The first transliteration example even uses sort in
the pair-wise form:

   $str.trans( %mapping.pairs.sort );

Can we drop the longest preference?

Brad

-- 
  By inconsistency and frivolity we stray from the Way and show ourselves
  to be beginners. In this we do much harm.
                                     -- Hagakure http://bereft.net/hagakure/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About