NAH 1.0.6
Native Application Host - Library API Reference
Loading...
Searching...
No Matches
expansion.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "nah/warnings.hpp"
4
5#include <string>
6#include <vector>
7#include <unordered_map>
8
9namespace nah {
10
11// ============================================================================
12// Placeholder Expansion (per SPEC L1017-L1042)
13// ============================================================================
14
15// Expansion limits per SPEC
16constexpr size_t MAX_EXPANDED_SIZE = 64 * 1024; // 64 KiB
17constexpr size_t MAX_PLACEHOLDERS = 128;
18
20 bool ok = true;
21 std::string value;
22 std::string error_reason; // "placeholder_limit" | "expansion_overflow"
23};
24
26 std::string value;
27 bool truncated = false;
28 bool limit_exceeded = false;
29};
30
31// Expand placeholders in a string using the environment map
32// Placeholders are exact tokens of the form {NAME}
33// - Single-pass expansion (no recursion)
34// - Missing placeholders emit warning and substitute empty string
35// - Exceeding limits emits warning and substitutes empty string
37 const std::string& input,
38 const std::unordered_map<std::string, std::string>& environment,
39 const std::string& source_path,
40 WarningCollector& warnings);
41
42// Simple overload for testing - returns expanded string and populates missing vars
44 const std::string& input,
45 const std::unordered_map<std::string, std::string>& environment,
46 std::vector<std::string>& missing_vars);
47
48// Expand with explicit limits (for testing)
50 const std::string& input,
51 const std::unordered_map<std::string, std::string>& environment,
52 std::vector<std::string>& missing_vars,
53 size_t max_size,
54 size_t max_placeholders);
55
56// Expand all values in an environment map (in lexicographic key order)
58 std::unordered_map<std::string, std::string>& environment,
59 WarningCollector& warnings);
60
61// Expand a vector of strings
62std::vector<std::string> expand_string_vector(
63 const std::vector<std::string>& input,
64 const std::unordered_map<std::string, std::string>& environment,
65 const std::string& source_path_prefix,
66 WarningCollector& warnings);
67
68// Simple overload for testing
69std::vector<std::string> expand_vector(
70 const std::vector<std::string>& input,
71 const std::unordered_map<std::string, std::string>& environment,
72 std::vector<std::string>& missing_vars);
73
74} // namespace nah
Result type for fallible operations.
Definition nahhost.hpp:109
constexpr size_t MAX_EXPANDED_SIZE
Definition expansion.hpp:16
ExpansionWithLimitsResult expand_placeholders_with_limits(const std::string &input, const std::unordered_map< std::string, std::string > &environment, std::vector< std::string > &missing_vars, size_t max_size, size_t max_placeholders)
ExpansionResult expand_placeholders(const std::string &input, const std::unordered_map< std::string, std::string > &environment, const std::string &source_path, WarningCollector &warnings)
std::vector< std::string > expand_vector(const std::vector< std::string > &input, const std::unordered_map< std::string, std::string > &environment, std::vector< std::string > &missing_vars)
constexpr size_t MAX_PLACEHOLDERS
Definition expansion.hpp:17
void expand_environment_map(std::unordered_map< std::string, std::string > &environment, WarningCollector &warnings)
std::vector< std::string > expand_string_vector(const std::vector< std::string > &input, const std::unordered_map< std::string, std::string > &environment, const std::string &source_path_prefix, WarningCollector &warnings)
std::string error_reason
Definition expansion.hpp:22