https://github.com/catisnotfound/ini-parser
A lightweight C++ INI file parser with basic key-value operations and array extension support.
https://github.com/catisnotfound/ini-parser
cpp exception-handling ini-parser key-value-store lightweight-library mit-license
Last synced: 8 months ago
JSON representation
A lightweight C++ INI file parser with basic key-value operations and array extension support.
- Host: GitHub
- URL: https://github.com/catisnotfound/ini-parser
- Owner: CatIsNotFound
- License: mit
- Created: 2025-03-08T12:15:04.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-20T08:21:07.000Z (about 1 year ago)
- Last Synced: 2025-10-14T19:04:38.424Z (8 months ago)
- Topics: cpp, exception-handling, ini-parser, key-value-store, lightweight-library, mit-license
- Language: C++
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# INI-Parser
[简体中文](README_CN.md)
[](https://github.com/CatIsNotFound/INI-Parser/blob/main/LICENSE)
A lightweight C++ INI file parser with basic key-value operations and array extension support.
## Features
- **Core Parsing**
✅ Read/Write/Delete sections and key-value pairs
✅ Automatic trimming of leading/trailing spaces
✅ Exception handling (file load failure, duplicate keys, etc.)
✅ UTF-8 encoding support (no auto line break conversion)
- **Extended Features (IniParserX)**
🚀 Array-type keys support (e.g., `key[] = value1`)
🚀 Experimental nested section inheritance
🚀 Array length queries and index-based access
## Quick Start
### Installation
Add `INI-Parser.h` directly to your project's header directory.
### Basic Usage
```cpp
#include "INI-Parser.h"
// Load config file
IniParser parser("config.ini");
// Read value
std::string& version = parser.value("General/version");
// Modify value
parser.value("Database/port") = "3306";
// Save changes
parser.save_ini_file();
```
### Array Operations
```cpp
#include "INI-Parser.h"
// Use extended parser
IniParserX parser_x("data.ini");
// Add an array
parser_x.add_array("Log", "files", {"app.log", "error.log", "debug.log"});
// Get array length
size_t count = parser_x.size_of_array("Log/files");
// Access array elements
std::string log_file = parser_x.value_of_array("Log", "files", 0);
```
## Exceptions
| Exception Type | Trigger Scenario |
|----------------------|-----------------------------------|
| `FileLoadedError` | File cannot be opened or lacks permissions |
| `KeyNotFound` | Accessing non-existent key/section |
| `KeyAlreadyExist` | Adding a duplicate key |
| `KeyIsArray` | Accessing an array as a regular key |
| `KeyNotArray` | Accessing a regular key as an array |
## Contribution & License
- **Repository**: [https://github.com/CatIsNotFound/INI-Parser](https://github.com/CatIsNotFound/INI-Parser)
- **License**: MIT License
- Issues and Pull Requests are welcome!
---
🐱 Maintained by [CatIsNotFound](mailto:liaoxinkai0408@outlook.com) | Last updated: March 9, 2025