24 Commits
1.0 ... 1.1

Author SHA1 Message Date
8d9d29a684 Fix comments not being serialized correctly 2025-11-14 00:57:55 +01:00
302b2b9a94 Add const array accessor 2025-02-15 01:09:15 +01:00
c304b50eb3 Fix float serialization 2025-02-11 20:03:13 +01:00
c6aa27f47b Add fstream compability 2025-02-10 02:05:06 +01:00
ceb392a198 Improve type safety in GetValueOrDefault 2025-02-07 22:27:57 +01:00
1fd3f05ebd Improve error logging 2025-02-06 05:04:38 +01:00
a518dcac54 Fixed issue where ParseValue does not return the result code 2025-02-06 04:51:20 +01:00
f465f2eb0f Improve error codes 2025-02-06 04:42:55 +01:00
87f39d93f0 Remove unnecessary nValue 2025-02-02 23:10:16 +01:00
b8f88e7586 Move ParseValue to Value base class 2025-02-02 22:55:31 +01:00
08f4df7b04 Improve error handling 2025-02-02 22:53:00 +01:00
4e54e828eb Merge branch 'master' of https://github.com/mariiaan/minipp 2025-02-02 21:47:25 +01:00
2880cfd2f3 Fix bug where escape sequences in string arrays are not parsed correctly 2025-02-02 21:47:21 +01:00
538c977f14 Update README.md 2025-02-02 20:55:11 +01:00
d7bc969b70 Update README.md 2025-02-02 20:54:38 +01:00
04dcc77db6 Update README.md 2025-02-02 20:51:45 +01:00
3f96d049e5 Update README.md 2025-02-02 05:40:57 +01:00
e3c3b76caa Add easy API 2025-02-02 05:39:08 +01:00
4ee8c32822 Change macro name + remove unnecessary assert 2025-02-02 04:39:50 +01:00
e13cc5a94e Add support for getting all sections 2025-02-01 23:29:56 +01:00
ef0f4ba908 Merge branch 'master' of https://github.com/mariiaan/minipp 2025-02-01 21:09:54 +01:00
43db485cec Fix newlines 2025-02-01 21:09:48 +01:00
46e2129787 Update README.md 2025-02-01 20:46:09 +01:00
27b720245c Fix links 2025-02-01 20:42:56 +01:00
6 changed files with 915 additions and 757 deletions

View File

