scrawl 9 years ago
parent 1a654fa451
commit f875597be5

@ -44,7 +44,7 @@ public:
typename Entry::childen_t::iterator current; typename Entry::childen_t::iterator current;
typename Entry::childen_t::iterator next; typename Entry::childen_t::iterator next;
current = mRoot.mChildren.find (tolower (*keyword.begin())); current = mRoot.mChildren.find (Misc::StringUtils::toLower (*keyword.begin()));
if (current == mRoot.mChildren.end()) if (current == mRoot.mChildren.end())
return false; return false;
else if (current->second.mKeyword.size() && Misc::StringUtils::ciEqual(current->second.mKeyword, keyword)) else if (current->second.mKeyword.size() && Misc::StringUtils::ciEqual(current->second.mKeyword, keyword))
@ -55,7 +55,7 @@ public:
for (Point i = ++keyword.begin(); i != keyword.end(); ++i) for (Point i = ++keyword.begin(); i != keyword.end(); ++i)
{ {
next = current->second.mChildren.find(tolower (*i)); next = current->second.mChildren.find(Misc::StringUtils::toLower (*i));
if (next == current->second.mChildren.end()) if (next == current->second.mChildren.end())
return false; return false;
if (Misc::StringUtils::ciEqual(next->second.mKeyword, keyword)) if (Misc::StringUtils::ciEqual(next->second.mKeyword, keyword))
@ -89,7 +89,7 @@ public:
// check first character // check first character
typename Entry::childen_t::iterator candidate = mRoot.mChildren.find (tolower (*i)); typename Entry::childen_t::iterator candidate = mRoot.mChildren.find (Misc::StringUtils::toLower (*i));
// no match, on to next character // no match, on to next character
if (candidate == mRoot.mChildren.end ()) if (candidate == mRoot.mChildren.end ())
@ -104,7 +104,7 @@ public:
while ((j + 1) != end) while ((j + 1) != end)
{ {
typename Entry::childen_t::iterator next = candidate->second.mChildren.find (tolower (*++j)); typename Entry::childen_t::iterator next = candidate->second.mChildren.find (Misc::StringUtils::toLower (*++j));
if (next == candidate->second.mChildren.end ()) if (next == candidate->second.mChildren.end ())
{ {
@ -136,7 +136,7 @@ public:
while (k != end && t != candidate->second.mKeyword.end ()) while (k != end && t != candidate->second.mKeyword.end ())
{ {
if (tolower (*k) != tolower (*t)) if (Misc::StringUtils::toLower (*k) != Misc::StringUtils::toLower (*t))
break; break;
++k, ++t; ++k, ++t;
@ -212,7 +212,7 @@ private:
void seed_impl (string_t keyword, value_t value, size_t depth, Entry & entry) void seed_impl (string_t keyword, value_t value, size_t depth, Entry & entry)
{ {
int ch = tolower (keyword.at (depth)); int ch = Misc::StringUtils::toLower (keyword.at (depth));
typename Entry::childen_t::iterator j = entry.mChildren.find (ch); typename Entry::childen_t::iterator j = entry.mChildren.find (ch);

@ -365,7 +365,7 @@ namespace MWGui
/* Is the beginning of the string different from the input string? If yes skip it. */ /* Is the beginning of the string different from the input string? If yes skip it. */
for( std::string::iterator iter=tmp.begin(), iter2=(*it).begin(); iter < tmp.end();++iter, ++iter2) { for( std::string::iterator iter=tmp.begin(), iter2=(*it).begin(); iter < tmp.end();++iter, ++iter2) {
if( tolower(*iter) != tolower(*iter2) ) { if( Misc::StringUtils::toLower(*iter) != Misc::StringUtils::toLower(*iter2) ) {
string_different=true; string_different=true;
break; break;
} }
@ -405,7 +405,7 @@ namespace MWGui
for(std::string::iterator iter=matches.front().begin()+tmp.length(); iter < matches.front().end(); ++iter, ++i) { for(std::string::iterator iter=matches.front().begin()+tmp.length(); iter < matches.front().end(); ++iter, ++i) {
for(std::vector<std::string>::iterator it=matches.begin(); it < matches.end();++it) { for(std::vector<std::string>::iterator it=matches.begin(); it < matches.end();++it) {
if( tolower((*it)[i]) != tolower(*iter) ) { if( Misc::StringUtils::toLower((*it)[i]) != Misc::StringUtils::toLower(*iter) ) {
/* Append the longest match to the end of the output string*/ /* Append the longest match to the end of the output string*/
output.append(matches.front().substr( 0, i)); output.append(matches.front().substr( 0, i));
return output; return output;

@ -315,7 +315,7 @@ struct JournalViewModelImpl : JournalViewModel
for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i) for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i)
{ {
if (i->first [0] != tolower (character)) if (i->first [0] != Misc::StringUtils::toLower(character))
continue; continue;
visitor (i->second.getName()); visitor (i->second.getName());

@ -8,6 +8,8 @@
#include <unistd.h> #include <unistd.h>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <components/misc/stringops.hpp>
namespace namespace
{ {
@ -139,7 +141,7 @@ boost::filesystem::path LinuxPath::getInstallPath() const
{ {
// Change drive letter to lowercase, so we could use // Change drive letter to lowercase, so we could use
// ~/.wine/dosdevices symlinks // ~/.wine/dosdevices symlinks
mwpath[0] = tolower(mwpath[0]); mwpath[0] = Misc::StringUtils::toLower(mwpath[0]);
installPath /= homePath; installPath /= homePath;
installPath /= ".wine/dosdevices/"; installPath /= ".wine/dosdevices/";
installPath /= mwpath; installPath /= mwpath;

@ -7,6 +7,8 @@
#include <unistd.h> #include <unistd.h>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <components/misc/stringops.hpp>
namespace namespace
{ {
boost::filesystem::path getUserHome() boost::filesystem::path getUserHome()
@ -129,7 +131,7 @@ boost::filesystem::path MacOsPath::getInstallPath() const
if (!mwpath.empty()) if (!mwpath.empty())
{ {
// Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks // Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks
mwpath[0] = tolower(mwpath[0]); mwpath[0] = Misc::StringUtils::toLower(mwpath[0]);
installPath /= homePath; installPath /= homePath;
installPath /= ".wine/dosdevices/"; installPath /= ".wine/dosdevices/";
installPath /= mwpath; installPath /= mwpath;

@ -8,6 +8,8 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <components/misc/stringops.hpp>
namespace Files namespace Files
{ {
struct NameEqual struct NameEqual
@ -28,8 +30,8 @@ namespace Files
for (std::size_t i=0; i<len; ++i) for (std::size_t i=0; i<len; ++i)
{ {
char l = tolower (left[i]); char l = Misc::StringUtils::toLower (left[i]);
char r = tolower (right[i]); char r = Misc::StringUtils::toLower (right[i]);
if (l!=r) if (l!=r)
return false; return false;

@ -8,6 +8,8 @@
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
#include <components/misc/stringops.hpp>
namespace Files namespace Files
{ {
typedef std::vector<boost::filesystem::path> PathContainer; typedef std::vector<boost::filesystem::path> PathContainer;
@ -27,8 +29,8 @@ namespace Files
for (std::size_t i=0; i<min; ++i) for (std::size_t i=0; i<min; ++i)
{ {
char l = tolower (left[i]); char l = Misc::StringUtils::toLower (left[i]);
char r = tolower (right[i]); char r = Misc::StringUtils::toLower (right[i]);
if (l<r) if (l<r)
return true; return true;

@ -1,11 +1,12 @@
#include "defines.hpp" #include "defines.hpp"
#include <algorithm>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include <components/misc/stringops.hpp>
namespace Interpreter{ namespace Interpreter{
bool check(const std::string& str, const std::string& escword, unsigned int* i, unsigned int* start) bool check(const std::string& str, const std::string& escword, unsigned int* i, unsigned int* start)
@ -35,7 +36,7 @@ namespace Interpreter{
{ {
retval << text.substr(start, i - start); retval << text.substr(start, i - start);
std::string temp = text.substr(i+1, 100); std::string temp = text.substr(i+1, 100);
transform(temp.begin(), temp.end(), temp.begin(), ::tolower); Misc::StringUtils::lowerCase(temp);
bool found = false; bool found = false;
try try

@ -12,11 +12,49 @@ class StringUtils
struct ci struct ci
{ {
bool operator()(char x, char y) const { bool operator()(char x, char y) const {
return tolower(x) < tolower(y); return toLower(x) < toLower(y);
} }
}; };
public: public:
/// Plain and simple locale-unaware toLower. Anything from A to Z is lower-cased, multibyte characters are unchanged.
/// Don't use std::tolower(char, locale&) because that is abysmally slow.
/// Don't use tolower(int) because that depends on global locale.
static char toLower(char c)
{
switch(c)
{
case 'A':return 'a';
case 'B':return 'b';
case 'C':return 'c';
case 'D':return 'd';
case 'E':return 'e';
case 'F':return 'f';
case 'G':return 'g';
case 'H':return 'h';
case 'I':return 'i';
case 'J':return 'j';
case 'K':return 'k';
case 'L':return 'l';
case 'M':return 'm';
case 'N':return 'n';
case 'O':return 'o';
case 'P':return 'p';
case 'Q':return 'q';
case 'R':return 'r';
case 'S':return 's';
case 'T':return 't';
case 'U':return 'u';
case 'V':return 'v';
case 'W':return 'w';
case 'X':return 'x';
case 'Y':return 'y';
case 'Z':return 'z';
default:return c;
};
}
static bool ciLess(const std::string &x, const std::string &y) { static bool ciLess(const std::string &x, const std::string &y) {
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), ci()); return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), ci());
} }
@ -28,7 +66,7 @@ public:
std::string::const_iterator xit = x.begin(); std::string::const_iterator xit = x.begin();
std::string::const_iterator yit = y.begin(); std::string::const_iterator yit = y.begin();
for (; xit != x.end(); ++xit, ++yit) { for (; xit != x.end(); ++xit, ++yit) {
if (tolower(*xit) != tolower(*yit)) { if (toLower(*xit) != toLower(*yit)) {
return false; return false;
} }
} }
@ -42,7 +80,7 @@ public:
for(;xit != x.end() && yit != y.end() && len > 0;++xit,++yit,--len) for(;xit != x.end() && yit != y.end() && len > 0;++xit,++yit,--len)
{ {
int res = *xit - *yit; int res = *xit - *yit;
if(res != 0 && tolower(*xit) != tolower(*yit)) if(res != 0 && toLower(*xit) != toLower(*yit))
return (res > 0) ? 1 : -1; return (res > 0) ? 1 : -1;
} }
if(len > 0) if(len > 0)
@ -58,7 +96,7 @@ public:
/// Transforms input string to lower case w/o copy /// Transforms input string to lower case w/o copy
static std::string &toLower(std::string &inout) { static std::string &toLower(std::string &inout) {
for (unsigned int i=0; i<inout.size(); ++i) for (unsigned int i=0; i<inout.size(); ++i)
inout[i] = tolower(inout[i]); inout[i] = toLower(inout[i]);
return inout; return inout;
} }

@ -3,6 +3,8 @@
#include <cctype> #include <cctype>
#include <stdexcept> #include <stdexcept>
#include <components/misc/stringops.hpp>
#include "archive.hpp" #include "archive.hpp"
namespace namespace
@ -15,7 +17,7 @@ namespace
char nonstrict_normalize_char(char ch) char nonstrict_normalize_char(char ch)
{ {
return ch == '\\' ? '/' : tolower(ch); return ch == '\\' ? '/' : Misc::StringUtils::toLower(ch);
} }
void normalize_path(std::string& path, bool strict) void normalize_path(std::string& path, bool strict)

Loading…
Cancel
Save