Created
January 9, 2012 16:26
-
-
Save ostronom/1583678 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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