diff --git a/space/space.cpp b/space/space.cpp index d1a6099..cffbe77 100644 --- a/space/space.cpp +++ b/space/space.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2008-2017, Tomasz Sowa + * Copyright (c) 2008-2018, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -240,11 +240,11 @@ return false; -std::wstring Space::Text(const wchar_t * name) const -{ - tmp_name = name; - return Text(tmp_name, L""); -} +//std::wstring Space::Text(const wchar_t * name) const +//{ +// tmp_name = name; +// return Text(tmp_name, L""); +//} @@ -265,7 +265,10 @@ std::wstring Space::Text(const std::wstring & name, const wchar_t * def) const } else { - return std::wstring(def); + if( def ) + return std::wstring(def); + else + return std::wstring(); } } @@ -287,11 +290,11 @@ std::wstring Space::Text(const std::wstring & name, const std::wstring & def) co -std::wstring & Space::TextRef(const wchar_t * name) -{ - tmp_name = name; - return TextRef(tmp_name, L""); -} +//std::wstring & Space::TextRef(const wchar_t * name) +//{ +// tmp_name = name; +// return TextRef(tmp_name, L""); +//} std::wstring & Space::TextRef(const wchar_t * name, const wchar_t * def) @@ -302,25 +305,27 @@ std::wstring & Space::TextRef(const wchar_t * name, const wchar_t * def) std::wstring & Space::TextRef(const std::wstring & name, const wchar_t * def) { + Value * value; Table::iterator t = table.find(name); - if( t == table.end() ) + if( t != table.end() ) { - Value & v = table[name]; - v.push_back(def); - return v[0]; - } - else - if( t->second.empty() ) - { - Value & v = t->second; - v.push_back(def); - return v[0]; + value = &t->second; } else { - return t->second[0]; + value = &table[name]; } + + if( value->empty() ) + { + if( def ) + value->push_back(def); + else + value->push_back(std::wstring()); + } + + return (*value)[0]; } @@ -332,11 +337,11 @@ std::wstring & Space::TextRef(const std::wstring & name, const std::wstring & de -std::string Space::TextA(const wchar_t * name) const -{ - tmp_name = name; - return TextA(tmp_name, ""); -} +//std::string Space::TextA(const wchar_t * name) const +//{ +// tmp_name = name; +// return TextA(tmp_name, ""); +//} @@ -359,7 +364,10 @@ std::string Space::TextA(const std::wstring & name, const char * def) const } else { - return def; + if( def ) + return std::string(def); + else + return std::string(); } } diff --git a/space/space.h b/space/space.h index 07e3dfc..928ad62 100644 --- a/space/space.h +++ b/space/space.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2010-2017, Tomasz Sowa + * Copyright (c) 2010-2018, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -239,21 +239,21 @@ public: AText(...) always returns a reference to UTF-8 string */ - std::wstring Text(const wchar_t * name) const; - std::wstring Text(const wchar_t * name, const wchar_t * def) const; - std::wstring Text(const std::wstring & name, const wchar_t * def) const; + //std::wstring Text(const wchar_t * name) const; + std::wstring Text(const wchar_t * name, const wchar_t * def = 0) const; + std::wstring Text(const std::wstring & name, const wchar_t * def = 0) const; std::wstring Text(const std::wstring & name, const std::wstring & def) const; // returns a reference // if there is no such an option then a new one (def value) is inserted - std::wstring & TextRef(const wchar_t * name); - std::wstring & TextRef(const wchar_t * name, const wchar_t * def); - std::wstring & TextRef(const std::wstring & name, const wchar_t * def); + //std::wstring & TextRef(const wchar_t * name); + std::wstring & TextRef(const wchar_t * name, const wchar_t * def = 0); + std::wstring & TextRef(const std::wstring & name, const wchar_t * def = 0); std::wstring & TextRef(const std::wstring & name, const std::wstring & def); // returns UTF-8 string - std::string TextA(const wchar_t * name) const; + //std::string TextA(const wchar_t * name) const; std::string TextA(const wchar_t * name, const char * def) const; std::string TextA(const std::wstring & name, const char * def) const; std::string TextA(const std::wstring & name, const std::string & def) const;