feisty meow concerns codebase  2.140
configuration::variable_tokenizer Class Reference

Manages a bank of textual definitions of variables. More...

#include <variable_tokenizer.h>

Inheritance diagram for configuration::variable_tokenizer:
Collaboration diagram for configuration::variable_tokenizer:

Public Types

enum  constraints { DEFAULT_MAX_BITS = 7 }
 

Public Member Functions

 variable_tokenizer (int max_bits=DEFAULT_MAX_BITS)
 creates a variable_tokenizer with the default characters. More...
 
 variable_tokenizer (const basis::astring &separator, const basis::astring &assignment, int max_bits=DEFAULT_MAX_BITS)
 creates an empty list of tokens and uses the specified sentinel chars. More...
 
 variable_tokenizer (const basis::astring &separator, const basis::astring &assignment, const basis::astring &quotes, bool nesting=true, int max_bits=DEFAULT_MAX_BITS)
 similar to the constructor above, but supports quoting. More...
 
 variable_tokenizer (const variable_tokenizer &to_copy)
 builds a variable_tokenizer that is identical to "to_copy". More...
 
virtual ~variable_tokenizer ()
 
 DEFINE_CLASS_NAME ("variable_tokenizer")
 
void set_comment_chars (const basis::astring &comments)
 establishes a set of characters in "comments" as the comment items. More...
 
variable_tokenizeroperator= (const variable_tokenizer &to_copy)
 makes this variable_tokenizer identical to "to_copy". More...
 
int symbols () const
 returns the number of entries in the variable_tokenizer. More...
 
void reset ()
 clears all of the entries out. More...
 
const structures::string_tabletable () const
 provides a constant peek at the string_table holding the values. More...
 
structures::string_tabletable ()
 provides direct access to the string_table holding the values. More...
 
bool parse (const basis::astring &to_tokenize)
 parses the string using our established sentinel characters. More...
 
basis::astring find (const basis::astring &name) const
 locates the value for a variable named "name" if it exists. More...
 
bool exists (const basis::astring &name) const
 returns true if the "name" exists in the variable_tokenizer. More...
 
basis::astring text_form () const
 creates a new token list as a string of text. More...
 
void text_form (basis::astring &to_fill) const
 like text_form() above, but stores into "to_fill". More...
 
bool add_spaces () const
 
void add_spaces (bool add_them)
 
bool okay_for_variable_name (char to_check) const
 true if "to_check" is a valid variable name character. More...
 
const basis::astringassignments () const
 provides a peek at the assignments list. More...
 
const basis::astringseparators () const
 provides a peek at the separators list. More...
 
const basis::astringquotes () const
 provides a peek at the quotes list. More...
 
bool assignment (char to_check) const
 true if "to_check" is a valid assignment operator. More...
 
bool separator (char to_check) const
 true if "to_check" is a valid separator. More...
 
bool comment_char (char to_check) const
 true if "to_check" is a registered comment character. More...
 
bool is_eol_a_separator () const
 reports whether any of the separators are an EOL character. More...
 
bool quote_mark (char to_check) const
 true if "to_check" is a member of the quotes list. More...
 

Detailed Description

Manages a bank of textual definitions of variables.

Manipulates strings containing variable definitions where a variable is syntactically defined as a name, an assignment operator, and a value. The string can optionally define many variables by placing a separator character between the definitions. The assignment and separator are referred to as sentinels in the following docs. This class also supports quoted values if the appropriate constructor is used.

Definition at line 32 of file variable_tokenizer.h.

Member Enumeration Documentation

◆ constraints

Enumerator
DEFAULT_MAX_BITS 

Definition at line 35 of file variable_tokenizer.h.

Constructor & Destructor Documentation

◆ variable_tokenizer() [1/4]

configuration::variable_tokenizer::variable_tokenizer ( int  max_bits = DEFAULT_MAX_BITS)

creates a variable_tokenizer with the default characters.

this will not look for quote characters. the "max_bits" establishes the hashing width for the internal table of strings; there will be 2 ^ "max_bits" of space in the table. the default assignment operator is '=' and the default separator is ','.

Definition at line 42 of file variable_tokenizer.cpp.

◆ variable_tokenizer() [2/4]

configuration::variable_tokenizer::variable_tokenizer ( const basis::astring separator,
const basis::astring assignment,
int  max_bits = DEFAULT_MAX_BITS 
)

creates an empty list of tokens and uses the specified sentinel chars.

