rookfighter / inifile-cpp Goto Github PK
View Code? Open in Web Editor NEWA header-only and easy to use Ini file parser for C++.
License: MIT License
A header-only and easy to use Ini file parser for C++.
License: MIT License
Allow ini files without sections, e.g.
foo=bar
hello=world
Add a script that installs dependencies locally.
How to disable ALPHABET sorting in output file?
It always broke my file structure...
For example...
[General]
NUM_AITEMS = 5
AITEMS_ENABLED = false
[AITEM1]
DATA = X
After save it make fully unreadabled:
[AITEM1]
DATA = X
[General]
AITEMS_ENABLED = false
NUM_AITEMS = 5
Add type uint and float for Ini fields.
Вы можете использовать такой код (inicpp.h:234)?
void decode(const std::string &value, double &result) {
std::stringstream stream;
stream << value;
stream >> result;
}
I think that INI files with duplicated sections are confusing and error prone. For example:
[Foo]
var1 = hi
[Bar]
var2 = 12
[Foo]
var3 = 14
[Foo] will end up having both variables var1 and var3.
It is easy to spot this duplication in such a small example, but with bigger INI files this can be problematic.
I've made the pull request #14 to make the code throw an exception in this case.
I have a ini file:
[/home/xxx/.gnupg/]
Acls=user::rwx;group::---;other::---
[/home/xxx/.gnupg/.#lkxxx.29271]
Acls=user::rw-;group::r--;other::r--
[/home/xxx/.gnupg/openpgp-revocs.d/xxx.rev]
Acls=user::rw-;group::---;other::---
[/home/xxx/.gnupg/private-keys-v1.d/xxx.key]
Acls=user::rw-;group::---;other::---
[/home/xxx/.gnupg/private-keys-v1.d/xxx.key]
Acls=user::rw-;group::---;other::---
[/home/xxx/.gnupg/pubring.kbx]
Acls=user::rw-;group::r--;other::r--
[/home/xxx/.gnupg/pubring.kbx~]
Acls=user::rw-;group::---;other::---
[/home/xxx/.gnupg/trustdb.gpg]
Acls=user::rw-;group::---;other::---
[/home/xxx/.ssh]
Acls=user::rwx;group::r--;other::r--
[/home/xxx/.ssh/id_rsa]
Acls=user::rw-;group::---;other::---
[/home/xxx/.ssh/id_rsa.pem]
Acls=user::rw-;group::r--;other::r--
[/home/xxx/.ssh/id_rsa.pub]
Acls=user::rw-;group::r--;other::r--
[/home/xxx/.ssh/known_hosts]
Acls=user::rw-;group::---;other::---
[/home/xxx/.ssh/known_hosts.old]
Acls=user::rw-;group::r--;other::r--
[Defaults]
Excludes=
Includes=/home/xxx/.ssh;/home/xxx/.gnupg/;
SaveAcls=true
Then I get a error when I rerun my programe:
erminate called after throwing an instance of 'std::logic_error'
what(): l4: ini parsing failed, section not closed
But I can't find any error about this ini file :(
Add the option to change the file separator '='.
Hi, @Rookfighter. thank you for a great tool.
I'm trying to read an example.ini. And if the group-key-pair not exist in the ini-file, it returns ""
that by converting to int
gives 0
and by converting to bool
gives false
. It is in my opinion an unexpected behavior.
example.ini
[Group_1]
key_1 = 1;
main.cpp
#include <iostream>
#include "inicpp.h"
int main() {
ini::IniFile inifile;
inifile.load("example.ini");
int val_1 = inifile["Group_1"]["key_1"].as<int>();
int val_2 = inifile["Group_1"]["key_2"].as<int>();
std::cout << "value 1 = " << val_1 << std::endl;
std::cout << "value 2 = " << val_2 << std::endl;
return 0;
}
Output:
value 1 = 1
value 2 = 0
My workaround for now is
#include <iostream>
#include <stdexcept>
#include "inicpp.h"
int readInt(ini::IniFile &inifile, const std::string &group, const std::string &key) {
if (inifile[group][key].as<std::string>() == "")
throw std::runtime_error(key + " is not found in " + group + "\n");
else
return inifile[group][key].as<int>();
}
int main() {
ini::IniFile inifile;
inifile.load("example.ini");
try
{
int val_1 = readInt(inifile, "Group_1", "key_1");
std::cout << "value 1 = " << val_1 << std::endl;
} catch (...)
{
std::cout << "key_1 is not found in Group_1" << std::endl;
inifile.clear();
return 1;
}
try
{
int val_2 = readInt(inifile, "Group_1", "key_2");
std::cout << "value 2 = " << val_2 << std::endl;
} catch (...)
{
std::cout << "key_2 is not found in Group_1" << std::endl;
inifile.clear();
return 1;
}
return 0;
}
Most implementations consider the semicolor ";" as the start of a comment
I believe this #22 should be enough?
Add option to change the char for comments.
Hello, my library figcone
depends on inifile-cpp
, which is downloaded during CMake configuration using FetchContent. As inifile-cpp
doesn't provide any version tags, I specified the master branch to download it. Recently (?) the master branch was removed, and it rendered all versions of figcone
broken unless the user disables the support of the ini
format. By default, all config formats are supported, so the build is failing during configuration while trying to download inifile-cpp
.
It will teach me to only use forked repositories for projects that don't have any versioning, but can you please restore the master branch to fix all previous releases of my library? I'm not asking to make it the main branch again, just to create it in the repo. There were no incompatible changes, so it can be set on the latest commit.
Add static default fields to IniFile class
Many INI files are edited directly by end users, and some of them want to use spaces to make the contents easy to read.
For example:
[SECT1]
#This comment is indented, as is the following lines, which are also aligned
John = 1
Evelyn = 2
Lucas = 3
I've made the pull request #11 to implement that.
Change structure to be header only
Add helper functions
@Rookfighter Thank you for this useful library.
I noticed that after updating the values and calling save
option, all the comments and empty lines in the ini file gets removed.
Since most of these files are edited manually by users, retaining comments and white spaces are essential while saving.
# Send a message to the world
[world]
message=Hello
# Just foo :)
[foo]
f1=123
#include <inicpp.h>
int main()
{
ini::IniFile myIni;
myIni.load("some/ini/path");
myIni["world"]["message"] = "Hello world";
myIni.save("some/ini/path");
}
[world]
message=Hello world
[foo]
f1=123
Do let me know if there is already an option to avoid them being removed.
Program crashes if invalid input found.
Need "bypass errors" option :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.