module Sound.Freesound.Util (
readMaybe,
findAttr,
findChild,
findChildren,
strContent,
findString
) where
import Data.List (isPrefixOf)
import qualified Text.XML.Light as XML
findString :: String -> String -> Maybe String
findString "" xs = Just xs
findString a "" = Nothing
findString a xs
| isPrefixOf a xs = Just xs
findString a (_:xs) = findString a xs
readMaybe :: (Read a) => String -> Maybe a
readMaybe s = case reads s of
[(a, "")] -> Just a
_ -> Nothing
findAttr :: String -> XML.Element -> Maybe String
findAttr name = XML.findAttr (XML.unqual name)
findChild :: String -> XML.Element -> Maybe XML.Element
findChild name = XML.findChild (XML.unqual name)
findChildren :: String -> XML.Element -> [XML.Element]
findChildren name = XML.findChildren (XML.unqual name)
strContent :: XML.Element -> Maybe String
strContent = return . XML.strContent