some work in Space

- default value returned from TextRef()



git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@1083 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2018-04-16 22:55:58 +00:00
parent c910e22c00
commit dc0cd13178
2 changed files with 46 additions and 38 deletions

View File

@ -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();
}
}

View File

@ -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;