Copyright | (c) 2016 Al Zohali |
---|---|
License | BSD3 |
Maintainer | Al Zohali <zohl@fmap.me> |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
Description
Common functions and types for StarDict dictionaries.
- data StarDictException
- checkFiles :: IfoFilePath -> [FilePath] -> IO (Maybe FilePath)
- checkGZFiles :: IfoFilePath -> [FilePath] -> [FilePath] -> IO (Maybe (Either FilePath FilePath))
- data IfoFile = IfoFile {
- ifoMagicData :: ByteString
- ifoVersion :: String
- ifoBookName :: Text
- ifoWordCount :: Int
- ifoIdxFileSize :: Int
- ifoIdxOffsetBits :: Maybe Int
- ifoSynWordCount :: Maybe Int
- ifoAuthor :: Maybe Text
- ifoEmail :: Maybe Text
- ifoWebsite :: Maybe Text
- ifoDescription :: Maybe Text
- ifoDate :: Maybe UTCTime
- ifoSameTypeSequence :: Maybe String
- ifoDictType :: Maybe String
- type IfoFilePath = FilePath
- ifoDateFormat :: String
- readIfoFile :: (MonadThrow m, MonadIO m) => FilePath -> m IfoFile
- renderIfoFile :: IfoFile -> Text
- type IndexEntry = (Text, (Int, Int))
- readIndexFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> Get Int -> m [IndexEntry]
- renderIndexFile :: [IndexEntry] -> (Int -> Builder) -> ByteString
- getIndexNumber :: Maybe Int -> Get Int
- putIndexNumber :: Maybe Int -> Int -> Builder
- checkDataFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> m FilePath
- data DataEntry
- type Renderer = DataEntry -> Text
- mkDataParser :: Maybe String -> Get [DataEntry]
- class Dictionary d => StarDict d where
Documentation
data StarDictException Source #
Exceptions that are thrown when something with this module went wrong.
WrongIfoFormat FilePath String | Thrown when information file (.ifo) has unsupported format. |
IndexNotFound FilePath | Thrown when index file (.idx, .idx.gz) is not found. |
WrongIndexFormat FilePath String | Thrown when index file has unsupported format. |
DictionaryNotFound FilePath | Thrown when dictionary file (.dict, .dict.dz) has unsupported format. |
checkFiles :: IfoFilePath -> [FilePath] -> IO (Maybe FilePath) Source #
Given .ifo file name and list of extensions, returns first existing file with the same basename.
checkGZFiles :: IfoFilePath -> [FilePath] -> [FilePath] -> IO (Maybe (Either FilePath FilePath)) Source #
Given .ifo file name and two lists of extensions, returns first existing file with with the same basename and extension from the first list or (if such file doesn't exists) from the second list.
Representation of .ifo file.
IfoFile | |
|
type IfoFilePath = FilePath Source #
Type synonym to distinguish usage of paths.
ifoDateFormat :: String Source #
Date format of ifoDate
in IfoFile.
readIfoFile :: (MonadThrow m, MonadIO m) => FilePath -> m IfoFile Source #
Read .ifo file at the given path.
readIndexFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> Get Int -> m [IndexEntry] Source #
Read .idx (.idx.gz) file.
renderIndexFile :: [IndexEntry] -> (Int -> Builder) -> ByteString Source #
Generates .idx file contents based on Index
.
getIndexNumber :: Maybe Int -> Get Int Source #
Get 32-bit or 64-bit integer depending on description in the .ifo file.
putIndexNumber :: Maybe Int -> Int -> Builder Source #
Put 32-bit or 64-bit integer depending on description in the .ifo file.
checkDataFile :: (MonadThrow m, MonadIO m) => IfoFilePath -> m FilePath Source #
Returns path of decompressed dictionary.
Possible dictionary entry formats.
type Renderer = DataEntry -> Text Source #
Type of function to transform dictionary entries to a text.
mkDataParser :: Maybe String -> Get [DataEntry] Source #
Returns parser based on description in .ifo file.
class Dictionary d => StarDict d where Source #
Classtype for stardict dictionaries.
getIfoFile :: d -> IfoFile Source #
mkDictionary :: (MonadThrow m, MonadIO m) => Tagged d IfoFilePath -> Renderer -> m d Source #