https://github.com/brglng/libtoml
Very tiny TOML parser in C
https://github.com/brglng/libtoml
c parse toml
Last synced: 3 months ago
JSON representation
Very tiny TOML parser in C
- Host: GitHub
- URL: https://github.com/brglng/libtoml
- Owner: brglng
- License: apache-2.0
- Created: 2017-11-23T08:07:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-11-17T07:54:32.000Z (over 1 year ago)
- Last Synced: 2025-07-09T01:45:31.149Z (12 months ago)
- Topics: c, parse, toml
- Language: C
- Homepage:
- Size: 103 KB
- Stars: 23
- Watchers: 5
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# libtoml
Very tiny [TOML](https://github.com/toml-lang/toml) parser and encoder in C.
# Build and Install
To build this library, compiler with C99 support is required.
On Linux and macOS:
mkdir build
cd build
cmake ..
make
sudo make install
On Windows:
mkdir build
cd build
cmake ..
cmake --build .
## CMake Support
Use `FetchContent`:
include(FetchContent)
FetchContent_Declare(libtoml
GIT_REPOSITORY "https://github.com/brglng/libtoml.git"
GIT_SHALLOW ON
)
FetchContent_MakeAvailable(libtoml)
add_executable(yourprogram yourprogram.c)
target_link_libraries(yourprogram toml::toml)
Use `add_subdirectory`:
add_subdirectory(libtoml)
add_executable(yourprogram yourprogram.c)
target_link_libraries(yourprogram toml::toml)
Use `find_package`:
find_package(toml)
add_executable(yourprogram yourprogram.c)
target_link_libraries(yourprogram toml::toml)
# Usage
Load from a file using a filename:
```c
TomlTable *table = toml_load_filename("path/to/my/file.toml");
if (toml_err()->code == TOML_OK) {
TomlTableIter it = toml_table_iter_new(table);
while (toml_table_iter_has_next(&it)) {
TomlKeyValue *keyval = toml_table_iter_get(&it);
/* do something */
toml_table_iter_next(&it);
}
toml_table_free(table);
} else {
fprintf(stderr, "toml: %d: %s\n", toml_err()->code, toml_err()->message);
/*
* If error occurred, toml_clear_err() must be called before the next call
* which can produce an error, or there can be an assertion failure.
*/
toml_err_clear();
}
```
# TODO
- [ ] Update to TOML v1.0 spec
- [ ] Array invariance checking
- [ ] Date-time support
- [ ] Support parsing while reading
- [ ] Travis CI support
- [ ] Encoding
- [ ] Encoding to JSON
- [ ] Documentation