Haskell, Char, Unicode, and Turkish

前端 未结 3 1326
借酒劲吻你
借酒劲吻你 2020-12-28 14:46

For the Char data-type, how do I specify that I want to use the Turkish i instead of the English i for the toLower and toUpper functions?

3条回答
  •  离开以前
    2020-12-28 15:14

    text and the text-icu package

    As of 2011, your best bet is to use the text package, and the toLower function of the Text ICU package, which supports Char operations parameterized by a locale,

    From this example:

    import Data.Text (pack, unpack)
    import Data.Text.ICU (LocaleName(Locale), toLower)
    
    main = do
      let trLocale = Locale "tr-TR"
          upStr    = "ÇIİĞÖŞÜ"
          lowStr   = unpack $ toLower trLocale $ pack upStr
      putStrLn $ "toLower " ++ upStr ++ " gives " ++ lowStr
    

    Running this:

    > toLower ÇIİĞÖŞÜ gives çıiğöşü
    

    while this example converts between String, you can also just leave the data in text format.

提交回复
热议问题