added: functions for dealing with white characters:

bool IsWhite(wchar_t c, bool check_additional_chars, bool treat_new_line_as_white) (checking unicode white characters too)
       CharType * SkipWhite(CharType * str, bool check_additional_chars = true, bool treat_new_line_as_white = true)
       IsDigit(wchar_t c, int base, int * digit)

added: functions to converting from a string to an integer:
       unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
       long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
       unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
       unsigned int  Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
       long          Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)
       int           Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0)

changed: some work in Space (new Api)       
       now Text() methods returns std::wstring by value (before they were returned by reference)
       added std::wstring & TextRef() methods
       added unsigned int UInt(), unsigned long ULong() and LongLong() and ULongLong()
       GetValue() renamed to GetFirstValue()
       AText() renamed to TextA() and they return std::string by value now
       



git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1066 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2017-12-05 16:32:21 +00:00
parent cde990ba82
commit 7d51372844
20 changed files with 970 additions and 138 deletions

View File

@@ -164,7 +164,16 @@ config syntax:
class Space
{
public:
/*
this is the table which represents your config file
in the Table map: the first (key) is your 'option' and the second is 'list'
*/
typedef std::vector<std::wstring> Value;
typedef std::map<std::wstring, Value> Table;
Space();
~Space();
@@ -174,13 +183,6 @@ public:
void Clear();
// these methods return true if 'name' was found
// in other case they return false and 'out' will be equal 'def'
// they can return a null pointer if there is not such a 'name'
std::wstring * GetValue(const wchar_t * name);
std::wstring * GetValue(const std::wstring & name);
const std::wstring * GetValue(const std::wstring & name) const;
/*
returns true if such an option has 'value'
@@ -192,6 +194,31 @@ public:
bool HasValue(const std::wstring & name, const std::wstring & value);
/*
*
* methods for getting/finding a value
*
*
*/
// moze tu powinno być FindValue?
Value * GetValue(const wchar_t * name);
Value * GetValue(const std::wstring & name);
const Value * GetValue(const wchar_t * name) const;
const Value * GetValue(const std::wstring & name) const;
// moze tu powinno być FindFirstValue?
// they can return a null pointer if there is not such a 'name'
std::wstring * GetFirstValue(const wchar_t * name);
std::wstring * GetFirstValue(const std::wstring & name);
const std::wstring * GetFirstValue(const wchar_t * name) const;
const std::wstring * GetFirstValue(const std::wstring & name) const;
/*
those methods are used to extract information from space.table
as a parameter they take the name of an option
@@ -204,24 +231,56 @@ public:
AText(...) always returns a reference to UTF-8 string
*/
std::wstring & Text(const wchar_t * name);
std::wstring & Text(const wchar_t * name, const wchar_t * def);
std::wstring & Text(const std::wstring & name, const wchar_t * def);
std::string & AText(const wchar_t * name);
std::string & AText(const wchar_t * name, const char * def);
std::string & AText(const std::wstring & name, const char * def);
int Int(const wchar_t * name);
int Int(const wchar_t * name, int def);
int Int(const std::wstring & name, int def);
long Long(const wchar_t * name);
long Long(const wchar_t * name, long def);
long Long(const std::wstring & name, long def);
size_t Size(const wchar_t * name);
size_t Size(const wchar_t * name, size_t def);
size_t Size(const std::wstring & name, size_t def);
bool Bool(const wchar_t *);
bool Bool(const wchar_t * name, bool def);
bool Bool(const std::wstring & name, bool def);
std::wstring Text(const wchar_t * name);
std::wstring Text(const wchar_t * name, const wchar_t * def);
std::wstring Text(const std::wstring & name, const wchar_t * def);
std::wstring Text(const std::wstring & name, const std::wstring & def);
// returns a reference
// if there is no such an option then a new one is inserted
std::wstring & TextRef(const wchar_t * name);
std::wstring & TextRef(const wchar_t * name, const wchar_t * def);
std::wstring & TextRef(const std::wstring & name, const wchar_t * def);
std::wstring & TextRef(const std::wstring & name, const std::wstring & def);
// returns UTF-8 string
std::string TextA(const wchar_t * name);
std::string TextA(const wchar_t * name, const char * def);
std::string TextA(const std::wstring & name, const char * def);
std::string TextA(const std::wstring & name, const std::string & def);
int Int(const wchar_t * name, int def = 0);
int Int(const std::wstring & name, int def = 0);
unsigned int UInt(const wchar_t * name, unsigned int def = 0);
unsigned int UInt(const std::wstring & name, unsigned int def = 0);
long Long(const wchar_t * name, long def = 0);
long Long(const std::wstring & name, long def = 0);
unsigned long ULong(const wchar_t * name, unsigned long def = 0);
unsigned long ULong(const std::wstring & name, unsigned long def = 0);
long long LongLong(const wchar_t * name, long long def = 0);
long long LongLong(const std::wstring & name, long long def = 0);
unsigned long long ULongLong(const wchar_t * name, unsigned long long def = 0);
unsigned long long ULongLong(const std::wstring & name, unsigned long long def = 0);
size_t Size(const wchar_t * name, size_t def = 0);
size_t Size(const std::wstring & name, size_t def = 0);
bool Bool(const wchar_t * name, bool def = false);
bool Bool(const std::wstring & name, bool def = false);
/*
*
* methods for adding a new value
*
*
*/
std::wstring & FindAdd(const wchar_t * name);
std::wstring & FindAdd(const std::wstring & name);
@@ -276,21 +335,12 @@ public:
*
*/
/*
this is the table which represents your config file
in the Table map: the first (key) is your 'option' and the second is 'list'
*/
typedef std::vector<std::wstring> Value;
typedef std::map<std::wstring, Value> Table;
std::wstring name; // space name
Table table; // std::map<std::wstring, std::vector<std::wstring> >
// childs
typedef std::vector<Space*> Spaces;
std::vector<Space*> spaces;
Spaces spaces;
// a parent space
// null means a root space
@@ -328,15 +378,23 @@ public:
private:
std::wstring tmp_name;
mutable std::wstring tmp_name;
std::wstring tmp_value;
std::wstring tmp_value_text;
std::string tmp_value_text_ascii;
int ToInt(const std::wstring & value);
long ToLong(const std::wstring & value);
size_t ToSize(const std::wstring & value);
bool ToBool(const std::wstring & value);
int CheckIntegerBase(const std::wstring & value, const wchar_t ** save_ptr);
unsigned int ToUInt(const std::wstring & value);
int ToInt(const std::wstring & value);
unsigned long ToULong(const std::wstring & value);
long ToLong(const std::wstring & value);
unsigned long long ToULongLong(const std::wstring & value);
long long ToLongLong(const std::wstring & value);
size_t ToSize(const std::wstring & value);
bool ToBool(const std::wstring & value);
wchar_t ToSmall(wchar_t c);
bool EqualNoCase(const wchar_t * str1, const wchar_t * str2);
static bool IsWhite(int c);