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 condense_to_line(std::string str);
38extern CGV_API std::string join(const std::vector<std::string>& strs, const std::string& sep, bool trailing_sep = false);
40extern CGV_API bool is_space(char c);
42extern CGV_API bool is_url_special(char c);
44extern CGV_API bool is_digit(char c);
46extern CGV_API bool is_letter(char c);
48extern CGV_API char to_lower(char c);
50extern CGV_API std::string to_hex(uint8_t v, bool use_upper_case = true);
52extern CGV_API uint8_t from_hex(char c);
54extern CGV_API std::vector<uint8_t> parse_hex_bytes(const std::string& byte_str);
56extern CGV_API std::string to_lower(const std::string& _s);
58extern CGV_API char to_upper(char c);
60extern CGV_API std::string to_upper(const std::string& _s);
62extern CGV_API std::string to_snake_case(const std::string& _s, bool separate_at_upper_case = false);
64extern CGV_API std::string snake_case_to_camel_case(const std::string& _s);
66extern CGV_API std::string snake_case_to_kebab_case(const std::string& _s);
68extern CGV_API std::string snake_case_to_pascal_case(const std::string& _s);
70extern CGV_API std::string snake_case_to_sentence_case(const std::string& _s);
72extern CGV_API std::string snake_case_to_capitalized_case(const std::string& _s);
74extern CGV_API std::string& remove(std::string& s, char c);
76extern CGV_API std::string remove_copy(const std::string& s, char c);
78extern CGV_API std::string replace_special(const std::string& _s);
80extern CGV_API unsigned int replace(std::string& _s, char c1, char c2);
82extern CGV_API unsigned int replace(std::string& _s, const std::string& s1, const std::string& s2);
84extern CGV_API std::string interpret_special(const std::string& s);
86extern CGV_API std::string escape_special(const std::string& s);
88extern CGV_API bool find_name(const std::string& s, const char* names[], int& idx);
90extern CGV_API bool is_element(char c, const std::string& s);
92extern CGV_API bool is_element(const std::string& e, const std::string& s, char sep = ';');
95extern CGV_API int get_element_index(const std::string& e, const std::string& s, char sep = ';');
97extern CGV_API std::string get_element(const std::string& s, int element_index, char sep = ';');
99extern CGV_API bool is_integer(const char* begin, const char* end, int& value);
101extern CGV_API bool is_integer(const std::string& s, int& value);
103extern CGV_API bool is_double(const char* begin, const char* end, double& value);
105extern CGV_API bool is_double(const std::string& s, double& value);
107extern CGV_API bool is_year(const char* begin, const char* end, unsigned short& year, bool short_allowed = true);
109extern CGV_API bool is_year(const std::string& s, unsigned short& year, bool short_allowed = true);
111extern CGV_API bool is_day(const char* begin, const char* end, unsigned char& day);
113extern CGV_API bool is_day(const std::string& s, unsigned char& day);
115extern CGV_API bool is_month(const char* begin, const char* end, unsigned char& month);
117extern CGV_API bool is_month(const std::string& s, unsigned char& month);
119extern CGV_API bool is_time(const char* begin, const char* end, cgv::utils::time& t, const char **new_end = 0);
121extern CGV_API bool is_time(const std::string& s, cgv::utils::time& t, const char** new_end = 0);
123extern CGV_API bool is_date(const char* begin, const char* end, cgv::utils::date& d, const char **new_end = 0);
125extern CGV_API bool is_date(const std::string& s, cgv::utils::date& d, const char **new_end = 0);
127extern CGV_API bool is_url(const char* begin, const char* end, const char** new_end = 0);
129extern CGV_API bool is_url(const std::string& s, const char** end = 0);
131extern CGV_API unsigned int levenshtein_distance(const std::string& s1, const std::string& s2);
132
133 }
134}
135
136#include <cgv/config/lib_end.h>
bool is_digit(char c)
check if char is a digit
Definition scan.cxx:20
std::string join(const InputIt first, const InputIt last, const std::string &separator, bool trailing_separator=false)
Concatenate elements in the range [first, last) to a std::string.
Definition algorithm.h:148
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:241
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:383
bool is_url(const std::string &s, const char **end)
check and extract end of valid url from string s
Definition scan.cxx:735
std::string condense_to_line(std::string str)
replace all newlines and white spaces with single spaces
Definition scan.cxx:815
std::string & rtrim(std::string &str, const std::string &chars)
trim white space or other characters from end of string
Definition scan.cxx:785
std::string interpret_special(const std::string &s)
interprets the C++ special characters \a, \b, \f, \n, \r, \t, \v, \\', \", \\, \?,...
Definition scan.cxx:309
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:449
std::string escape_special(const std::string &s)
escapes the C++ special characters \a, \b, \f, \n, \r, \t, \v, \\', \", \\, \?
Definition scan.cxx:287
bool is_month(const char *begin, const char *end, unsigned char &month)
check and extract month from string token [begin, end]
Definition scan.cxx:602
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:791
std::string snake_case_to_pascal_case(const std::string &_s)
convert string from "snake_case" to "PascalCase"
Definition scan.cxx:177
std::string to_snake_case(const std::string &_s, bool separate_at_upper_case)
convert string to "snake_case" by trimming leading and trailing whitespaces and underscores,...
Definition scan.cxx:127
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:572
std::string & ltrim(std::string &str, const std::string &chars)
trim white space or other characters from start of string
Definition scan.cxx:779
bool is_url_special(char c)
check if char is a special character from an url
Definition scan.cxx:16
std::string snake_case_to_camel_case(const std::string &_s)
convert string from "snake_case" to "camelCase"
Definition scan.cxx:154
std::string snake_case_to_capitalized_case(const std::string &_s)
convert string from "snake_case" to "Capitalized Case"
Definition scan.cxx:192
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:673
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:216
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:589
std::string replace_special(const std::string &_s)
replaces the german special characters ä,ö,ü,ß,Ä,Ö,Ü
Definition scan.cxx:223
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:508
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:633
bool is_element(char c, const std::string &s)
check if char c arises in string s
Definition scan.cxx:373
const char * cutoff_spaces(const char *begin, const char *end)
return new end pointer by cutting off spaces at the end
Definition scan.cxx:772
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:209
std::string snake_case_to_kebab_case(const std::string &_s)
convert string from "snake_case" to "kebab-case"
Definition scan.cxx:169
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:405
const char * skip_spaces(const char *begin, const char *end)
return new start pointer by skipping spaces at begin
Definition scan.cxx:765
std::vector< uint8_t > parse_hex_bytes(const std::string &byte_str)
parse bytes hex coded bytes
Definition scan.cxx:91
std::string snake_case_to_sentence_case(const std::string &_s)
convert string from "snake_case" to "Sentence case"
Definition scan.cxx:184
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:839
the cgv namespace
Definition print.h:11