Trie and hyphenator RAII.
This commit is contained in:
@ -49,21 +49,18 @@ std::map< std::string, std::unique_ptr< Hyphenator > > Hyphenator::hyphenators;
|
||||
|
||||
Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack)
|
||||
{
|
||||
trie = NULL; // As long we are not sure whether a pattern file can be read.
|
||||
|
||||
using namespace std::literals::string_literals;
|
||||
FILE *trieF = fopen ( (patFile + ".trie"s).c_str(), "r");
|
||||
|
||||
if (trieF) {
|
||||
trie = new Trie ();
|
||||
trie = std::make_unique< Trie >();
|
||||
if (trie->load (trieF) != 0) {
|
||||
delete trie;
|
||||
trie = NULL;
|
||||
trie= nullptr;
|
||||
}
|
||||
fclose (trieF);
|
||||
}
|
||||
|
||||
if (trie == NULL) {
|
||||
if (trie == nullptr) {
|
||||
TrieBuilder trieBuilder(pack);
|
||||
FILE *patF = fopen (patFile, "r");
|
||||
if (patF) {
|
||||
@ -103,11 +100,6 @@ Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack)
|
||||
}
|
||||
}
|
||||
|
||||
Hyphenator::~Hyphenator ()
|
||||
{
|
||||
delete trie;
|
||||
}
|
||||
|
||||
Hyphenator *Hyphenator::getHyphenator (const char *lang)
|
||||
{
|
||||
auto &hyphenator= hyphenators[ lang ];
|
||||
@ -468,7 +460,8 @@ int TrieBuilder::stateStackPop ()
|
||||
return next;
|
||||
}
|
||||
|
||||
Trie *TrieBuilder::createTrie ()
|
||||
std::unique_ptr< Trie >
|
||||
TrieBuilder::createTrie ()
|
||||
{
|
||||
// we need to sort the patterns as byte strings not as unicode
|
||||
qsort (dataList->getArray (), dataList->size (),
|
||||
@ -483,7 +476,7 @@ Trie *TrieBuilder::createTrie ()
|
||||
stateStackPop ();
|
||||
|
||||
int size = tree->size ();
|
||||
Trie *trie = new Trie(tree->detachArray(), size, true, dataZone);
|
||||
auto trie = std::make_unique< Trie >( tree->detachArray(), size, true, dataZone );
|
||||
dataZone = NULL;
|
||||
return trie;
|
||||
}
|
||||
|
Reference in New Issue
Block a user