Restructure into umbrella modules (~55 -> 16 targets)
Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
da2e93c405
commit
28b94883fd
156 files changed
+278
-220
No files matched your search
@@ -0,0 +1,163 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Void::Ini
|
||||
{
|
||||
|
||||
// ── IniFile ───────────────────────────────────────────────────────────────────
|
||||
// Parses .ini / .cfg files with sections ([section]) and key=value pairs.
|
||||
// Comments start with ';' or '#'. Inline comments are NOT stripped.
|
||||
// Values may be quoted ("hello world") — quotes are stripped.
|
||||
|
||||
class IniFile
|
||||
{
|
||||
public:
|
||||
using Section = std::unordered_map<std::string, std::string>;
|
||||
|
||||
struct ParseError
|
||||
{
|
||||
std::size_t line;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
// Parse from a string. Returns error on malformed input.
|
||||
[[nodiscard]] static std::optional<ParseError>
|
||||
parse(IniFile& out, std::string_view text)
|
||||
{
|
||||
out.data_.clear();
|
||||
std::string current_section;
|
||||
std::size_t lineno = 0;
|
||||
|
||||
auto sv_trim = [](std::string_view s) {
|
||||
while (!s.empty() && (s.front() == ' ' || s.front() == '\t')) s.remove_prefix(1);
|
||||
while (!s.empty() && (s.back() == ' ' || s.back() == '\t' ||
|
||||
s.back() == '\r')) s.remove_suffix(1);
|
||||
return s;
|
||||
};
|
||||
|
||||
std::string_view remaining = text;
|
||||
while (!remaining.empty()) {
|
||||
++lineno;
|
||||
const auto nl = remaining.find('\n');
|
||||
std::string_view line = sv_trim(
|
||||
nl == std::string_view::npos ? remaining
|
||||
: remaining.substr(0, nl));
|
||||
remaining = nl == std::string_view::npos
|
||||
? std::string_view{}
|
||||
: remaining.substr(nl + 1);
|
||||
|
||||
if (line.empty() || line[0] == ';' || line[0] == '#') continue;
|
||||
|
||||
if (line[0] == '[') {
|
||||
const auto close = line.find(']');
|
||||
if (close == std::string_view::npos) {
|
||||
return ParseError{lineno, "unclosed '['"};
|
||||
}
|
||||
current_section = std::string{line.substr(1, close - 1)};
|
||||
out.data_[current_section]; // ensure section exists
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto eq = line.find('=');
|
||||
if (eq == std::string_view::npos) {
|
||||
if (!line.empty()) {
|
||||
return ParseError{lineno, std::string{"expected '=' in: "} + std::string{line}};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string key{sv_trim(line.substr(0, eq))};
|
||||
std::string_view val_sv = sv_trim(line.substr(eq + 1));
|
||||
|
||||
// Strip optional quotes
|
||||
std::string val;
|
||||
if (val_sv.size() >= 2 && val_sv.front() == '"' && val_sv.back() == '"') {
|
||||
val = std::string{val_sv.substr(1, val_sv.size() - 2)};
|
||||
} else {
|
||||
val = std::string{val_sv};
|
||||
}
|
||||
|
||||
out.data_[current_section][std::move(key)] = std::move(val);
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
[[nodiscard]] static IniFile from_string(std::string_view text)
|
||||
{
|
||||
IniFile f;
|
||||
parse(f, text);
|
||||
return f;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<std::string>
|
||||
get(std::string_view section, std::string_view key) const
|
||||
{
|
||||
auto sec_it = data_.find(std::string{section});
|
||||
if (sec_it == data_.end()) return std::nullopt;
|
||||
auto key_it = sec_it->second.find(std::string{key});
|
||||
if (key_it == sec_it->second.end()) return std::nullopt;
|
||||
return key_it->second;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string
|
||||
get_or(std::string_view section, std::string_view key,
|
||||
std::string_view fallback) const
|
||||
{
|
||||
return get(section, key).value_or(std::string{fallback});
|
||||
}
|
||||
|
||||
void set(std::string_view section, std::string_view key, std::string value)
|
||||
{
|
||||
data_[std::string{section}][std::string{key}] = std::move(value);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool has_section(std::string_view section) const
|
||||
{
|
||||
return data_.contains(std::string{section});
|
||||
}
|
||||
|
||||
[[nodiscard]] bool has_key(std::string_view section,
|
||||
std::string_view key) const
|
||||
{
|
||||
return get(section, key).has_value();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<std::string> sections() const
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
result.reserve(data_.size());
|
||||
for (const auto& [k, _] : data_) result.push_back(k);
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] const Section* section(std::string_view name) const
|
||||
{
|
||||
auto it = data_.find(std::string{name});
|
||||
return it == data_.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
// Serialize back to INI text.
|
||||
[[nodiscard]] std::string serialize() const
|
||||
{
|
||||
std::string out;
|
||||
for (const auto& [sec, kv] : data_) {
|
||||
out += '['; out += sec; out += "]\n";
|
||||
for (const auto& [k, v] : kv) {
|
||||
out += k; out += " = "; out += v; out += '\n';
|
||||
}
|
||||
out += '\n';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, Section> data_;
|
||||
};
|
||||
|
||||
} // namespace Void::Ini
|
||||
Reference in new issue
Block a user