GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Util.h
Go to the documentation of this file.
1
2#ifndef __GCW_UTIL_H___
3#define __GCW_UTIL_H___
4
5#include <string>
6#include <vector>
7
8#include <Wt/WItemDelegate.h>
9#include <Wt/WTemplate.h>
10
11namespace GCW {
12
13std::string makeFileName( const std::string & value );
14
15/*!
16** \brief Check if a File or Folder exists
17**
18**
19*/
20bool fileExists( const std::string & fileName );
21
22/*!
23** \brief Execute a system command
24**
25** This runs a command in the console and returns the result code.
26**
27*/
28int system_command( const std::string & cmd, bool show = false );
29
30/*!
31** \brief File Listing
32**
33** This procedure will scan a folder and return a list of all the files
34** in it.
35*/
36std::vector<std::string> fileList( const std::string & folder );
37
38/*!
39** \brief Find File
40**
41** This scans a directory folder and returns a list containing
42** the full file-name of all the files that matche the value.
43**
44*/
45std::vector<std::string> findFiles( const std::string & folder, const std::string & match );
46
47/*!
48** \brief Convert a String to an Integer
49**
50*/
51int stoi( const std::string & value );
52
53/*!
54** \brief Convert an Integer to a String
55**
56*/
57std::string itos( int value );
58
59/*!
60** \brief Convert a String to Float
61**
62*/
63double stof( const std::string & value );
64
65/*!
66** \brief Convert a Float to String with decimal precision
67**
68*/
69std::string ftos( double value, int decimals = 2 );
70std::string ftos( double value, const std::string & suffix, int decimals = 2 );
71std::string ftos( const std::string & prefix, double value, int decimals = 2 );
72std::string ftom( double value, int decimals = 2 );
73std::string ftom( const std::string & prefix, double value, int decimals = 2 );
74
75/*!
76** \brief Check if a string ends with another string
77**
78*/
79bool ends_with( const std::string & value, const std::string & ending );
80
81/*!
82** \brief Append a string to string
83**
84** This will append a string to another string and place
85** a separator if there is already data in the lead string
86**
87*/
88std::string append( const std::string & s, const std::string & append, const std::string & separator );
89
90/*!
91** \brief Prepend some number of characters in front of another string
92**
93** This procedure is often used to zero-pad a number, such that numbers
94** like 23 and 2005 and 10553 will always appear as 00023 and 02005
95** and 10553 respectively.
96**
97*/
98std::string prepend( const std::string & s, int length = 0, char pad = '0' );
99
100/*!
101** \brief Upper Case a string
102**
103** this procedure converts a string to all upper case
104*/
105std::string ucase( const std::string & value );
106
107/*!
108** \brief Lower Case a string
109**
110** this procedure converts a string to all lower case
111*/
112std::string lcase( const std::string & value );
113
114/*!
115** \brief Round a number up
116**
117** This will round a number up
118**
119*/
120int roundUp( float value );
121
122/*!
123** \brief Round a number down
124**
125** This will round a number down
126**
127*/
128int roundDown( float value );
129
130/*!
131** \brief Round a number for Currency
132**
133** This will round a number up or down depending on the value
134** of the currency. 1.3999999 becomes 1.4
135**
136*/
137float roundCurrency( float value );
138
139/*!
140** \brief Replace a String
141**
142** This will replace all occurrences of a substring within another string with some other string;
143**
144*/
145std::string replace( const std::string & string, const std::string & before, const std::string & after );
146
147void ltrim(std::string &s);
148void rtrim(std::string &s);
149void trim(std::string &s);
150std::string ltrim_copy(std::string s);
151std::string rtrim_copy(std::string s);
152std::string trim_copy(std::string s);
153
154std::vector<std::string> readCSVRow( const std::string & row );
155
156/*!
157** This compares two floating point numbers if they are equal
158**
159*/
160bool feq( double a, double b, double epsilon = 0.005f, bool trace = false );
161
162std::string to_string( Wt::WTemplate & templt );
163std::string to_string( Wt::WTemplate * templt );
164
165bool to_htmlfile( Wt::WTemplate & templt, const std::string & folderName, const std::string & fileName );
166bool to_htmlfile( Wt::WTemplate * templt, const std::string & folderName, const std::string & fileName );
167
168std::string hexDump( const std::string & data, int start = -1, int end = -1 );
169
170typedef struct CharConv
171{
172 const char * symbol;
173 const char * html;
174 const char * utf8;
175 const char * pdf;
176 const char * description;
177
179
180extern const CharConv_t g_iso8859Conv[256];
181
182} // endnamespace Wtx
183
184#endif // #ifndef __WTX_UTIL_H___
185
186
Definition App.h:18
std::string lcase(const std::string &value)
Lower Case a string.
bool to_htmlfile(Wt::WTemplate &templt, const std::string &folderName, const std::string &fileName)
bool ends_with(const std::string &value, const std::string &ending)
Check if a string ends with another string.
int roundDown(float value)
Round a number down.
std::string hexDump(const std::string &data, int start=-1, int end=-1)
const CharConv_t g_iso8859Conv[256]
bool fileExists(const std::string &fileName)
Check if a File or Folder exists.
bool feq(double a, double b, double epsilon=0.005f, bool trace=false)
std::string trim_copy(std::string s)
std::string to_string(Wt::WTemplate &templt)
void rtrim(std::string &s)
int stoi(const std::string &value)
Convert a String to an Integer.
std::string ltrim_copy(std::string s)
struct GCW::CharConv CharConv_t
double stof(const std::string &value)
Convert a String to Float.
std::string ftom(double value, int decimals=2)
int system_command(const std::string &cmd, bool show=false)
Execute a system command.
std::string append(const std::string &s, const std::string &append, const std::string &separator)
Append a string to string.
float roundCurrency(float value)
Round a number for Currency.
std::vector< std::string > fileList(const std::string &folder)
File Listing.
std::string makeFileName(const std::string &value)
std::string replace(const std::string &string, const std::string &before, const std::string &after)
Replace a String.
std::string prepend(const std::string &s, int length=0, char pad='0')
Prepend some number of characters in front of another string.
std::vector< std::string > findFiles(const std::string &folder, const std::string &match)
Find File.
std::string rtrim_copy(std::string s)
void ltrim(std::string &s)
int roundUp(float value)
Round a number up.
std::vector< std::string > readCSVRow(const std::string &row)
std::string ftos(double value, int decimals=2)
Convert a Float to String with decimal precision.
std::string itos(int value)
Convert an Integer to a String.
void trim(std::string &s)
std::string ucase(const std::string &value)
Upper Case a string.
const char * html
Definition Util.h:173
const char * utf8
Definition Util.h:174
const char * description
Definition Util.h:176
const char * pdf
Definition Util.h:175
const char * symbol
Definition Util.h:172