Skip to content

Commit

Permalink
Refactoring: modernize emoji class
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Jan 22, 2021
1 parent 554c5e1 commit 60adbd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/emoji.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,18 +1521,15 @@ EmojiEntityMapper *EmojiEntityMapper::s_instance = 0;

EmojiEntityMapper::EmojiEntityMapper()
{
m_name2symGh = new QDict<int>(1009);
m_name2symGh->setAutoDelete(TRUE);
// 2 loops to be able to give precedence to the unicodeName (CLDR)
for (int i = 0; i < g_numEmojiEntities; i++)
{
m_name2symGh->insert(g_emojiEntities[i].name, new int(i));
m_name2symGh.insert(std::make_pair(g_emojiEntities[i].name, i));
}
}

EmojiEntityMapper::~EmojiEntityMapper()
{
delete m_name2symGh;
}

/** Returns the one and only instance of the Emoji entity mapper */
Expand Down Expand Up @@ -1560,8 +1557,8 @@ void EmojiEntityMapper::deleteInstance()
*/
int EmojiEntityMapper::symbol2index(const QCString &symName) const
{
int *val = m_name2symGh->find(symName);
return val ? *val : -1;
auto it = m_name2symGh.find(symName.str());
return it!=m_name2symGh.end() ? it->second : -1;
}

/*!
Expand Down
6 changes: 4 additions & 2 deletions src/emoji.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#ifndef EMOJIENTITY_H
#define EMOJIENTITY_H

#include <qdict.h>
#include <map>
#include <string>

#include <qfile.h>

class FTextStream;
Expand All @@ -35,7 +37,7 @@ class EmojiEntityMapper
EmojiEntityMapper();
~EmojiEntityMapper();
static EmojiEntityMapper *s_instance;
QDict<int> *m_name2symGh;
std::map<std::string,int> m_name2symGh;
};

#endif

0 comments on commit 60adbd5

Please sign in to comment.