hxIni

hxIni is a fast, light and simple library to read and write INI files, using hashes.


Keywords
cpp, flash, ini, js, neko, haxe, lib, library, openfl
License
QPL-1.0
Install
haxelib install hxIni 1.0.1

Documentation

MIT License Haxelib Version CircleCI

hxIni

Introduction

hxIni is a fast, light and simple library to read and write INI files, using hashes.

Checkout wikipedia for more information about INI Files.

Install

Use haxelib to install the release version of the library (if avaliable):

> haxelib install hxIni

Otherwise, you can download this repository as a zip from GitHub (you can try this link), and use the local installer from haxelib:

> haxelib local hxIni-master.zip

Also, don't forget to add

<haxelib name="hxIni" />

to your xml project file, or, for a standard Haxe project, add

-l hxini

in your hxml build file.

Usage

Let's explain this with an example. Imagine you have this example.ini file:

; - example.ini
; last modified 1 April 2001 by John Doe
[owner]
name=John Doe
organization=Acme Widgets Inc.

[database]
; use IP address in case network name resolution is not working
server=192.0.2.62
port=143
file="payroll.dat"

There we have two sections (owner and database), and each one has its own parameters ([name, organization] and [server, port, file]).

Now, to parse this with hxIni, we must create an Ini object with IniManager class:

var ini: Ini = IniManager.loadFromFile("example.ini");

Or, if you have that stored in a String, you can use:

var ini: Ini = IniManager.loadFromString(str_data);

And, the access to parameters it's pretty simple. Imagine a map of maps, so a section if linked to a map of parameters, and you can access like this:

var name = ini["owner"]["name"];

Finally, you can transform them to a string (after modifications), or save it to a file:

IniManager.writeToFile(ini, "test.ini");
trace( IniManager.toString(ini) );

Also, don't forget to import the classes!

import hxIni.IniManager;
import hxIni.IniManager.Ini;

Parse rules

  1. Comments (lines starting with ;) and white lines will be ignored.
  2. Every parameter must belong to at least one section.
  3. If a parameter with an used name is found on the same section, it will be replaced.
  4. If no section is declared, the Global section will be used by default (IniManager.GLOBAL_SECTION).
  5. UTF-8 is usable, but not recommend.
  6. You can use Escaped characters.
  7. Parameters keys and values are case sensitive.

Development

Clone the repository:

$ git clone https://github.com/wikiti/hxini

Then, setup the development directory:

$ haxelib dev hxini hxini

To run tests use munit:

$ haxelib install munit
$ haxelib run munit test

Contributors

The following people have helped to develop this library:

Avatar Name Nickname Contact
Daniel Herzog Wikiti wikiti.doghound@gmail.com
Thomas ten Cate ttencate GitHub Profile

Links