Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
d1dbefc0
Commit
d1dbefc0
authored
2 years ago
by
Kitty Barnett
Browse files
Options
Downloads
Patches
Plain Diff
Refactor emoji matching
parent
fb1553d8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
indra/llui/llemojidictionary.cpp
+42
-28
42 additions, 28 deletions
indra/llui/llemojidictionary.cpp
indra/llui/llemojidictionary.h
+1
-1
1 addition, 1 deletion
indra/llui/llemojidictionary.h
with
43 additions
and
29 deletions
indra/llui/llemojidictionary.cpp
+
42
−
28
View file @
d1dbefc0
...
@@ -31,6 +31,8 @@
...
@@ -31,6 +31,8 @@
#include
"llsdserialize.h"
#include
"llsdserialize.h"
#include
<boost/algorithm/string.hpp>
#include
<boost/algorithm/string.hpp>
#include
<boost/range/adaptor/filtered.hpp>
#include
<boost/range/algorithm/transform.hpp>
// ============================================================================
// ============================================================================
// Constants
// Constants
...
@@ -89,6 +91,41 @@ bool LLEmojiDescriptor::isValid() const
...
@@ -89,6 +91,41 @@ bool LLEmojiDescriptor::isValid() const
!
Categories
.
empty
();
!
Categories
.
empty
();
}
}
struct
emoji_filter_base
{
emoji_filter_base
(
const
std
::
string
&
needle
)
{
// Search without the colon (if present) so the user can type ':food' and see all emojis in the 'Food' category
mNeedle
=
(
boost
::
starts_with
(
needle
,
":"
))
?
needle
.
substr
(
1
)
:
needle
;
LLStringUtil
::
toLower
(
mNeedle
);
}
protected
:
std
::
string
mNeedle
;
};
struct
emoji_filter_shortcode_or_category_contains
:
public
emoji_filter_base
{
emoji_filter_shortcode_or_category_contains
(
const
std
::
string
&
needle
)
:
emoji_filter_base
(
needle
)
{}
bool
operator
()(
const
LLEmojiDescriptor
&
descr
)
const
{
for
(
const
auto
&
short_code
:
descr
.
ShortCodes
)
{
if
(
boost
::
icontains
(
short_code
,
mNeedle
))
return
true
;
}
for
(
const
auto
&
category
:
descr
.
Categories
)
{
if
(
boost
::
icontains
(
category
,
mNeedle
))
return
true
;
}
return
false
;
}
};
// ============================================================================
// ============================================================================
// LLEmojiDictionary class
// LLEmojiDictionary class
//
//
...
@@ -130,35 +167,12 @@ void LLEmojiDictionary::initClass()
...
@@ -130,35 +167,12 @@ void LLEmojiDictionary::initClass()
}
}
}
}
LLWString
LLEmojiDictionary
::
findMatchingEmojis
(
std
::
string
needle
)
LLWString
LLEmojiDictionary
::
findMatchingEmojis
(
const
std
::
string
&
needle
)
const
{
{
// Search without the colon (if present) so the user can type ':food' and see all emojis in the 'Food' category
LLWString
result
;
LLStringUtil
::
toLower
(
needle
);
boost
::
transform
(
mEmojis
|
boost
::
adaptors
::
filtered
(
emoji_filter_shortcode_or_category_contains
(
needle
)),
const
auto
kitty_needle
=
boost
::
make_iterator_range
((
boost
::
starts_with
(
needle
,
":"
))
?
needle
.
begin
()
+
1
:
needle
.
begin
(),
needle
.
end
());
std
::
back_inserter
(
result
),
[](
const
auto
&
descr
)
{
return
descr
.
Character
;
});
return
result
;
LLWString
wstr
;
for
(
const
auto
&
descr
:
mEmojis
)
{
for
(
const
auto
&
short_code
:
descr
.
ShortCodes
)
{
if
(
boost
::
icontains
(
short_code
,
kitty_needle
))
{
wstr
.
push_back
(
descr
.
Character
);
continue
;
}
}
for
(
const
auto
&
category
:
descr
.
Categories
)
{
if
(
boost
::
icontains
(
category
,
kitty_needle
))
{
wstr
.
push_back
(
descr
.
Character
);
continue
;
}
}
}
return
wstr
;
}
}
std
::
string
LLEmojiDictionary
::
getNameFromEmoji
(
llwchar
ch
)
std
::
string
LLEmojiDictionary
::
getNameFromEmoji
(
llwchar
ch
)
...
...
This diff is collapsed.
Click to expand it.
indra/llui/llemojidictionary.h
+
1
−
1
View file @
d1dbefc0
...
@@ -57,7 +57,7 @@ class LLEmojiDictionary : public LLParamSingleton<LLEmojiDictionary>, public LLI
...
@@ -57,7 +57,7 @@ class LLEmojiDictionary : public LLParamSingleton<LLEmojiDictionary>, public LLI
public
:
public
:
static
void
initClass
();
static
void
initClass
();
LLWString
findMatchingEmojis
(
std
::
string
needle
);
LLWString
findMatchingEmojis
(
const
std
::
string
&
needle
)
const
;
std
::
string
getNameFromEmoji
(
llwchar
ch
);
std
::
string
getNameFromEmoji
(
llwchar
ch
);
private
:
private
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment