module Text.BibTeX.Entry where

import Data.Char (toLower, )
import Data.Tuple.HT (mapFst, )


data T =
   Cons {
      T -> String
entryType :: String,
      T -> String
identifier :: String,
      T -> [(String, String)]
fields :: [(String, String)]
   }
   deriving (Int -> T -> ShowS
[T] -> ShowS
T -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [T] -> ShowS
$cshowList :: [T] -> ShowS
show :: T -> String
$cshow :: T -> String
showsPrec :: Int -> T -> ShowS
$cshowsPrec :: Int -> T -> ShowS
Show)

{- |
Convert the name style \"Surname, First name\" into \"First name Surname\".
-}
flipName :: String -> String
flipName :: ShowS
flipName String
name =
   let (String
surname, String
firstName) = forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char
','forall a. Eq a => a -> a -> Bool
==) String
name
   in  forall a. (a -> Bool) -> [a] -> [a]
dropWhile (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem String
", ") String
firstName forall a. [a] -> [a] -> [a]
++ String
" " forall a. [a] -> [a] -> [a]
++ String
surname

lowerCaseFieldNames :: T -> T
lowerCaseFieldNames :: T -> T
lowerCaseFieldNames T
entry =
   T
entry {fields :: [(String, String)]
fields = forall a b. (a -> b) -> [a] -> [b]
map (forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst (forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower)) forall a b. (a -> b) -> a -> b
$ T -> [(String, String)]
fields T
entry}