cgv
|
namespace that holds tools that dont fit any other namespace More...
Classes | |
class | big_binary_file |
struct | line |
class | Profiler |
struct | progression |
class | statistics |
class | stopwatch |
struct | token |
class | tokenizer |
struct | typed_token |
Enumerations | |
enum | token_type |
different types that a typed_token can have | |
Functions | |
void | split_to_tokens (const char *begin, const char *end, std::vector< token > &tokens, const std::string &separators, bool merge_separators, const std::string &open_parenthesis, const std::string &close_parenthesis, const std::string &whitespaces, unsigned int max_nr_tokens) |
void | split_to_lines (const char *global_begin, const char *global_end, std::vector< line > &lines, bool truncate_trailing_spaces) |
bool | balanced_find_content (const char *begin, const char *end, token &content, char open_parenthesis, char close_parenthesis) |
void | split_to_tokens (const token &tok, std::vector< token > &tokens, const std::string &separators, bool merge_separators=true, const std::string &open_parenthesis="", const std::string &close_parenthesis="", const std::string &whitespaces=" \t\n", unsigned int=-1) |
text range given as token | |
void | split_to_tokens (const std::string &s, std::vector< token > &tokens, const std::string &separators, bool merge_separators=true, const std::string &open_parenthesis="", const std::string &close_parenthesis="", const std::string &whitespaces=" \t\n", unsigned int=(unsigned int) -1) |
text range given as string | |
void | split_to_lines (const token &tok, std::vector< line > &lines, bool truncate_trailing_spaces=true) |
text range given as token | |
void | split_to_lines (const std::string &s, std::vector< line > &lines, bool truncate_trailing_spaces=true) |
text range given as string | |
bool | is_bit_set (unsigned int bit_idx, unsigned int bit_field) |
check if a bit of a bit field is set | |
void | enable_upper_bits (unsigned int &bit_field, unsigned int fst_bit_idx) |
set all the bits of bit_field with index equal or larger than fst_bit_idx | |
void | disable_upper_bits (unsigned int &bit_field, unsigned int fst_bit_idx) |
clear all the bits of bit_field with index equal or larger than fst_bit_idx | |
void | enable_lower_bits (unsigned int &bit_field, unsigned int fst_bit_idx) |
set all the bits of bit_field with index equal or less than fst_bit_idx | |
void | disable_lower_bits (unsigned int &bit_field, unsigned int fst_bit_idx) |
clear all the bits of bit_field with index equal or less than fst_bit_idx | |
void | set_bits (unsigned int &bit_field, unsigned int off, unsigned int n, unsigned int value) |
set n bits starting with index off of the given bit field from the first bits of the given integer value | |
std::wstring | str2wstr (const std::string &s) |
convert a 8-bit string to a 16-bit string | |
std::string | wstr2str (const std::wstring &s) |
convert a 16-bit string to a 8-bit string | |
std::string | encode_base64 (const std::string &s) |
encode a string into base64 | |
std::string | decode_base64 (const std::string &s) |
decode a base64 encoded string | |
template<> | |
std::string | to_string (const std::string &v, unsigned int w, unsigned int p) |
specialization of conversion from string to strings | |
template<> | |
bool | from_string (std::string &v, const std::string &s) |
specialization to extract string value from string | |
template<typename T > | |
std::string | to_string (const T &v, unsigned int w=-1, unsigned int p=-1) |
convert a numeric type T into string of width w and precision p | |
template<typename T > | |
std::string | to_string (const T &v, unsigned int w, char fill_char) |
convert an integer type T into string of width w with given fill character | |
template<typename T > | |
bool | from_string (T &v, const std::string &s) |
extract value from string | |
bool | has_option (const std::string &option) |
check whether the system variable CGV_OPTIONS contains the given option (the comparison is case insensitve) within a semicolon separated list | |
void | enumerate_options (std::vector< std::string > &options) |
push back all options provided in the CGV_OPTIONS system variable | |
bool | is_space (char c) |
check if char is a whitespace | |
bool | is_url_special (char c) |
check if char is a special character from an url | |
bool | is_digit (char c) |
check if char is a digit | |
bool | is_letter (char c) |
check if char is a letter | |
char | to_lower (char c) |
convert char to lower case | |
std::string | to_hex (uint8_t v, bool use_upper_case=true) |
convert to hex | |
std::string | to_lower (const std::string &_s) |
convert string to lower case | |
char | to_upper (char c) |
convert char to upper case | |
std::string | to_upper (const std::string &_s) |
convert string to upper case | |
std::string | replace_special (const std::string &_s) |
replaces the german special characters ä,ö,ü,ß,Ä,Ö,Ü | |
unsigned int | replace (std::string &_s, char c1, char c2) |
replace char c1 with c2 in the given string _s and return number of replacements | |
unsigned int | replace (std::string &_s, const std::string &s1, const std::string &s2) |
replace string s1 with s2 in the given string _s and return number of replacements | |
std::string | escape_special (const std::string &s) |
escapes the C++ special characters \a , \b , \f , \n , \r , \t , \v , \\' , \" , \\ , \ ? | |
std::string | interpret_special (const std::string &s) |
interprets the C++ special characters \a , \b , \f , \n , \r , \t , \v , \\' , \" , \\ , \ ?, \ooo , \xhh | |
bool | is_element (char c, const std::string &s) |
check if char c arises in string s | |
bool | is_element (const std::string &e, const std::string &s, char sep=';') |
check if the string e is contained as element in the string s, which is a list separated by sep | |
std::string | get_element (const std::string &s, int element_index, char sep) |
int | get_element_index (const std::string &e, const std::string &s, char sep) |
bool | is_integer (const char *begin, const char *end, int &value) |
check if the text range (begin,end( defines an integer value. If yes, store the value in the passed reference. | |
bool | is_integer (const std::string &s, int &value) |
check if the passed string defines an integer value. If yes, store the value in the passed reference. | |
bool | is_double (const char *begin, const char *end, double &value) |
check if the text range (begin,end( defines a double value. If yes, store the value in the passed reference. | |
bool | is_double (const std::string &s, double &value) |
check if the passed string defines a double value. If yes, store the value in the passed reference. | |
bool | is_year (const char *begin, const char *end, unsigned short &year, bool short_allowed=true) |
check and extract year from string token [begin , end ] | |
bool | is_year (const std::string &s, unsigned short &year, bool short_allowed=true) |
check and extract year from string s | |
bool | find_name (const std::string &s, const char *names[], int &idx) |
check if string s is contained in the given array of names and in case of success store name index in idx | |
bool | is_month (const char *begin, const char *end, unsigned char &month) |
check and extract month from string token [begin , end ] | |
bool | is_month (const std::string &s, unsigned char &month) |
check and extract month from string s | |
bool | is_time (const std::string &s, cgv::utils::time &t, const char **new_end=0) |
check and extract time from string token [begin , end ] | |
bool | is_date (const std::string &s, cgv::utils::date &d, const char **new_end=0) |
check and extract date from string token [begin , end ] | |
bool | is_time (const char *begin, const char *end, cgv::utils::time &t, const char **new_end=0) |
check and extract time from string s | |
bool | is_date (const char *begin, const char *end, cgv::utils::date &d, const char **new_end=0) |
check and extract date from string s | |
bool | is_url (const std::string &s, const char **end=0) |
check and extract end of valid url from string s | |
bool | is_url (const char *begin, const char *end, const char **new_end=0) |
check and extract end of valid url from string token [begin , end ] | |
const char * | skip_spaces (const char *begin, const char *end) |
return new start pointer by skipping spaces at begin | |
const char * | cutoff_spaces (const char *begin, const char *end) |
return new end pointer by cutting off spaces at the end | |
CGV_API bool | is_day (const char *begin, const char *end, unsigned char &day) |
check and extract day from string token [begin , end ] | |
CGV_API bool | is_day (const std::string &s, unsigned char &day) |
check and extract day from string s | |
void | parse_enum_declarations (const std::string &enum_declarations, std::vector< token > &enum_names, std::vector< int > &enum_values) |
parse an enum declaration string into names and values | |
unsigned | find_enum_index (int value, const std::vector< int > &enum_values) |
convert value to index | |
unsigned | find_enum_index (const std::string &name, const std::vector< token > &enum_names) |
convert name to index | |
std::string | find_enum_name (const std::string &enum_declarations, int value) |
lookup name of value in enum declaration | |
std::string | to_string (const token &t) |
convert to string | |
std::ostream & | operator<< (std::ostream &os, const token &t) |
stream out operator | |
void | bite_all (tokenizer &t, std::vector< token > &result) |
bite all tokens into a token vector | |
namespace that holds tools that dont fit any other namespace
CGV_API bool cgv::utils::balanced_find_content | ( | const char * | begin, |
const char * | end, | ||
token & | content, | ||
char | open_parenthesis, | ||
char | close_parenthesis | ||
) |
the input range must begin with an open parenthesis. The function finds the matching closing parenthesis and returns a token with the content inside the parentheses.
Examples:
balanced_find_content( "a+b", => , '(', ')' ) ==> false; balanced_find_content( "(a+b)", => "a+b", '(', ')' ) ==> true; balanced_find_content( "(a+(c*d),b)", => "a+(c*d),b", '(', ')' ) ==> true;
CGV_API std::string cgv::utils::get_element | ( | const std::string & | s, |
int | element_index, | ||
char | sep = ';' |
||
) |
interpret s as a list separated by sep and return the element with the given element index. If index is out of range, return empty string.
CGV_API int cgv::utils::get_element_index | ( | const std::string & | e, |
const std::string & | s, | ||
char | sep = ';' |
||
) |
check if the string e is contained as element in the string s, which is a list separated by sep and return the index of the element. If not contained, return -1.
CGV_API void cgv::utils::split_to_lines | ( | const char * | begin, |
const char * | end, | ||
std::vector< line > & | lines, | ||
bool | truncate_trailing_spaces = true |
||
) |
this function splits a text range at the newline characters into single lines. If truncate_trailing_spaces is true all spaces and tabs at the end of the line are excluded.
CGV_API void cgv::utils::split_to_tokens | ( | const char * | begin, |
const char * | end, | ||
std::vector< token > & | tokens, | ||
const std::string & | separators, | ||
bool | merge_separators = true , |
||
const std::string & | open_parenthesis = "" , |
||
const std::string & | close_parenthesis = "" , |
||
const std::string & | whitespaces = " \t\n" , |
||
unsigned int | max_nr_tokens = -1 |
||
) |
this function splits a text range into tokens. The function is typically applied to a line. One can specify whitespaces that are used to detect split locations but do not generate any tokens. The separators also mark split locations and generate tokens. If merge_separators is true, successive separators are merged into one token. Finally, one can specify a pair of character lists open_paranthesis and close_paranthesis that are used to overwrite the splitting mechanism and allow to generate tokens including whitespaces and separators. Some examples:
applying
vector<token> tokens; split_to_tokens(line.begin, line.end, tokens, ".,;:", "'{", "'}", " \t");
to the line
Hello world... This is a "split to tokens" test line. {copyright: S. G.}
generates the following tokens:
Hello world ... This is a split to tokens test line copyright: S. G.