aboutsummaryrefslogtreecommitdiff
path: root/common/src/Common/Util/Text.hs
blob: b49fc554b6b8e263c5ed2884e8eba5c8a9769a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Common.Util.Text
  ( search
  , unaccent
  ) where

import           Data.Text (Text)
import qualified Data.Text as T

search :: Text -> Text -> Bool
search s t =
  (format s) `T.isInfixOf` (format t)
  where format = T.toLower . unaccent

unaccent :: Text -> Text
unaccent = T.map unaccentChar

unaccentChar :: Char -> Char
unaccentChar c = case c of
  'à' -> 'a'
  'á' -> 'a'
  'â' -> 'a'
  'ã' -> 'a'
  'ä' -> 'a'
  'ç' -> 'c'
  'è' -> 'e'
  'é' -> 'e'
  'ê' -> 'e'
  'ë' -> 'e'
  'ì' -> 'i'
  'í' -> 'i'
  'î' -> 'i'
  'ï' -> 'i'
  'ñ' -> 'n'
  'ò' -> 'o'
  'ó' -> 'o'
  'ô' -> 'o'
  'õ' -> 'o'
  'ö' -> 'o'
  'š' -> 's'
  'ù' -> 'u'
  'ú' -> 'u'
  'û' -> 'u'
  'ü' -> 'u'
  'ý' -> 'y'
  'ÿ' -> 'y'
  'ž' -> 'z'
  _   -> c