Skip to content

Commit

Permalink
Improved PropVal::atOrNone to return None for any key on None values
Browse files Browse the repository at this point in the history
  • Loading branch information
oschulz committed Jul 8, 2015
1 parent 9acbe08 commit b5cf945
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Props.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ class PropVal final: public virtual Printable {
if (m_type == Type::PROPS) {
auto result = m_content.o->find(key);
return (result != m_content.o->end() ? result->second : s_noneValue);
} else if (m_type == Type::NONE) {
return s_noneValue;
} else if (key.isInteger()) {
Integer index = key.asInteger();
if (m_type == Type::ARRAY) return m_content.a->at(index);
Expand All @@ -569,8 +571,11 @@ class PropVal final: public virtual Printable {
if (m_type == Type::PROPS) {
auto result = m_content.o->find(index);
return (result != m_content.o->end() ? result->second : s_noneValue);
} else if (m_type == Type::ARRAY) return m_content.a->at(index);
else {
} else if (m_type == Type::ARRAY) {
return m_content.a->at(index);
} else if (m_type == Type::NONE) {
return s_noneValue;
} else {
if (index == 0) return *this;
else throw std::out_of_range("PropVal of this type has fixed size 1");
}
Expand Down

0 comments on commit b5cf945

Please sign in to comment.