Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed|libdoomsday|DEDRegister: Finding definitions case-insensitively
The lookup value must be converted to lower case because the values
entered into the lookup dictionary are also lower-cased.
  • Loading branch information
skyjake committed Aug 9, 2014
1 parent 843840a commit 430b13f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doomsday/libdoomsday/include/doomsday/defs/dedregister.h
Expand Up @@ -103,7 +103,7 @@ class LIBDOOMSDAY_PUBLIC DEDRegister
de::Record const & operator [] (int index) const;

de::Record * tryFind(de::String const &key, de::String const &value);
de::Record const * tryFind(de::String const &key, de::String const &value) const;
de::Record const * tryFind(de::String const &key, de::String value) const;

de::Record & find(de::String const &key, de::String const &value);
de::Record const & find(de::String const &key, de::String const &value) const;
Expand Down
19 changes: 12 additions & 7 deletions doomsday/libdoomsday/src/defs/dedregister.cpp
Expand Up @@ -304,16 +304,21 @@ Record const &DEDRegister::operator [] (int index) const

Record *DEDRegister::tryFind(String const &key, String const &value)
{
if(!has(key, value)) return 0;
RecordValue &val = d->lookup(key).element(TextValue(value)).as<RecordValue>();
return val.record();
return const_cast<Record *>(const_cast<DEDRegister const *>(this)->tryFind(key, value));
}

Record const *DEDRegister::tryFind(String const &key, String const &value) const
Record const *DEDRegister::tryFind(String const &key, String value) const
{
if(!has(key, value)) return 0;
RecordValue const &val = d->lookup(key).element(TextValue(value)).as<RecordValue>();
return val.record();
auto foundKey = d->keys.constFind(key);
if(foundKey == d->keys.constEnd()) return 0;

if(!foundKey.value().flags.testFlag(CaseSensitive))
{
// Case insensitive lookup is done in lower case.
value = value.lower();
}

return d->lookup(key).element(TextValue(value)).as<RecordValue>().record();
}

Record &DEDRegister::find(String const &key, String const &value)
Expand Down

0 comments on commit 430b13f

Please sign in to comment.