GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
GCW::Core Namespace Reference

helper functions and features More...

Classes

struct  CharConv
 

Typedefs

typedef struct GCW::Core::CharConv CharConv_t
 

Functions

std::vector< std::string > split (const std::string &value, char delim)
 
std::string & rtrim (std::string &s, const char *t=trim_ws)
 
std::string & ltrim (std::string &s, const char *t=trim_ws)
 
std::string & trim (std::string &s, const char *t=trim_ws)
 
std::string toupper (const std::string &s)
 
std::string tolower (const std::string &s)
 
Wt::Json::Object toJson (Wt::WTreeView *_view)
 
std::string hexDump (const std::string &data, int start=-1, int end=-1)
 
auto newGuid () -> std::string
 Generate new GUID string value.
 
auto currentDateTime () -> Wt::WDateTime
 Current Date/Time.
 
auto dateStorageString (const Wt::WDate *_date) -> std::string
 
auto dateTimeStorageString (const Wt::WDateTime &_dateTime) -> std::string
 
auto dateTimeDisplayString (const Wt::WDateTime &_dateTime) -> std::string
 
auto currentDateTimeStorageString () -> std::string
 
auto currentDateTimeDisplayString () -> std::string
 
std::string makeFileName (const std::string &value)
 Make File Name.
 
bool fileExists (const std::string &fileName)
 Check if a File or Folder exists.
 
int system_command (const std::string &cmd, bool show=false)
 Execute a system command.
 
std::vector< std::string > fileList (const std::string &folder)
 File Listing.
 
std::vector< std::string > findFiles (const std::string &folder, const std::string &match)
 Find File.
 
int stoi (const std::string &value)
 Convert a String to an Integer.
 
std::string itos (int value)
 Convert an Integer to a String.
 
double stof (const std::string &value)
 Convert a String to Float.
 
std::string ftos (double value, int decimals=2)
 Convert a Float to String with decimal precision.
 
std::string ftos (double value, const std::string &suffix, int decimals=2)
 
std::string ftos (const std::string &prefix, double value, int decimals=2)
 
std::string ftom (double value, int decimals=2)
 
std::string ftom (const std::string &prefix, double value, int decimals=2)
 
bool ends_with (const std::string &value, const std::string &ending)
 Check if a string ends with another string.
 
std::string append (const std::string &s, const std::string &append, const std::string &separator)
 Append a string to 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::string ucase (const std::string &value)
 Upper Case a string.
 
std::string lcase (const std::string &value)
 Lower Case a string.
 
int roundUp (float value)
 Round a number up.
 
int roundDown (float value)
 Round a number down.
 
float roundCurrency (float value)
 Round a number for Currency.
 
std::string replace (const std::string &string, const std::string &before, const std::string &after)
 Replace a String.
 
std::vector< std::string > readCSVRow (const std::string &row)
 
bool feq (double a, double b, double epsilon=0.005f, bool trace=false)
 
std::string to_string (Wt::WTemplate &templt)
 
std::string to_string (Wt::WTemplate *templt)
 
bool to_htmlfile (Wt::WTemplate &templt, const std::string &folderName, const std::string &fileName)
 
bool to_htmlfile (Wt::WTemplate *templt, const std::string &folderName, const std::string &fileName)
 

Variables

const char * trim_ws = " \t\n\r\f\v"
 
const CharConv_t g_iso8859Conv [256]
 

Detailed Description

helper functions and features

Typedef Documentation

◆ CharConv_t

Function Documentation

◆ append()

auto GCW::Core::append ( const std::string &  s,
const std::string &  append,
const std::string &  separator 
)

Append a string to string.

This will append a string to another string and place a separator if there is already data in the lead string

Definition at line 705 of file Core.cpp.

References append(), and ends_with().

Referenced by append().

◆ currentDateTime()

auto GCW::Core::currentDateTime ( ) -> Wt::WDateTime

Current Date/Time.

This will return the current date/time suitable for back-end storage

Definition at line 269 of file Core.cpp.

References Wt::WDateTime::currentDateTime().

Referenced by currentDateTimeDisplayString(), and currentDateTimeStorageString().

◆ currentDateTimeDisplayString()

auto GCW::Core::currentDateTimeDisplayString ( ) -> std::string

Definition at line 320 of file Core.cpp.

References currentDateTime(), and dateTimeDisplayString().

Referenced by GCW::Gui::BillPay::PaymentWidget::loadData().

◆ currentDateTimeStorageString()

auto GCW::Core::currentDateTimeStorageString ( ) -> std::string

Definition at line 299 of file Core.cpp.

References currentDateTime(), and dateTimeStorageString().

Referenced by GCW::Gui::BillPay::PaymentWidget::saveData().

◆ dateStorageString()

auto GCW::Core::dateStorageString ( const Wt::WDate _date) -> std::string

◆ dateTimeDisplayString()

auto GCW::Core::dateTimeDisplayString ( const Wt::WDateTime _dateTime) -> std::string

Definition at line 308 of file Core.cpp.

