cgv
Loading...
Searching...
No Matches
cgv::utils Namespace Reference

namespace that holds tools that dont fit any other namespace More...

Classes

class  big_binary_file
 class to handle files with very large sizes (>=2GB) hiding the ugly win32 api calls More...
 
struct  date
 
struct  date_time
 
struct  guid
 simple struct to represent guid More...
 
struct  line
 a line in a text is simply represented as a token More...
 
class  pointer_test
 
class  Profiler
 A profiler class for managing different stopwatches. More...
 
struct  progression
 progression provides a simple possibility to show progression of process in console. More...
 
class  statistics
 incrementally accumulate statistical information More...
 
class  stopwatch
 A trivial stop watch class for time measurement. More...
 
struct  time
 
struct  token
 representation of a token in a text by two pointers begin and end, that point to the first character of the token and behind the last character of the token. More...
 
class  tokenizer
 the tokenizer allows to split text into tokens in a convenient way. More...
 
struct  typed_token
 a typed token also stores the type and value of a parsed token. More...
 

Enumerations

enum  token_type {
  PLAIN , URL , FLOAT_VALUE , TIME_VALUE ,
  DATE_VALUE
}
 different types that a typed_token can have More...
 

Functions

void 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.
 
void 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.
 
bool 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.
 
std::string strip_cpp_comments (const std::string &source, bool correct_new_lines=true)
 remove cpp-style comments from string
 
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 balanced_find_content (const token &expression, token &content, char open_parenthesis, char close_parenthesis)
 
bool balanced_find_content (const std::string &expression, token &content, char open_parenthesis, char close_parenthesis)
 
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
 
static bool is_base64 (unsigned char c)
 
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, bool)
 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, bool fixed=false)
 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<>
CGV_API std::string to_string (const std::string &v, unsigned int w, unsigned int p, bool)
 specialization of conversion from string to strings
 
template<typename T >
bool from_string (T &v, const std::string &s)
 extract value from string
 
template<>
CGV_API bool from_string (std::string &v, const std::string &s)
 specialization to extract string value from string
 
time_t convert_to_time (const date_time &dt)
 
date_time convert_to_date_time (time_t ti)
 
date_time now ()
 
std::ostream & operator<< (std::ostream &os, const time &T)
 
std::ostream & operator<< (std::ostream &os, const date &D)
 
std::ostream & operator<< (std::ostream &os, const date_time &DT)
 
guid guid_from_string (const std::string &str)
 convert string to guid
 
std::string to_string (const guid &_id)
 convert guid to string
 
bool operator< (const guid &g1, const guid &g2)
 comparison operation
 
bool operator== (const guid &g1, const guid &g2)
 comparison operation
 
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
 
uint8_t from_hex (char c)
 convert from hex character
 
std::vector< uint8_t > parse_hex_bytes (const std::string &byte_str)
 parse bytes hex coded bytes
 
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 & remove (std::string &s, char c)
 remove char c from the given string s and return a reference to the same string object
 
std::string remove_copy (const std::string &s, char c)
 return a copy of the given string s with all occurences of char removed
 
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=';')
 interpret s as a list separated by sep and return the element with the given element index.
 
int 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.
 
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 s
 
bool is_date (const std::string &s, cgv::utils::date &d, const char **new_end=0)
 check and extract date from string s
 
bool is_time (const char *begin, const char *end, cgv::utils::time &t, const char **new_end=0)
 check and extract time from string token [begin, end]
 
bool is_date (const char *begin, const char *end, cgv::utils::date &d, const char **new_end=0)
 check and extract date from string token [begin, end]
 
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
 
std::string & ltrim (std::string &str, const std::string &chars="\t\n\v\f\r ")
 trim white space or other characters from start of string
 
std::string & rtrim (std::string &str, const std::string &chars="\t\n\v\f\r ")
 trim white space or other characters from end of string
 
std::string & trim (std::string &str, const std::string &chars="\t\n\v\f\r ")
 trim white space or other characters from start and end of string
 
std::string ltrim (const std::string &str, const std::string &chars="\t\n\v\f\r ")
 trim white space or other characters from start of string
 
std::string rtrim (const std::string &str, const std::string &chars="\t\n\v\f\r ")
 trim white space or other characters from end of string
 
std::string trim (const std::string &str, const std::string &chars="\t\n\v\f\r ")
 trim white space or other characters from start and end of string
 
std::string join (const std::vector< std::string >::const_iterator first, const std::vector< std::string >::const_iterator last, const std::string &sep, bool trailing_sep=false)
 joins a given range of strings, separating them by the given separator; if trailing_sep is true, also puts a separator at the end
 
std::string join (const std::vector< std::string > &strs, const std::string &sep, bool trailing_sep=false)
 joins a given list of strings, separating them by the given separator; if trailing_sep is true, also puts a separator at the end
 
std::string join (const std::vector< cgv::utils::token >::const_iterator first, const std::vector< cgv::utils::token >::const_iterator last, const std::string &sep, bool trailing_sep)
 joins a given range of tokens, separating them by the given separator; if trailing_sep is true, also puts a separator at the end
 
unsigned int levenshtein_distance (const std::string &s1, const std::string &s2)
 compute the levenshtein distance between two strings s1 and s2
 
CGV_API std::string join (const std::vector< token >::const_iterator first, const std::vector< token >::const_iterator last, const std::string &sep, bool trailing_sep=false)
 joins a given range of tokens, separating them by the given separator; if trailing_sep is true, also puts a separator 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::ostream & operator<< (std::ostream &os, const statistics &s)
 
std::string to_string (const token &t)
 convert to string
 
std::vector< std::string > to_strings (const std::vector< token >::const_iterator first, const std::vector< token >::const_iterator last)
 convert to strings
 
std::vector< std::string > to_strings (const std::vector< token > &ts)
 convert to strings
 
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
 

Variables

static const std::string base64_chars
 
const unsigned char AE = static_cast<unsigned char>(142)
 
const unsigned char ae = static_cast<unsigned char>(132)
 
const unsigned char OE = static_cast<unsigned char>(153)
 
const unsigned char oe = static_cast<unsigned char>(148)
 
const unsigned char UE = static_cast<unsigned char>(154)
 
const unsigned char ue = static_cast<unsigned char>(129)
 
const unsigned char ss = static_cast<unsigned char>(225)
 
constexpr auto S_TO_NS =1000000000LL
 
constexpr auto NS_TO_S =(1.0/double(S_TO_NS))
 

Detailed Description

namespace that holds tools that dont fit any other namespace

Enumeration Type Documentation

◆ token_type

different types that a typed_token can have

Definition at line 25 of file advanced_scan.h.

Function Documentation

◆ balanced_find_content() [1/3]

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;

Definition at line 87 of file advanced_scan.cxx.

References cgv::utils::token::begin, and skip_spaces().

◆ balanced_find_content() [2/3]

bool cgv::utils::balanced_find_content ( const std::string &  expression,
token content,
char  open_parenthesis,
char  close_parenthesis 
)
inline

Definition at line 154 of file advanced_scan.h.

◆ balanced_find_content() [3/3]

bool cgv::utils::balanced_find_content ( const token expression,
token content,
char  open_parenthesis,
char  close_parenthesis 
)
inline

Definition at line 147 of file advanced_scan.h.

◆ bite_all()

◆ convert_to_date_time()

date_time cgv::utils::convert_to_date_time ( time_t  ti)

Definition at line 46 of file date_time.cxx.

◆ convert_to_time()

time_t cgv::utils::convert_to_time ( const date_time dt)

Definition at line 32 of file date_time.cxx.

◆ cutoff_spaces()

CGV_API const char * cgv::utils::cutoff_spaces ( const char *  begin,
const char *  end 
)

return new end pointer by cutting off spaces at the end

Definition at line 690 of file scan.cxx.

References is_space().

Referenced by cgv::base::analyze_command().

◆ decode_base64()

CGV_API std::string cgv::utils::decode_base64 ( std::string const &  encoded_string)

decode a base64 encoded string

Definition at line 105 of file convert.cxx.

Referenced by cgv::render::shader_code::decode_if_base64().

◆ disable_lower_bits()

CGV_API void cgv::utils::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

Definition at line 51 of file bit_operations.cxx.

Referenced by set_bits().

◆ disable_upper_bits()

CGV_API void cgv::utils::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

Definition at line 29 of file bit_operations.cxx.

Referenced by cgv::data::packing_info::get_signed(), cgv::data::packing_info::get_unsigned(), and set_bits().

◆ enable_lower_bits()

CGV_API void cgv::utils::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

Definition at line 40 of file bit_operations.cxx.

◆ enable_upper_bits()

CGV_API void cgv::utils::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

Definition at line 17 of file bit_operations.cxx.

Referenced by cgv::data::packing_info::get_signed().

◆ encode_base64()

CGV_API std::string cgv::utils::encode_base64 ( const std::string &  s)

encode a string into base64

Definition at line 61 of file convert.cxx.

◆ enumerate_options()

void CGV_API cgv::utils::enumerate_options ( std::vector< std::string > &  options)

push back all options provided in the CGV_OPTIONS system variable

Definition at line 18 of file options.cxx.

References split_to_tokens(), and to_string().

Referenced by has_option().

◆ escape_special()

CGV_API std::string cgv::utils::escape_special ( const std::string &  s)

escapes the C++ special characters \a, \b, \f, \n, \r, \t, \v, \\', \", \\, \?

Definition at line 205 of file scan.cxx.

Referenced by cgv::reflect::debug_reflection_handler::reflect_member_void(), and cgv::data::ascii_write_reflection_handler::reflect_member_void().

◆ find_enum_index() [1/2]

CGV_API unsigned cgv::utils::find_enum_index ( const std::string &  name,
const std::vector< token > &  enum_names 
)

convert name to index

Definition at line 44 of file scan_enum.cxx.

◆ find_enum_index() [2/2]

CGV_API unsigned cgv::utils::find_enum_index ( int  value,
const std::vector< int > &  enum_values 
)

◆ find_enum_name()

CGV_API std::string cgv::utils::find_enum_name ( const std::string &  enum_declarations,
int  value 
)

lookup name of value in enum declaration

Definition at line 53 of file scan_enum.cxx.

References find_enum_index(), parse_enum_declarations(), and to_string().

◆ find_name()

CGV_API bool cgv::utils::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

Definition at line 507 of file scan.cxx.

Referenced by is_month().

◆ from_hex()

CGV_API uint8_t cgv::utils::from_hex ( char  c)

convert from hex character

Definition at line 60 of file scan.cxx.

Referenced by parse_hex_bytes().

◆ from_string() [1/3]

template<>
bool cgv::utils::from_string ( std::string &  v,
const std::string &  s 
)

specialization to extract string value from string

Definition at line 13 of file convert_string.cxx.

Referenced by cgv::gui::key_control< T >::set_void(), and cgv::gui::key_control< bool >::set_void().

◆ from_string() [2/3]

template<>
CGV_API bool cgv::utils::from_string ( std::string &  v,
const std::string &  s 
)

specialization to extract string value from string

Definition at line 13 of file convert_string.cxx.

Referenced by cgv::gui::key_control< T >::set_void(), and cgv::gui::key_control< bool >::set_void().

◆ from_string() [3/3]

template<typename T >
bool cgv::utils::from_string ( T &  v,
const std::string &  s 
)

extract value from string

Definition at line 45 of file convert_string.h.

◆ get_element()

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.

Definition at line 301 of file scan.cxx.

Referenced by vr_emulator::stream_stats().

◆ get_element_index()

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.

Definition at line 323 of file scan.cxx.

Referenced by is_element().

◆ guid_from_string()

CGV_API guid cgv::utils::guid_from_string ( const std::string &  str)

convert string to guid

Definition at line 5 of file guid.cxx.

◆ has_option()

bool CGV_API cgv::utils::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

Definition at line 8 of file options.cxx.

References enumerate_options(), and to_upper().

Referenced by vr_test::init().

◆ interpret_special()

CGV_API std::string cgv::utils::interpret_special ( const std::string &  s)

interprets the C++ special characters \a, \b, \f, \n, \r, \t, \v, \\', \", \\, \?, \ooo, \xhh

Definition at line 227 of file scan.cxx.

References is_digit(), and to_lower().

Referenced by cgv::data::ascii_read_reflection_handler::reflect_member_void().

◆ is_base64()

static bool cgv::utils::is_base64 ( unsigned char  c)
inlinestatic

Definition at line 57 of file convert.cxx.

◆ is_bit_set()

CGV_API bool cgv::utils::is_bit_set ( unsigned int  bit_idx,
unsigned int  bit_field 
)

check if a bit of a bit field is set

Definition at line 7 of file bit_operations.cxx.

Referenced by cgv::data::packing_info::get_signed().

◆ is_date() [1/2]

CGV_API bool cgv::utils::is_date ( const char *  begin,
const char *  end,
cgv::utils::date d,
const char **  new_end 
)

check and extract date from string token [begin, end]

Definition at line 642 of file scan.cxx.

References is_date().

◆ is_date() [2/2]

CGV_API bool cgv::utils::is_date ( const std::string &  s,
cgv::utils::date d,
const char **  new_end 
)

check and extract date from string s

Definition at line 591 of file scan.cxx.

References is_digit(), is_integer(), is_month(), is_url_special(), and is_year().

Referenced by is_date().

◆ is_digit()

CGV_API bool cgv::utils::is_digit ( char  c)

check if char is a digit

Definition at line 20 of file scan.cxx.

Referenced by interpret_special(), is_date(), is_integer(), is_time(), gui_config_file_observer::multi_observe(), and cgv::base::base::multi_set().

◆ is_double() [1/2]

CGV_API bool cgv::utils::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.

Definition at line 426 of file scan.cxx.

Referenced by is_double(), cgv::media::mesh::obj_reader_generic< T >::parse_vec2(), and cgv::media::mesh::obj_reader_generic< T >::parse_vec3().

◆ is_double() [2/2]

CGV_API bool cgv::utils::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.

Definition at line 484 of file scan.cxx.

References is_double().

◆ is_element() [1/2]

◆ is_element() [2/2]

CGV_API bool cgv::utils::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

Definition at line 296 of file scan.cxx.

References get_element_index().

◆ is_integer() [1/2]

CGV_API bool cgv::utils::is_integer ( const char *  begin,
const char *  end,
int &  value 
)

◆ is_integer() [2/2]

CGV_API bool cgv::utils::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.

Definition at line 421 of file scan.cxx.

References is_integer().

◆ is_letter()

CGV_API bool cgv::utils::is_letter ( char  c)

check if char is a letter

Definition at line 24 of file scan.cxx.

References to_lower().

◆ is_month() [1/2]

CGV_API bool cgv::utils::is_month ( const char *  begin,
const char *  end,
unsigned char &  month 
)

check and extract month from string token [begin, end]

Definition at line 520 of file scan.cxx.

References find_name(), is_integer(), replace_special(), and to_lower().

Referenced by is_date(), and is_month().

◆ is_month() [2/2]

CGV_API bool cgv::utils::is_month ( const std::string &  s,
unsigned char &  month 
)

check and extract month from string s

Definition at line 546 of file scan.cxx.

References is_month().

◆ is_space()

CGV_API bool cgv::utils::is_space ( char  c)

◆ is_time() [1/2]

CGV_API bool cgv::utils::is_time ( const char *  begin,
const char *  end,
cgv::utils::time t,
const char **  new_end 
)

check and extract time from string token [begin, end]

Definition at line 631 of file scan.cxx.

References is_time().

◆ is_time() [2/2]

CGV_API bool cgv::utils::is_time ( const std::string &  s,
cgv::utils::time t,
const char **  new_end 
)

check and extract time from string s

Definition at line 551 of file scan.cxx.

References is_digit(), is_integer(), and is_url_special().

Referenced by is_time().

◆ is_url() [1/2]

CGV_API bool cgv::utils::is_url ( const char *  begin,
const char *  end,
const char **  new_end 
)

check and extract end of valid url from string token [begin, end]

Definition at line 672 of file scan.cxx.

References is_url().

◆ is_url() [2/2]

CGV_API bool cgv::utils::is_url ( const std::string &  s,
const char **  end 
)

check and extract end of valid url from string s

Definition at line 653 of file scan.cxx.

References is_url_special().

Referenced by is_url().

◆ is_url_special()

CGV_API bool cgv::utils::is_url_special ( char  c)

check if char is a special character from an url

Definition at line 16 of file scan.cxx.

Referenced by is_date(), is_time(), and is_url().

◆ is_year() [1/2]

CGV_API bool cgv::utils::is_year ( const char *  begin,
const char *  end,
unsigned short &  year,
bool  short_allowed 
)

check and extract year from string token [begin, end]

Definition at line 490 of file scan.cxx.

References is_integer().

Referenced by is_date(), and is_year().

◆ is_year() [2/2]

CGV_API bool cgv::utils::is_year ( const std::string &  s,
unsigned short &  year,
bool  short_allowed 
)

check and extract year from string s

Definition at line 502 of file scan.cxx.

References is_year().

◆ join() [1/4]

std::string cgv::utils::join ( const std::vector< cgv::utils::token >::const_iterator  first,
const std::vector< cgv::utils::token >::const_iterator  last,
const std::string &  sep,
bool  trailing_sep 
)

joins a given range of tokens, separating them by the given separator; if trailing_sep is true, also puts a separator at the end

Definition at line 753 of file scan.cxx.

References join(), and to_strings().

◆ join() [2/4]

CGV_API std::string cgv::utils::join ( const std::vector< std::string > &  strs,
const std::string &  sep,
bool  trailing_sep 
)

joins a given list of strings, separating them by the given separator; if trailing_sep is true, also puts a separator at the end

Definition at line 748 of file scan.cxx.

References join().

◆ join() [3/4]

CGV_API std::string cgv::utils::join ( const std::vector< std::string >::const_iterator  first,
const std::vector< std::string >::const_iterator  last,
const std::string &  sep,
bool  trailing_sep 
)

joins a given range of strings, separating them by the given separator; if trailing_sep is true, also puts a separator at the end

Definition at line 733 of file scan.cxx.

Referenced by cgv::gui::file_helper::add_multi_filter(), join(), and join().

◆ join() [4/4]

CGV_API std::string cgv::utils::join ( const std::vector< token >::const_iterator  first,
const std::vector< token >::const_iterator  last,
const std::string &  sep,
bool  trailing_sep = false 
)
extern

joins a given range of tokens, separating them by the given separator; if trailing_sep is true, also puts a separator at the end

Definition at line 753 of file scan.cxx.

References join(), and to_strings().

◆ levenshtein_distance()

CGV_API unsigned int cgv::utils::levenshtein_distance ( const std::string &  s1,
const std::string &  s2 
)

compute the levenshtein distance between two strings s1 and s2

Definition at line 759 of file scan.cxx.

◆ ltrim() [1/2]

CGV_API std::string cgv::utils::ltrim ( const std::string &  str,
const std::string &  chars 
)

trim white space or other characters from start of string

Definition at line 714 of file scan.cxx.

◆ ltrim() [2/2]

CGV_API std::string & cgv::utils::ltrim ( std::string &  str,
const std::string &  chars 
)

trim white space or other characters from start of string

Definition at line 697 of file scan.cxx.

Referenced by trim(), and trim().

◆ now()

CGV_API date_time cgv::utils::now ( )

Definition at line 70 of file date_time.cxx.

◆ operator<()

CGV_API bool cgv::utils::operator< ( const guid g1,
const guid g2 
)

comparison operation

Definition at line 19 of file guid.cxx.

◆ operator<<() [1/5]

CGV_API std::ostream & cgv::utils::operator<< ( std::ostream &  os,
const date D 
)

Definition at line 80 of file date_time.cxx.

◆ operator<<() [2/5]

CGV_API std::ostream & cgv::utils::operator<< ( std::ostream &  os,
const date_time DT 
)

Definition at line 85 of file date_time.cxx.

◆ operator<<() [3/5]

CGV_API std::ostream & cgv::utils::operator<< ( std::ostream &  os,
const statistics s 
)

Definition at line 72 of file statistics.cxx.

◆ operator<<() [4/5]

CGV_API std::ostream & cgv::utils::operator<< ( std::ostream &  os,
const time T 
)

Definition at line 75 of file date_time.cxx.

◆ operator<<() [5/5]

std::ostream & cgv::utils::operator<< ( std::ostream &  os,
const token t 
)
inline

stream out operator

Definition at line 72 of file token.h.

References cgv::utils::token::begin, cgv::utils::token::empty(), and cgv::utils::token::get_length().

◆ operator==()

CGV_API bool cgv::utils::operator== ( const guid g1,
const guid g2 
)

comparison operation

Definition at line 27 of file guid.cxx.

◆ parse_enum_declarations()

CGV_API void cgv::utils::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

Definition at line 10 of file scan_enum.cxx.

References is_integer(), and cgv::utils::tokenizer::set_ws().

Referenced by find_enum_name().

◆ parse_hex_bytes()

CGV_API std::vector< uint8_t > cgv::utils::parse_hex_bytes ( const std::string &  byte_str)

parse bytes hex coded bytes

Definition at line 91 of file scan.cxx.

References from_hex().

◆ remove()

CGV_API std::string & cgv::utils::remove ( std::string &  s,
char  c 
)

remove char c from the given string s and return a reference to the same string object

Definition at line 127 of file scan.cxx.

◆ remove_copy()

CGV_API std::string cgv::utils::remove_copy ( const std::string &  s,
char  c 
)

return a copy of the given string s with all occurences of char removed

Definition at line 134 of file scan.cxx.

◆ replace() [1/2]

◆ replace() [2/2]

CGV_API unsigned int cgv::utils::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

Definition at line 171 of file scan.cxx.

◆ replace_special()

CGV_API std::string cgv::utils::replace_special ( const std::string &  _s)

replaces the german special characters ä,ö,ü,ß,Ä,Ö,Ü

Definition at line 141 of file scan.cxx.

Referenced by is_month().

◆ rtrim() [1/2]

CGV_API std::string cgv::utils::rtrim ( const std::string &  str,
const std::string &  chars 
)

trim white space or other characters from end of string

Definition at line 721 of file scan.cxx.

◆ rtrim() [2/2]

CGV_API std::string & cgv::utils::rtrim ( std::string &  str,
const std::string &  chars 
)

trim white space or other characters from end of string

Definition at line 703 of file scan.cxx.

Referenced by trim(), and trim().

◆ set_bits()

CGV_API void cgv::utils::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

Definition at line 64 of file bit_operations.cxx.

References disable_lower_bits(), and disable_upper_bits().

Referenced by cgv::data::packing_info::set_signed(), and cgv::data::packing_info::set_unsigned().

◆ skip_spaces()

CGV_API const char * cgv::utils::skip_spaces ( const char *  begin,
const char *  end 
)

return new start pointer by skipping spaces at begin

Definition at line 683 of file scan.cxx.

References is_space().

Referenced by cgv::base::analyze_command(), balanced_find_content(), and cgv::ppp::command_token::is_empty().

◆ split_to_lines() [1/3]

CGV_API void cgv::utils::split_to_lines ( const char *  begin,
const char *  end,
std::vector< line > &  lines,
bool  truncate_trailing_spaces = true 
)

◆ split_to_lines() [2/3]

void cgv::utils::split_to_lines ( const std::string &  s,
std::vector< line > &  lines,
bool  truncate_trailing_spaces = true 
)
inline

text range given as string

Definition at line 126 of file advanced_scan.h.

References split_to_lines().

◆ split_to_lines() [3/3]

void cgv::utils::split_to_lines ( const token tok,
std::vector< line > &  lines,
bool  truncate_trailing_spaces = true 
)
inline

text range given as token

Definition at line 119 of file advanced_scan.h.

References cgv::utils::token::begin, and split_to_lines().

◆ split_to_tokens() [1/3]

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.

Definition at line 6 of file advanced_scan.cxx.

References is_element().

Referenced by enumerate_options(), cgv::render::shader_program::extract_instances(), cgv::render::shader_code::set_vertex_attrib_locations(), split_to_tokens(), and split_to_tokens().

◆ split_to_tokens() [2/3]

void cgv::utils::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 
)
inline

text range given as string

Definition at line 100 of file advanced_scan.h.

References split_to_tokens().

◆ split_to_tokens() [3/3]

void cgv::utils::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 
)
inline

text range given as token

Definition at line 84 of file advanced_scan.h.

References cgv::utils::token::begin, and split_to_tokens().

◆ str2wstr()

CGV_API std::wstring cgv::utils::str2wstr ( const std::string &  s)

convert a 8-bit string to a 16-bit string

Definition at line 11 of file convert.cxx.

Referenced by cgv::data::ascii_write_reflection_handler::ascii_write_reflection_handler(), and cgv::type::variant< T >::set().

◆ strip_cpp_comments()

CGV_API std::string cgv::utils::strip_cpp_comments ( const std::string &  source,
bool  correct_new_lines = true 
)

remove cpp-style comments from string

Parameters
sourcesource string from which to strip cpp style comments
correct_new_lineswhether to replace two character new lines with single character new lines
Returns
source string without any comments

Definition at line 115 of file advanced_scan.cxx.

Referenced by cgv::render::shader_code::set_vertex_attrib_locations().

◆ to_hex()

CGV_API std::string cgv::utils::to_hex ( uint8_t  v,
bool  use_upper_case 
)

convert to hex

Definition at line 52 of file scan.cxx.

◆ to_lower() [1/2]

◆ to_lower() [2/2]

CGV_API std::string cgv::utils::to_lower ( const std::string &  _s)

convert string to lower case

Definition at line 98 of file scan.cxx.

References to_lower().

◆ to_string() [1/6]

CGV_API std::string cgv::utils::to_string ( const guid id)

convert guid to string

Definition at line 12 of file guid.cxx.

References to_string().

◆ to_string() [2/6]

template<>
std::string cgv::utils::to_string ( const std::string &  v,
unsigned int  w,
unsigned int  p,
bool   
)

specialization of conversion from string to strings

Definition at line 7 of file convert_string.cxx.

References to_string().

Referenced by cgv::gui::provider::add_tree_node(), cgv::base::analyze_command(), cgv::render::shader_program::attach_program(), cgv::gui::provider::begin_tree_node_void(), cgv::render::shader_program::build_program(), cgv::render::shader_program::collect_program(), cgv::render::mesh_render_info::configure_vbos(), vr_emulator::create_controller_gui(), vr_test::create_gui(), cgv::render::texture::deduce_file_names(), enumerate_options(), cgv::ppp::expression_processor::evaluate(), cgv::render::shader_program::extract_instances(), cgv::render::extract_mesh(), find_enum_name(), cgv::render::shader_code::get_last_error(), cgv::ppp::variant::get_str(), config_view< T >::get_user_data(), cgv::render::context::get_window_matrix(), cgv::reflect::reflection_handler::group_traversal_name(), cgv::base::base::is_property(), cgv::base::load_plugin(), gui_config_file_observer::multi_observe(), cgv::base::base::multi_set(), cgv::utils::token::operator!=(), cgv::utils::token::operator!=(), cgv::utils::token::operator==(), cgv::utils::token::operator==(), cgv::gui::base_provider_generator::parse_gui_file(), cgv::media::mesh::obj_reader_base::parse_obj(), cgv::plot::plot2d::plot2d(), cgv::plot::plot3d::plot3d(), cgv::gui::question(), cgv::render::gl::gl_context::read_frame_buffer(), cgv::media::mesh::obj_reader_base::read_mtl(), cgv::base::ref_data_path_list(), cgv::base::property_declaration_reflection_handler::reflect_group_begin(), cgv::reflect::debug_reflection_handler::reflect_group_begin(), cgv::render::shader_code::resolve_includes(), cgv::type::variant< T >::set(), cgv::data::component_format::set_component_format(), cgv::render::context::set_current_lights(), cgv::data::data_format::set_data_format(), cgv::render::shader_code::set_vertex_attrib_locations(), cgv::ppp::command_token::split_off_from(), to_string(), to_string(), to_string(), to_string(), to_string(), and to_strings().

◆ to_string() [3/6]

template<>
CGV_API std::string cgv::utils::to_string ( const std::string &  v,
unsigned int  w,
unsigned int  p,
bool   
)

specialization of conversion from string to strings

Definition at line 7 of file convert_string.cxx.

References to_string().

Referenced by cgv::gui::provider::add_tree_node(), cgv::base::analyze_command(), cgv::render::shader_program::attach_program(), cgv::gui::provider::begin_tree_node_void(), cgv::render::shader_program::build_program(), cgv::render::shader_program::collect_program(), cgv::render::mesh_render_info::configure_vbos(), vr_emulator::create_controller_gui(), vr_test::create_gui(), cgv::render::texture::deduce_file_names(), enumerate_options(), cgv::ppp::expression_processor::evaluate(), cgv::render::shader_program::extract_instances(), cgv::render::extract_mesh(), find_enum_name(), cgv::render::shader_code::get_last_error(), cgv::ppp::variant::get_str(), config_view< T >::get_user_data(), cgv::render::context::get_window_matrix(), cgv::reflect::reflection_handler::group_traversal_name(), cgv::base::base::is_property(), cgv::base::load_plugin(), gui_config_file_observer::multi_observe(), cgv::base::base::multi_set(), cgv::utils::token::operator!=(), cgv::utils::token::operator!=(), cgv::utils::token::operator==(), cgv::utils::token::operator==(), cgv::gui::base_provider_generator::parse_gui_file(), cgv::media::mesh::obj_reader_base::parse_obj(), cgv::plot::plot2d::plot2d(), cgv::plot::plot3d::plot3d(), cgv::gui::question(), cgv::render::gl::gl_context::read_frame_buffer(), cgv::media::mesh::obj_reader_base::read_mtl(), cgv::base::ref_data_path_list(), cgv::base::property_declaration_reflection_handler::reflect_group_begin(), cgv::reflect::debug_reflection_handler::reflect_group_begin(), cgv::render::shader_code::resolve_includes(), cgv::type::variant< T >::set(), cgv::data::component_format::set_component_format(), cgv::render::context::set_current_lights(), cgv::data::data_format::set_data_format(), cgv::render::shader_code::set_vertex_attrib_locations(), cgv::ppp::command_token::split_off_from(), to_string(), to_string(), to_string(), to_string(), to_string(), and to_strings().

◆ to_string() [4/6]

template<typename T >
std::string cgv::utils::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

Definition at line 33 of file convert_string.h.

References to_string().

◆ to_string() [5/6]

template<typename T >
std::string cgv::utils::to_string ( const T &  v,
unsigned int  w = -1,
unsigned int  p = -1,
bool  fixed = false 
)

convert a numeric type T into string of width w and precision p

Definition at line 18 of file convert_string.h.

References to_string().

◆ to_string() [6/6]

std::string cgv::utils::to_string ( const token t)
inline

convert to string

Definition at line 60 of file token.h.

References cgv::utils::token::begin, cgv::utils::token::empty(), cgv::utils::token::get_length(), and to_string().

◆ to_strings() [1/2]

std::vector< std::string > cgv::utils::to_strings ( const std::vector< token > &  ts)
inline

convert to strings

Definition at line 68 of file token.h.

References to_strings().

◆ to_strings() [2/2]

std::vector< std::string > cgv::utils::to_strings ( const std::vector< token >::const_iterator  first,
const std::vector< token >::const_iterator  last 
)
inline

convert to strings

Definition at line 62 of file token.h.

References to_string().

Referenced by join(), and to_strings().

◆ to_upper() [1/2]

◆ to_upper() [2/2]

CGV_API std::string cgv::utils::to_upper ( const std::string &  _s)

convert string to upper case

Definition at line 119 of file scan.cxx.

References to_upper().

◆ trim() [1/2]

CGV_API std::string cgv::utils::trim ( const std::string &  str,
const std::string &  chars 
)

trim white space or other characters from start and end of string

Definition at line 728 of file scan.cxx.

References ltrim(), and rtrim().

◆ trim() [2/2]

CGV_API std::string & cgv::utils::trim ( std::string &  str,
const std::string &  chars 
)

trim white space or other characters from start and end of string

Definition at line 709 of file scan.cxx.

References ltrim(), and rtrim().

Referenced by cgv::gui::help_menu_entry::on_register(), and cgv::render::shader_code::resolve_includes().

◆ wstr2str()

CGV_API std::string cgv::utils::wstr2str ( const std::wstring &  ws)

convert a 16-bit string to a 8-bit string

Definition at line 26 of file convert.cxx.

Referenced by cgv::type::variant< T >::get().

Variable Documentation

◆ AE

const unsigned char cgv::utils::AE = static_cast<unsigned char>(142)

Definition at line 31 of file scan.cxx.

◆ ae

const unsigned char cgv::utils::ae = static_cast<unsigned char>(132)

Definition at line 32 of file scan.cxx.

◆ base64_chars

const std::string cgv::utils::base64_chars
static
Initial value:
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/"

Definition at line 51 of file convert.cxx.

◆ NS_TO_S

constexpr auto cgv::utils::NS_TO_S =(1.0/double(S_TO_NS))
constexpr

Definition at line 20 of file stopwatch.cxx.

◆ OE

const unsigned char cgv::utils::OE = static_cast<unsigned char>(153)

Definition at line 33 of file scan.cxx.

◆ oe

const unsigned char cgv::utils::oe = static_cast<unsigned char>(148)

Definition at line 34 of file scan.cxx.

◆ S_TO_NS

constexpr auto cgv::utils::S_TO_NS =1000000000LL
constexpr

Definition at line 19 of file stopwatch.cxx.

◆ ss

const unsigned char cgv::utils::ss = static_cast<unsigned char>(225)

Definition at line 37 of file scan.cxx.

◆ UE

const unsigned char cgv::utils::UE = static_cast<unsigned char>(154)

Definition at line 35 of file scan.cxx.

◆ ue

const unsigned char cgv::utils::ue = static_cast<unsigned char>(129)

Definition at line 36 of file scan.cxx.