Code Monkey home page Code Monkey logo

inih's Introduction

inih

Build Status

This is a header only C++ version of inih.

inih (INI Not Invented Here) is a simple .INI file parser written in C. It's only a couple of pages of code, and it was designed to be small and simple, so it's good for embedded systems. It's also more or less compatible with Python's ConfigParser style of .INI files, including RFC 822-style multi-line syntax and name: value entries.

Usage

All you need to do is to include INIReader.h. Consider the following example (INIReaderTest.cpp):

#include <iostream>
#include "INIReader.h"

int main() {

    INIReader reader("test.ini");

    if (reader.ParseError() != 0) {
        std::cout << "Can't load 'test.ini'\n";
        return 1;
    }
    std::cout << "Config loaded from 'test.ini': version="
              << reader.GetInteger("protocol", "version", -1) << ", name="
              << reader.Get("user", "name", "UNKNOWN") << ", email="
              << reader.Get("user", "email", "UNKNOWN") << ", pi="
              << reader.GetReal("user", "pi", -1) << ", active="
              << reader.GetBoolean("user", "active", true) << "\n";
    return 0;

}

To compile and run:

g++ INIReaderTest.cpp -o INIReaderTest.out
./INIReaderTest.out
# Config loaded from 'test.ini': version=6, name=Bob Smith, [email protected], pi=3.14159, active=1

inih's People

Contributors

admiralakber avatar ajshephard avatar arcan1s avatar benhoyt avatar cosmy1 avatar jtilly avatar kuznetsss avatar liamkarlmitchell avatar misson20000 avatar nabijaczleweli avatar nicolasaunai avatar silviucpp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

inih's Issues

Mark the getter functions as const.

The current version of inih has marked the GetX() methods as const, and they should be updated here as well. Since they don't modify any state of the class, this should be a fairly simple fix.

How implementing custom or string-based I/O

    /* Same as ini_parse(), but takes an ini_reader function pointer instead of
   filename. Used for implementing custom or string-based I/O. */
    int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
                         void *user);

How I use ini_parse_stream , implementing custom or string-based I/O

Quoting values containing '/' leads to misinterpretation, missing quotation support

Take this .ini file as reference:

[database-mysql]
hostA = "tcp://127.0.0.1:3306"
hostB = tcp://127.0.0.1:3306

When trying to retrieve hostA, it will evaluate to "tcp while hostB evaluates correctly.
As shown in INI file, quoting of values should be perfectly fine. The closing " is missing too.

By looking at the code, it seems to me that quoting wasn't considered at all. Is this on purpose?

Passing objects by referrence instead by value.

Hello,

I see all over the places that objects are passed by value instead by reference:

INIReader(std::string filename);

You probably know that it is a bad idea to pass objects by value due to its performance impact.

Correct is:

INIReader(const std::string& filename);

C4996 Warnings Are Not Suppressed

Hi, there are C4996 warnings when I try to compile my code with #include "INIReader.h" in multiple files. I didn't add _CRT_SECURE_NO_WARNINGS for my project but it should be fine as INIReader.h attempts to suppress this particular warning for its codes using codes below.

#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif

Is there anything missing in code or I need to define _CRT_SECURE_NO_WARNINGS explicitly?


Information about the IDE I am using:

  • IDE: Visual Studio 2017
  • Windows SDK Version: 10.0.17134.0
  • Platform Toolset: Visual Studio 2017 (v141)

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.