Kaydet (Commit) c490bfac authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in shell::Substitutor

Change-Id: Iee1be29bb4f6a90ccc38d2da8372046350ada438
Reviewed-on: https://gerrit.libreoffice.org/61111
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 93edc2cf
...@@ -199,7 +199,7 @@ class Substitutor ...@@ -199,7 +199,7 @@ class Substitutor
{ {
private: private:
typedef std::map<std::string, std::string> replacement_table_t; typedef std::map<std::string, std::string> replacement_table_t;
typedef std::map<std::string, replacement_table_t*> iso_lang_replacement_table_t; typedef std::map<std::string, replacement_table_t> iso_lang_replacement_table_t;
public: public:
typedef iso_lang_replacement_table_t::iterator iterator; typedef iso_lang_replacement_table_t::iterator iterator;
...@@ -215,17 +215,6 @@ public: ...@@ -215,17 +215,6 @@ public:
Substitutor() {}; Substitutor() {};
~Substitutor()
{
iso_lang_replacement_table_t::iterator iter_end = iso_lang_replacement_table_.end();
iso_lang_replacement_table_t::iterator iter = iso_lang_replacement_table_.begin();
for( /* no init */; iter != iter_end; ++iter)
delete iter->second;
iso_lang_replacement_table_.clear();
}
void set_language(const iso_lang_identifier& iso_lang) void set_language(const iso_lang_identifier& iso_lang)
{ {
active_iso_lang_ = iso_lang; active_iso_lang_ = iso_lang;
...@@ -235,42 +224,26 @@ public: ...@@ -235,42 +224,26 @@ public:
//its substitute else leave it unchanged //its substitute else leave it unchanged
void substitute(std::string& Text) void substitute(std::string& Text)
{ {
replacement_table_t* prt = get_replacement_table(active_iso_lang_.make_std_string()); replacement_table_t& prt = get_replacement_table(active_iso_lang_.make_std_string());
OSL_ASSERT(prt); replacement_table_t::iterator iter = prt.find(Text);
replacement_table_t::iterator iter = prt->find(Text); if (iter != prt.end())
if (iter != prt->end())
Text = iter->second; Text = iter->second;
} }
void add_substitution( void add_substitution(
const std::string& Placeholder, const std::string& Substitute) const std::string& Placeholder, const std::string& Substitute)
{ {
replacement_table_t* prt = get_replacement_table(active_iso_lang_.make_std_string()); replacement_table_t& prt = get_replacement_table(active_iso_lang_.make_std_string());
OSL_ASSERT(prt); prt.insert(std::make_pair(Placeholder, Substitute));
prt->insert(std::make_pair(Placeholder, Substitute));
} }
private: private:
// Return the replacement table for the iso lang id // Return the replacement table for the iso lang id
// create a new one if not already present // create a new one if not already present
replacement_table_t* get_replacement_table(const std::string& iso_lang) replacement_table_t& get_replacement_table(const std::string& iso_lang)
{ {
iso_lang_replacement_table_t::iterator iter = return iso_lang_replacement_table_[iso_lang];
iso_lang_replacement_table_.find(iso_lang);
replacement_table_t* prt = nullptr;
if (iso_lang_replacement_table_.end() == iter)
{
prt = new replacement_table_t;
iso_lang_replacement_table_.insert(std::make_pair(iso_lang, prt));
}
else
{
prt = iter->second;
}
return prt;
} }
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment