GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Core.h
Go to the documentation of this file.
1#line 2 "src/Glb/Core.h"
2
3#ifndef __GCW_CORE_H___
4#define __GCW_CORE_H___
5
6#include <string>
7#include <vector>
8
9#include <Wt/Json/Object.h>
10#include <Wt/WTemplate.h>
11
12#include "Numeric.h"
13
14//#define COUT_FLF __FILE__, __LINE__, __FUNCTION__
15//#define COUT_BEG std::cout << __FILE__ << ":" << __LINE__ << "(" << __PRETTY_FUNCTION__ << ") "
16//#define COUT_END std::endl
17//#define COUT_LINE std::cout << __FILE__ << ":" << __LINE__ << "(" << __PRETTY_FUNCTION__ << ")" << COUT_END
18//#define COUT_(x) COUT_BEG << x << COUT_END
19
20
21namespace GCW {
22
23 /*!
24 ** \brief helper functions and features
25 **
26 */
27 namespace Core {
28
29
30std::vector<std::string> split( const std::string & value, char delim );
31
32extern const char* trim_ws;
33std::string & rtrim( std::string & s, const char* t = trim_ws );
34std::string & ltrim( std::string & s, const char* t = trim_ws );
35std::string & trim( std::string & s, const char* t = trim_ws );
36std::string toupper( const std::string & s );
37std::string tolower( const std::string & s );
38
40
41std::string hexDump( const std::string & data, int start = -1, int end = -1 );
42
43/*!
44** \brief Generate new GUID string value
45**
46** This GUID is suitable for use as the primary-guid-key value for the
47** data tables.
48**
49*/
50auto newGuid()-> std::string ;
51
52/*!
53** \brief Current Date/Time
54**
55** This will return the current date/time suitable for back-end storage
56**
57*/
59
60auto dateStorageString( const Wt::WDate * _date )-> std::string ;
61auto dateStorageString( const Wt::WDate & _date )-> std::string ;
62auto dateTimeStorageString( const Wt::WDateTime & _dateTime )-> std::string ;
63auto dateTimeDisplayString( const Wt::WDateTime & _dateTime )-> std::string ;
64auto currentDateTimeStorageString()-> std::string ;
65auto currentDateTimeDisplayString()-> std::string ;
66
67/* * * * * * * * * * * * * * * * * * * * */
68
69std::string makeFileName( const std::string & value );
70
71/*!
72** \brief Check if a File or Folder exists
73**
74**
75*/
76bool fileExists( const std::string & fileName );
77
78/*!
79** \brief Execute a system command
80**
81** This runs a command in the console and returns the result code.
82**
83*/
84int system_command( const std::string & cmd, bool show = false );
85
86/*!
87** \brief File Listing
88**
89** This procedure will scan a folder and return a list of all the files
90** in it.
91*/
92std::vector<std::string> fileList( const std::string & folder );
93
94/*!
95** \brief Find File
96**
97** This scans a directory folder and returns a list containing
98** the full file-name of all the files that matche the value.
99**
100*/
101std::vector<std::string> findFiles( const std::string & folder, const std::string & match );
102
103/*!
104** \brief Convert a String to an Integer
105**
106*/
107int stoi( const std::string & value );
108
109/*!
110** \brief Convert an Integer to a String
111**
112*/
113std::string itos( int value );
114
115/*!
116** \brief Convert a String to Float
117**
118*/
119double stof( const std::string & value );
120
121/*!
122** \brief Convert a Float to String with decimal precision
123**
124*/
125std::string ftos( double value, int decimals = 2 );
126std::string ftos( double value, const std::string & suffix, int decimals = 2 );
127std::string ftos( const std::string & prefix, double value, int decimals = 2 );
128std::string ftom( double value, int decimals = 2 );
129std::string ftom( const std::string & prefix, double value, int decimals = 2 );
130
131/*!
132** \brief Check if a string ends with another string
133**
134*/
135bool ends_with( const std::string & value, const std::string & ending );
136
137/*!
138** \brief Append a string to string
139**
140** This will append a string to another string and place
141** a separator if there is already data in the lead string
142**
143*/
144std::string append( const std::string & s, const std::string & append, const std::string & separator );
145
146/*!
147** \brief Prepend some number of characters in front of another string
148**
149** This procedure is often used to zero-pad a number, such that numbers
150** like 23 and 2005 and 10553 will always appear as 00023 and 02005
151** and 10553 respectively.
152**
153*/
154std::string prepend( const std::string & s, int length = 0, char pad = '0' );
155
156/*!
157** \brief Upper Case a string
158**
159** this procedure converts a string to all upper case
160*/
161std::string ucase( const std::string & value );
162
163/*!
164** \brief Lower Case a string
165**
166** this procedure converts a string to all lower case
167*/
168std::string lcase( const std::string & value );
169
170/*!
171** \brief Round a number up
172**
173** This will round a number up
174**
175*/
176int roundUp( float value );
177
178/*!
179** \brief Round a number down
180**
181** This will round a number down
182**
183*/
184int roundDown( float value );
185
186/*!
187** \brief Round a number for Currency
188**
189** This will round a number up or down depending on the value
190** of the currency. 1.3999999 becomes 1.4
191**
192*/
193float roundCurrency( float value );
194
195/*!
196** \brief Replace a String
197**
198** This will replace all occurrences of a substring within another string with some other string;
199**
200*/
201std::string replace( const std::string & string, const std::string & before, const std::string & after );
202
203std::vector<std::string> readCSVRow( const std::string & row );
204
205/*!
206** This compares two floating point numbers if they are equal
207**
208*/
209bool feq( double a, double b, double epsilon = 0.005f, bool trace = false );
210
211std::string to_string( Wt::WTemplate & templt );
212std::string to_string( Wt::WTemplate * templt );
213
214bool to_htmlfile( Wt::WTemplate & templt, const std::string & folderName, const std::string & fileName );
215bool to_htmlfile( Wt::WTemplate * templt, const std::string & folderName, const std::string & fileName );
216
217typedef struct CharConv
218{
219 const char * symbol;
220 const char * html;
221 const char * utf8;
222 const char * pdf;
223 const char * description;
224
226
227extern const CharConv_t g_iso8859Conv[256];
228
229 } // endnamespace Core
230} // endnamespace GCW
231
232#endif
233
const char * trim_ws
Definition Core.cpp:47
struct GCW::Core::CharConv CharConv_t
int system_command(const std::string &cmd, bool show=false)
Execute a system command.
Definition Core.cpp:423
int roundUp(float value)
Round a number up.
Definition Core.cpp:782
double stof(const std::string &value)
Convert a String to Float.
Definition Core.cpp:611
std::string toupper(const std::string &s)
Definition Core.cpp:77
std::string lcase(const std::string &value)
Lower Case a string.
Definition Core.cpp:771
auto currentDateTime() -> Wt::WDateTime
Current Date/Time.
Definition Core.cpp:270
std::string ucase(const std::string &value)
Upper Case a string.
Definition Core.cpp:760
std::string tolower(const std::string &s)
Definition Core.cpp:88
bool ends_with(const std::string &value, const std::string &ending)
Check if a string ends with another string.
Definition Core.cpp:704
int roundDown(float value)
Round a number down.
Definition Core.cpp:795
std::string ftom(double value, int decimals=2)
Definition Core.cpp:677
auto dateTimeDisplayString(const Wt::WDateTime &_dateTime) -> std::string
Definition Core.cpp:319
bool fileExists(const std::string &fileName)
Check if a File or Folder exists.
Definition Core.cpp:569
std::string append(const std::string &s, const std::string &append, const std::string &separator)
Append a string to string.
Definition Core.cpp:716
std::string ftos(double value, int decimals=2)
Convert a Float to String with decimal precision.
Definition Core.cpp:638
std::vector< std::string > split(const std::string &value, char delim)
Definition Core.cpp:40
bool feq(double a, double b, double epsilon=0.005f, bool trace=false)
Definition Core.cpp:947
float roundCurrency(float value)
Round a number for Currency.
Definition Core.cpp:804
std::string itos(int value)
Convert an Integer to a String.
Definition Core.cpp:598
auto dateStorageString(const Wt::WDate *_date) -> std::string
Definition Core.cpp:280
std::string & trim(std::string &s, const char *t=trim_ws)
Definition Core.cpp:70
std::string & ltrim(std::string &s, const char *t=trim_ws)
Definition Core.cpp:61
std::string replace(const std::string &string, const std::string &before, const std::string &after)
Replace a String.
Definition Core.cpp:819
std::string makeFileName(const std::string &value)
Make File Name.
Definition Core.cpp:353
std::vector< std::string > findFiles(const std::string &folder, const std::string &match)
Find File.
Definition Core.cpp:554
int stoi(const std::string &value)
Convert a String to an Integer.
Definition Core.cpp:579
auto currentDateTimeDisplayString() -> std::string
Definition Core.cpp:331
std::string prepend(const std::string &s, int length=0, char pad='0')
Prepend some number of characters in front of another string.
Definition Core.cpp:746
const CharConv_t g_iso8859Conv[256]
Definition Core.cpp:1025
std::string hexDump(const std::string &data, int start=-1, int end=-1)
Definition Core.cpp:180
std::string to_string(Wt::WTemplate &templt)
Definition Core.cpp:971
std::string & rtrim(std::string &s, const char *t=trim_ws)
Definition Core.cpp:52
bool to_htmlfile(Wt::WTemplate &templt, const std::string &folderName, const std::string &fileName)
Definition Core.cpp:1006
Wt::Json::Object toJson(Wt::WTreeView *_view)
Definition Core.cpp:158
std::vector< std::string > readCSVRow(const std::string &row)
Definition Core.cpp:845
auto dateTimeStorageString(const Wt::WDateTime &_dateTime) -> std::string
Definition Core.cpp:298
auto newGuid() -> std::string
Generate new GUID string value.
Definition Core.cpp:245
auto currentDateTimeStorageString() -> std::string
Definition Core.cpp:310
std::vector< std::string > fileList(const std::string &folder)
File Listing.
Definition Core.cpp:474
Definition App.h:18
const char * pdf
Definition Core.h:222
const char * description
Definition Core.h:223
const char * utf8
Definition Core.h:221
const char * symbol
Definition Core.h:219
const char * html
Definition Core.h:220