HyperDbg Debugger
Loading...
Searching...
No Matches
inipp::Ini< CharT > Class Template Reference

#include <inipp.h>

Public Types

using String = std::basic_string<CharT>
 
using Section = std::map<String, String>
 
using Sections = std::map<String, Section>
 

Public Member Functions

 Ini ()
 
 Ini (std::shared_ptr< Format< CharT > > fmt)
 
void generate (std::basic_ostream< CharT > &os) const
 
void parse (std::basic_istream< CharT > &is)
 
void interpolate ()
 
void default_section (const Section &sec)
 
void strip_trailing_comments ()
 
void clear ()
 

Public Attributes

Sections sections
 
std::list< Stringerrors
 
std::shared_ptr< Format< CharT > > format
 

Static Public Attributes

static const int max_interpolation_depth = 10
 

Member Typedef Documentation

◆ Section

template<class CharT >
using inipp::Ini< CharT >::Section = std::map<String, String>

◆ Sections

template<class CharT >
using inipp::Ini< CharT >::Sections = std::map<String, Section>

◆ String

template<class CharT >
using inipp::Ini< CharT >::String = std::basic_string<CharT>

Constructor & Destructor Documentation

◆ Ini() [1/2]

template<class CharT >
inipp::Ini< CharT >::Ini ( )
inline
184 :
185 format(std::make_shared<Format<CharT>>()) {};
std::shared_ptr< Format< CharT > > format
Definition inipp.h:180

◆ Ini() [2/2]

template<class CharT >
inipp::Ini< CharT >::Ini ( std::shared_ptr< Format< CharT > > fmt)
inline
186 :
187 format(fmt) {};

Member Function Documentation

◆ clear()

template<class CharT >
void inipp::Ini< CharT >::clear ( )
inline
282 {
283 sections.clear();
284 errors.clear();
285 }
Sections sections
Definition inipp.h:178
std::list< String > errors
Definition inipp.h:179

◆ default_section()

template<class CharT >
void inipp::Ini< CharT >::default_section ( const Section & sec)
inline
264 {
265 for (auto & sec2 : sections)
266 for (const auto & val : sec)
267 sec2.second.insert(val);
268 }
val
Definition test-case-generator.py:590
for(;;x)
Definition script-test-cases.txt:2

◆ generate()

template<class CharT >
void inipp::Ini< CharT >::generate ( std::basic_ostream< CharT > & os) const
inline
190 {
191 for (auto const & sec : sections)
192 {
193 os << format->char_section_start << sec.first << format->char_section_end << std::endl;
194 for (auto const & val : sec.second)
195 {
196 os << val.first << format->char_assign << val.second << std::endl;
197 }
198 os << std::endl;
199 }
200 }

◆ interpolate()

template<class CharT >
void inipp::Ini< CharT >::interpolate ( )
inline
247 {
248 int global_iteration = 0;
249 auto changed = false;
250 // replace each "${variable}" by "${section:variable}"
251 for (auto & sec : sections)
252 replace_symbols(local_symbols(sec.first, sec.second), sec.second);
253 // replace each "${section:variable}" by its value
254 do
255 {
256 changed = false;
257 const auto syms = global_symbols();
258 for (auto & sec : sections)
259 changed |= replace_symbols(syms, sec.second);
260 } while (changed && (max_interpolation_depth > global_iteration++));
261 }
static const int max_interpolation_depth
Definition inipp.h:182

◆ parse()

template<class CharT >
void inipp::Ini< CharT >::parse ( std::basic_istream< CharT > & is)
inline
203 {
204 String line;
205 String section;
206 const std::locale loc {"C"};
207 while (std::getline(is, line))
208 {
209 detail::ltrim(line, loc);
210 detail::rtrim(line, loc);
211 const auto length = line.length();
212 if (length > 0)
213 {
214 const auto pos = std::find_if(line.begin(), line.end(), [this](CharT ch) { return format->is_assign(ch); });
215 const auto & front = line.front();
216 if (format->is_comment(front))
217 {
218 }
219 else if (format->is_section_start(front))
220 {
221 if (format->is_section_end(line.back()))
222 section = line.substr(1, length - 2);
223 else
224 errors.push_back(line);
225 }
226 else if (pos != line.begin() && pos != line.end())
227 {
228 String variable(line.begin(), pos);
229 String value(pos + 1, line.end());
230 detail::rtrim(variable, loc);
231 detail::ltrim(value, loc);
232 auto & sec = sections[section];
233 if (sec.find(variable) == sec.end())
234 sec.emplace(variable, value);
235 else
236 errors.push_back(line);
237 }
238 else
239 {
240 errors.push_back(line);
241 }
242 }
243 }
244 }
std::basic_string< CharT > String
Definition inipp.h:174
void rtrim(std::basic_string< CharT > &s, const std::locale &loc)
Definition inipp.h:56
void ltrim(std::basic_string< CharT > &s, const std::locale &loc)
Definition inipp.h:48

◆ strip_trailing_comments()

template<class CharT >
void inipp::Ini< CharT >::strip_trailing_comments ( )
inline
271 {
272 const std::locale loc {"C"};
273 for (auto & sec : sections)
274 for (auto & val : sec.second)
275 {
276 detail::rtrim2(val.second, [this](CharT ch) { return format->is_comment(ch); });
277 detail::rtrim(val.second, loc);
278 }
279 }
void rtrim2(std::basic_string< CharT > &s, UnaryPredicate pred)
Definition inipp.h:64

Member Data Documentation

◆ errors

template<class CharT >
std::list<String> inipp::Ini< CharT >::errors

◆ format

template<class CharT >
std::shared_ptr<Format<CharT> > inipp::Ini< CharT >::format

◆ max_interpolation_depth

template<class CharT >
const int inipp::Ini< CharT >::max_interpolation_depth = 10
static

◆ sections

template<class CharT >
Sections inipp::Ini< CharT >::sections

The documentation for this class was generated from the following file: