cgv
Loading...
Searching...
No Matches
scan.h
Go to the documentation of this file.
1#pragma once
2
7#include <cstdint>
8#include <string>
9#include <vector>
10
11#include "date_time.h"
12#include "token.h"
13
14#include "lib_begin.h"
15
16namespace cgv {
17 namespace utils {
18
20extern CGV_API const char* skip_spaces(const char* begin, const char* end);
22extern CGV_API const char* cutoff_spaces(const char* begin, const char* end);
24extern CGV_API std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
26extern CGV_API std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
28extern CGV_API std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ");
30extern CGV_API std::string ltrim(const std::string& str, const std::string& chars = "\t\n\v\f\r ");
32extern CGV_API std::string rtrim(const std::string& str, const std::string& chars = "\t\n\v\f\r ");
34extern CGV_API std::string trim(const std::string& str, const std::string& chars = "\t\n\v\f\r ");
36extern CGV_API 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);
38extern CGV_API std::string join(const std::vector<std::string>&strs, const std::string & sep, bool trailing_sep = false);
40extern 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);
42extern CGV_API bool is_space(char c);
44extern CGV_API bool is_url_special(char c);
46extern CGV_API bool is_digit(char c);
48extern CGV_API bool is_letter(char c);
50extern CGV_API char to_lower(char c);
52extern CGV_API std::string to_hex(uint8_t v, bool use_upper_case = true);
54extern CGV_API uint8_t from_hex(char c);
56extern CGV_API std::vector<uint8_t> parse_hex_bytes(const std::string& byte_str);
58extern CGV_API std::string to_lower(const std::string& _s);
60extern CGV_API char to_upper(char c);
62extern CGV_API std::string to_upper(const std::string& _s);
64extern CGV_API std::string& remove(std::string& s, char c);
66extern CGV_API std::string remove_copy(const std::string& s, char c);
68extern CGV_API std::string replace_special(const std::string& _s);
70extern CGV_API unsigned int replace(std::string& _s, char c1, char c2);
72extern CGV_API unsigned int replace(std::string& _s, const std::string& s1, const std::string& s2);
74extern CGV_API std::string interpret_special(const std::string& s);
76extern CGV_API std::string escape_special(const std::string& s);
78extern CGV_API bool find_name(const std::string& s, const char* names[], int& idx);
80extern CGV_API bool is_element(char c, const std::string& s);
82extern CGV_API bool is_element(const std::string& e, const std::string& s, char sep = ';');
85extern CGV_API int get_element_index(const std::string& e, const std::string& s, char sep = ';');
87extern CGV_API std::string get_element(const std::string& s, int element_index, char sep = ';');
89extern CGV_API bool is_integer(const char* begin, const char* end, int& value);
91extern CGV_API bool is_integer(const std::string& s, int& value);
93extern CGV_API bool is_double(const char* begin, const char* end, double& value);
95extern CGV_API bool is_double(const std::string& s, double& value);
97extern CGV_API bool is_year(const char* begin, const char* end, unsigned short& year, bool short_allowed = true);
99extern CGV_API bool is_year(const std::string& s, unsigned short& year, bool short_allowed = true);
101extern CGV_API bool is_day(const char* begin, const char* end, unsigned char& day);
103extern CGV_API bool is_day(const std::string& s, unsigned char& day);
105extern CGV_API bool is_month(const char* begin, const char* end, unsigned char& month);
107extern CGV_API bool is_month(const std::string& s, unsigned char& month);
109extern CGV_API bool is_time(const char* begin, const char* end, cgv::utils::time& t, const char **new_end = 0);
111extern CGV_API bool is_time(const std::string& s, cgv::utils::time& t, const char** new_end = 0);
113extern CGV_API bool is_date(const char* begin, const char* end, cgv::utils::date& d, const char **new_end = 0);
115extern CGV_API bool is_date(const std::string& s, cgv::utils::date& d, const char **new_end = 0);
117extern CGV_API bool is_url(const char* begin, const char* end, const char** new_end = 0);
119extern CGV_API bool is_url(const std::string& s, const char** end = 0);
121extern CGV_API unsigned int levenshtein_distance(const std::string& s1, const std::string& s2);
122
123 }
124}
125
126#include <cgv/config/lib_end.h>
bool is_digit(char c)
check if char is a digit
Definition scan.cxx:20
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
Definition scan.cxx:159
std::string to_hex(uint8_t v, bool use_upper_case)
convert to hex
Definition scan.cxx:52
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.
Definition scan.cxx:301
bool is_url(const std::string &s, const char **end)
check and extract end of valid url from string s
Definition scan.cxx:653
std::string & rtrim(std::string &str, const std::string &chars)
trim white space or other characters from end of string
Definition scan.cxx:703
std::string interpret_special(const std::string &s)
interprets the C++ special characters \a, \b, \f, \n, \r, \t, \v, \\', \", \\, \?,...
Definition scan.cxx:227
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 r...
Definition scan.cxx:367
std::string escape_special(const std::string &s)
escapes the C++ special characters \a, \b, \f, \n, \r, \t, \v, \\', \", \\, \?
Definition scan.cxx:205
bool is_month(const char *begin, const char *end, unsigned char &month)
check and extract month from string token [begin, end]
Definition scan.cxx:520
std::string & trim(std::string &str, const std::string &chars)
trim white space or other characters from start and end of string
Definition scan.cxx:709
bool is_year(const char *begin, const char *end, unsigned short &year, bool short_allowed)
check and extract year from string token [begin, end]
Definition scan.cxx:490
std::string & ltrim(std::string &str, const std::string &chars)
trim white space or other characters from start of string
Definition scan.cxx:697
bool is_url_special(char c)
check if char is a special character from an url
Definition scan.cxx:16
char to_lower(char c)
convert char to lower case
Definition scan.cxx:39
bool is_date(const std::string &s, cgv::utils::date &d, const char **new_end)
check and extract date from string s
Definition scan.cxx:591
char to_upper(char c)
convert char to upper case
Definition scan.cxx:106
std::string remove_copy(const std::string &s, char c)
return a copy of the given string s with all occurences of char removed
Definition scan.cxx:134
bool is_space(char c)
check if char is a whitespace
Definition scan.cxx:12
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...
Definition scan.cxx:507
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)
joins a given range of strings, separating them by the given separator; if trailing_sep is true,...
Definition scan.cxx:733
std::string replace_special(const std::string &_s)
replaces the german special characters ä,ö,ü,ß,Ä,Ö,Ü
Definition scan.cxx:141
CGV_API bool is_day(const char *begin, const char *end, unsigned char &day)
check and extract day from string token [begin, end]
bool is_letter(char c)
check if char is a letter
Definition scan.cxx:24
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 ref...
Definition scan.cxx:426
bool is_time(const std::string &s, cgv::utils::time &t, const char **new_end)
check and extract time from string s
Definition scan.cxx:551
bool is_element(char c, const std::string &s)
check if char c arises in string s
Definition scan.cxx:291
const char * cutoff_spaces(const char *begin, const char *end)
return new end pointer by cutting off spaces at the end
Definition scan.cxx:690
uint8_t from_hex(char c)
convert from hex character
Definition scan.cxx:60
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
Definition scan.cxx:127
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 r...
Definition scan.cxx:323
const char * skip_spaces(const char *begin, const char *end)
return new start pointer by skipping spaces at begin
Definition scan.cxx:683
std::vector< uint8_t > parse_hex_bytes(const std::string &byte_str)
parse bytes hex coded bytes
Definition scan.cxx:91
unsigned int levenshtein_distance(const std::string &s1, const std::string &s2)
compute the levenshtein distance between two strings s1 and s2
Definition scan.cxx:759
the cgv namespace
Definition print.h:11