diff options
author | Enne Walker <ennewalker@users.sourceforge.net> | 2009-10-31 10:59:52 -0400 |
---|---|---|
committer | Enne Walker <ennewalker@users.sourceforge.net> | 2009-10-31 11:09:28 -0400 |
commit | 95746496df9bc09763421a35bb5c3cbc1ff4ad54 (patch) | |
tree | 941adb4b2e042d6f63a2c467d96e431464cbc145 /crawl-ref/source/libutil.cc | |
parent | 3877db329ce13f8d527b2954c3f9d5857a2b6b35 (diff) | |
download | crawl-ref-95746496df9bc09763421a35bb5c3cbc1ff4ad54.tar.gz crawl-ref-95746496df9bc09763421a35bb5c3cbc1ff4ad54.zip |
Adding you.in_branch(string) as a lua function.
This also removes you.where_are_you() so as not to require lua scripts to
know the value of C++ enums. This change also fixes stricmp incorrectly
falling through to strcmp on non-MSVC platforms.
Diffstat (limited to 'crawl-ref/source/libutil.cc')
-rw-r--r-- | crawl-ref/source/libutil.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc index a73bc7276d..5b37cd5fd6 100644 --- a/crawl-ref/source/libutil.cc +++ b/crawl-ref/source/libutil.cc @@ -221,6 +221,32 @@ int ends_with(const std::string &s, const char *suffixes[]) return (0); } +#ifdef UNIX +extern "C" int stricmp(const char *str1, const char *str2) +{ + int ret = 0; + + // No need to check for *str1. If str1 ends, then tolower(*str1) will be + // 0, ret will be -1, and the loop will break. + while (!ret && *str2) + { + unsigned char c1 = tolower(*str1); + unsigned char c2 = tolower(*str2); + + ret = c1 - c2; + str1++; + str2++; + } + + if (ret < 0) + ret = -1; + else if (ret > 0) + ret = 1; + + return (ret); +} +#endif + // Returns true if s contains tag 'tag', and strips out tag from s. bool strip_tag(std::string &s, const std::string &tag, bool skip_padding) { |