Coder Social home page Coder Social logo

inipp's Introduction

IniPP

Simple header-only C++ ini parser and generator.

Build Status Build status

Features

  • Header-only.
  • Both parsing and generating.
  • Wide character support for native unicode on Windows.
  • Default section support (similar to Python's ConfigParser).
  • Interpolation support (i.e. variable substitution, similar to Python's ConfigParser).
  • Simple design and implementation.
  • Permissive MIT license.

Example

#include <fstream>
#include "inipp.h"

int main() {
	inipp::Ini<char> ini;
	std::ifstream is("example.ini");
	ini.parse(is);
	std::cout << "raw ini file:" << std::endl;
	ini.generate(std::cout);
	ini.default_section(ini.sections["DEFAULT"]);
	ini.interpolate();
	std::cout << "ini file after default section and interpolation:" << std::endl;
	ini.generate(std::cout);
	int compression_level = -1;
	inipp::extract(ini.sections["bitbucket.org"]["CompressionLevel"], compression_level);
	std::cout << "bitbucket.org compression level: " << compression_level << std::endl;
	return 0;
}

Parsing algorithm

  • The section is set to the empty string.

  • Every line is read from the file and trimmed from whitespace.

    • If line is empty or starts with ; then nothing happens.

    • Otherwise, if line starts with [ then section is changed to the string between [ and ]. If line does not end with ] then an error is reported.

    • Otherwise, if line contains an = sign, then all characters before = are treated as variable and all characters following = are treated as value. Both are trimmed. If the variable was already assigned earlier, an error is reported. Otherwise, the corresponding assigment is added to the section.

    • Otherwise, the line is reported as an error.

Default section algorithm

Insert every variable from the default section into every other section, without overwriting existing variables.

Interpolation algorithm

  1. Locally within each section, every occurrence "${variable}" is replaced by "${section:variable}".
  2. Every occurrence of "${section:variable}" is replaced by its value.
  3. The previous step is repeated until no more replacements are possible, or until the recursion depth (by default, 10) is reached.

inipp's People

Contributors

mcmtroffaes avatar

Watchers

 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.