我需要解析iCalendar格式,这基本上就是Google和几乎所有日历应用程序所使用的格式。
我找到了这个包裹iCalendar黑客
但是我不知道如何在这个包中使用parseICalendar函数,如果有人能告诉我我做错了什么,那就太好了。
主要是我不知道如何构造DecodingFunctions类型的参数
parseICalendar :: DecodingFunctions
-> FilePath -- ^ Used in error messages.
-> ByteString
-> Either String ([VCalendar], [String])我的努力:
module CalendarReader
( getCalendar
, getSummary
) where
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Lazy as B -- package "bytestring"
import qualified Text.ICalendar as ICal -- package "iCalendar"
import qualified Data.Map as Map -- package "containers"
import Network.HTTP.Simple -- package "http-conduit"
import qualified Time -- local module
import Constants
getCalendar :: IO B.ByteString
getCalendar = do
request <- parseRequest $ "GET" ++ calendarURL
response <- httpLBS request
return $ getResponseBody response
getSummary :: B.ByteString -> Time.DateTime -> Int -> String
getSummary cal dateTime dayOffset = summary
where
summary = "Event Summary"
((ICal.VCalendar { ICal.vcEvents = vcEvents' }), _) = ICal.parseICalendar ?missingArgument? logFile cal发布于 2017-05-12 10:56:34
DecodingFunctions应该包含一个函数,用于将您的ByteString (二进制数组)转换为Text (表示字符串的unicode字符),并对不区分大小写的表示进行同样的转换(我想是为了比较的目的)。如果您的iCalendar是“普通”的,并且是以utf-8编码的,您可以简单地使用DecodingFunctions的Default实例:
parseICalendar def logFile cal(别忘了从某个地方导入def )
如果您的iCalendar不在Utf-8中,则必须使用来自Data.Text.Lazy.Encoding的decode...函数和来自Data.CaseInsensitive的mk。对于Utf16,您应该有:
decodings = DecodingFunctions decodeUtf16LE (mk . decodeUtf16LE)用正确的进口。
https://stackoverflow.com/questions/43931811
复制相似问题