Add ToLower/ToUpper
This commit is contained in:
parent
36a545124e
commit
30dd49235d
@ -468,9 +468,7 @@ std::vector<ByteString> Client::DirectorySearch(ByteString directory, ByteString
|
|||||||
{
|
{
|
||||||
std::vector<ByteString> extensions;
|
std::vector<ByteString> extensions;
|
||||||
extensions.push_back(extension);
|
extensions.push_back(extension);
|
||||||
for (ByteString::iterator iter = search.begin(); iter != search.end(); ++iter)
|
return DirectorySearch(directory, search.ToUpper(), extensions);
|
||||||
*iter = toupper(*iter);
|
|
||||||
return DirectorySearch(directory, search, extensions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ByteString> Client::DirectorySearch(ByteString directory, ByteString search, std::vector<ByteString> extensions)
|
std::vector<ByteString> Client::DirectorySearch(ByteString directory, ByteString search, std::vector<ByteString> extensions)
|
||||||
@ -531,12 +529,10 @@ std::vector<ByteString> Client::DirectorySearch(ByteString directory, ByteString
|
|||||||
if(filename.EndsWith(*extIter))
|
if(filename.EndsWith(*extIter))
|
||||||
{
|
{
|
||||||
extensionMatch = true;
|
extensionMatch = true;
|
||||||
tempfilename = filename.SubstrFromEnd(0, (*extIter).size());
|
tempfilename = filename.SubstrFromEnd(0, (*extIter).size()).ToUpper();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (ByteString::iterator iter = tempfilename.begin(); iter != tempfilename.end(); ++iter)
|
|
||||||
*iter = toupper(*iter);
|
|
||||||
bool searchMatch = !search.size();
|
bool searchMatch = !search.size();
|
||||||
if(search.size() && tempfilename.Contains(search))
|
if(search.size() && tempfilename.Contains(search))
|
||||||
searchMatch = true;
|
searchMatch = true;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <limits>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -56,6 +57,11 @@
|
|||||||
Contains(value_type infix)
|
Contains(value_type infix)
|
||||||
Self-explanatory.
|
Self-explanatory.
|
||||||
|
|
||||||
|
ToLower()
|
||||||
|
ToUpper()
|
||||||
|
Lowercases/Uppercases characters in the string. Only works on
|
||||||
|
characters in the ASCII range.
|
||||||
|
|
||||||
ByteString::FromUtf8(bool ignoreError = true)
|
ByteString::FromUtf8(bool ignoreError = true)
|
||||||
Decodes UTF-8 byte sequences into Unicode codepoints.
|
Decodes UTF-8 byte sequences into Unicode codepoints.
|
||||||
If ignoreError is true, then invalid byte sequences are widened
|
If ignoreError is true, then invalid byte sequences are widened
|
||||||
@ -324,6 +330,24 @@ public:
|
|||||||
inline ByteString &Erase(size_t pos, size_t count) { super::erase(pos, count); return *this; }
|
inline ByteString &Erase(size_t pos, size_t count) { super::erase(pos, count); return *this; }
|
||||||
inline ByteString &EraseBetween(size_t from, size_t to) { if(from < to) super::erase(from, to - from); return *this; }
|
inline ByteString &EraseBetween(size_t from, size_t to) { if(from < to) super::erase(from, to - from); return *this; }
|
||||||
|
|
||||||
|
inline ByteString ToLower() const
|
||||||
|
{
|
||||||
|
std::locale const &loc = std::locale::classic();
|
||||||
|
ByteString value(*this);
|
||||||
|
for(value_type &ch : value)
|
||||||
|
ch = std::tolower(ch, loc);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ByteString ToUpper() const
|
||||||
|
{
|
||||||
|
std::locale const &loc = std::locale::classic();
|
||||||
|
ByteString value(*this);
|
||||||
|
for(value_type &ch : value)
|
||||||
|
ch = std::toupper(ch, loc);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
String FromUtf8(bool ignoreError = true) const;
|
String FromUtf8(bool ignoreError = true) const;
|
||||||
inline String FromAscii() const;
|
inline String FromAscii() const;
|
||||||
template<typename... Ts> static ByteString Build(Ts&&... args);
|
template<typename... Ts> static ByteString Build(Ts&&... args);
|
||||||
@ -479,6 +503,26 @@ public:
|
|||||||
inline String &Erase(size_t pos, size_t count) { super::erase(pos, count); return *this; }
|
inline String &Erase(size_t pos, size_t count) { super::erase(pos, count); return *this; }
|
||||||
inline String &EraseBetween(size_t from, size_t to) { if(from < to) super::erase(from, to - from); return *this; }
|
inline String &EraseBetween(size_t from, size_t to) { if(from < to) super::erase(from, to - from); return *this; }
|
||||||
|
|
||||||
|
inline String ToLower() const
|
||||||
|
{
|
||||||
|
std::locale const &loc = std::locale::classic();
|
||||||
|
String value(*this);
|
||||||
|
for(value_type &ch : value)
|
||||||
|
if(ch <= std::numeric_limits<ByteString::value_type>::max())
|
||||||
|
ch = std::tolower(ch, loc);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline String ToUpper() const
|
||||||
|
{
|
||||||
|
std::locale const &loc = std::locale::classic();
|
||||||
|
String value(*this);
|
||||||
|
for(value_type &ch : value)
|
||||||
|
if(ch <= std::numeric_limits<ByteString::value_type>::max())
|
||||||
|
ch = std::toupper(ch, loc);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
ByteString ToUtf8() const;
|
ByteString ToUtf8() const;
|
||||||
ByteString ToAscii() const;
|
ByteString ToAscii() const;
|
||||||
template<typename... Ts> static String Build(Ts&&... args);
|
template<typename... Ts> static String Build(Ts&&... args);
|
||||||
|
@ -104,8 +104,7 @@ void ElementSearchActivity::searchTools(String query)
|
|||||||
ui::Point viewPosition = searchField->Position + ui::Point(2+0, searchField->Size.Y+2+8);
|
ui::Point viewPosition = searchField->Position + ui::Point(2+0, searchField->Size.Y+2+8);
|
||||||
ui::Point current = ui::Point(0, 0);
|
ui::Point current = ui::Point(0, 0);
|
||||||
|
|
||||||
ByteString queryLower = query.ToAscii();
|
ByteString queryLower = query.ToUtf8().ToLower();
|
||||||
std::transform(queryLower.begin(), queryLower.end(), queryLower.begin(), ::tolower);
|
|
||||||
|
|
||||||
std::vector<Tool *> matches;
|
std::vector<Tool *> matches;
|
||||||
std::vector<Tool *> frontmatches;
|
std::vector<Tool *> frontmatches;
|
||||||
@ -113,8 +112,7 @@ void ElementSearchActivity::searchTools(String query)
|
|||||||
|
|
||||||
for(std::vector<Tool*>::const_iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter)
|
for(std::vector<Tool*>::const_iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter)
|
||||||
{
|
{
|
||||||
ByteString nameLower = (*iter)->GetName();
|
ByteString nameLower = (*iter)->GetName().ToLower();
|
||||||
std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
|
|
||||||
if(nameLower == queryLower)
|
if(nameLower == queryLower)
|
||||||
exactmatches.push_back(*iter);
|
exactmatches.push_back(*iter);
|
||||||
else if(nameLower.BeginsWith(queryLower))
|
else if(nameLower.BeginsWith(queryLower))
|
||||||
|
@ -58,11 +58,7 @@ class LoadFilesTask: public Task
|
|||||||
virtual bool doWork()
|
virtual bool doWork()
|
||||||
{
|
{
|
||||||
std::vector<ByteString> files = Client::Ref().DirectorySearch(directory, search, ".cps");
|
std::vector<ByteString> files = Client::Ref().DirectorySearch(directory, search, ".cps");
|
||||||
std::sort(files.rbegin(), files.rend(), [](ByteString a, ByteString b) {
|
std::sort(files.rbegin(), files.rend(), [](ByteString a, ByteString b) { return a.ToLower() < b.ToLower(); });
|
||||||
std::transform(a.begin(), a.end(), a.begin(), ::tolower);
|
|
||||||
std::transform(b.begin(), b.end(), b.begin(), ::tolower);
|
|
||||||
return a < b;
|
|
||||||
});
|
|
||||||
|
|
||||||
notifyProgress(-1);
|
notifyProgress(-1);
|
||||||
for(std::vector<ByteString>::iterator iter = files.begin(), end = files.end(); iter != end; ++iter)
|
for(std::vector<ByteString>::iterator iter = files.begin(), end = files.end(); iter != end; ++iter)
|
||||||
|
@ -289,8 +289,7 @@ void PreviewView::CheckComment()
|
|||||||
{
|
{
|
||||||
if (!commentWarningLabel)
|
if (!commentWarningLabel)
|
||||||
return;
|
return;
|
||||||
String text = addCommentBox->GetText();
|
String text = addCommentBox->GetText().ToLower();
|
||||||
std::transform(text.begin(), text.end(), text.begin(), ::tolower);
|
|
||||||
if (!userIsAuthor && (text.Contains("stolen") || text.Contains("copied")))
|
if (!userIsAuthor && (text.Contains("stolen") || text.Contains("copied")))
|
||||||
{
|
{
|
||||||
if (!commentHelpText)
|
if (!commentHelpText)
|
||||||
|
@ -56,9 +56,7 @@ void initLegacyProps()
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ByteString temp = ByteString(prop.Name);
|
legacyPropNames.insert(std::pair<ByteString, StructProperty>(prop.Name.ToLower(), prop));
|
||||||
std::transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
|
|
||||||
legacyPropNames.insert(std::pair<ByteString, StructProperty>(temp, prop));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,6 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
|
|||||||
initPlatformAPI();
|
initPlatformAPI();
|
||||||
|
|
||||||
//Old TPT API
|
//Old TPT API
|
||||||
char tmpname[12];
|
|
||||||
int currentElementMeta, currentElement;
|
int currentElementMeta, currentElement;
|
||||||
const static struct luaL_Reg tptluaapi [] = {
|
const static struct luaL_Reg tptluaapi [] = {
|
||||||
{"test", &luatpt_test},
|
{"test", &luatpt_test},
|
||||||
@ -295,10 +294,6 @@ tpt.partsdata = nil");
|
|||||||
tptElements = lua_gettop(l);
|
tptElements = lua_gettop(l);
|
||||||
for (int i = 1; i < PT_NUM; i++)
|
for (int i = 1; i < PT_NUM; i++)
|
||||||
{
|
{
|
||||||
for (size_t j = 0; j < luacon_sim->elements[i].Name.size(); j++)
|
|
||||||
tmpname[j] = tolower(luacon_sim->elements[i].Name[j]);
|
|
||||||
tmpname[luacon_sim->elements[i].Name.size()] = 0;
|
|
||||||
|
|
||||||
lua_newtable(l);
|
lua_newtable(l);
|
||||||
currentElement = lua_gettop(l);
|
currentElement = lua_gettop(l);
|
||||||
lua_pushinteger(l, i);
|
lua_pushinteger(l, i);
|
||||||
@ -312,7 +307,7 @@ tpt.partsdata = nil");
|
|||||||
lua_setfield(l, currentElementMeta, "__index");
|
lua_setfield(l, currentElementMeta, "__index");
|
||||||
lua_setmetatable(l, currentElement);
|
lua_setmetatable(l, currentElement);
|
||||||
|
|
||||||
lua_setfield(l, tptElements, tmpname);
|
lua_setfield(l, tptElements, luacon_sim->elements[i].Name.ToLower().c_str());
|
||||||
}
|
}
|
||||||
lua_setfield(l, tptProperties, "el");
|
lua_setfield(l, tptProperties, "el");
|
||||||
|
|
||||||
@ -320,10 +315,6 @@ tpt.partsdata = nil");
|
|||||||
tptElementTransitions = lua_gettop(l);
|
tptElementTransitions = lua_gettop(l);
|
||||||
for (int i = 1; i < PT_NUM; i++)
|
for (int i = 1; i < PT_NUM; i++)
|
||||||
{
|
{
|
||||||
for (size_t j = 0; j < luacon_sim->elements[i].Name.size(); j++)
|
|
||||||
tmpname[j] = tolower(luacon_sim->elements[i].Name[j]);
|
|
||||||
tmpname[luacon_sim->elements[i].Name.size()] = 0;
|
|
||||||
|
|
||||||
lua_newtable(l);
|
lua_newtable(l);
|
||||||
currentElement = lua_gettop(l);
|
currentElement = lua_gettop(l);
|
||||||
lua_newtable(l);
|
lua_newtable(l);
|
||||||
@ -336,7 +327,7 @@ tpt.partsdata = nil");
|
|||||||
lua_setfield(l, currentElementMeta, "__index");
|
lua_setfield(l, currentElementMeta, "__index");
|
||||||
lua_setmetatable(l, currentElement);
|
lua_setmetatable(l, currentElement);
|
||||||
|
|
||||||
lua_setfield(l, tptElementTransitions, tmpname);
|
lua_setfield(l, tptElementTransitions, luacon_sim->elements[i].Name.ToLower().c_str());
|
||||||
}
|
}
|
||||||
lua_setfield(l, tptProperties, "eltransition");
|
lua_setfield(l, tptProperties, "eltransition");
|
||||||
|
|
||||||
@ -810,10 +801,8 @@ void LuaScriptInterface::initSimulationAPI()
|
|||||||
particleProperties = new StructProperty[particlePropertiesV.size()];
|
particleProperties = new StructProperty[particlePropertiesV.size()];
|
||||||
for(std::vector<StructProperty>::iterator iter = particlePropertiesV.begin(), end = particlePropertiesV.end(); iter != end; ++iter)
|
for(std::vector<StructProperty>::iterator iter = particlePropertiesV.begin(), end = particlePropertiesV.end(); iter != end; ++iter)
|
||||||
{
|
{
|
||||||
ByteString propertyName = (*iter).Name;
|
|
||||||
std::transform(propertyName.begin(), propertyName.end(), propertyName.begin(), ::toupper);
|
|
||||||
lua_pushinteger(l, particlePropertiesCount);
|
lua_pushinteger(l, particlePropertiesCount);
|
||||||
lua_setfield(l, -2, ("FIELD_"+propertyName).c_str());
|
lua_setfield(l, -2, ("FIELD_" + (*iter).Name.ToUpper()).c_str());
|
||||||
particleProperties[particlePropertiesCount++] = *iter;
|
particleProperties[particlePropertiesCount++] = *iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2533,10 +2522,8 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
|
|||||||
ByteString group, id, identifier;
|
ByteString group, id, identifier;
|
||||||
luaL_checktype(l, 1, LUA_TSTRING);
|
luaL_checktype(l, 1, LUA_TSTRING);
|
||||||
luaL_checktype(l, 2, LUA_TSTRING);
|
luaL_checktype(l, 2, LUA_TSTRING);
|
||||||
group = ByteString(lua_tostring(l, 1));
|
group = ByteString(lua_tostring(l, 1)).ToUpper();
|
||||||
std::transform(group.begin(), group.end(), group.begin(), ::toupper);
|
id = ByteString(lua_tostring(l, 2)).ToUpper();
|
||||||
id = ByteString(lua_tostring(l, 2));
|
|
||||||
std::transform(id.begin(), id.end(), id.begin(), ::toupper);
|
|
||||||
|
|
||||||
if(group == "DEFAULT")
|
if(group == "DEFAULT")
|
||||||
return luaL_error(l, "You cannot create elements in the 'default' group.");
|
return luaL_error(l, "You cannot create elements in the 'default' group.");
|
||||||
|
Reference in New Issue
Block a user