30 #ifdef DEBUG_INI_PARSER
31 #define LOG(to_print) printf("%s\n", astring(to_print).s())
38 using namespace basis;
64 void ini_parser::chow_through_eol(
astring &to_chow)
70 *_preface += to_chow[0];
75 *_preface += to_chow[0];
112 _well_formed =
false;
123 while (parsing.
length()) {
125 bool found_sect = parse_section(parsing, section_name);
128 chow_through_eol(parsing);
133 for (next_sect = 0; next_sect < parsing.
length(); next_sect++) {
139 if (parsing[next_sect + 1] ==
'[') {
146 if (next_sect >= parsing.
length()) next_sect--;
148 LOG(
a_sprintf(
"bounds are %d to %d, string len is %d.", 0, next_sect,
151 LOG(
astring(
"going to parse: >>") + sect_parsing +
"<<");
152 parsing.
zap(0, next_sect);
155 section_reader.
parse(sect_parsing);
173 for (
int i = 0; i < to_merge.
symbols(); i++)
174 put(section_name, to_merge.
name(i), to_merge[i]);
177 bool ini_parser::parse_section(
astring &to_parse,
astring §ion_name)
183 SEEKING_OPENING_BRACKET,
186 states state = SEEKING_OPENING_BRACKET;
189 for (
int i = 0; i < to_parse.
length(); i++) {
190 char curr = to_parse[i];
193 case SEEKING_OPENING_BRACKET:
195 if (parser_bits::white_space(curr))
continue;
196 if (curr !=
'[')
return false;
197 state = EATING_SECTION_NAME;
199 case EATING_SECTION_NAME:
208 section_name += curr;
225 for (
int i = 0; i < sects.
length(); i++) {
226 new_ini +=
astring(
"[") + sects[i] +
"]" + parser_bits::platform_eol_to_chars();
a_sprintf is a specialization of astring that provides printf style support.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
void reset()
clears out the contents string.
int length() const
Returns the current length of the string.
void add(const basis::astring &to_parse)
merges items parsed from "to_parse" into the current set.
void merge_section(const basis::astring §ion_name, const structures::string_table &to_merge)
merges the table "to_merge" into the "section_name".
bool restate(basis::astring &new_ini, bool add_spaces=false)
stores a cleaned version of the internal state into "new_ini".
Supports the configurator interface using a collection of string tables.
virtual bool put(const basis::astring §ion, const basis::astring &entry, const basis::astring &to_store)
implements the configurator storage function.
virtual void sections(structures::string_array &list)
retrieves the section names into "list".
virtual bool section_exists(const basis::astring §ion)
true if the "section" is presently in the table config.
virtual bool put_section(const basis::astring §ion, const structures::string_table &info)
writes a table called "info" into the "section" held here.
virtual bool get_section(const basis::astring §ion, structures::string_table &info)
reads the entire table held under "section" into a table called "info".
Manages a bank of textual definitions of variables.
const structures::string_table & table() const
provides a constant peek at the string_table holding the values.
basis::astring text_form() const
creates a new token list as a string of text.
void set_comment_chars(const basis::astring &comments)
establishes a set of characters in "comments" as the comment items.
bool parse(const basis::astring &to_tokenize)
parses the string using our established sentinel characters.
An array of strings with some additional helpful methods.
Provides a symbol_table that holds strings as the content.
basis::astring text_form() const
prints the contents of the table into the returned string.
const basis::astring & name(int index) const
returns the name held at the "index".
int symbols() const
returns the number of symbols listed in the table.
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
A dynamic container class that holds any kind of object via pointers.
bool is_eol(char to_check)