Skip to content

Instantly share code, notes, and snippets.

@ostronom
Created January 9, 2012 16:26
Show Gist options
  • Save ostronom/1583678 to your computer and use it in GitHub Desktop.
Save ostronom/1583678 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings, PackageImports #-}
module Hyphen (hyphenizeString) where
import qualified Text.Regex as R
hyphenizeString :: String -> String
hyphenizeString x = foldl subHyphen x (map compileRule rules)
where rus_v = "[аеёиоуыэюя]" :: String
rus_n = "[бвгджзклмнпрстфхцчшщ]" :: String
rus_x = "[йъь]" :: String
rus_a = "[абвгдеёжзийклмнопрстуфхцчшщъыьэюя]" ::String
rules = [( rus_v ++ rus_n ++ rus_n, rus_n ++ rus_n ++ rus_v )
,( rus_v ++ rus_n, rus_n ++ rus_n ++ rus_v )
,( rus_n ++ rus_v, rus_n ++ rus_v )
,( rus_v ++ rus_n, rus_n ++ rus_v )
,( rus_v, rus_v ++ rus_a )
,( rus_x, rus_a ++ rus_a )
]
compileRule :: (String, String) -> R.Regex
compileRule (predRule, postRule) = R.mkRegexWithOpts ("(" ++ predRule ++ ")(" ++ postRule ++ ")") True False
subHyphen :: String -> R.Regex -> String
subHyphen a r = R.subRegex r a "\\1\173\\2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment