quotes
This commit is contained in:
27
src/MyLib.hs
27
src/MyLib.hs
@@ -72,12 +72,11 @@ fullwidthCJKsymCJK :: Rule
|
|||||||
fullwidthCJKsymCJK = do
|
fullwidthCJKsymCJK = do
|
||||||
lcjk <- cjkChar
|
lcjk <- cjkChar
|
||||||
_ <- many (char ' ')
|
_ <- many (char ' ')
|
||||||
sym <- fmap T.unpack (chunk ".") <|> some (oneOf (":" :: [Char]))
|
sym <- try (some (char ':')) <|> count 1 (char '.')
|
||||||
_ <- many (char ' ')
|
_ <- many (char ' ')
|
||||||
rcjk <- cjkChar
|
rcjk <- cjkChar
|
||||||
|
let transformedsym = map convertToFullwidth sym
|
||||||
let transformedsym = T.pack $ map convertToFullwidth sym
|
return $ T.pack $ [lcjk] ++ transformedsym ++ [rcjk]
|
||||||
return $ T.pack [lcjk] <> transformedsym <> T.pack [rcjk]
|
|
||||||
|
|
||||||
fullwidthCJKsym :: Rule
|
fullwidthCJKsym :: Rule
|
||||||
fullwidthCJKsym = do
|
fullwidthCJKsym = do
|
||||||
@@ -101,18 +100,31 @@ fixCJKcolAN = do
|
|||||||
an <- alphaNumChar
|
an <- alphaNumChar
|
||||||
return $ T.pack $ [cjk] ++ ":" ++ [an]
|
return $ T.pack $ [cjk] ++ ":" ++ [an]
|
||||||
|
|
||||||
|
-- quotes
|
||||||
|
-- seems confusing ...
|
||||||
|
quotesym :: [Char]
|
||||||
|
quotesym = "\x05f4\"\'`"
|
||||||
|
|
||||||
cjkquote :: Rule
|
cjkquote :: Rule
|
||||||
cjkquote = do
|
cjkquote = do
|
||||||
cjk <- cjkChar
|
cjk <- cjkChar
|
||||||
quote <- oneOf ("\x05f4\"\'" :: [Char])
|
quote <- oneOf quotesym
|
||||||
return $ T.pack $ [cjk] ++ " " ++ [quote]
|
return $ T.pack $ [cjk] ++ " " ++ [quote]
|
||||||
|
|
||||||
quoteCJK :: Rule
|
quoteCJK :: Rule
|
||||||
quoteCJK = do
|
quoteCJK = do
|
||||||
quote <- oneOf ("\x05f4\"\'" :: [Char])
|
quote <- oneOf quotesym
|
||||||
cjk <- cjkChar
|
cjk <- cjkChar
|
||||||
return $ T.pack $ [quote] ++ " " ++ [cjk]
|
return $ T.pack $ [quote] ++ " " ++ [cjk]
|
||||||
|
|
||||||
|
fixQuote :: Rule
|
||||||
|
fixQuote = do
|
||||||
|
openQuotes <- T.pack <$> some (oneOf quotesym)
|
||||||
|
_ <- many spaceChar
|
||||||
|
content <- T.pack <$> someTill anySingle (lookAhead $ some (oneOf quotesym))
|
||||||
|
closeQuotes <- T.pack <$> some (oneOf quotesym)
|
||||||
|
return $ openQuotes <> T.strip content <> closeQuotes
|
||||||
|
|
||||||
-- the rule set
|
-- the rule set
|
||||||
myRules :: RuleSet
|
myRules :: RuleSet
|
||||||
myRules =
|
myRules =
|
||||||
@@ -121,5 +133,6 @@ myRules =
|
|||||||
dotsCJK,
|
dotsCJK,
|
||||||
fixCJKcolAN,
|
fixCJKcolAN,
|
||||||
cjkquote,
|
cjkquote,
|
||||||
quoteCJK
|
quoteCJK,
|
||||||
|
fixQuote
|
||||||
]
|
]
|
||||||
@@ -15,6 +15,7 @@ main = hspec $ do
|
|||||||
applyRules myRules "你…好" `shouldBe` "你… 好"
|
applyRules myRules "你…好" `shouldBe` "你… 好"
|
||||||
applyRules myRules "你...好" `shouldBe` "你... 好"
|
applyRules myRules "你...好" `shouldBe` "你... 好"
|
||||||
applyRules myRules "你:0" `shouldBe` "你:0"
|
applyRules myRules "你:0" `shouldBe` "你:0"
|
||||||
-- applyRules myRules "我说:\" 他说:\'你好\'\"" `shouldBe` "我说:“他说:‘你好’”"
|
applyRules myRules "我说:\" 他说:\'你好\'\"" `shouldBe` "我说:\"他说:\'你好\'\""
|
||||||
it "adds spaces" $ do
|
it "adds spaces" $ do
|
||||||
applyRules myRules "\'你好\'" `shouldBe` "\'你好\'"
|
applyRules myRules "\'你好\'" `shouldBe` "\'你好\'"
|
||||||
|
applyRules myRules "你\'hello\'" `shouldBe` "你 \'hello\'"
|
||||||
Reference in New Issue
Block a user