diff --git a/dw/hyphenator.cc b/dw/hyphenator.cc index fd1553c..bdaad71 100644 --- a/dw/hyphenator.cc +++ b/dw/hyphenator.cc @@ -45,8 +45,7 @@ using namespace lout::unicode; namespace dw { -HashTable *Hyphenator::hyphenators = - new HashTable (true, true); +std::map< std::string, std::unique_ptr< Hyphenator > > Hyphenator::hyphenators; Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack) { @@ -111,12 +110,10 @@ Hyphenator::~Hyphenator () Hyphenator *Hyphenator::getHyphenator (const char *lang) { - String *langString = new String (lang); + auto &hyphenator= hyphenators[ lang ]; - Hyphenator *hyphenator = hyphenators->get (langString); - if (hyphenator) - delete langString; - else { + if( not hyphenator ) + { using namespace std::literals::string_literals; std::string patFile= DILLO_LIBDIR + "/hyphenation/"s + lang + ".pat"; std::string excFile= DILLO_LIBDIR + "/hyphenation"s + lang + ".exc"; @@ -124,15 +121,14 @@ Hyphenator *Hyphenator::getHyphenator (const char *lang) //printf ("Loading hyphenation patterns for language '%s' from '%s' and " // "exceptions from '%s' ...\n", lang, patFile, excFile); - hyphenator = new Hyphenator (patFile.c_str(), excFile.c_str()); - hyphenators->put (langString, hyphenator); + hyphenator= std::make_unique< Hyphenator >( patFile.c_str(), excFile.c_str() ); } //lout::misc::StringBuffer sb; //hyphenators->intoStringBuffer (&sb); //printf ("%s\n", sb.getChars ()); - return hyphenator; + return hyphenator.get(); } void Hyphenator::insertPattern (TrieBuilder *trieBuilder, char *s) diff --git a/dw/hyphenator.hh b/dw/hyphenator.hh index ad77b4f..ebcd4dc 100644 --- a/dw/hyphenator.hh +++ b/dw/hyphenator.hh @@ -85,8 +85,7 @@ class TrieBuilder { class Hyphenator: public lout::object::Object { - static lout::container::typed::HashTable - *hyphenators; + static std::map< std::string, std::unique_ptr< Hyphenator > > hyphenators; Trie *trie; // Only instantiated when needed.