Coder Social home page Coder Social logo

adm244 / ini-parser Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 10 KB

Basic INI-like file parser with no dynamic heap memory allocations that supports integer, float, boolean, string and wide-string types.

License: The Unlicense

C 83.91% C++ 10.46% Batchfile 5.63%

ini-parser's Introduction

Simple INI file parser

Basic INI-like file parser with no dynamic memory allocations that supports integer, float, boolean, string and wide-string types.

Example

global_key = 0

; this is a line comment
[Main Section]

key1 = 16
key2 = -123
key3 = +1 ; comments in values are also valid
key4 = 0.03
key5 = true
key6 = false

[Strings]
key1 = "some c-string"
key2 = L"some wide string (converted to utf16)"

Notes

  • No dynamic memory allocations
  • Uses two arenas to store parsed data
  • Uses WinAPI for file reads and utf8-to-utf16 conversion
  • CR (carrige return) characters are replaces with SPACE (' ')
  • Blank lines are ignored
  • Empty (global) section is supported
  • Section name is considered to be a string enclosed in DOUBLE_QUOTE ('"')
  • Key is one word only
  • Value can be INT, FLOAT, BOOL, STRING (char *) or WSTRING (wchar_t *)
  • WSTRING is assumed to be in UTF-8 encoding
  • Hexadecimal\octal\binary format of INT is NOT supported
  • Escaped characters (\t, \n, \x, etc.) are NOT supported

Usage

  #define INI_STORAGE_SIZE 1024
  internal char ini_storage[INI_STORAGE_SIZE];
  
  int main(int argc, char *argv[])
  {
    ini_init("..\\data\\test.ini", ini_storage, INI_STORAGE_SIZE);
    bool parse_result = ini_parse();
    if (!parse_result) {
      printf("Can't read file or some lines couldn't be parsed and were skipped!");
    }
    
    int int_value = ini_read_int("section", "key", 0);
    float float_value = ini_read_float("section", "key", 0.0f);
    bool bool_value = ini_read_bool(0, "globalkey", false);
    char *str_value = ini_read_string("section", "key", "default");
    wchar_t *wstr_value = ini_read_wstring("section", "key", L"default");
  }

License

Public domain

ini-parser's People

Contributors

adm244 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.