added support for UTF-8
now the UTF-8 is a default charset git-svn-id: svn://ttmath.org/publicrep/winix/trunk@677 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -151,6 +151,8 @@ public:
|
||||
*/
|
||||
Status Parse(const char * file_name);
|
||||
Status Parse(const std::string & file_name);
|
||||
Status Parse(const wchar_t * file_name);
|
||||
Status Parse(const std::wstring & file_name);
|
||||
|
||||
|
||||
/*
|
||||
@@ -163,8 +165,8 @@ 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::string> Value;
|
||||
typedef std::map<std::string, Value> Table;
|
||||
typedef std::vector<std::wstring> Value;
|
||||
typedef std::map<std::wstring, Value> Table;
|
||||
Table table;
|
||||
|
||||
|
||||
@@ -174,10 +176,10 @@ public:
|
||||
option2 = value2
|
||||
then you can call SplitSingle(true) for not inserting single values to
|
||||
previous 'table' but instead to 'table_single'
|
||||
table_single as the second parameter takes only std::string (instead of the whole std::vector)
|
||||
table_single as the second parameter takes only std::wstring (instead of the whole std::vector)
|
||||
so you can save a little memory from not using std::vector
|
||||
*/
|
||||
typedef std::map<std::string, std::string> TableSingle;
|
||||
typedef std::map<std::wstring, std::wstring> TableSingle;
|
||||
TableSingle table_single;
|
||||
|
||||
|
||||
@@ -219,18 +221,21 @@ public:
|
||||
they return appropriate value (either text, int or boolean)
|
||||
(in lists they return the first item if exists)
|
||||
*/
|
||||
std::string Text(const char * name);
|
||||
std::string Text(const char * name, const char * def);
|
||||
std::string Text(const std::string & name, const std::string & def);
|
||||
int Int(const char *);
|
||||
int Int(const char * name, int def);
|
||||
int Int(const std::string & name, int def);
|
||||
size_t Size(const char *);
|
||||
size_t Size(const char * name, size_t def);
|
||||
size_t Size(const std::string & name, size_t def);
|
||||
bool Bool(const char *);
|
||||
bool Bool(const char * name, bool def);
|
||||
bool Bool(const std::string & 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 std::wstring & def);
|
||||
std::string AText(const wchar_t * name);
|
||||
std::string AText(const wchar_t * name, const wchar_t * def);
|
||||
std::string AText(const std::wstring & name, const std::wstring & def);
|
||||
int Int(const wchar_t *);
|
||||
int Int(const wchar_t * name, int def);
|
||||
int Int(const std::wstring & name, int def);
|
||||
size_t Size(const wchar_t *);
|
||||
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);
|
||||
|
||||
|
||||
/*
|
||||
@@ -242,7 +247,7 @@ public:
|
||||
default int or size is: 0
|
||||
default bool is: false
|
||||
*/
|
||||
void SetDefaultText(const std::string & def);
|
||||
void SetDefaultText(const std::wstring & def);
|
||||
void SetDefaultInt(int def);
|
||||
void SetDefaultSize(size_t def);
|
||||
void SetDefaultBool(bool def);
|
||||
@@ -252,8 +257,21 @@ public:
|
||||
those methods are used to extract lists
|
||||
note: if there is one option in table_single they will return it
|
||||
*/
|
||||
void ListText(const char * name, std::vector<std::string> & list);
|
||||
void ListText(const std::string & name, std::vector<std::string> & list);
|
||||
void ListText(const wchar_t * name, std::vector<std::wstring> & list);
|
||||
void ListText(const std::wstring & name, std::vector<std::wstring> & list);
|
||||
|
||||
|
||||
/*
|
||||
if true then the input file is treated as UTF-8
|
||||
*/
|
||||
void UTF8(bool utf);
|
||||
|
||||
|
||||
/*
|
||||
printing the content
|
||||
(for debug purposes)
|
||||
*/
|
||||
void Print(std::ostream & out);
|
||||
|
||||
|
||||
private:
|
||||
@@ -261,13 +279,13 @@ private:
|
||||
/*
|
||||
last read variable (option)
|
||||
*/
|
||||
std::string variable;
|
||||
std::wstring variable;
|
||||
|
||||
|
||||
/*
|
||||
last read list item
|
||||
*/
|
||||
std::string value_item;
|
||||
std::wstring value_item;
|
||||
|
||||
|
||||
/*
|
||||
@@ -308,6 +326,7 @@ private:
|
||||
|
||||
/*
|
||||
last read char
|
||||
or -1 if the end
|
||||
*/
|
||||
int lastc;
|
||||
|
||||
@@ -335,25 +354,34 @@ private:
|
||||
bool skip_empty;
|
||||
|
||||
|
||||
/*
|
||||
input file is in UTF-8
|
||||
default: false
|
||||
*/
|
||||
bool input_as_utf8;
|
||||
|
||||
|
||||
/*
|
||||
if true you can use an escape character '\' in quoted values
|
||||
*/
|
||||
bool use_escape_char;
|
||||
|
||||
std::string default_str;
|
||||
std::string afile_name;
|
||||
|
||||
std::wstring default_str;
|
||||
int default_int;
|
||||
size_t default_size;
|
||||
bool default_bool;
|
||||
|
||||
int ToInt(const std::string & value);
|
||||
size_t ToSize(const std::string & value);
|
||||
bool ToBool(const std::string & value);
|
||||
int ToInt(const std::wstring & value);
|
||||
size_t ToSize(const std::wstring & value);
|
||||
bool ToBool(const std::wstring & value);
|
||||
|
||||
Status ParseFile();
|
||||
void AddOption();
|
||||
|
||||
void DeleteFromTable(const std::string & var);
|
||||
void DeleteFromTableSingle(const std::string & var);
|
||||
void DeleteFromTable(const std::wstring & var);
|
||||
void DeleteFromTableSingle(const std::wstring & var);
|
||||
|
||||
bool ReadVariable();
|
||||
bool ReadValue();
|
||||
@@ -362,13 +390,15 @@ private:
|
||||
bool ReadValueQuoted();
|
||||
bool ReadValueSimple(bool use_list_delimiter = false);
|
||||
|
||||
int ReadUTF8Char();
|
||||
int ReadASCIIChar();
|
||||
int ReadChar();
|
||||
bool IsWhite(int c);
|
||||
bool IsVariableChar(int c);
|
||||
void SkipWhite();
|
||||
void SkipWhiteLines();
|
||||
void SkipLine();
|
||||
void Trim(std::string & s);
|
||||
void Trim(std::wstring & s);
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user