From 8018179b3df34cd7fdbd77c7a08b21fd8d5b5b31 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 27 Sep 2021 16:43:13 -0700 Subject: Better implementation of splitStrWhen --- src/Text/Pandoc/Citeproc/BibTeX.hs | 19 +++++++------------ 1 file 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 = -- cgit v1.2.3