References GCW_DATE_FORMAT_DISPLAY.

Referenced by currentDateTimeDisplayString().

◆ dateTimeStorageString()

auto GCW::Core::dateTimeStorageString ( const Wt::WDateTime _dateTime) -> std::string

Definition at line 287 of file Core.cpp.

References GCW_DATETIME_FORMAT_STORAGE.

Referenced by currentDateTimeStorageString().

◆ ends_with()

auto GCW::Core::ends_with ( const std::string &  value,
const std::string &  ending 
)

Check if a string ends with another string.

Definition at line 693 of file Core.cpp.

Referenced by append().

◆ feq()

auto GCW::Core::feq ( double  a,
double  b,
double  epsilon = 0.005f,
bool  trace = false 
)

This compares two floating point numbers if they are equal

Definition at line 936 of file Core.cpp.

◆ fileExists()

auto GCW::Core::fileExists ( const std::string &  fileName)

Check if a File or Folder exists.

Definition at line 558 of file Core.cpp.

◆ fileList()

auto GCW::Core::fileList ( const std::string &  folder)

File Listing.

This procedure will scan a folder and return a list of all the files in it.

Definition at line 463 of file Core.cpp.

References ialphasort().

Referenced by findFiles().

◆ findFiles()

auto GCW::Core::findFiles ( const std::string &  folder,
const std::string &  match 
)

Find File.

This scans a directory folder and returns a list containing the full file-name of all the files that matche the value.

Definition at line 543 of file Core.cpp.

References fileList().

◆ ftom() [1/2]

auto GCW::Core::ftom ( const std::string &  prefix,
double  value,
int  decimals = 2 
)

Definition at line 679 of file Core.cpp.

◆ ftom() [2/2]

auto GCW::Core::ftom ( double  value,
int  decimals = 2 
)

Definition at line 666 of file Core.cpp.

◆ ftos() [1/3]

auto GCW::Core::ftos ( const std::string &  prefix,
double  value,
int  decimals = 2 
)

Definition at line 653 of file Core.cpp.

◆ ftos() [2/3]

auto GCW::Core::ftos ( double  value,
const std::string &  suffix,
int  decimals = 2 
)

Definition at line 640 of file Core.cpp.

◆ ftos() [3/3]

auto GCW::Core::ftos ( double  value,
int  decimals = 2 
)

Convert a Float to String with decimal precision.

Definition at line 627 of file Core.cpp.

◆ hexDump()

auto GCW::Core::hexDump ( const std::string &  data,
int  start = -1,
int  end = -1 
)

Definition at line 179 of file Core.cpp.

◆ itos()

auto GCW::Core::itos ( int  value)

Convert an Integer to a String.

Definition at line 587 of file Core.cpp.

References Wt::WString::arg(), and Wt::WString::toUTF8().

Referenced by GCW::Gui::BillPay::YearSelector::YearSelector().

◆ lcase()

auto GCW::Core::lcase ( const std::string &  value)

Lower Case a string.

this procedure converts a string to all lower case

Definition at line 760 of file Core.cpp.

◆ ltrim()

std::string & GCW::Core::ltrim ( std::string &  s,
const char *  t = trim_ws 
)

Definition at line 60 of file Core.cpp.

Referenced by trim().

◆ makeFileName()

auto GCW::Core::makeFileName ( const std::string &  value)

Make File Name.

This will take an odrinary string and remove anything that is not acceptable in a valid file-name. The intended use for this function is to take something like a person's name or a company name and remove and replace anything in those strings that might not produce a disk-compatible file-name. This includes things like ':' colons and '/' forward and back slashes and anything else that looks just plain weird.

All non-printable characters are simply discarded

The routine performs simple character-by-character substitution. In some cases the substitution is 'nothing', like in the case of '.' (period) and ',' (comma) other characters are simply replaced with suitable replacements that have similar appearance but are not likely to mess up a file-name on disk. Odd punctuation characters are removed since this function is a string-to-filename conversion, therefore absolute punctuation has less meaning in a file-name than it does in the database.

Examples
std::cout << makeFileName("LORIMARK SOLUTIONS, LLC.") << std::endl;
std::cout << makeFileName("Bridge On The River Kwai") << std::endl;
std::cout << makeFileName("He said \"no\", She said \"yes\"") << std::endl;
std::cout << makeFileName("Chicago <south> Storage_Facility") << std::endl;
std::cout << makeFileName("Boat (float) :/: or Ship Sink") << std::endl;
result:
LORIMARK SOLUTIONS LLC
Bridge On The River Kwai
He said 'no' She said 'yes'
Chicago (south) Storage_Facility
Boat (float) -- or Ship Sink
std::string makeFileName(const std::string &value)
Make File Name.
Definition Core.cpp:343

'.' period -> nothing

',' comma -> nothing

'<' less than -> open paren

'>' greater than -> close paren

':' colon -> dash ~ sometimes works, but is actually NTFS Alternate Data Streams

'"' double quote -> single quote

'/' forward slash -> dash

'\'backslash -> dash

'|' vertical bar or pipe -> nothing

'?' question mark -> nothing

'*' asterisk -> nothing

Definition at line 342 of file Core.cpp.

◆ newGuid()

auto GCW::Core::newGuid ( ) -> std::string

Generate new GUID string value.

This GUID is suitable for use as the primary-guid-key value for the data tables.

Definition at line 244 of file Core.cpp.

Referenced by GCW::Eng::Transaction::Manager::newTransaction(), and GCW::Gui::BillPay::EditWidget::saveData().

◆ prepend()

auto GCW::Core::prepend ( const std::string &  s,
int  length = 0,
char  pad = '0' 
)

Prepend some number of characters in front of another string.

This procedure is often used to zero-pad a number, such that numbers like 23 and 2005 and 10553 will always appear as 00023 and 02005 and 10553 respectively.

Definition at line 735 of file Core.cpp.

◆ readCSVRow()

auto GCW::Core::readCSVRow ( const std::string &  row)

Definition at line 834 of file Core.cpp.

References QuotedField, QuotedQuote, and UnquotedField.

◆ replace()

auto GCW::Core::replace ( const std::string &  string,
const std::string &  before,
const std::string &  after 
)

Replace a String.

This will replace all occurrences of a substring within another string with some other string;

Definition at line 808 of file Core.cpp.

◆ roundCurrency()

auto GCW::Core::roundCurrency ( float  value)

Round a number for Currency.

This will round a number up or down depending on the value of the currency. 1.3999999 becomes 1.4

Definition at line 793 of file Core.cpp.

◆ roundDown()

auto GCW::Core::roundDown ( float  value)

Round a number down.

This will round a number down

Definition at line 784 of file Core.cpp.

◆ roundUp()

auto GCW::Core::roundUp ( float  value)

Round a number up.

This will round a number up

Definition at line 771 of file Core.cpp.

◆ rtrim()

std::string & GCW::Core::rtrim ( std::string &  s,
const char *  t = trim_ws 
)

Definition at line 51 of file Core.cpp.

Referenced by trim().

◆ split()

std::vector< std::string > GCW::Core::split ( const std::string &  value,
char  delim 
)

Definition at line 39 of file Core.cpp.

References split().

Referenced by GCW::Dbo::Accounts::byFullName().

◆ stof()

auto GCW::Core::stof ( const std::string &  value)

Convert a String to Float.

Definition at line 600 of file Core.cpp.

◆ stoi()

auto GCW::Core::stoi ( const std::string &  value)

Convert a String to an Integer.

Definition at line 568 of file Core.cpp.

Referenced by GCW::Gui::BillPay::ToolBar::selectedYear(), and GCW::Gui::BillPay::YearSelector::YearSelector().

◆ system_command()

auto GCW::Core::system_command ( const std::string &  cmd,
bool  show = false 
)

Execute a system command.

This runs a command in the console and returns the result code.

Definition at line 412 of file Core.cpp.

◆ to_htmlfile() [1/2]

auto GCW::Core::to_htmlfile ( Wt::WTemplate templt,
const std::string &  folderName,
const std::string &  fileName 
)

Definition at line 995 of file Core.cpp.

References to_string().

Referenced by to_htmlfile().

◆ to_htmlfile() [2/2]

auto GCW::Core::to_htmlfile ( Wt::WTemplate templt,
const std::string &  folderName,
const std::string &  fileName 
)

Definition at line 1006 of file Core.cpp.

References to_htmlfile().

◆ to_string() [1/2]

auto GCW::Core::to_string ( Wt::WTemplate templt)

Definition at line 960 of file Core.cpp.

Referenced by to_htmlfile(), and to_string().

◆ to_string() [2/2]

auto GCW::Core::to_string ( Wt::WTemplate templt)

Definition at line 987 of file Core.cpp.

References to_string().

◆ toJson()

Wt::Json::Object GCW::Core::toJson ( Wt::WTreeView _view)

Definition at line 157 of file Core.cpp.

References Wt::WString::arg(), iterate(), and Wt::WString::toUTF8().

◆ tolower()

std::string GCW::Core::tolower ( const std::string &  s)

Definition at line 87 of file Core.cpp.

◆ toupper()

std::string GCW::Core::toupper ( const std::string &  s)

Definition at line 76 of file Core.cpp.

◆ trim()

std::string & GCW::Core::trim ( std::string &  s,
const char *  t = trim_ws 
)

Definition at line 69 of file Core.cpp.

References ltrim(), and rtrim().

◆ ucase()

auto GCW::Core::ucase ( const std::string &  value)

Upper Case a string.

this procedure converts a string to all upper case

Definition at line 749 of file Core.cpp.

Variable Documentation

◆ g_iso8859Conv

const GCW::Core::CharConv_t GCW::Core::g_iso8859Conv
extern

Definition at line 1015 of file Core.cpp.

◆ trim_ws

const char * GCW::Core::trim_ws = " \t\n\r\f\v"
extern

Definition at line 47 of file Core.cpp.