@@ -1,6 +1,6 @@
# minipp # minipp
A lightweight, header-only C++14 parser and writer for the mini config format. A lightweight, header-only C++14 parser and writer for the [mini config format](https://github.com/ToyB-Chan/mini-file-format).
## Description ## Description
minipp provides a convenient way to parse and write configuration files in the "mini" format. This format is characterized by its human-readable structure and nested sections, making it ideal for application configurations. minipp provides a convenient way to parse and write configuration files in the "mini" format. This format is characterized by its human-readable structure and nested sections, making it ideal for application configurations.
@@ -15,17 +15,6 @@ minipp provides a convenient way to parse and write configuration files in the "
- **Single Header**: minipp is a single-header library, meaning you only need to include one file. - **Single Header**: minipp is a single-header library, meaning you only need to include one file.
## Usage
To use minipp in your project:
```cpp
#define MINIPP_IMPLEMENTATION
#include "minipp.hpp"
```
Then, you can use `minipp::MiniPPFile` to parse and write mini files throughout your code.
### Example Usage ### Example Usage
```cpp ```cpp
@@ -45,12 +34,16 @@ int main()
MiniPPFile::Section* gameSection = nullptr; MiniPPFile::Section* gameSection = nullptr;
result = root.GetSubSection("game", &gameSection); result = root.GetSubSection("game", &gameSection);
// "Easy" API
int64_t test = gameSection.GetValueOrDefault<MiniPPFile::Values::IntValue>("year", 1999);
// Verbose API
MiniPPFile::Values::StringValue* nameValue = nullptr; MiniPPFile::Values::StringValue* nameValue = nullptr;
result = gameSection->GetValue("name", &nameValue); result = gameSection->GetValue("name", &nameValue);
MiniPPFile::Values::IntValue* yearValue = nullptr; MiniPPFile::Values::IntValue* yearValue = nullptr;
result = gameSection->GetValue("year", &yearValue); result = gameSection->GetValue("year", &yearValue);
// Get a sub-section (section of a section (stated in the MINI file with "[game.window]") // Get a sub-section (section of a section, stated in the MINI file with "[game.window]")
MiniPPFile::Section* windowSection = nullptr; MiniPPFile::Section* windowSection = nullptr;
result = gameSection->GetSubSection("window", &windowSection); result = gameSection->GetSubSection("window", &windowSection);
@@ -58,12 +51,12 @@ int main()
// Get a sub-section by using the dot operator // Get a sub-section by using the dot operator
result = gameSection->GetSubSection("window.platform", &windowPlatformSection); result = gameSection->GetSubSection("window.platform", &windowPlatformSection);
MiniPPFile::Values::ArrayValue* pointsValue = nullptr; MiniPPFile::Values::ArrayValue* platformTargetsValue = nullptr;
// Retrieve an array by using the relative value path (the game section is a child of the root section) // Retrieve an array by using the relative value path (the game section is a child of the root section)
result = root.GetValue("game.window.platform.targets", &pointsValue); result = root.GetValue("game.window.platform.targets", &platformTargetsValue);
// Modify the "targets" array by adding a new value // Modify the "targets" array by adding a new value
pointsValue->GetValues().push_back(std::make_unique<MiniPPFile::Values::StringValue>("haiku")); platformTargetsValue->GetValue().push_back(std::make_unique<MiniPPFile::Values::StringValue>("haiku"));
// Serialize the config // Serialize the config
result = file.Write("test_out.mini"); result = file.Write("test_out.mini");
@@ -100,8 +93,11 @@ int main()
MiniPPFile::Values::StringValue* nameValue = nullptr; MiniPPFile::Values::StringValue* nameValue = nullptr;
result = gameSection->GetValue("name", &nameValue); result = gameSection->GetValue("name", &nameValue);
// Navigate nested sections // .. OR ..
std::string nameValue = gameSection->GetValueOrDefault<MiniPPFile::Values::StringValue>("name", "Unknown");
// Navigate nested sections
MiniPPFile::Section* windowSection = nullptr; MiniPPFile::Section* windowSection = nullptr;
result = gameSection->GetSubSection("window", &windowSection); result = gameSection->GetSubSection("window", &windowSection);
@@ -121,7 +117,7 @@ int main()
result = root.GetValue("game.window.platform.points", &pointsValue); result = root.GetValue("game.window.platform.points", &pointsValue);
// Modify the array values (or read them) // Modify the array values (or read them)
pointsValue->GetValues().push_back(std::make_unique<MiniPPFile::Values::StringValue>("haiku")); pointsValue->GetValue().push_back(std::make_unique<MiniPPFile::Values::StringValue>("haiku"));
``` ```
5. **Write new files**: 5. **Write new files**:
@@ -132,11 +128,11 @@ int main()
## Example ## Example
An example mini file is contained in this [repository](test.mini). The full mini file format specilization can be found [here](https://github.com/ToyB-Chan/mini-file-format). An example mini file is contained in this [repository](minipp/test.mini). The full mini file format specification can be found [here](https://github.com/ToyB-Chan/mini-file-format).
## Installation ## Installation
1. Copy the contents of "minipp.hpp" to a new file in your project. 1. Copy the contents of [minipp.hpp](minipp/minipp.hpp) to a new file in your project.
2. #Include "minipp.hpp" after defining MINIPP_IMPLEMENTATION in one single cpp file. 2. #Include "minipp.hpp" after defining MINIPP_IMPLEMENTATION in one single cpp file.
3. #Include "minipp.hpp" in any other desired files without the IMPLEMENTATION define! 3. #Include "minipp.hpp" in any other desired files without the IMPLEMENTATION define!

File diff suppressed because it is too large Load Diff

2
minipp/simple.mini Normal file
View File

@@ -0,0 +1,2 @@
[game]
what=["test\t\\yeah", "hai"]

View File

@@ -10,7 +10,7 @@ int main()
MiniPPFile file; MiniPPFile file;
result = file.Parse("test.mini"); result = file.Parse("test.mini");
auto& root = file.GetRoot(); auto& root = file.GetRoot();
MiniPPFile::Section* gameSection = nullptr; MiniPPFile::Section* gameSection = nullptr;
result = root.GetSubSection("game", &gameSection); result = root.GetSubSection("game", &gameSection);
@@ -42,5 +42,6 @@ int main()
result = file.Write("test_out.mini"); result = file.Write("test_out.mini");
int64_t test = root.GetValueOrDefault<MiniPPFile::Values::IntValue>("game.year", 1999);
return 0; return 0;
} }

View File

@@ -1,10 +1,13 @@
[game] [game]
name = "Test Game" name = "Test Game\nNext Line"
version = "1.0.0" version = "1.0.0"
year = 2025 year = 2025
completionPercentage = 50.0f completionPercentage = 50.0f
# Should only be true if completionPercentage is 100 # Should only be true if completionPercentage is 100
is_completed = false is_completed = false
testargs = ["this is a \\\"test\"", "this is\n the next line"]
testTestArg = [["yeah", "new\nline"], ["hallo\ttest\n\\\\"]]
testEmpty = []
# This section is about # This section is about
# the settings of a game window # the settings of a game window

View File

@@ -1,7 +1,10 @@
[game] [game]
name = "Test Game" testEmpty = []
name = "Test Game\nNext Line"
testTestArg = [["yeah", "new\nline"], ["hallo\ttest\n\\\\"]]
completionPercentage = 50.000000 completionPercentage = 50.000000
version = "1.0.0" version = "1.0.0"
testargs = ["this is a \\\"test\"", "this is\n the next line"]
year = 2025 year = 2025
# Should only be true if completionPercentage is 100 # Should only be true if completionPercentage is 100
is_completed = false is_completed = false