diff options
author | Joseph C. Sible <josephcsible@users.noreply.github.com> | 2020-02-07 02:42:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 08:42:46 +0100 |
commit | 60a3158bf9b6f4d16bb5fc6cac61b5c305ad40e3 (patch) | |
tree | 4112e9795a47630c48576393687f703e4de9e8e5 /src/Text/Pandoc/BCP47.hs | |
parent | a5a3ac994618d71ecaf2e8bd40251d792edc9c22 (diff) | |
download | pandoc-60a3158bf9b6f4d16bb5fc6cac61b5c305ad40e3.tar.gz |
More in-depth refactoring and cleanup (#6123)
* Avoid duplicating the dash case
* Pull common functions out of case branches
* Make sure list lengths are only calculated once
* Use unless
* Simplify parseURIReference' and avoid an unnecessary call to length
* Use <$> instead of reimplementing it
* Use swap instead of reimplementing it
* Remove eta-expansion that's been unnecessary since 90f5dd8
* Use tailDef instead of reimplementing it
* Use second instead of fmap, per @tarleb
Diffstat (limited to 'src/Text/Pandoc/BCP47.hs')
-rw-r--r-- | src/Text/Pandoc/BCP47.hs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Text/Pandoc/BCP47.hs b/src/Text/Pandoc/BCP47.hs index e25134976..c9f144aa4 100644 --- a/src/Text/Pandoc/BCP47.hs +++ b/src/Text/Pandoc/BCP47.hs @@ -93,14 +93,16 @@ parseBCP47 lang = ds <- P.option "" (P.count 1 P.digit) cs <- P.many1 asciiLetter let var = ds ++ cs + lv = length var guard $ if null ds - then length var >= 5 && length var <= 8 - else length var == 4 + then lv >= 5 && lv <= 8 + else lv == 4 return $ T.toLower $ T.pack var pExtension = P.try $ do P.char '-' cs <- P.many1 $ P.satisfy (\c -> isAscii c && isAlphaNum c) - guard $ length cs >= 2 && length cs <= 8 + let lcs = length cs + guard $ lcs >= 2 && lcs <= 8 return $ T.toLower $ T.pack cs pPrivateUse = P.try $ do P.char '-' |