diff options
author | Neil Moore <neil@s-z.org> | 2014-07-11 00:41:31 -0400 |
---|---|---|
committer | Neil Moore <neil@s-z.org> | 2014-07-11 01:02:22 -0400 |
commit | 1cf06be6ea1471d9273a24fb7f95bde6938b7d3c (patch) | |
tree | 1a20996fb8275609ecc8b9fd8a308dc7213b58e1 /crawl-ref/source/spl-util.cc | |
parent | 9555e25a93d5bb2fa10eefe79a362f5ddb270cde (diff) | |
download | crawl-ref-1cf06be6ea1471d9273a24fb7f95bde6938b7d3c.tar.gz crawl-ref-1cf06be6ea1471d9273a24fb7f95bde6938b7d3c.zip |
Refactor god and spell search using templates.
Diffstat (limited to 'crawl-ref/source/spl-util.cc')
-rw-r--r-- | crawl-ref/source/spl-util.cc | 28 |
1 files changed, 2 insertions, 26 deletions
diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc index 3587a71a69..15fb9d2536 100644 --- a/crawl-ref/source/spl-util.cc +++ b/crawl-ref/source/spl-util.cc @@ -148,32 +148,8 @@ spell_type spell_by_name(string name, bool partial_match) return SPELL_NO_SPELL; } - // Find the spell with the earliest match for the string. - spell_type spellmatch = SPELL_NO_SPELL; - size_t bestpos = string::npos; - for (int i = 0; i < NUM_SPELLS; i++) - { - const spell_type type = static_cast<spell_type>(i); - - if (!is_valid_spell(type)) - continue; - - const string spell_name = lowercase_string(spell_title(type)); - const size_t pos = spell_name.find(name); - - if (pos < bestpos) - { - // Exact match is better than prefix match. - if (spell_name == name) - return type; - - // npos is never less than bestpos, so the spec was found. - bestpos = pos; - spellmatch = type; - } - } - - return spellmatch; + return find_earliest_match(name, SPELL_NO_SPELL, NUM_SPELLS, + is_valid_spell, spell_title); } spschool_flag_type school_by_name(string name) |