From cde990ba8295cc43f15b2d61bc4a9d1c8a8bd8e3 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 27 Jun 2017 16:51:55 +0000 Subject: [PATCH] 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 --- Makefile | 4 +- mainspaceparser/mainspaceparser.cpp | 4 +- space/jsontospaceparser.cpp | 29 +- space/jsontospaceparser.h | 28 +- space/space.cpp | 415 ++++++++++++++-------------- space/space.h | 74 ++--- space/spaceparser.cpp | 29 +- space/spaceparser.h | 28 +- space/spacetojson.h | 42 +-- 9 files changed, 253 insertions(+), 400 deletions(-) diff --git a/Makefile b/Makefile index 486de37..b17a30a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/mainspaceparser/mainspaceparser.cpp b/mainspaceparser/mainspaceparser.cpp index 1894104..454aa30 100644 --- a/mainspaceparser/mainspaceparser.cpp +++ b/mainspaceparser/mainspaceparser.cpp @@ -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 { diff --git a/space/jsontospaceparser.cpp b/space/jsontospaceparser.cpp index c31f5c5..e019fd2 100644 --- a/space/jsontospaceparser.cpp +++ b/space/jsontospaceparser.cpp @@ -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); - } + space->table[key] = value; } diff --git a/space/jsontospaceparser.h b/space/jsontospaceparser.h index c75b530..385aced 100644 --- a/space/jsontospaceparser.h +++ b/space/jsontospaceparser.h @@ -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); diff --git a/space/space.cpp b/space/space.cpp index 987a9de..1905c78 100644 --- a/space/space.cpp +++ b/space/space.cpp @@ -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 ; isecond.empty() ) { - return &i->second; + return 0; } else { - Table::iterator t = table.find(name); - - if( t == table.end() || t->second.empty() ) - { - return 0; - } - else - { - return &t->second[0]; - } + return &t->second[0]; } } @@ -139,24 +128,15 @@ std::wstring * Space::GetValue(const std::wstring & name) const std::wstring * Space::GetValue(const std::wstring & name) const { - TableSingle::const_iterator i = table_single.find(name); + Table::const_iterator t = table.find(name); - if( i != table_single.end() ) + if( t == table.end() || t->second.empty() ) { - return &i->second; + return 0; } else { - Table::const_iterator t = table.find(name); - - if( t == table.end() || t->second.empty() ) - { - return 0; - } - else - { - return &t->second[0]; - } + return &t->second[0]; } } @@ -189,22 +169,13 @@ 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); + Table::const_iterator t = table.find(name); - if( i != table_single.end() ) + if( t != table.end() ) { - return i->second == value; - } - else - { - Table::const_iterator t = table.find(name); - - if( t != table.end() ) - { - for(size_t i=0 ; i < t->second.size() ; ++i) - if( t->second[i] == value ) - return true; - } + for(size_t i=0 ; i < t->second.size() ; ++i) + 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(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(res); @@ -401,9 +375,9 @@ bool Space::Bool(const wchar_t * name, bool def) bool Space::ToBool(const std::wstring & value) { - return ( EqualNoCase(value.c_str(), L"true") || - EqualNoCase(value.c_str(), L"yes") || - EqualNoCase(value.c_str(), L"1") + 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 ; iname == 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 & 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 & list) { @@ -738,34 +772,11 @@ bool Space::ListText(const wchar_t * name, std::vector & list) } -bool Space::ListText(const std::wstring & name, std::vector & 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; diff --git a/space/space.h b/space/space.h index c2367c8..9130277 100644 --- a/space/space.h +++ b/space/space.h @@ -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 TableSingle; - - std::wstring name; // space name - TableSingle table_single; // std::map Table table; // std::map > // childs @@ -313,10 +300,9 @@ 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 & list); + bool ListText(const wchar_t * name, std::vector & list); bool ListText(const std::wstring & name, std::vector & list); @@ -326,9 +312,6 @@ public: template void Serialize(Stream & out, bool use_indents = false, bool use_comments = false, int level = 0) const; - template - void SerializeTableSingle(Stream & out, bool use_indents, int level) const; - template 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 -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 @@ -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 ; itable_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); - } + space->table[key] = value; } diff --git a/space/spaceparser.h b/space/spaceparser.h index 07ab7c6..2cff901 100644 --- a/space/spaceparser.h +++ b/space/spaceparser.h @@ -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); diff --git a/space/spacetojson.h b/space/spacetojson.h index c2296df..03c9d44 100644 --- a/space/spacetojson.h +++ b/space/spacetojson.h @@ -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 - void SerializeTableSingle(Space & space, Stream & out, bool use_indents, int level, bool use_comma); - template 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 -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 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; }