| Safe Haskell | None |
|---|
Data.Ini
Description
Clean configuration files in the INI format.
Format rules and recommendations:
- The
:syntax is space-sensitive. - Keys are case-sensitive.
- Lower-case is recommended.
- Values can be empty.
- Keys cannot key separators, section delimiters, or comment markers.
- Comments must start at the beginning of the line and start with
;or#.
An example configuration file:
# Some comment. [SERVER] port=6667 hostname=localhost ; another comment here [AUTH] user: hello pass: world salt:
Parsing example:
>>>parseIni "[SERVER]\nport: 6667\nhostname: localhost"Right (Ini {unIni = fromList [("SERVER",fromList [("hostname","localhost"),("port","6667")])]})
- readIniFile :: FilePath -> IO (Either String Ini)
- parseIni :: Text -> Either String Ini
- lookupValue :: Ini -> Text -> Text -> Either String Text
- readValue :: Ini -> Text -> Text -> (Text -> Either String (a, Text)) -> Either String a
- writeIniFile :: FilePath -> Ini -> IO ()
- printIni :: Ini -> Text
- newtype Ini = Ini {}
- iniParser :: Parser Ini
- sectionParser :: Parser (Text, HashMap Text Text)
- keyValueParser :: Parser (Text, Text)
Reading
readValue :: Ini -> Text -> Text -> (Text -> Either String (a, Text)) -> Either String aSource
Read a value using a reader from Data.Text.Read.
Writing
writeIniFile :: FilePath -> Ini -> IO ()Source
Print the INI config to a file.
Types
An INI configuration.
Parsers
sectionParser :: Parser (Text, HashMap Text Text)Source
A section. Format: [foo]. Conventionally, [FOO].
keyValueParser :: Parser (Text, Text)Source
A key-value pair. Either foo: bar or foo=bar.