GithubHelp home page GithubHelp logo

brinkqiang2cpp / ctoml Goto Github PK

View Code? Open in Web Editor NEW

This project forked from evilncrazy/ctoml

0.0 1.0 0.0 140 KB

Fast TOML parser written in C++

Home Page: https://github.com/mojombo/toml

License: MIT License

C++ 100.00%

ctoml's Introduction

Ctoml

A statically typed parser for @mojombo's TOML, written in C++11. Currently supports commit c6ea50d of the TOML spec, with a few exceptions:

  • Unicode support for strings
  • Null characters ('\0') in string literals

Usage

#include "toml.h"

#include <iostream>

using namespace ctoml;

int main() {
	TomlParser toml("example.toml");
	auto doc = toml.parse();

	// Get the value of a key
	auto val = doc.get("potatoe.cake");

	// You can print it out
	std::cout << val->to_string() << std::endl;

	// Or check equality
	if (val->equals("foobar")) {
		// ....
	}

	// To use the primitive value of a key, you can do:
	std::cout << doc.get_as<float>("pi") * 2 << std::endl;

	// We can iterate through all the keys
	for (auto it = doc.cbegin(); it != doc.cend(); ++it) {
		std::cout << it->first << " = " << it->second->to_string() << std::endl;
	}

	// We can modify the document on the fly
	doc.set("title", TomlValue::create_string("Hello world!"));

	// You can even write the document to a stream
	doc.write(std::cout);
}

Command line tool

A command line tool that parses TOML is provided (src/main.cc). It can take a file as input. If the parse is successful, it spews out every key and its value.

./ctoml "path/to/file"

Licence

This software is released under the MIT licence (see LICENCE).

Todo

  • Needs more powerful write to stream methods
    • Write only certain key groups to a stream

ctoml's People

Contributors

evilncrazy avatar

Watchers

James Cloos 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.