changed: class name: ConfParser -> SpaceParser

git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@402 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-04-30 13:10:55 +00:00
parent 02645de1f6
commit cd3a1b853f
7 changed files with 56 additions and 55 deletions

View File

@ -13,10 +13,10 @@ export CXX
export CXXFLAGS export CXXFLAGS
all: confparser mainparser utf8 all: space mainparser utf8
confparser: FORCE space: FORCE
@cd confparser ; $(MAKE) -e @cd space ; $(MAKE) -e
mainparser: FORCE mainparser: FORCE
@cd mainparser ; $(MAKE) -e @cd mainparser ; $(MAKE) -e
@ -29,11 +29,11 @@ FORCE:
clean: clean:
@cd confparser ; $(MAKE) -e clean @cd space ; $(MAKE) -e clean
@cd mainparser ; $(MAKE) -e clean @cd mainparser ; $(MAKE) -e clean
@cd utf8 ; $(MAKE) -e clean @cd utf8 ; $(MAKE) -e clean
depend: depend:
@cd confparser ; $(MAKE) -e depend @cd space ; $(MAKE) -e depend
@cd mainparser ; $(MAKE) -e depend @cd mainparser ; $(MAKE) -e depend
@cd utf8 ; $(MAKE) -e depend @cd utf8 ; $(MAKE) -e depend

View File

@ -1,6 +1,6 @@
include Makefile.o.dep include Makefile.o.dep
libname=confparser.a libname=space.a
all: $(libname) all: $(libname)

View File

@ -1,4 +1,4 @@
# DO NOT DELETE # DO NOT DELETE
confparser.o: confparser.h space.h ../utf8/utf8.h
space.o: space.h ../utf8/utf8.h space.o: space.h ../utf8/utf8.h
spaceparser.o: ../utf8/utf8.h

View File

@ -1 +1 @@
o = confparser.o space.o o = space.o spaceparser.o

View File

@ -58,10 +58,10 @@ A config file can look like this:
variable4 = (" value 1 " , "value2", value 3) variable4 = (" value 1 " , "value2", value 3)
sample of use: sample of use:
ConfParser parser; SpaceParser parser;
parser.Parse("/path/to/config"); parser.Parse("/path/to/config");
if( parser.status == ConfParser::ok ) if( parser.status == SpaceParser::ok )
{ {
// the whole config we have in parser.table (parser.table_single) // the whole config we have in parser.table (parser.table_single)
} }

View File

@ -46,26 +46,26 @@ namespace PT
ConfParser::ConfParser() SpaceParser::SpaceParser()
{ {
root_space = 0; root_space = 0;
SetDefault(); SetDefault();
} }
void ConfParser::SetSpace(Space * pspace) void SpaceParser::SetSpace(Space * pspace)
{ {
root_space = pspace; root_space = pspace;
} }
void ConfParser::SetSpace(Space & pspace) void SpaceParser::SetSpace(Space & pspace)
{ {
root_space = &pspace; root_space = &pspace;
} }
void ConfParser::SetDefault() void SpaceParser::SetDefault()
{ {
// you can change this separators to what you want // you can change this separators to what you want
// you shoud not use only white characters here (as expected by IsWhite() method) // you shoud not use only white characters here (as expected by IsWhite() method)
@ -82,25 +82,25 @@ void ConfParser::SetDefault()
} }
void ConfParser::SplitSingle(bool split) void SpaceParser::SplitSingle(bool split)
{ {
split_single = split; split_single = split;
} }
void ConfParser::SkipEmpty(bool skip) void SpaceParser::SkipEmpty(bool skip)
{ {
skip_empty = skip; skip_empty = skip;
} }
void ConfParser::UseEscapeChar(bool escape) void SpaceParser::UseEscapeChar(bool escape)
{ {
use_escape_char = escape; use_escape_char = escape;
} }
void ConfParser::UTF8(bool utf) void SpaceParser::UTF8(bool utf)
{ {
input_as_utf8 = utf; input_as_utf8 = utf;
} }
@ -108,7 +108,7 @@ void ConfParser::UTF8(bool utf)
ConfParser::Status ConfParser::Parse(const char * file_name) SpaceParser::Status SpaceParser::Parse(const char * file_name)
{ {
reading_from_file = true; reading_from_file = true;
@ -130,7 +130,7 @@ return status;
ConfParser::Status ConfParser::Parse(const std::string & file_name) SpaceParser::Status SpaceParser::Parse(const std::string & file_name)
{ {
return Parse(file_name.c_str()); return Parse(file_name.c_str());
} }
@ -138,7 +138,7 @@ ConfParser::Status ConfParser::Parse(const std::string & file_name)
ConfParser::Status ConfParser::Parse(const wchar_t * file_name) SpaceParser::Status SpaceParser::Parse(const wchar_t * file_name)
{ {
PT::WideToUTF8(file_name, afile_name); PT::WideToUTF8(file_name, afile_name);
return Parse(afile_name.c_str()); return Parse(afile_name.c_str());
@ -146,14 +146,14 @@ ConfParser::Status ConfParser::Parse(const wchar_t * file_name)
ConfParser::Status ConfParser::Parse(const std::wstring & file_name) SpaceParser::Status SpaceParser::Parse(const std::wstring & file_name)
{ {
return Parse(file_name.c_str()); return Parse(file_name.c_str());
} }
ConfParser::Status ConfParser::ParseString(const char * str) SpaceParser::Status SpaceParser::ParseString(const char * str)
{ {
reading_from_file = false; reading_from_file = false;
reading_from_wchar_string = false; reading_from_wchar_string = false;
@ -166,13 +166,13 @@ return status;
} }
ConfParser::Status ConfParser::ParseString(const std::string & str) SpaceParser::Status SpaceParser::ParseString(const std::string & str)
{ {
return ParseString(str.c_str()); return ParseString(str.c_str());
} }
ConfParser::Status ConfParser::ParseString(const wchar_t * str) SpaceParser::Status SpaceParser::ParseString(const wchar_t * str)
{ {
reading_from_file = false; reading_from_file = false;
reading_from_wchar_string = true; reading_from_wchar_string = true;
@ -185,13 +185,13 @@ return status;
} }
ConfParser::Status ConfParser::ParseString(const std::wstring & str) SpaceParser::Status SpaceParser::ParseString(const std::wstring & str)
{ {
return ParseString(str.c_str()); return ParseString(str.c_str());
} }
void ConfParser::Parse() void SpaceParser::Parse()
{ {
if( !root_space ) if( !root_space )
{ {
@ -215,7 +215,7 @@ void ConfParser::Parse()
} }
void ConfParser::ParseLoop() void SpaceParser::ParseLoop()
{ {
while( status == ok && lastc != -1 ) while( status == ok && lastc != -1 )
{ {
@ -248,7 +248,7 @@ void ConfParser::ParseLoop()
} }
void ConfParser::SpaceEnds() void SpaceParser::SpaceEnds()
{ {
if( space == root_space ) if( space == root_space )
{ {
@ -263,7 +263,7 @@ void ConfParser::SpaceEnds()
} }
void ConfParser::SpaceStarts() void SpaceParser::SpaceStarts()
{ {
Space * new_space = new Space(); Space * new_space = new Space();
space->spaces.push_back(new_space); space->spaces.push_back(new_space);
@ -275,7 +275,7 @@ void ConfParser::SpaceStarts()
} }
void ConfParser::ReadAddValue() void SpaceParser::ReadAddValue()
{ {
ReadChar(); // skipping separator '=' ReadChar(); // skipping separator '='
@ -290,7 +290,7 @@ void ConfParser::ReadAddValue()
} }
bool ConfParser::IsVariableChar(int c) bool SpaceParser::IsVariableChar(int c)
{ {
if( (c>='a' && c<='z') || if( (c>='a' && c<='z') ||
(c>='A' && c<='Z') || (c>='A' && c<='Z') ||
@ -302,7 +302,7 @@ return false;
} }
bool ConfParser::IsWhite(int c) bool SpaceParser::IsWhite(int c)
{ {
// dont use '\n' here // dont use '\n' here
// 13 (\r) is at the end of a line in a dos file \r\n // 13 (\r) is at the end of a line in a dos file \r\n
@ -315,7 +315,7 @@ return false;
void ConfParser::SkipWhite() void SpaceParser::SkipWhite()
{ {
while( IsWhite(lastc) || lastc == commentary ) while( IsWhite(lastc) || lastc == commentary )
{ {
@ -327,7 +327,7 @@ void ConfParser::SkipWhite()
} }
void ConfParser::SkipWhiteLines() void SpaceParser::SkipWhiteLines()
{ {
while( IsWhite(lastc) || lastc == commentary || lastc=='\n' ) while( IsWhite(lastc) || lastc == commentary || lastc=='\n' )
{ {
@ -339,7 +339,7 @@ void ConfParser::SkipWhiteLines()
} }
void ConfParser::SkipLine() void SpaceParser::SkipLine()
{ {
while( lastc != -1 && lastc != '\n' ) while( lastc != -1 && lastc != '\n' )
ReadChar(); ReadChar();
@ -347,7 +347,7 @@ void ConfParser::SkipLine()
void ConfParser::Trim(std::wstring & s) void SpaceParser::Trim(std::wstring & s)
{ {
std::wstring::size_type i; std::wstring::size_type i;
@ -380,7 +380,7 @@ std::wstring::size_type i;
void ConfParser::AddOption() void SpaceParser::AddOption()
{ {
if( value.empty() && skip_empty ) if( value.empty() && skip_empty )
{ {
@ -403,7 +403,7 @@ void ConfParser::AddOption()
void ConfParser::DeleteFromTable(const std::wstring & var) void SpaceParser::DeleteFromTable(const std::wstring & var)
{ {
Space::Table::iterator i = space->table.find(var); Space::Table::iterator i = space->table.find(var);
@ -413,7 +413,7 @@ void ConfParser::DeleteFromTable(const std::wstring & var)
void ConfParser::DeleteFromTableSingle(const std::wstring & var) void SpaceParser::DeleteFromTableSingle(const std::wstring & var)
{ {
Space::TableSingle::iterator i = space->table_single.find(var); Space::TableSingle::iterator i = space->table_single.find(var);
@ -423,7 +423,7 @@ void ConfParser::DeleteFromTableSingle(const std::wstring & var)
void ConfParser::ReadVariable() void SpaceParser::ReadVariable()
{ {
variable.clear(); variable.clear();
SkipWhite(); SkipWhite();
@ -439,7 +439,7 @@ void ConfParser::ReadVariable()
bool ConfParser::ReadValue() bool SpaceParser::ReadValue()
{ {
value.clear(); value.clear();
SkipWhite(); SkipWhite();
@ -452,7 +452,7 @@ bool ConfParser::ReadValue()
bool ConfParser::ReadValueList() bool SpaceParser::ReadValueList()
{ {
ReadChar(); // skipping first list character '(' ReadChar(); // skipping first list character '('
SkipWhiteLines(); // lists can be split into several lines SkipWhiteLines(); // lists can be split into several lines
@ -479,7 +479,7 @@ return true;
bool ConfParser::ReadValueNoList(bool use_list_delimiter) bool SpaceParser::ReadValueNoList(bool use_list_delimiter)
{ {
bool res; bool res;
@ -505,11 +505,12 @@ return res;
bool ConfParser::ReadValueQuoted() bool SpaceParser::ReadValueQuoted()
{ {
ReadChar(); // skipping the first quote ReadChar(); // skipping the first quote
// !! dodac obsluge innych escapowanych znakow w szczegolnosci \0 (serializator Space juz tak zapisuje) // !! IMPROVE ME
// add some other escaped characters especialy \0 (the serializator is working that way now)
while( lastc != '"' && lastc != -1 ) while( lastc != '"' && lastc != -1 )
{ {
@ -531,7 +532,7 @@ return true;
bool ConfParser::ReadValueSimple(bool use_list_delimiter) bool SpaceParser::ReadValueSimple(bool use_list_delimiter)
{ {
int list_delimiter1 = -1; int list_delimiter1 = -1;
int list_delimiter2 = -1; int list_delimiter2 = -1;
@ -556,7 +557,7 @@ return true;
} }
int ConfParser::ReadUTF8Char() int SpaceParser::ReadUTF8Char()
{ {
int c; int c;
bool correct; bool correct;
@ -582,7 +583,7 @@ return lastc;
int ConfParser::ReadASCIIChar() int SpaceParser::ReadASCIIChar()
{ {
lastc = file.get(); lastc = file.get();
@ -595,7 +596,7 @@ return lastc;
int ConfParser::ReadCharFromWcharString() int SpaceParser::ReadCharFromWcharString()
{ {
if( *pchar_unicode == 0 ) if( *pchar_unicode == 0 )
lastc = -1; lastc = -1;
@ -609,7 +610,7 @@ return lastc;
} }
int ConfParser::ReadCharFromUTF8String() int SpaceParser::ReadCharFromUTF8String()
{ {
int c; int c;
bool correct; bool correct;
@ -636,7 +637,7 @@ return lastc;
} }
int ConfParser::ReadCharFromAsciiString() int SpaceParser::ReadCharFromAsciiString()
{ {
if( *pchar_ascii == 0 ) if( *pchar_ascii == 0 )
lastc = -1; lastc = -1;
@ -650,7 +651,7 @@ return lastc;
} }
int ConfParser::ReadChar() int SpaceParser::ReadChar()
{ {
if( reading_from_file ) if( reading_from_file )
{ {

View File

@ -48,7 +48,7 @@ namespace PT
class ConfParser class SpaceParser
{ {
public: public:
@ -56,7 +56,7 @@ public:
/* /*
ctor -- setting default values (SetDefault() method) ctor -- setting default values (SetDefault() method)
*/ */
ConfParser(); SpaceParser();
/* /*