the character that is expected to be between name/value pairs is "separator". the "assignment" character is expected to be between each name and its value. note that if the "separator" or "assignment" are more than one character long, these will be taken as a set of valid characters that can be used for those purposes.

Definition at line 53 of file variable_tokenizer.cpp.

◆ variable_tokenizer() [3/4]

configuration::variable_tokenizer::variable_tokenizer ( const basis::astring separator,
const basis::astring assignment,
const basis::astring quotes,
bool  nesting = true,
int  max_bits = DEFAULT_MAX_BITS 
)

similar to the constructor above, but supports quoting.

if the "quotes" list is not empty, then those characters will be treated as quoting characters that must be matched in pairs. inside a quote, separators are ignored. if "nesting" is not true, then only one level of quotes will be considered; the occurrence of other types of quotes will be ignored until the original type is completed.

Definition at line 65 of file variable_tokenizer.cpp.

◆ variable_tokenizer() [4/4]

configuration::variable_tokenizer::variable_tokenizer ( const variable_tokenizer to_copy)

builds a variable_tokenizer that is identical to "to_copy".

Definition at line 77 of file variable_tokenizer.cpp.

◆ ~variable_tokenizer()

configuration::variable_tokenizer::~variable_tokenizer ( )
virtual

Definition at line 88 of file variable_tokenizer.cpp.

References basis::WHACK().

Member Function Documentation

◆ add_spaces() [1/2]

bool configuration::variable_tokenizer::add_spaces ( ) const
inline

Definition at line 138 of file variable_tokenizer.h.

◆ add_spaces() [2/2]

void configuration::variable_tokenizer::add_spaces ( bool  add_them)
inline

Definition at line 139 of file variable_tokenizer.h.

◆ assignment()

bool configuration::variable_tokenizer::assignment ( char  to_check) const

true if "to_check" is a valid assignment operator.

Definition at line 154 of file variable_tokenizer.cpp.

Referenced by okay_for_variable_name(), and parse().

◆ assignments()

const astring & configuration::variable_tokenizer::assignments ( ) const

provides a peek at the assignments list.

Definition at line 102 of file variable_tokenizer.cpp.

◆ comment_char()

bool configuration::variable_tokenizer::comment_char ( char  to_check) const

true if "to_check" is a registered comment character.

Definition at line 160 of file variable_tokenizer.cpp.

Referenced by parse().

◆ DEFINE_CLASS_NAME()

configuration::variable_tokenizer::DEFINE_CLASS_NAME ( "variable_tokenizer"  )

◆ exists()

bool configuration::variable_tokenizer::exists ( const basis::astring name) const

returns true if the "name" exists in the variable_tokenizer.

Definition at line 108 of file variable_tokenizer.cpp.

References structures::symbol_table< contents >::find().

◆ find()

astring configuration::variable_tokenizer::find ( const basis::astring name) const

locates the value for a variable named "name" if it exists.

if "name" doesn't exist, then it returns an empty string. note that an empty string might also indicate that the value is blank; locate is the way to tell if a field is really missing. also note that when a variable name is followed by an assignment operator and an empty value (e.g., "avversione=" has no value), then a value of a single space character will be stored. this ensures that the same format is used on the output side, but it also means that if you access the table directly, then you will get a space as the value. however, this function returns an empty string for those entries to keep consistent with expectations.

Definition at line 129 of file variable_tokenizer.cpp.

References basis::astring::equal_to(), structures::symbol_table< contents >::find(), and SPECIAL_VALUE.

Referenced by processes::configured_applications::parse_startup_entry().

◆ is_eol_a_separator()

bool configuration::variable_tokenizer::is_eol_a_separator ( ) const

reports whether any of the separators are an EOL character.

Definition at line 351 of file variable_tokenizer.cpp.

References basis::astring::get(), is_eol(), and basis::astring::length().

Referenced by parse(), and text_form().

◆ okay_for_variable_name()

bool configuration::variable_tokenizer::okay_for_variable_name ( char  to_check) const

true if "to_check" is a valid variable name character.

this includes any characters besides separators and assignments.

Definition at line 139 of file variable_tokenizer.cpp.

References assignment(), and separator().

Referenced by parse().

◆ operator=()

variable_tokenizer & configuration::variable_tokenizer::operator= ( const variable_tokenizer to_copy)

makes this variable_tokenizer identical to "to_copy".

Definition at line 117 of file variable_tokenizer.cpp.

◆ parse()

bool configuration::variable_tokenizer::parse ( const basis::astring to_tokenize)

parses the string using our established sentinel characters.

attempts to snag as many value/pairs from "to_tokenize" as are possible by using the current separator and assignment characters.
E.G.: if the separator is ';' and the assignment character is '=', then one's string would look something like:

state_folder=/home/fred/state; GLOB=/usr/bin/glob.exe; ....

whitespace is ignored if it's found (1) after a separator and before the next variable name, (2) after the variable name and before the assignment character, (3) after the assignment character and before the value. this unfortunately implies that white space cannot begin or end a value. NOTE: unpredictable results will occur: if one's variables are improperly formed, if assignment operators are missing or misplaced, or if the separator character is used within the value. NOTE: carriage returns are considered white-space and can exist in the string as described above. NOTE: parse is additive; if multiple calls to parse() occur, then the symbol_table will be built from the most recent values found in the parameters to parse(). if this is not desired, the symbol table's reset() function can be used to empty out all variables.

Definition at line 172 of file variable_tokenizer.cpp.

References structures::symbol_table< contents >::add(), assignment(), CHOP, comment_char(), COOL, basis::astring::end(), basis::astring::equal_to(), FUNCDEF, basis::astring::insert(), is_eol(), is_eol_a_separator(), structures::stack< contents >::kind(), LOG, okay_for_variable_name(), structures::stack< contents >::pop(), structures::stack< contents >::push(), quote_mark(), basis::astring::reset(), separator(), structures::stack< contents >::size(), SPECIAL_VALUE, STRTAB_COMMENT_PREFIX, basis::astring::t(), structures::stack< contents >::top(), and basis::astring::zap().

Referenced by configuration::ini_parser::add(), write_build_config::execute(), configuration::ini_configurator::get_section(), write_build_config::output_definition_macro(), and processes::configured_applications::parse_startup_entry().

◆ quote_mark()

bool configuration::variable_tokenizer::quote_mark ( char  to_check) const

true if "to_check" is a member of the quotes list.

Definition at line 157 of file variable_tokenizer.cpp.

Referenced by parse().

◆ quotes()

const astring & configuration::variable_tokenizer::quotes ( ) const

provides a peek at the quotes list.

Definition at line 106 of file variable_tokenizer.cpp.

◆ reset()

void configuration::variable_tokenizer::reset ( )

clears all of the entries out.

Definition at line 111 of file variable_tokenizer.cpp.

References structures::symbol_table< contents >::reset().

◆ separator()

bool configuration::variable_tokenizer::separator ( char  to_check) const

true if "to_check" is a valid separator.

Definition at line 145 of file variable_tokenizer.cpp.

References is_eol().

Referenced by okay_for_variable_name(), and parse().

◆ separators()

const astring & configuration::variable_tokenizer::separators ( ) const

provides a peek at the separators list.

Definition at line 104 of file variable_tokenizer.cpp.

◆ set_comment_chars()

void configuration::variable_tokenizer::set_comment_chars ( const basis::astring comments)

establishes a set of characters in "comments" as the comment items.

comments will be specially handled by being added to the string table with the comment prefix. this allows them to be regenerated uniquely later.

Definition at line 99 of file variable_tokenizer.cpp.

Referenced by configuration::ini_parser::add().

◆ symbols()

int configuration::variable_tokenizer::symbols ( ) const

◆ table() [1/2]

string_table & configuration::variable_tokenizer::table ( )

provides direct access to the string_table holding the values.

Definition at line 115 of file variable_tokenizer.cpp.

◆ table() [2/2]

const string_table & configuration::variable_tokenizer::table ( ) const

provides a constant peek at the string_table holding the values.

Definition at line 113 of file variable_tokenizer.cpp.

Referenced by configuration::ini_parser::add(), write_build_config::execute(), configuration::ini_configurator::get_section(), and write_build_config::output_definition_macro().

◆ text_form() [1/2]

astring configuration::variable_tokenizer::text_form ( ) const

creates a new token list as a string of text.

the first separator and assignment characters in each set are used to generate it. note that the whitespace that existed in the original parsed string might not be exactly the same in the generated string.

Definition at line 395 of file variable_tokenizer.cpp.

Referenced by configuration::ini_parser::add().

◆ text_form() [2/2]

void configuration::variable_tokenizer::text_form ( basis::astring to_fill) const

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