mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 12:44:53 +00:00
Add base::utf8_icmp()
This commit is contained in:
parent
64b8b8ef82
commit
432dd33281
@ -25,6 +25,7 @@
|
|||||||
#include "app/modules/gfx.h"
|
#include "app/modules/gfx.h"
|
||||||
#include "app/thumbnail_generator.h"
|
#include "app/thumbnail_generator.h"
|
||||||
#include "app/ui/skin/skin_theme.h"
|
#include "app/ui/skin/skin_theme.h"
|
||||||
|
#include "base/string.h"
|
||||||
#include "she/font.h"
|
#include "she/font.h"
|
||||||
#include "she/surface.h"
|
#include "she/surface.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
@ -261,9 +262,7 @@ bool FileList::onProcessMessage(Message* msg)
|
|||||||
|
|
||||||
for (i=MAX(select, 0); i<bottom; ++i, ++link) {
|
for (i=MAX(select, 0); i<bottom; ++i, ++link) {
|
||||||
IFileItem* fi = *link;
|
IFileItem* fi = *link;
|
||||||
if (strnicmp(fi->getDisplayName().c_str(),
|
if (base::utf8_icmp(fi->getDisplayName(), m_isearch, chrs) == 0) {
|
||||||
m_isearch.c_str(),
|
|
||||||
chrs) == 0) {
|
|
||||||
select = i;
|
select = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -177,4 +177,32 @@ int utf8_length(const std::string& utf8string)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int utf8_icmp(const std::string& a, const std::string& b, int n)
|
||||||
|
{
|
||||||
|
utf8_const_iterator a_it(a.begin());
|
||||||
|
utf8_const_iterator a_end(a.end());
|
||||||
|
utf8_const_iterator b_it(b.begin());
|
||||||
|
utf8_const_iterator b_end(b.end());
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (; (n == 0 || i < n) && a_it != a_end && b_it != b_end; ++a_it, ++b_it, ++i) {
|
||||||
|
int a_chr = std::tolower(*a_it);
|
||||||
|
int b_chr = std::tolower(*b_it);
|
||||||
|
|
||||||
|
if (a_chr < b_chr)
|
||||||
|
return -1;
|
||||||
|
else if (a_chr > b_chr)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > 0 && i == n)
|
||||||
|
return 0;
|
||||||
|
else if (a_it == a_end && b_it == b_end)
|
||||||
|
return 0;
|
||||||
|
else if (a_it == a_end)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
@ -20,6 +20,7 @@ namespace base {
|
|||||||
std::wstring from_utf8(const std::string& utf8string);
|
std::wstring from_utf8(const std::string& utf8string);
|
||||||
|
|
||||||
int utf8_length(const std::string& utf8string);
|
int utf8_length(const std::string& utf8string);
|
||||||
|
int utf8_icmp(const std::string& a, const std::string& b, int n = 0);
|
||||||
|
|
||||||
template<typename SubIterator>
|
template<typename SubIterator>
|
||||||
class utf8_iteratorT : public std::iterator<std::forward_iterator_tag,
|
class utf8_iteratorT : public std::iterator<std::forward_iterator_tag,
|
||||||
|
@ -66,6 +66,27 @@ TEST(String, Utf8Iterator)
|
|||||||
ASSERT_TRUE((utf8_iterator(d.begin())+1) == utf8_iterator(d.end()));
|
ASSERT_TRUE((utf8_iterator(d.begin())+1) == utf8_iterator(d.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(String, Utf8ICmp)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(-1, utf8_icmp("a", "b"));
|
||||||
|
EXPECT_EQ(-1, utf8_icmp("a", "b", 1));
|
||||||
|
EXPECT_EQ(-1, utf8_icmp("a", "b", 2));
|
||||||
|
EXPECT_EQ(-1, utf8_icmp("a", "aa"));
|
||||||
|
EXPECT_EQ(-1, utf8_icmp("A", "aa", 3));
|
||||||
|
EXPECT_EQ(-1, utf8_icmp("a", "ab"));
|
||||||
|
|
||||||
|
EXPECT_EQ(0, utf8_icmp("AaE", "aae"));
|
||||||
|
EXPECT_EQ(0, utf8_icmp("AaE", "aae", 3));
|
||||||
|
EXPECT_EQ(0, utf8_icmp("a", "aa", 1));
|
||||||
|
EXPECT_EQ(0, utf8_icmp("a", "ab", 1));
|
||||||
|
|
||||||
|
EXPECT_EQ(1, utf8_icmp("aaa", "Aa", 3));
|
||||||
|
EXPECT_EQ(1, utf8_icmp("Bb", "b"));
|
||||||
|
EXPECT_EQ(1, utf8_icmp("z", "b"));
|
||||||
|
EXPECT_EQ(1, utf8_icmp("z", "b", 1));
|
||||||
|
EXPECT_EQ(1, utf8_icmp("z", "b", 2));
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user