start changing the Space API

removed table_single from Space



git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1065 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2017-06-27 16:51:55 +00:00
parent 62f16ecb1b
commit cde990ba82
9 changed files with 253 additions and 400 deletions

View File

@ -16,8 +16,8 @@ ifndef AR
AR = ar
endif
#CXX=g++48
#CXXFLAGS=-Wall -O0 -g
#CXX=g++5
#CXXFLAGS=-Wall -O0 -g3 -gdwarf-2 -std=c++14
export CXX
export CXXFLAGS

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2016, Tomasz Sowa
* Copyright (c) 2016-2017, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -239,7 +239,7 @@ void MainSpaceParser::AddValueToItem(const std::wstring & name, const std::wstri
{
table_value = &space->table[name];
table_value->push_back(*val);
space->table_single.erase(name);
//space->table_single.erase(name);
}
else
{

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012, Tomasz Sowa
* Copyright (c) 2012-2017, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -76,7 +76,6 @@ void JSONToSpaceParser::SetDefault()
table_start = '[';
table_end = ']';
option_delimiter = ',';
split_single = true;
skip_empty = false;
use_escape_char = true;
input_as_utf8 = true;
@ -85,11 +84,6 @@ void JSONToSpaceParser::SetDefault()
}
void JSONToSpaceParser::SplitSingle(bool split)
{
split_single = split;
}
void JSONToSpaceParser::SkipEmpty(bool skip)
{
@ -503,15 +497,6 @@ void JSONToSpaceParser::DeleteFromTable(const std::wstring & var)
void JSONToSpaceParser::DeleteFromTableSingle(const std::wstring & var)
{
Space::TableSingle::iterator i = space->table_single.find(var);
if( i != space->table_single.end() )
space->table_single.erase(i);
}
void JSONToSpaceParser::ReadTokenQuoted()
@ -673,20 +658,10 @@ void JSONToSpaceParser::AddKeyValuePair()
if( value.empty() && skip_empty )
{
DeleteFromTable(key);
DeleteFromTableSingle(key);
return;
}
if( split_single && value.size() == 1 )
{
space->table_single[key] = value[0];
DeleteFromTable(key);
}
else
{
space->table[key] = value;
DeleteFromTableSingle(key);
}
}

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012, Tomasz Sowa
* Copyright (c) 2012-2017, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -68,7 +68,7 @@ public:
/*
setting options of the parser to the default values
utf8, split single etc.
utf8 etc.
*/
void SetDefault();
@ -124,23 +124,11 @@ public:
Status ParseString(const std::wstring & str);
/*
if your list consists of only one item, e.g:
option1 = value 1
option2 = "value 2"
option3 = ( "value 3" )
then if you call SplitSingle(true) then such values will be stored in
'table_single' instead of 'table' map
default: false
*/
void SplitSingle(bool split);
/*
if true then empty values and lists, e.g:
option =
option2 = ()
will be omitted (not inserted to 'table' or 'table_single')
will be omitted (not inserted to 'table')
default: false
*/
void SkipEmpty(bool skip);
@ -276,18 +264,11 @@ private:
std::ifstream file;
/*
if true then lists with one item will be put into 'table_single' table
default: false
*/
bool split_single;
/*
if true then empty lists, e.g:
option =
option2 = ()
will be omitted (not inserted to 'table' or 'table_single')
will be omitted (not inserted to 'table')
default: false
*/
bool skip_empty;
@ -345,7 +326,6 @@ private:
void SpaceStarts(bool has_space_name, bool skip_space_char = true);
void DeleteFromTable(const std::wstring & var);
void DeleteFromTableSingle(const std::wstring & var);
void ReadTokenQuoted();
void ReadTokenSingle(bool white_delimit, bool new_line_delimit, int delimit1, int delimit2);

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2013, Tomasz Sowa
* Copyright (c) 2008-2017, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -71,7 +71,6 @@ Space & Space::operator=(const Space & s)
Clear();
name = s.name;
table_single = s.table_single;
table = s.table;
parent = s.parent;
@ -93,7 +92,6 @@ return *this;
void Space::Clear()
{
name.clear();
table_single.clear();
table.clear();
for(size_t i=0 ; i<spaces.size() ; ++i)
@ -114,14 +112,6 @@ std::wstring * Space::GetValue(const wchar_t * name)
std::wstring * Space::GetValue(const std::wstring & name)
{
TableSingle::iterator i = table_single.find(name);
if( i != table_single.end() )
{
return &i->second;
}
else
{
Table::iterator t = table.find(name);
if( t == table.end() || t->second.empty() )
@ -132,21 +122,12 @@ std::wstring * Space::GetValue(const std::wstring & name)
{
return &t->second[0];
}
}
}
const std::wstring * Space::GetValue(const std::wstring & name) const
{
TableSingle::const_iterator i = table_single.find(name);
if( i != table_single.end() )
{
return &i->second;
}
else
{
Table::const_iterator t = table.find(name);
if( t == table.end() || t->second.empty() )
@ -157,7 +138,6 @@ const std::wstring * Space::GetValue(const std::wstring & name) const
{
return &t->second[0];
}
}
}
@ -189,14 +169,6 @@ return HasValue(name, tmp_value_text);
bool Space::HasValue(const std::wstring & name, const std::wstring & value)
{
TableSingle::const_iterator i = table_single.find(name);
if( i != table_single.end() )
{
return i->second == value;
}
else
{
Table::const_iterator t = table.find(name);
if( t != table.end() )
@ -205,7 +177,6 @@ bool Space::HasValue(const std::wstring & name, const std::wstring & value)
if( t->second[i] == value )
return true;
}
}
return false;
}
@ -296,6 +267,7 @@ int Space::Int(const wchar_t * name, int def)
int Space::ToInt(const std::wstring & value)
{
// !! FIXME what if value is empty?
long res = (value[0] == '0')? wcstol(value.c_str() + 1, 0, 8) : wcstol(value.c_str(), 0, 10);
return static_cast<int>(res);
@ -332,6 +304,7 @@ long Space::Long(const wchar_t * name, long def)
long Space::ToLong(const std::wstring & value)
{
// !! FIXME what if value is empty?
return (value[0] == '0')? wcstol(value.c_str() + 1, 0, 8) : wcstol(value.c_str(), 0, 10);
}
@ -365,6 +338,7 @@ size_t Space::Size(const wchar_t * name, size_t def)
size_t Space::ToSize(const std::wstring & value)
{
// !! FIXME what if value is empty?
unsigned long res = (value[0] == '0')? wcstoul(value.c_str() + 1, 0, 8) : wcstoul(value.c_str(), 0, 10);
return static_cast<size_t>(res);
@ -401,7 +375,7 @@ bool Space::Bool(const wchar_t * name, bool def)
bool Space::ToBool(const std::wstring & value)
{
return ( EqualNoCase(value.c_str(), L"true") ||
return (EqualNoCase(value.c_str(), L"true") ||
EqualNoCase(value.c_str(), L"yes") ||
EqualNoCase(value.c_str(), L"1")
);
@ -419,67 +393,162 @@ return def;
}
// !! CHECKME
std::wstring & Space::FindAdd(const std::wstring & name)
{
Value * value;
Table::iterator t = table.find(name);
if( t != table.end() )
{
value = &t->second;
}
else
{
value = &table[name];
}
if( value->empty() )
value->push_back(std::wstring());
return (*value)[0];
}
// !! CHECKME
std::wstring & Space::FindAdd(const wchar_t * name)
{
tmp_name = name;
std::wstring * value = GetValue(tmp_name);
if( !value )
{
value = &table_single[tmp_name];
table.erase(tmp_name);
}
return *value;
}
std::wstring & Space::FindAdd(const std::wstring & name)
{
std::wstring * value = GetValue(name);
if( !value )
{
value = &table_single[name];
table.erase(name);
}
return *value;
return FindAdd(tmp_name);
}
// !! CHECKME
std::wstring & Space::FindAdd(const WTextStream & name)
{
name.to_string(tmp_name);
std::wstring * value = GetValue(tmp_name);
if( !value )
{
value = &table_single[tmp_name];
table.erase(tmp_name);
}
return *value;
return FindAdd(tmp_name);
}
std::wstring & Space::Add(const wchar_t * name, bool value)
/*
*
*
*
*
* CHECKME !!
*/
std::wstring & Space::Add(const std::wstring & name, const std::wstring & value, bool replace_existing)
{
Table::iterator i = table.find(name);
if( i == table.end() )
{
Value & val = table[name];
val.push_back(value);
return val.back();
}
else
{
Value & val = i->second;
if( replace_existing )
val.clear();
val.push_back(value);
return val.back();
}
}
// CHECKME !!
std::wstring & Space::Add(const std::wstring & name, const wchar_t * value, bool replace_existing)
{
tmp_value = value;
return Add(name, tmp_value, replace_existing);
}
// CHECKME !!
std::wstring & Space::Add(const wchar_t * name, const wchar_t * value, bool replace_existing)
{
tmp_name = name;
tmp_value = value;
return Add(tmp_name, tmp_value, replace_existing);
}
// CHECKME !!
std::wstring & Space::Add(const wchar_t * name, const std::wstring & value, bool replace_existing)
{
tmp_name = name;
return Add(tmp_name, value, replace_existing);
}
// CHECKME !!
std::wstring & Space::Add(const wchar_t * name, const WTextStream & value, bool replace_existing)
{
tmp_name = name;
value.to_string(tmp_value);
return Add(tmp_name, tmp_value, replace_existing);
}
// CHECKME !!
std::wstring & Space::Add(const std::wstring & name, const WTextStream & value, bool replace_existing)
{
value.to_string(tmp_value);
return Add(name, tmp_value, replace_existing);
}
// CHECKME !!
std::wstring & Space::Add(const WTextStream & name, const WTextStream & value, bool replace_existing)
{
name.to_string(tmp_name);
value.to_string(tmp_value);
return Add(tmp_name, tmp_value, replace_existing);
}
/*
*
*
*
*
*
*/
// CHECKME
std::wstring & Space::Add(const std::wstring & name, bool value, bool replace_existing)
{
if( value )
return Add(name, L"true");
return Add(name, L"true", replace_existing);
else
return Add(name, L"false");
return Add(name, L"false", replace_existing);
}
std::wstring & Space::Add(const std::wstring & name, bool value)
// CHECKME
std::wstring & Space::Add(const wchar_t * name, bool value, bool replace_existing)
{
return Add(name.c_str(), value);
tmp_name = name;
return Add(tmp_name, value, replace_existing);
}
std::wstring & Space::Add(const wchar_t * name, int value)
// CHECKME
std::wstring & Space::Add(const std::wstring & name, int value, bool replace_existing)
{
wchar_t value_str[50];
@ -489,17 +558,23 @@ wchar_t value_str[50];
swprintf(value_str, sizeof(value_str)/sizeof(wchar_t), L"%d", value);
#endif
return Add(name, value_str);
return Add(name, value_str, replace_existing);
}
std::wstring & Space::Add(const std::wstring & name, int value)
// CHECKME
std::wstring & Space::Add(const wchar_t * name, int value, bool replace_existing)
{
return Add(name.c_str(), value);
tmp_name = name;
return Add(tmp_name, value, replace_existing);
}
std::wstring & Space::Add(const wchar_t * name, long value)
// CHECKME
std::wstring & Space::Add(const std::wstring & name, long value, bool replace_existing)
{
wchar_t value_str[50];
@ -509,18 +584,21 @@ wchar_t value_str[50];
swprintf(value_str, sizeof(value_str)/sizeof(wchar_t), L"%ld", value);
#endif
return Add(name, value_str);
return Add(name, value_str, replace_existing);
}
std::wstring & Space::Add(const std::wstring & name, long value)
// CHECKME
std::wstring & Space::Add(const wchar_t * name, long value, bool replace_existing)
{
return Add(name.c_str(), value);
tmp_name = name;
return Add(tmp_name, value, replace_existing);
}
std::wstring & Space::Add(const wchar_t * name, size_t value)
std::wstring & Space::Add(const std::wstring & name, size_t value, bool replace_existing)
{
wchar_t value_str[50];
@ -531,111 +609,38 @@ wchar_t value_str[50];
swprintf(value_str, sizeof(value_str)/sizeof(wchar_t), L"%zu", value);
#endif
return Add(name, value_str);
return Add(name, value_str, replace_existing);
}
std::wstring & Space::Add(const std::wstring & name, size_t value)
{
return Add(name.c_str(), value);
}
std::wstring & Space::Add(const wchar_t * name, const wchar_t * value)
std::wstring & Space::Add(const wchar_t * name, size_t value, bool replace_existing)
{
tmp_name = name;
std::wstring & val = table_single[tmp_name];
val = value;
return val;
return Add(tmp_name, value, replace_existing);
}
std::wstring & Space::Add(const wchar_t * name, const std::wstring & value)
void Space::Remove(const std::wstring & name)
{
tmp_name = name;
std::wstring & val = table_single[tmp_name];
val = value;
return val;
table.erase(name);
}
std::wstring & Space::Add(const std::wstring & name, const std::wstring & value)
{
std::wstring & val = table_single[name];
val = value;
return val;
}
std::wstring & Space::Add(const wchar_t * name, const WTextStream & value)
{
tmp_name = name;
std::wstring & val = table_single[tmp_name];
value.to_string(val, true);
return val;
}
std::wstring & Space::Add(const std::wstring & name, const WTextStream & value)
{
std::wstring & val = table_single[name];
value.to_string(val, true);
return val;
}
std::wstring & Space::Add(const WTextStream & name, const WTextStream & value)
{
name.to_string(tmp_name, true);
std::wstring & val = table_single[tmp_name];
value.to_string(val, true);
return val;
}
void Space::Remove(const wchar_t * name)
{
tmp_name = name;
table_single.erase(tmp_name);
table.erase(tmp_name);
}
void Space::Remove(const std::wstring & name)
{
table_single.erase(name);
table.erase(name);
Remove(tmp_name);
}
Space & Space::AddSpace(const wchar_t * name)
{
spaces.push_back(new Space());
spaces.back()->name = name;
spaces.back()->parent = this;
return *spaces.back();
}
// CHECKME
Space & Space::AddSpace(const std::wstring & name)
{
spaces.push_back(new Space());
@ -646,11 +651,21 @@ return *spaces.back();
}
// CHECKME
Space & Space::AddSpace(const wchar_t * name)
{
tmp_name = name;
return AddSpace(tmp_name);
}
Space * Space::FindSpace(const wchar_t * name)
{
for(size_t i=0 ; i<spaces.size() ; ++i)
{
if( spaces[i]->name == name )
if( spaces[i]->name == name ) // there is a special == operator in string class taking c-string as an argument
return spaces[i];
}
@ -730,6 +745,25 @@ void Space::RemoveSpace(size_t child_index)
bool Space::ListText(const std::wstring & name, std::vector<std::wstring> & list)
{
list.clear();
Table::iterator t = table.find(name);
if( t != table.end() )
{
list = t->second;
return true;
}
return false;
}
// in lists we don't use default values
bool Space::ListText(const wchar_t * name, std::vector<std::wstring> & list)
{
@ -738,34 +772,11 @@ bool Space::ListText(const wchar_t * name, std::vector<std::wstring> & list)
}
bool Space::ListText(const std::wstring & name, std::vector<std::wstring> & list)
{
list.clear();
TableSingle::iterator i = table_single.find(name);
if( i != table_single.end() )
{
list.push_back(i->second);
return true;
}
else
{
Table::iterator t = table.find(name);
if( t != table.end() )
{
list = t->second;
return true;
}
}
return false;
}
wchar_t Space::ToSmall(wchar_t c)
{
if( c>='A' && c<='Z' )
if( c >= 'A' && c <= 'Z' )
c = c - 'A' + 'a';
return c;

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2012, Tomasz Sowa
* Copyright (c) 2010-2017, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -65,7 +65,7 @@ sample of use:
if( parser.status == SpaceParser::ok )
{
// the whole config we have in parser.table (parser.table_single)
// the whole config we have in parser.table
}
config syntax:
@ -174,8 +174,6 @@ public:
void Clear();
// first we are searching in 'table_single' and if there is not
// such a 'name' there then we are looking in 'table' (for the first item in the vector)
// 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'
@ -195,7 +193,7 @@ public:
/*
those methods are used to extract information from space.table or space.table_single
those methods are used to extract information from space.table
as a parameter they take the name of an option
and a default value (if there is no such a parameter),
they return appropriate value (either text, int or boolean)
@ -229,21 +227,23 @@ public:
std::wstring & FindAdd(const std::wstring & name);
std::wstring & FindAdd(const WTextStream & name);
std::wstring & Add(const wchar_t * name, bool value);
std::wstring & Add(const std::wstring & name, bool value);
std::wstring & Add(const wchar_t * name, int value);
std::wstring & Add(const std::wstring & name, int value);
std::wstring & Add(const wchar_t * name, long value);
std::wstring & Add(const std::wstring & name, long value);
std::wstring & Add(const wchar_t * name, size_t value);
std::wstring & Add(const std::wstring & name, size_t value);
std::wstring & Add(const wchar_t * name, const wchar_t * value);
std::wstring & Add(const wchar_t * name, const std::wstring & value);
std::wstring & Add(const std::wstring & name, const std::wstring & value);
std::wstring & Add(const wchar_t * name, bool value, bool replace_existing = true);
std::wstring & Add(const std::wstring & name, bool value, bool replace_existing = true);
std::wstring & Add(const wchar_t * name, int value, bool replace_existing = true);
std::wstring & Add(const std::wstring & name, int value, bool replace_existing = true);
std::wstring & Add(const wchar_t * name, long value, bool replace_existing = true);
std::wstring & Add(const std::wstring & name, long value, bool replace_existing = true);
std::wstring & Add(const wchar_t * name, size_t value, bool replace_existing = true);
std::wstring & Add(const std::wstring & name, size_t value, bool replace_existing = true);
std::wstring & Add(const wchar_t * name, const WTextStream & value);
std::wstring & Add(const std::wstring & name, const WTextStream & value);
std::wstring & Add(const WTextStream & name, const WTextStream & value);
std::wstring & Add(const std::wstring & name, const std::wstring & value, bool replace_existing = true);
std::wstring & Add(const std::wstring & name, const wchar_t * value, bool replace_existing = true);
std::wstring & Add(const wchar_t * name, const wchar_t * value, bool replace_existing = true);
std::wstring & Add(const wchar_t * name, const std::wstring & value, bool replace_existing = true);
std::wstring & Add(const wchar_t * name, const WTextStream & value, bool replace_existing = true);
std::wstring & Add(const std::wstring & name, const WTextStream & value, bool replace_existing = true);
std::wstring & Add(const WTextStream & name, const WTextStream & value, bool replace_existing = true);
void Remove(const wchar_t * name);
void Remove(const std::wstring & name);
@ -285,20 +285,7 @@ public:
/*
if your config file consists mainly of single forms such as:
option = value
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::wstring (instead of the whole std::vector)
so you can save a little memory from not using std::vector
*/
typedef std::map<std::wstring, std::wstring> TableSingle;
std::wstring name; // space name
TableSingle table_single; // std::map<std::wstring, std::wstring>
Table table; // std::map<std::wstring, std::vector<std::wstring> >
// childs
@ -313,7 +300,6 @@ public:
/*
those methods are used to extract lists
note: if there is one option in table_single they will return it
return true if such an option exists (but value can be an empty list)
*/
bool ListText(const wchar_t * name, std::vector<std::wstring> & list);
@ -326,9 +312,6 @@ 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;
@ -346,6 +329,7 @@ public:
private:
std::wstring tmp_name;
std::wstring tmp_value;
std::wstring tmp_value_text;
std::string tmp_value_text_ascii;
@ -415,21 +399,6 @@ bool use_quote = false;
}
template<class Stream>
void Space::SerializeTableSingle(Stream & out, bool use_indents, int level) const
{
TableSingle::const_iterator i;
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';
}
}
template<class Stream>
@ -489,7 +458,6 @@ void Space::Serialize(Stream & out, bool use_indents, bool use_comments, int lev
}
}
SerializeTableSingle(out, use_indents, level);
SerializeTableMulti(out, use_indents, level);
for(size_t i=0 ; i<spaces.size() ; ++i)

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2012, Tomasz Sowa
* Copyright (c) 2008-2017, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -75,18 +75,12 @@ void SpaceParser::SetDefault()
list_start = '(';
list_end = ')';
list_delimiter = ',';
split_single = true;
skip_empty = false;
use_escape_char = true;
input_as_utf8 = true;
}
void SpaceParser::SplitSingle(bool split)
{
split_single = split;
}
void SpaceParser::SkipEmpty(bool skip)
{
@ -389,15 +383,6 @@ void SpaceParser::DeleteFromTable(const std::wstring & var)
void SpaceParser::DeleteFromTableSingle(const std::wstring & var)
{
Space::TableSingle::iterator i = space->table_single.find(var);
if( i != space->table_single.end() )
space->table_single.erase(i);
}
void SpaceParser::ReadTokenQuoted()
@ -527,20 +512,10 @@ void SpaceParser::AddKeyValuePair()
if( value.empty() && skip_empty )
{
DeleteFromTable(key);
DeleteFromTableSingle(key);
return;
}
if( split_single && value.size() == 1 )
{
space->table_single[key] = value[0];
DeleteFromTable(key);
}
else
{
space->table[key] = value;
DeleteFromTableSingle(key);
}
}

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2012, Tomasz Sowa
* Copyright (c) 2010-2017, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -68,7 +68,7 @@ public:
/*
setting options of the parser to the default values
utf8, split single etc.
utf8 etc.
*/
void SetDefault();
@ -117,23 +117,11 @@ public:
Status ParseString(const std::wstring & str);
/*
if your list consists of only one item, e.g:
option1 = value 1
option2 = "value 2"
option3 = ( "value 3" )
then if you call SplitSingle(true) then such values will be stored in
'table_single' instead of 'table' map
default: false
*/
void SplitSingle(bool split);
/*
if true then empty values and lists, e.g:
option =
option2 = ()
will be omitted (not inserted to 'table' or 'table_single')
will be omitted (not inserted to 'table')
default: false
*/
void SkipEmpty(bool skip);
@ -267,18 +255,11 @@ private:
std::ifstream file;
/*
if true then lists with one item will be put into 'table_single' table
default: false
*/
bool split_single;
/*
if true then empty lists, e.g:
option =
option2 = ()
will be omitted (not inserted to 'table' or 'table_single')
will be omitted (not inserted to 'table')
default: false
*/
bool skip_empty;
@ -311,7 +292,6 @@ private:
void SpaceStarts();
void DeleteFromTable(const std::wstring & var);
void DeleteFromTableSingle(const std::wstring & var);
void ReadTokenQuoted();
void ReadTokenSingle(bool white_delimit, bool new_line_delimit, int delimit1, int delimit2);

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2013, Tomasz Sowa
* Copyright (c) 2012-2017, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -77,9 +77,6 @@ private:
void Serialize(Space & space, Stream & out, bool use_indents, int level,
bool use_comma, bool treat_as_table, bool skip_name);
template<class Stream>
void SerializeTableSingle(Space & space, Stream & out, bool use_indents, int level, bool use_comma);
template<class Stream>
void SerializeTableMulti(Space & space, Stream & out, bool use_indents, int level, bool use_comma);
@ -144,38 +141,6 @@ void SpaceToJSON::PrintToken(Stream & out, const StringType & str, bool is_speci
template<class Stream>
void SpaceToJSON::SerializeTableSingle(Space & space, Stream & out, bool use_indents, int level, bool use_comma)
{
Space::TableSingle::const_iterator i;
size_t index = 0;
bool is_special;
if( use_comma && !space.table_single.empty() )
{
PrintLevel(out, use_indents, level);
out << L",\n";
}
for(i=space.table_single.begin() ; i != space.table_single.end() ; ++i, ++index)
{
is_special = IsNumeric(i->first) || IsBool(i->first);
PrintLevel(out, use_indents, level);
PrintToken(out, i->first);
out << L": ";
PrintToken(out, i->second, is_special);
if( index + 1 < space.table_single.size() )
out << ',';
out << '\n';
}
}
template<class Stream>
void SpaceToJSON::SerializeTableMulti(Space & space, Stream & out, bool use_indents, int level, bool use_comma)
{
@ -257,10 +222,9 @@ void SpaceToJSON::Serialize(Space & space, Stream & out, bool use_indents, int l
if( !treat_as_table )
{
SerializeTableSingle(space, out, use_indents, level, false);
SerializeTableMulti(space, out, use_indents, level, !space.table_single.empty());
SerializeTableMulti(space, out, use_indents, level, false);
if( !space.table_single.empty() || !space.table.empty() )
if( !space.table.empty() )
printed_something = true;
}