From e2246546b0ad74e1c5232a8e53565a8e19c2d599 Mon Sep 17 00:00:00 2001 From: twanvl Date: Mon, 2 Jun 2008 21:25:53 +0000 Subject: [PATCH] Case insensitive string compare inside installers git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@954 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/util/io/package_manager.cpp | 2 +- src/util/string.cpp | 11 +++++++++++ src/util/string.hpp | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/util/io/package_manager.cpp b/src/util/io/package_manager.cpp index e30d635e..00ae37e8 100644 --- a/src/util/io/package_manager.cpp +++ b/src/util/io/package_manager.cpp @@ -348,7 +348,7 @@ bool PackageDirectory::actual_install(const InstallablePackage& package, const S const Packaged::FileInfos& file_infos = installer.getFileInfos(); for (Packaged::FileInfos::const_iterator it = file_infos.begin() ; it != file_infos.end() ; ++it) { String file = it->first; - if (!is_substr(file,0,name)) continue; // not the right package + if (!is_substr_i(file,0,name)) continue; // not the right package // correct filename String local_file = install_dir + file.substr(name.length()); create_parent_dirs(local_file); diff --git a/src/util/string.cpp b/src/util/string.cpp index d845c499..bf1d6773 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -370,6 +370,17 @@ bool is_substr(const String& str, size_t pos, const String& cmp) { return is_substr(str, pos, cmp.c_str()); } + +bool is_substr_i(const String& str, size_t pos, const Char* cmp) { + for (String::const_iterator it = str.begin() + pos ; *cmp && it < str.end() ; ++cmp, ++it) { + if (toLower(*cmp) != toLower(*it)) return false; + } + return *cmp == _('\0'); +} +bool is_substr_i(const String& str, size_t pos, const String& cmp) { + return is_substr_i(str, pos, cmp.c_str()); +} + bool cannocial_name_compare(const String& as, const Char* b) { const Char* a = as.c_str(); while (true) { diff --git a/src/util/string.hpp b/src/util/string.hpp index dc125ccb..cd2fcf0c 100644 --- a/src/util/string.hpp +++ b/src/util/string.hpp @@ -178,6 +178,11 @@ bool is_substr(const String& str, size_t pos, const Char* cmp); /// Return whether str contains the string cmp at position pos bool is_substr(const String& str, size_t pos, const String& cmp); +/// Return whether str contains the string cmp at position pos, case insensitive compare +bool is_substr_i(const String& str, size_t pos, const Char* cmp); +/// Return whether str contains the string cmp at position pos, case insensitive compare +bool is_substr_i(const String& str, size_t pos, const String& cmp); + /// Compare two strings for equality, b may contain '_' where a contains ' ' bool cannocial_name_compare(const String& a, const Char* b);