aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2021-09-27 16:43:13 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2021-09-27 16:43:13 -0700
commit8018179b3df34cd7fdbd77c7a08b21fd8d5b5b31 (patch)
tree1e97dde5c3cd7ddb695730482a6187d3c03356dc /src/Text/Pandoc
parentdf57d0930bf4c6b369b1cd35a98bd8b7238da0d1 (diff)
downloadpandoc-8018179b3df34cd7fdbd77c7a08b21fd8d5b5b31.tar.gz
Better implementation of splitStrWhen
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Citeproc/BibTeX.hs19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Citeproc/BibTeX.hs b/src/Text/Pandoc/Citeproc/BibTeX.hs
index 13baabccb..5c7bdd9b5 100644
--- a/src/Text/Pandoc/Citeproc/BibTeX.hs
+++ b/src/Text/Pandoc/Citeproc/BibTeX.hs
@@ -1256,19 +1256,14 @@ toName opts ils = do
, nameStaticOrdering = False
}
+-- Split Str elements so that characters satisfying the
+-- predicate each have their own Str.
splitStrWhen :: (Char -> Bool) -> [Inline] -> [Inline]
-splitStrWhen _ [] = []
-splitStrWhen p (Str xs : ys) = map Str (go xs) ++ splitStrWhen p ys
- where go s =
- let (w,z) = T.break p s
- in if T.null z
- then if T.null w
- then []
- else [w]
- else if T.null w
- then (T.take 1 z : go (T.drop 1 z))
- else (w : T.take 1 z : go (T.drop 1 z))
-splitStrWhen p (x : ys) = x : splitStrWhen p ys
+splitStrWhen p = foldr go []
+ where
+ go (Str t) = (map Str (T.groupBy goesTogether t) ++)
+ go x = (x :)
+ goesTogether c d = not (p c || p d)
ordinalize :: Locale -> Text -> Text
ordinalize locale n =