mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-30 13:57:59 +03:00
Merge https://github.com/zinnschlag/openmw into comparestring
Conflicts: apps/openmw/mwdialogue/dialoguemanagerimp.cpp apps/openmw/mwworld/worldimp.cpp components/esm_store/reclists.hpp components/misc/stringops.hpp
This commit is contained in:
commit
c85400b809
358 changed files with 30413 additions and 2929 deletions
|
@ -2,9 +2,60 @@
|
|||
#define MISC_STRINGOPS_H
|
||||
|
||||
#include <string>
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include <algorithm>
|
||||
>>>>>>> 92623921add0d6e16a34973dcf6f2ee1f52dbbe7
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
class StringUtils
|
||||
{
|
||||
struct ci
|
||||
{
|
||||
bool operator()(int x, int y) const {
|
||||
return std::tolower(x) < std::tolower(y);
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
static bool ciLess(const std::string &x, const std::string &y) {
|
||||
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), ci());
|
||||
}
|
||||
|
||||
static bool ciEqual(const std::string &x, const std::string &y) {
|
||||
if (x.size() != y.size()) {
|
||||
return false;
|
||||
}
|
||||
std::string::const_iterator xit = x.begin();
|
||||
std::string::const_iterator yit = y.begin();
|
||||
for (; xit != x.end(); ++xit, ++yit) {
|
||||
if (std::tolower(*xit) != std::tolower(*yit)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Transforms input string to lower case w/o copy
|
||||
static std::string &toLower(std::string &inout) {
|
||||
std::transform(
|
||||
inout.begin(),
|
||||
inout.end(),
|
||||
inout.begin(),
|
||||
(int (*)(int)) std::tolower
|
||||
);
|
||||
return inout;
|
||||
}
|
||||
|
||||
/// Returns lower case copy of input string
|
||||
static std::string lowerCase(const std::string &in)
|
||||
{
|
||||
std::string out = in;
|
||||
return toLower(out);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// Returns true if str1 begins with substring str2
|
||||
bool begins(const char* str1, const char* str2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue