Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions src/lib/coil/common/coil/Properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ namespace coil
*/
const std::string& Properties::getProperty(const std::string& key) const
{
if (coil::eraseBothEndsBlank(key).empty())
{
return m_empty;
}
std::vector<std::string> keys;
split(key, '.', keys);
Properties* node(nullptr);
Expand All @@ -188,6 +192,10 @@ namespace coil
const std::string& Properties::getProperty(const std::string& key,
const std::string& def) const
{
if (coil::eraseBothEndsBlank(key).empty())
{
return m_empty;
}
const std::string& invalue((*this)[key]);

return invalue.empty() ? def : invalue;
Expand Down Expand Up @@ -230,6 +238,12 @@ namespace coil
const std::string& Properties::getDefault(const std::string& key) const
{
std::vector<std::string> keys;

if (coil::eraseBothEndsBlank(key).empty())
{
return m_empty;
}

split(key, '.', keys);
Properties* node(nullptr);
if ((node = _getNode(keys, 0, this)) != nullptr)
Expand All @@ -250,6 +264,12 @@ namespace coil
const std::string& invalue)
{
std::vector<std::string> keys;

if (coil::eraseBothEndsBlank(key).empty())
{
return m_empty;
}

split(key, '.', keys);

Properties* curr(this);
Expand Down Expand Up @@ -280,6 +300,10 @@ namespace coil
std::string Properties::setDefault(const std::string& key,
const std::string& invalue)
{
if (coil::eraseBothEndsBlank(key).empty())
{
return m_empty;
}
std::vector<std::string> keys;
split(key, '.', keys);

Expand Down Expand Up @@ -371,6 +395,15 @@ namespace coil
continue;
}

size_t end = tmp.find_last_not_of(" \t");
if (end != std::string::npos &&
tmp[end] == '\\' &&
!coil::isEscaped(tmp, end))
{
std::cerr << "Warning: Trailing whitespace after '\\' prevents line continuation: " << tmp << std::endl;
}


std::string key, invalue;
splitKeyValue(pline, key, invalue);
setProperty(eraseBothEndsBlank(coil::unescape(std::move(key))),
Expand Down Expand Up @@ -446,7 +479,7 @@ namespace coil
*/
Properties* Properties::findNode(const std::string& key) const
{
if (key.empty())
if (coil::eraseBothEndsBlank(key).empty())
{
return nullptr;
}
Expand All @@ -464,7 +497,7 @@ namespace coil
*/
Properties& Properties::getNode(const std::string& key)
{
if (key.empty())
if (coil::eraseBothEndsBlank(key).empty())
{
return *this;
}
Expand All @@ -486,7 +519,7 @@ namespace coil
*/
bool Properties::createNode(const std::string& key)
{
if (key.empty())
if (coil::eraseBothEndsBlank(key).empty())
{
return false;
}
Expand Down Expand Up @@ -532,6 +565,10 @@ namespace coil
*/
Properties* Properties::hasKey(const char* key) const
{
if (coil::eraseBothEndsBlank(key).empty())
{
return nullptr;
}
for (auto prop : leaf)
{
if (prop->name == key)
Expand Down
Loading
Loading