changed: we do not make a 'base redirect' when the request method is POST
changed: ConfParser -- now we have spaces (only one level) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@767 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2010, Tomasz Sowa
|
||||
* Copyright (c) 2008-2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
@@ -10,30 +10,35 @@
|
||||
#include <cstdlib>
|
||||
#include <wchar.h>
|
||||
#include "confparser.h"
|
||||
#include "misc.h"
|
||||
#include "utf8.h"
|
||||
|
||||
|
||||
|
||||
ConfParser::ConfParser()
|
||||
{
|
||||
SetDefault();
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SetDefault()
|
||||
{
|
||||
// you can change this separators to what you want
|
||||
// you shoud not use only white characters here (as expected by IsWhite() method)
|
||||
// and new line characters ('\n')
|
||||
separator = '=';
|
||||
commentary = '#';
|
||||
list_start = '(';
|
||||
list_end = ')';
|
||||
list_delimiter = ',';
|
||||
split_single = false;
|
||||
skip_empty = false;
|
||||
separator = '=';
|
||||
commentary = '#';
|
||||
list_start = '(';
|
||||
list_end = ')';
|
||||
list_delimiter = ',';
|
||||
split_single = false;
|
||||
skip_empty = false;
|
||||
use_escape_char = true;
|
||||
input_as_utf8 = false;
|
||||
input_as_utf8 = false;
|
||||
|
||||
default_str = L"";
|
||||
default_int = 0;
|
||||
default_size = 0;
|
||||
default_bool = false;
|
||||
default_str = L"";
|
||||
default_int = 0;
|
||||
default_size = 0;
|
||||
default_bool = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,22 +60,38 @@ void ConfParser::UseEscapeChar(bool escape)
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::UTF8(bool utf)
|
||||
{
|
||||
input_as_utf8 = utf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::Clear()
|
||||
{
|
||||
space.table.clear();
|
||||
space.table_single.clear();
|
||||
spaces.clear();
|
||||
|
||||
line = 1;
|
||||
using_global_space = true;
|
||||
pchar_ascii = 0;
|
||||
pchar_unicode = 0;
|
||||
status = ok;
|
||||
}
|
||||
|
||||
|
||||
ConfParser::Status ConfParser::Parse(const char * file_name)
|
||||
{
|
||||
Clear();
|
||||
reading_from_file = true;
|
||||
line = 1;
|
||||
table.clear();
|
||||
table_single.clear();
|
||||
|
||||
file.clear();
|
||||
file.open( file_name );
|
||||
|
||||
if( file )
|
||||
{
|
||||
status = ParseFile();
|
||||
Parse();
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
@@ -108,15 +129,12 @@ ConfParser::Status ConfParser::Parse(const std::wstring & file_name)
|
||||
|
||||
ConfParser::Status ConfParser::ParseString(const char * str)
|
||||
{
|
||||
Clear();
|
||||
reading_from_file = false;
|
||||
reading_from_wchar_string = false;
|
||||
line = 1;
|
||||
table.clear();
|
||||
table_single.clear();
|
||||
pchar_ascii = str;
|
||||
pchar_unicode = 0;
|
||||
pchar_ascii = str;
|
||||
|
||||
status = ParseFile();
|
||||
Parse();
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -130,15 +148,12 @@ ConfParser::Status ConfParser::ParseString(const std::string & str)
|
||||
|
||||
ConfParser::Status ConfParser::ParseString(const wchar_t * str)
|
||||
{
|
||||
Clear();
|
||||
reading_from_file = false;
|
||||
reading_from_wchar_string = true;
|
||||
line = 1;
|
||||
table.clear();
|
||||
table_single.clear();
|
||||
pchar_ascii = 0;
|
||||
pchar_unicode = str;
|
||||
pchar_unicode = str;
|
||||
|
||||
status = ParseFile();
|
||||
Parse();
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -150,35 +165,89 @@ ConfParser::Status ConfParser::ParseString(const std::wstring & str)
|
||||
}
|
||||
|
||||
|
||||
ConfParser::Status ConfParser::ParseFile()
|
||||
void ConfParser::Parse()
|
||||
{
|
||||
status = ok;
|
||||
ReadChar();
|
||||
SkipWhiteLines();
|
||||
|
||||
while( lastc != -1 )
|
||||
while( status == ok && lastc != -1 )
|
||||
{
|
||||
if( !ReadVariable() )
|
||||
return syntax_error;
|
||||
if( lastc == list_end )
|
||||
{
|
||||
TestListEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadVariable();
|
||||
|
||||
if( lastc != separator )
|
||||
return syntax_error;
|
||||
|
||||
if( !ReadValue() )
|
||||
return syntax_error;
|
||||
if( lastc == list_start )
|
||||
{
|
||||
TestListStart();
|
||||
}
|
||||
else
|
||||
if( lastc == separator && !variable.empty() )
|
||||
{
|
||||
ReadAddValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
status = syntax_error;
|
||||
}
|
||||
}
|
||||
|
||||
AddOption();
|
||||
SkipWhite();
|
||||
|
||||
if( lastc != -1 && lastc != '\n' )
|
||||
return syntax_error; // some characters have left at the end of an option
|
||||
|
||||
SkipWhiteLines();
|
||||
if( status == ok )
|
||||
SkipWhiteLines();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::TestListEnd()
|
||||
{
|
||||
if( using_global_space )
|
||||
{
|
||||
// there cannot be a loose list end character in the global space
|
||||
status = syntax_error;
|
||||
}
|
||||
else
|
||||
{
|
||||
using_global_space = true;
|
||||
ReadChar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::TestListStart()
|
||||
{
|
||||
if( using_global_space )
|
||||
{
|
||||
spaces.insert(spaces.end(), Space());
|
||||
spaces.back().name = variable;
|
||||
using_global_space = false;
|
||||
ReadChar();
|
||||
}
|
||||
else
|
||||
{
|
||||
// only one additional level of spaces is allowed
|
||||
status = syntax_error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::ReadAddValue()
|
||||
{
|
||||
ReadChar(); // skipping separator '='
|
||||
|
||||
if( ReadValue() )
|
||||
{
|
||||
AddOption();
|
||||
}
|
||||
else
|
||||
{
|
||||
status = syntax_error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::IsVariableChar(int c)
|
||||
{
|
||||
@@ -192,6 +261,105 @@ return false;
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::IsWhite(int c)
|
||||
{
|
||||
// dont use '\n' here
|
||||
// 13 (\r) is at the end of a line in a dos file \r\n
|
||||
// 160 is an unbreakable space
|
||||
if( c==' ' || c=='\t' || c==13 || c==160 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::SkipWhite()
|
||||
{
|
||||
while( IsWhite(lastc) || lastc == commentary )
|
||||
{
|
||||
if( lastc == commentary )
|
||||
SkipLine();
|
||||
else
|
||||
ReadChar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SkipWhiteLines()
|
||||
{
|
||||
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' )
|
||||
{
|
||||
if( lastc == commentary )
|
||||
SkipLine();
|
||||
else
|
||||
ReadChar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SkipLine()
|
||||
{
|
||||
while( lastc != -1 && lastc != '\n' )
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::Trim(std::wstring & s)
|
||||
{
|
||||
std::wstring::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for white characters at the end
|
||||
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
|
||||
|
||||
if( i==0 && IsWhite(s[i]) )
|
||||
{
|
||||
// the whole string has white characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting white characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, std::wstring::npos);
|
||||
|
||||
// looking for white characters at the beginning
|
||||
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
|
||||
|
||||
// deleting white characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
|
||||
wchar_t ConfParser::ToSmall(wchar_t c)
|
||||
{
|
||||
if( c>='A' && c<='Z' )
|
||||
c = c - 'A' + 'a';
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::EqualNoCase(const wchar_t * str1, const wchar_t * str2)
|
||||
{
|
||||
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
|
||||
{
|
||||
++str1;
|
||||
++str2;
|
||||
}
|
||||
|
||||
if( *str1 == 0 && *str2 == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::AddOption()
|
||||
{
|
||||
@@ -202,14 +370,19 @@ void ConfParser::AddOption()
|
||||
return;
|
||||
}
|
||||
|
||||
Space * ps = &space;
|
||||
|
||||
if( !using_global_space && !spaces.empty() )
|
||||
ps = &spaces.back();
|
||||
|
||||
if( split_single && value.size() == 1 )
|
||||
{
|
||||
table_single[variable] = value[0];
|
||||
ps->table_single[variable] = value[0];
|
||||
DeleteFromTable(variable);
|
||||
}
|
||||
else
|
||||
{
|
||||
table[variable] = value;
|
||||
ps->table[variable] = value;
|
||||
DeleteFromTableSingle(variable);
|
||||
}
|
||||
}
|
||||
@@ -218,25 +391,35 @@ void ConfParser::AddOption()
|
||||
|
||||
void ConfParser::DeleteFromTable(const std::wstring & var)
|
||||
{
|
||||
Table::iterator i = table.find(var);
|
||||
Space * ps = &space;
|
||||
|
||||
if( i != table.end() )
|
||||
table.erase(i);
|
||||
if( !using_global_space && !spaces.empty() )
|
||||
ps = &spaces.back();
|
||||
|
||||
Table::iterator i = ps->table.find(var);
|
||||
|
||||
if( i != ps->table.end() )
|
||||
ps->table.erase(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::DeleteFromTableSingle(const std::wstring & var)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(var);
|
||||
Space * ps = &space;
|
||||
|
||||
if( i != table_single.end() )
|
||||
table_single.erase(i);
|
||||
if( !using_global_space && !spaces.empty() )
|
||||
ps = &spaces.back();
|
||||
|
||||
TableSingle::iterator i = ps->table_single.find(var);
|
||||
|
||||
if( i != ps->table_single.end() )
|
||||
ps->table_single.erase(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ReadVariable()
|
||||
void ConfParser::ReadVariable()
|
||||
{
|
||||
variable.clear();
|
||||
SkipWhite();
|
||||
@@ -248,8 +431,6 @@ bool ConfParser::ReadVariable()
|
||||
}
|
||||
|
||||
SkipWhite();
|
||||
|
||||
return !variable.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +438,6 @@ return !variable.empty();
|
||||
bool ConfParser::ReadValue()
|
||||
{
|
||||
value.clear();
|
||||
ReadChar(); // skipping separator '='
|
||||
SkipWhite();
|
||||
|
||||
if( lastc == list_start )
|
||||
@@ -351,10 +531,10 @@ bool ConfParser::ReadValueSimple(bool use_list_delimiter)
|
||||
int list_delimiter2 = -1;
|
||||
|
||||
if( use_list_delimiter )
|
||||
{
|
||||
list_delimiter1 = list_delimiter;
|
||||
|
||||
if( use_list_delimiter || !using_global_space )
|
||||
list_delimiter2 = list_end;
|
||||
}
|
||||
|
||||
while( lastc!=-1 && lastc!='\n' && lastc!=commentary &&
|
||||
lastc!=list_delimiter1 && lastc!=list_delimiter2 )
|
||||
@@ -490,148 +670,128 @@ int ConfParser::ReadChar()
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::IsWhite(int c)
|
||||
|
||||
|
||||
|
||||
bool ConfParser::Space::GetValue(const wchar_t * name, std::wstring & out)
|
||||
{
|
||||
// dont use '\n' here
|
||||
// 13 (\r) is at the end of a line in a dos file \r\n
|
||||
// 160 is an unbreakable space
|
||||
if( c==' ' || c=='\t' || c==13 || c==160 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
tmp_name = name;
|
||||
return GetValue(tmp_name, out, L"");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::SkipWhite()
|
||||
bool ConfParser::Space::GetValue(const wchar_t * name, std::wstring & out, const wchar_t * def)
|
||||
{
|
||||
while( IsWhite(lastc) || lastc == commentary )
|
||||
{
|
||||
if( lastc == commentary )
|
||||
SkipLine();
|
||||
else
|
||||
ReadChar();
|
||||
}
|
||||
tmp_name = name;
|
||||
return GetValue(tmp_name, out, def);
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SkipWhiteLines()
|
||||
bool ConfParser::Space::GetValue(const std::wstring & name, std::wstring & out)
|
||||
{
|
||||
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' )
|
||||
{
|
||||
if( lastc == commentary )
|
||||
SkipLine();
|
||||
else
|
||||
ReadChar();
|
||||
}
|
||||
return GetValue(name, out, L"");
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SkipLine()
|
||||
{
|
||||
while( lastc != -1 && lastc != '\n' )
|
||||
ReadChar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::Trim(std::wstring & s)
|
||||
{
|
||||
std::wstring::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for white characters at the end
|
||||
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
|
||||
|
||||
if( i==0 && IsWhite(s[i]) )
|
||||
{
|
||||
// the whole string has white characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting white characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, std::wstring::npos);
|
||||
|
||||
// looking for white characters at the beginning
|
||||
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
|
||||
|
||||
// deleting white characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::wstring ConfParser::Text(const wchar_t * name)
|
||||
{
|
||||
return Text(std::wstring(name), default_str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::wstring ConfParser::Text(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
return Text(std::wstring(name), std::wstring(def));
|
||||
}
|
||||
|
||||
|
||||
std::wstring ConfParser::Text(const std::wstring & name, const std::wstring & def)
|
||||
bool ConfParser::Space::GetValue(const std::wstring & name, std::wstring & out, const wchar_t * def)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i == table_single.end() )
|
||||
if( i != table_single.end() )
|
||||
{
|
||||
out = i->second;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
return def;
|
||||
|
||||
return t->second[0];
|
||||
{
|
||||
out = def;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
out = t->second[0];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string ConfParser::AText(const wchar_t * name)
|
||||
|
||||
void ConfParser::ToText(const wchar_t * name, std::wstring & out)
|
||||
{
|
||||
std::wstring res = Text(name);
|
||||
std::string ares;
|
||||
tmp_name = name;
|
||||
return ToText(tmp_name, out, default_str.c_str());
|
||||
}
|
||||
|
||||
Ezc::WideToUTF8(res, ares);
|
||||
|
||||
return ares;
|
||||
void ConfParser::ToText(const wchar_t * name, std::wstring & out, const wchar_t * def)
|
||||
{
|
||||
tmp_name = name;
|
||||
return ToText(tmp_name, out, def);
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::ToText(const std::wstring & name, std::wstring & out, const wchar_t * def)
|
||||
{
|
||||
space.GetValue(name, out, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string ConfParser::AText(const wchar_t * name, const wchar_t * def)
|
||||
|
||||
std::wstring & ConfParser::Text(const wchar_t * name)
|
||||
{
|
||||
std::wstring res = Text(name, def);
|
||||
std::string ares;
|
||||
|
||||
Ezc::WideToUTF8(res, ares);
|
||||
|
||||
return ares;
|
||||
ToText(name, tmp_value_text);
|
||||
return tmp_value_text;
|
||||
}
|
||||
|
||||
|
||||
std::string ConfParser::AText(const std::wstring & name, const std::wstring & def)
|
||||
|
||||
std::wstring & ConfParser::Text(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
std::wstring res = Text(name, def);
|
||||
std::string ares;
|
||||
ToText(name, tmp_value_text, def);
|
||||
return tmp_value_text;
|
||||
}
|
||||
|
||||
Ezc::WideToUTF8(res, ares);
|
||||
|
||||
return ares;
|
||||
std::wstring & ConfParser::Text(const std::wstring & name, const wchar_t * def)
|
||||
{
|
||||
ToText(name, tmp_value_text, def);
|
||||
return tmp_value_text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string & ConfParser::AText(const wchar_t * name)
|
||||
{
|
||||
ToText(name, tmp_value_text);
|
||||
Ezc::WideToUTF8(tmp_value_text, tmp_value_text_ascii);
|
||||
|
||||
return tmp_value_text_ascii;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string & ConfParser::AText(const wchar_t * name, const wchar_t * def)
|
||||
{
|
||||
ToText(name, tmp_value_text, def);
|
||||
Ezc::WideToUTF8(tmp_value_text, tmp_value_text_ascii);
|
||||
|
||||
return tmp_value_text_ascii;
|
||||
}
|
||||
|
||||
|
||||
std::string & ConfParser::AText(const std::wstring & name, const wchar_t * def)
|
||||
{
|
||||
ToText(name, tmp_value_text, def);
|
||||
Ezc::WideToUTF8(tmp_value_text, tmp_value_text_ascii);
|
||||
|
||||
return tmp_value_text_ascii;
|
||||
}
|
||||
|
||||
|
||||
@@ -639,13 +799,15 @@ return ares;
|
||||
|
||||
int ConfParser::Int(const wchar_t * name)
|
||||
{
|
||||
return Int(std::wstring(name), default_int);
|
||||
tmp_name = name;
|
||||
return Int(tmp_name, default_int);
|
||||
}
|
||||
|
||||
|
||||
int ConfParser::Int(const wchar_t * name, int def)
|
||||
{
|
||||
return Int(std::wstring(name), def);
|
||||
tmp_name = name;
|
||||
return Int(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
@@ -659,32 +821,25 @@ return static_cast<int>(res);
|
||||
|
||||
int ConfParser::Int(const std::wstring & name, int def)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i == table_single.end() )
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
if( space.GetValue(name, tmp_value_text) )
|
||||
return ToInt(tmp_value_text);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
return def;
|
||||
|
||||
return ToInt(t->second[0]);
|
||||
}
|
||||
|
||||
return ToInt(i->second);
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t ConfParser::Size(const wchar_t * name)
|
||||
{
|
||||
return Size(std::wstring(name), default_size);
|
||||
tmp_name = name;
|
||||
return Size(tmp_name, default_size);
|
||||
}
|
||||
|
||||
|
||||
size_t ConfParser::Size(const wchar_t * name, size_t def)
|
||||
{
|
||||
return Size(std::wstring(name), def);
|
||||
tmp_name = name;
|
||||
return Size(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
@@ -699,19 +854,10 @@ return static_cast<size_t>(res);
|
||||
|
||||
size_t ConfParser::Size(const std::wstring & name, size_t def)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i == table_single.end() )
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
if( space.GetValue(name, tmp_value_text) )
|
||||
return ToSize(tmp_value_text);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
return def;
|
||||
|
||||
return ToSize(t->second[0]);
|
||||
}
|
||||
|
||||
return ToSize(i->second);
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
@@ -719,16 +865,19 @@ return ToSize(i->second);
|
||||
|
||||
bool ConfParser::Bool(const wchar_t * name)
|
||||
{
|
||||
return Bool(std::wstring(name), default_bool);
|
||||
tmp_name = name;
|
||||
return Bool(tmp_name, default_bool);
|
||||
}
|
||||
|
||||
|
||||
bool ConfParser::Bool(const wchar_t * name, bool def)
|
||||
{
|
||||
return Bool(std::wstring(name), def);
|
||||
tmp_name = name;
|
||||
return Bool(tmp_name, def);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ConfParser::ToBool(const std::wstring & value)
|
||||
{
|
||||
return ( EqualNoCase(value.c_str(), L"true") ||
|
||||
@@ -740,22 +889,18 @@ bool ConfParser::ToBool(const std::wstring & value)
|
||||
|
||||
bool ConfParser::Bool(const std::wstring & name, bool def)
|
||||
{
|
||||
TableSingle::iterator i = table_single.find(name);
|
||||
|
||||
if( i == table_single.end() )
|
||||
{
|
||||
Table::iterator t = table.find(name);
|
||||
if( space.GetValue(name, tmp_value_text) )
|
||||
return ToBool(tmp_value_text);
|
||||
|
||||
if( t == table.end() || t->second.empty() )
|
||||
return def;
|
||||
|
||||
return ToBool(t->second[0]);
|
||||
}
|
||||
|
||||
return ToBool(i->second);
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::SetDefaultText(const wchar_t * def)
|
||||
{
|
||||
default_str = def;
|
||||
}
|
||||
|
||||
void ConfParser::SetDefaultText(const std::wstring & def)
|
||||
{
|
||||
default_str = def;
|
||||
@@ -782,45 +927,38 @@ void ConfParser::SetDefaultBool(bool def)
|
||||
// in lists we don't use default values
|
||||
void ConfParser::ListText(const wchar_t * name, std::vector<std::wstring> & list)
|
||||
{
|
||||
ListText(std::wstring(name), list);
|
||||
tmp_name = name;
|
||||
ListText(tmp_name, list);
|
||||
}
|
||||
|
||||
|
||||
void ConfParser::ListText(const std::wstring & name, std::vector<std::wstring> & list)
|
||||
{
|
||||
list.clear();
|
||||
|
||||
ConfParser::TableSingle::iterator i = table_single.find(name);
|
||||
ConfParser::TableSingle::iterator i = space.table_single.find(name);
|
||||
|
||||
if( i != table_single.end() )
|
||||
if( i != space.table_single.end() )
|
||||
{
|
||||
list.push_back(i->second);
|
||||
return;
|
||||
}
|
||||
|
||||
ConfParser::Table::iterator z = table.find(name);
|
||||
|
||||
if( z != table.end() )
|
||||
else
|
||||
{
|
||||
list = z->second;
|
||||
return;
|
||||
ConfParser::Table::iterator z = space.table.find(name);
|
||||
|
||||
if( z != space.table.end() )
|
||||
list = z->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::UTF8(bool utf)
|
||||
{
|
||||
input_as_utf8 = utf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfParser::Print(std::ostream & out)
|
||||
{
|
||||
TableSingle::iterator i1;
|
||||
|
||||
for(i1 = table_single.begin() ; i1 != table_single.end() ; ++i1)
|
||||
for(i1 = space.table_single.begin() ; i1 != space.table_single.end() ; ++i1)
|
||||
{
|
||||
Ezc::WideToUTF8(i1->first, out);
|
||||
out << '=';
|
||||
@@ -831,7 +969,7 @@ void ConfParser::Print(std::ostream & out)
|
||||
Table::iterator i2;
|
||||
Value::iterator i3;
|
||||
|
||||
for(i2 = table.begin() ; i2 != table.end() ; ++i2)
|
||||
for(i2 = space.table.begin() ; i2 != space.table.end() ; ++i2)
|
||||
{
|
||||
Ezc::WideToUTF8(i2->first, out);
|
||||
out << '=';
|
||||
|
Reference in New Issue
Block a user