std.string.toUpper() for greek characters
Jakob Ovrum
jakobovrum at gmail.com
Wed Oct 3 04:03:36 PDT 2012
On Wednesday, 3 October 2012 at 10:56:11 UTC, Minas wrote:
> Currently, toUpper() (and probably toLower()) does not handle
> greek characters correctly. I fixed toUpper() by making a
> another function for greek characters
>
> // called if (c >= 0x387 && c <= 0x3CE)
> dchar toUpperGreek(dchar c)
> {
> if( c >= 'α' && c <= 'ω' )
> {
> if( c == 'ς' )
> c = 'Σ';
> else
> c -= 32;
> }
> else
> {
> dchar[dchar] map;
> map['ά'] = 'Ά';
> map['έ'] = 'Έ';
> map['ή'] = 'Ή';
> map['ί'] = 'Ί';
> map['ϊ'] = 'Ϊ';
> map['ΐ'] = 'Ϊ';
> map['ό'] = 'Ό';
> map['ύ'] = 'Ύ';
> map['ϋ'] = 'Ϋ';
> map['ΰ'] = 'Ϋ';
> map['ώ'] = 'Ώ';
>
> c = map[c];
> }
>
> return c;
> }
>
> Then, in toUpper()
> {
> ....
> if (c >= 0x387 && c <= 0x3CE)
> c = toUpperGreek()...
> ///
> }
>
> Do you think it should stay like that or I should copy-paste it
> in the body of toUpper()?
>
> I'm going to fix toLower() as well and make a pull request.
A switch with 11 cases is very likely going to be a lot faster
than the hash table approach you're using, especially since the
AA is not cached and will be dynamically allocated on every call.
More information about the Digitalmars-d-announce
mailing list