Skip to content

Commit

Permalink
Prioritise exact matches, fix escaping bug
Browse files Browse the repository at this point in the history
  • Loading branch information
meyer committed Feb 2, 2017
1 parent f5fdfce commit 7abeff4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions emoji.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def codepoints_to_ruby(arr); arr.map(&:to_i).int_to_hex.map {|d| "\\u{#{d}}"}.jo
def codepoints_to_emoji(arr); arr.map(&:to_i).pack('U*'); end

STDERR.puts '===='
STDERR.puts "ARGV: #{ARGV}"
STDERR.puts "ARGV: `#{ARGV}`"
STDERR.puts '===='

OptionParser.new do |opts|
Expand Down Expand Up @@ -102,7 +102,7 @@ def items2xml(results)
begin
raise if $debug_mode
guts = Marshal.load(f.read)
STDERR.puts "LOADING FROM MARSHAL: #{MARSHAL_TMP_FILE}"
STDERR.puts "LOADING FROM MARSHAL: `#{MARSHAL_TMP_FILE}`"
guts
rescue
STDERR.puts "LOADING FROM EMOJI-DB"
Expand All @@ -114,10 +114,12 @@ def items2xml(results)
fc['db'].each do |k, v|
fc['db'][k]['name'] = CGI.escapeHTML(fc['db'][k]['name'] || '')
fc['search_strings'][k] = [
'',
v['name'].split(/\s+/),
v['keywords'],
v['codepoints'].map(&:to_unicode),
fc['db'][k]['fitz'] ? 'fitz' : [],
'',
].compact.join(' ').downcase
fc['db'][k]['image'] = EMOJI_DB_PATH.join(fc['db'][k]['image'])
if fc['db'][k]['fitz']
Expand All @@ -134,23 +136,27 @@ def items2xml(results)

### SEARCH SHIT

exact_matches = []
matches = []

unless ARGV.empty?
query = ARGV.join(' ').downcase
STDERR.puts "QUERY: #{query}"
query = ARGV.join(' ').downcase.strip
STDERR.puts "QUERY: `#{query}`"
if query.strip != ''
EMOJIS['search_strings'].each do |key, ss|
if ss.include?(query)
if ss.include?(" #{query} ")
exact_matches.push key
STDERR.puts "`#{EMOJIS['db'][key]['name']}` is an exact match!"
elsif ss.include?(query)
matches.push key
STDERR.puts "`#{EMOJIS['db'][key]['name']}` is a match!"
end
end
end
end

items = matches.map do |emojilib_key|
STDERR.puts "CODEPOINT: #{emojilib_key}"
items = (exact_matches + matches).map do |emojilib_key|
STDERR.puts "CODEPOINT: `#{emojilib_key}`"
emoji = EMOJIS['db'][emojilib_key]

path = emoji['image']
Expand All @@ -169,7 +175,7 @@ def items2xml(results)

path = emoji['fitz'][$skin_tone - 1] if fitz

STDERR.puts "KEYWORDS: #{EMOJIS['search_strings'][emojilib_key]}"
STDERR.puts "KEYWORDS: `#{EMOJIS['search_strings'][emojilib_key]}`"
STDERR.puts path

codepoints = [
Expand Down
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>100</integer>
<integer>126</integer>
<key>keyword</key>
<string>testmoji</string>
<key>queuedelaycustom</key>
Expand Down

0 comments on commit 7abeff4

Please sign in to comment.