changed: SpaceParser -- parser's engine has been rewritten
now we can map all strings to all strings documentation in space.h need to be updated yet git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@407 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
161
space/space.h
161
space/space.h
@@ -307,7 +307,29 @@ public:
|
||||
template<class Stream>
|
||||
void Serialize(Stream & out, bool use_indents = false, bool use_comments = false, int level = 0) const;
|
||||
|
||||
template<class Stream>
|
||||
void SerializeTableSingle(Stream & out, bool use_indents, int level) const;
|
||||
|
||||
template<class Stream>
|
||||
void SerializeTableMulti(Stream & out, bool use_indents, int level) const;
|
||||
|
||||
template<class Stream>
|
||||
static void PrintValue(Stream & out, const std::wstring & str, bool use_quote = true);
|
||||
|
||||
// for other uses
|
||||
template<class Stream>
|
||||
static void PrintValue(Stream & out, const std::string & str, bool use_quote = true);
|
||||
|
||||
template<class Stream>
|
||||
static void PrintKey(Stream & out, const std::wstring & str);
|
||||
|
||||
template<class Stream>
|
||||
static void PrintLevel(Stream & out, bool use_indents, int level);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::wstring tmp_name;
|
||||
std::wstring tmp_value_text;
|
||||
std::string tmp_value_text_ascii;
|
||||
@@ -318,19 +340,8 @@ private:
|
||||
bool ToBool(const std::wstring & value);
|
||||
wchar_t ToSmall(wchar_t c);
|
||||
bool EqualNoCase(const wchar_t * str1, const wchar_t * str2);
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void PrintLevel(Stream & out, bool use_indents, int level) const;
|
||||
|
||||
template<class Stream>
|
||||
void SerializeTableSingle(Stream & out, bool use_indents, int level) const;
|
||||
|
||||
template<class Stream>
|
||||
void SerializeTableMulti(Stream & out, bool use_indents, int level) const;
|
||||
|
||||
template<class Stream>
|
||||
void PrintValue(Stream & out, const std::wstring & str) const;
|
||||
static bool IsWhite(int c);
|
||||
static bool HasWhite(const std::wstring & str);
|
||||
|
||||
};
|
||||
|
||||
@@ -339,7 +350,7 @@ private:
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void Space::PrintLevel(Stream & out, bool use_indents, int level) const
|
||||
void Space::PrintLevel(Stream & out, bool use_indents, int level)
|
||||
{
|
||||
if( use_indents )
|
||||
{
|
||||
@@ -349,10 +360,12 @@ void Space::PrintLevel(Stream & out, bool use_indents, int level) const
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void Space::PrintValue(Stream & out, const std::wstring & str) const
|
||||
void Space::PrintValue(Stream & out, const std::wstring & str, bool use_quote)
|
||||
{
|
||||
out << '\"';
|
||||
if( use_quote )
|
||||
out << '\"';
|
||||
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
{
|
||||
@@ -362,30 +375,78 @@ void Space::PrintValue(Stream & out, const std::wstring & str) const
|
||||
if( str[i] == '"' )
|
||||
out << L"\\\"";
|
||||
else
|
||||
if( str[i] == '\r' )
|
||||
out << L"\\r";
|
||||
else
|
||||
if( str[i] == '\n' )
|
||||
out << L"\\n";
|
||||
else
|
||||
if( str[i] == 0 )
|
||||
out << L"\\0";
|
||||
else
|
||||
out << str[i];
|
||||
}
|
||||
|
||||
out << '\"';
|
||||
if( use_quote )
|
||||
out << '\"';
|
||||
}
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void Space::PrintValue(Stream & out, const std::string & str, bool use_quote)
|
||||
{
|
||||
if( use_quote )
|
||||
out << '\"';
|
||||
|
||||
for(size_t i=0 ; i<str.size() ; ++i)
|
||||
{
|
||||
if( str[i] == '\\' )
|
||||
out << "\\\\";
|
||||
else
|
||||
if( str[i] == '"' )
|
||||
out << "\\\"";
|
||||
else
|
||||
if( str[i] == '\r' )
|
||||
out << "\\r";
|
||||
else
|
||||
if( str[i] == '\n' )
|
||||
out << "\\n";
|
||||
else
|
||||
if( str[i] == 0 )
|
||||
out << "\\0";
|
||||
else
|
||||
out << str[i];
|
||||
}
|
||||
|
||||
if( use_quote )
|
||||
out << '\"';
|
||||
}
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void Space::PrintKey(Stream & out, const std::wstring & str)
|
||||
{
|
||||
bool use_quote = false;
|
||||
|
||||
if( str.empty() || HasWhite(str) )
|
||||
use_quote = true;
|
||||
|
||||
PrintValue(out, str, use_quote);
|
||||
}
|
||||
|
||||
|
||||
template<class Stream>
|
||||
void Space::SerializeTableSingle(Stream & out, bool use_indents, int level) const
|
||||
{
|
||||
if( !table_single.empty() )
|
||||
{
|
||||
TableSingle::const_iterator i;
|
||||
TableSingle::const_iterator i;
|
||||
|
||||
for(i = table_single.begin() ; i != table_single.end() ; ++i)
|
||||
{
|
||||
PrintLevel(out, use_indents, level);
|
||||
out << i->first << L" = ";
|
||||
PrintValue(out, i->second);
|
||||
out << '\n';
|
||||
}
|
||||
for(i=table_single.begin() ; i != table_single.end() ; ++i)
|
||||
{
|
||||
PrintLevel(out, use_indents, level);
|
||||
PrintKey(out, i->first);
|
||||
out << L" = ";
|
||||
PrintValue(out, i->second);
|
||||
out << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,33 +458,30 @@ void Space::SerializeTableMulti(Stream & out, bool use_indents, int level) const
|
||||
Table::const_iterator i2;
|
||||
size_t v;
|
||||
|
||||
|
||||
if( !table.empty() )
|
||||
for(i2 = table.begin() ; i2 != table.end() ; ++i2)
|
||||
{
|
||||
for(i2 = table.begin() ; i2 != table.end() ; ++i2)
|
||||
PrintLevel(out, use_indents, level);
|
||||
PrintKey(out, i2->first);
|
||||
out << L" = ";
|
||||
|
||||
if( i2->second.size() != 1 )
|
||||
out << '(';
|
||||
|
||||
for(v = 0 ; v < i2->second.size() ; ++v)
|
||||
{
|
||||
PrintLevel(out, use_indents, level);
|
||||
out << i2->first << L" = ";
|
||||
if( v > 0 )
|
||||
PrintLevel(out, use_indents, level + i2->first.size() + 3);
|
||||
|
||||
if( i2->second.size() != 1 )
|
||||
out << '(';
|
||||
PrintValue(out, i2->second[v]);
|
||||
|
||||
for(v = 0 ; v < i2->second.size() ; ++v)
|
||||
{
|
||||
if( v > 0 )
|
||||
PrintLevel(out, use_indents, level + i2->first.size() + 3);
|
||||
|
||||
PrintValue(out, i2->second[v]);
|
||||
|
||||
if( v + 1 < i2->second.size() )
|
||||
out << '\n';
|
||||
}
|
||||
|
||||
if( i2->second.size() != 1 )
|
||||
out << ')';
|
||||
|
||||
out << '\n';
|
||||
if( v + 1 < i2->second.size() )
|
||||
out << '\n';
|
||||
}
|
||||
|
||||
if( i2->second.size() != 1 )
|
||||
out << ')';
|
||||
|
||||
out << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,7 +495,10 @@ void Space::Serialize(Stream & out, bool use_indents, bool use_comments, int lev
|
||||
PrintLevel(out, use_indents, level);
|
||||
|
||||
if( !name.empty() )
|
||||
out << name << ' ';
|
||||
{
|
||||
PrintKey(out, name);
|
||||
out << ' ';
|
||||
}
|
||||
|
||||
out << L"(\n";
|
||||
|
||||
|
Reference in New Issue
Block a user