Implement emoji exact search functions

v1
Tony Olagbaiye 7 years ago
parent c1e7e096d0
commit 48257b7cc1
No known key found for this signature in database
GPG Key ID: 7420820577A31D11

1
.gitattributes vendored

@ -1,2 +1,3 @@
# Github language display # Github language display
*.h linguist-language=C *.h linguist-language=C
*.inc linguist-language=C

@ -10,3 +10,78 @@
#include "slack-emoji.inc" #include "slack-emoji.inc"
static int emoji_byname_cmp(const void *p1, const void *p2)
{
return strcasecmp(((struct t_slack_emoji_by_name *)p1)->name,
((struct t_slack_emoji_by_name *)p2)->name);
}
static int emoji_bytext_cmp(const void *p1, const void *p2)
{
return strcasecmp(((struct t_slack_emoji_by_text *)p1)->text,
((struct t_slack_emoji_by_text *)p2)->text);
}
const char *slack_emoji_get_unicode_by_name(const char *name)
{
struct t_slack_emoji_by_name *result;
struct t_slack_emoji_by_name key;
key.name = name;
size_t emoji_count = sizeof(slack_emoji_by_name)
/ sizeof(struct t_slack_emoji_by_name);
result = (struct t_slack_emoji_by_name *)bsearch(
&key, slack_emoji_by_name, emoji_count,
sizeof(struct t_slack_emoji_by_name),
emoji_byname_cmp);
return result->unicode;
}
const char *slack_emoji_get_unicode_by_text(const char *text)
{
struct t_slack_emoji_by_text *result;
struct t_slack_emoji_by_text key;
key.text = text;
size_t emoji_count = sizeof(slack_emoji_by_text)
/ sizeof(struct t_slack_emoji_by_text);
result = (struct t_slack_emoji_by_text *)bsearch(
&key, slack_emoji_by_text, emoji_count,
sizeof(struct t_slack_emoji_by_text),
emoji_bytext_cmp);
return result->unicode;
}
const char *slack_emoji_get_text_by_name(const char *name)
{
struct t_slack_emoji_by_name *result;
struct t_slack_emoji_by_name key;
key.name = name;
size_t emoji_count = sizeof(slack_emoji_by_name)
/ sizeof(struct t_slack_emoji_by_name);
result = (struct t_slack_emoji_by_name *)bsearch(
&key, slack_emoji_by_name, emoji_count,
sizeof(struct t_slack_emoji_by_name),
emoji_byname_cmp);
return result->text_to;
}
const char *slack_emoji_get_text_by_text(const char *text)
{
struct t_slack_emoji_by_text *result;
struct t_slack_emoji_by_text key;
key.text = text;
size_t emoji_count = sizeof(slack_emoji_by_text)
/ sizeof(struct t_slack_emoji_by_text);
result = (struct t_slack_emoji_by_text *)bsearch(
&key, slack_emoji_by_text, emoji_count,
sizeof(struct t_slack_emoji_by_text),
emoji_bytext_cmp);
return result->text_to;
}

@ -5,6 +5,12 @@
#ifndef _SLACK_EMOJI_H_ #ifndef _SLACK_EMOJI_H_
#define _SLACK_EMOJI_H_ #define _SLACK_EMOJI_H_
const char *slack_emoji_get_unicode_by_name(const char *name);
const char *slack_emoji_get_unicode_by_text(const char *text);
const char *slack_emoji_get_text_by_name(const char *name);
const char *slack_emoji_get_text_by_text(const char *text);
#endif /*SLACK_EMOJI_H*/ #endif /*SLACK_EMOJI_H*/

@ -1,4 +1,8 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <stdlib.h> #include <stdlib.h>
#define MAX_TEXTS 7 #define MAX_TEXTS 7

@ -1,5 +1,9 @@
#!/usr/bin/perl -l #!/usr/bin/perl -l
# This Source Code Form is subject to the terms of the Mozilla Public
# License, version 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use strict; use strict;
use warnings; use warnings;
@ -17,6 +21,10 @@ my $maxtexts = max (map { 1 + @{$_} } (grep defined, map { $_->{'texts'} } @arra
my $maxnames = max (map { 1 + @{$_} } (grep defined, map { $_->{'short_names'} } @array)); my $maxnames = max (map { 1 + @{$_} } (grep defined, map { $_->{'short_names'} } @array));
print " print "
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <stdlib.h> #include <stdlib.h>
#define MAX_TEXTS $maxtexts #define MAX_TEXTS $maxtexts

@ -1,6 +1,10 @@
#!/usr/bin/python #!/usr/bin/python
# Compatible with python v2 and v3 # Compatible with python v2 and v3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, version 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import requests import requests
import json import json
import ast import ast
@ -8,6 +12,10 @@ import ast
emoji = requests.get("https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json").json() emoji = requests.get("https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json").json()
print(""" print("""
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <stdlib.h> #include <stdlib.h>
#define MAX_TEXTS %d #define MAX_TEXTS %d

Loading…
Cancel
Save