feisty meow concerns codebase  2.140
textual::list_parsing Class Reference

A set of functions that help out with parsing lists of things. More...

#include <list_parsing.h>

Public Member Functions

virtual ~list_parsing ()
 
 DEFINE_CLASS_NAME ("list_parsing")
 

Static Public Member Functions

static bool get_ids_from_string (const basis::astring &string, structures::int_set &ids)
 returns true if a set of unique ids can be extracted from "string". More...
 
static bool get_ids_from_string (const basis::astring &string, basis::int_array &ids)
 same as above except result is an array – to preserve order. More...
 
static basis::astring put_ids_in_string (const structures::int_set &ids, char separator=',')
 returns a string containing a "separator" separated list of ids. More...
 
static basis::astring put_ids_in_string (const basis::int_array &ids, char separator=',')
 operates on an array instead of a set. More...
 
static basis::astring emit_quoted_chunk (const basis::astring &to_emit)
 ensures that quotes inside the string "to_emit" are escaped. More...
 
static bool parse_csv_line (const basis::astring &to_parse, structures::string_array &fields)
 examines the string "to_parse" which should be in csv format. More...
 
static void create_csv_line (const structures::string_array &to_csv, basis::astring &target)
 
static void create_csv_line (const structures::string_table &to_csv, basis::astring &target)
 writes a CSV line of text into the "target" from the items in "to_csv". More...
 

Detailed Description

A set of functions that help out with parsing lists of things.

Definition at line 28 of file list_parsing.h.

Constructor & Destructor Documentation

◆ ~list_parsing()

textual::list_parsing::~list_parsing ( )
virtual

Definition at line 34 of file list_parsing.cpp.

Member Function Documentation

◆ create_csv_line() [1/2]

void textual::list_parsing::create_csv_line ( const structures::string_array to_csv,
basis::astring target 
)
static

◆ create_csv_line() [2/2]

void textual::list_parsing::create_csv_line ( const structures::string_table to_csv,
basis::astring target 
)
static

writes a CSV line of text into the "target" from the items in "to_csv".

the "target" is reset before the line is stored there; thus, this is not cumulative. further, the end of line character is not appended. this will escape quote and backslash characters with a prepended backslash.

Definition at line 148 of file list_parsing.cpp.

References basis::astring::empty_string(), structures::symbol_table< contents >::name(), and structures::symbol_table< contents >::symbols().

◆ DEFINE_CLASS_NAME()

textual::list_parsing::DEFINE_CLASS_NAME ( "list_parsing"  )

◆ emit_quoted_chunk()

astring textual::list_parsing::emit_quoted_chunk ( const basis::astring to_emit)
static

ensures that quotes inside the string "to_emit" are escaped.

Definition at line 135 of file list_parsing.cpp.

References basis::astring::length().

◆ get_ids_from_string() [1/2]

bool textual::list_parsing::get_ids_from_string ( const basis::astring string,
basis::int_array ids 
)
static

same as above except result is an array – to preserve order.

this also retains duplicates.

Definition at line 48 of file list_parsing.cpp.

References basis::astring::length(), MAXINT32, and basis::array< contents >::reset().

◆ get_ids_from_string() [2/2]

bool textual::list_parsing::get_ids_from_string ( const basis::astring string,
structures::int_set ids 
)
static

returns true if a set of unique ids can be extracted from "string".

valid separators are spaces, commas, hyphens. note that this returns an int_set although the integers will all be non-negative. e.g. "1-4,5 6 7,30-25" is a valid string.

Definition at line 37 of file list_parsing.cpp.

References structures::set< contents >::add(), structures::set< contents >::clear(), and basis::array< contents >::length().

◆ parse_csv_line()

bool textual::list_parsing::parse_csv_line ( const basis::astring to_parse,
structures::string_array fields 
)
static

examines the string "to_parse" which should be in csv format.

the "fields" list is set to the entries found on the line. true is returned if the line parsed without any errors. this method will accept a backslash as an escape character if it is immediately followed by a quote character or another backslash character. no other escapes are currently supported; backslashes will be taken literally otherwise.

Definition at line 196 of file list_parsing.cpp.

◆ put_ids_in_string() [1/2]

astring textual::list_parsing::put_ids_in_string ( const basis::int_array ids,
char  separator = ',' 
)
static

operates on an array instead of a set.

Definition at line 121 of file list_parsing.cpp.

References basis::array< contents >::length().

◆ put_ids_in_string() [2/2]

astring textual::list_parsing::put_ids_in_string ( const structures::int_set ids,
char  separator = ',' 
)
static

returns a string containing a "separator" separated list of ids.

spaces are also used between entries for readability.

Definition at line 107 of file list_parsing.cpp.

References basis::array< contents >::length().


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