From 9a907a0501308d277decac2a2e266a484579373cda64748bf566d02bfdc1b2c0 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sat, 9 Aug 2025 15:31:50 -0400 Subject: [PATCH] More non-STL containers contained. --- dw/hyphenator.cc | 27 ++++++++++++--------------- dw/hyphenator.hh | 6 +++--- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/dw/hyphenator.cc b/dw/hyphenator.cc index ccfc14f..f8dcd11 100644 --- a/dw/hyphenator.cc +++ b/dw/hyphenator.cc @@ -86,11 +86,9 @@ Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack) } } - exceptions = NULL; // Again, only instantiated when needed. - FILE *excF = fopen (excFile, "r"); if (excF) { - exceptions = new HashTable > (true, true); + exceptions.emplace(); while (!feof (excF)) { char buf[LEN + 1]; char *s = fgets (buf, LEN, excF); @@ -109,7 +107,6 @@ Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack) Hyphenator::~Hyphenator () { delete trie; - delete exceptions; } Hyphenator *Hyphenator::getHyphenator (const char *lang) @@ -174,15 +171,15 @@ void Hyphenator::insertPattern (TrieBuilder *trieBuilder, char *s) void Hyphenator::insertException (char *s) { - Vector *breaks = new Vector (1, true); + std::vector< int > breaks; int len = strlen (s); for (int i = 0; i < len - 1; i++) if((unsigned char)s[i] == 0xc2 && (unsigned char)s[i + 1] == 0xad) - breaks->put (new Integer (i - 2 * breaks->size())); + breaks.push_back( i - 2 * breaks.size() ); std::string noHyphens; - noHyphens.resize( len - 2 * breaks->size() + 1 ); + noHyphens.resize( len - 2 * breaks.size() + 1 ); int j = 0; for (int i = 0; i < len; ) { if(i < len - 1 && @@ -193,7 +190,7 @@ void Hyphenator::insertException (char *s) } noHyphens[j] = 0; - exceptions->put (new String (noHyphens.c_str()), breaks); + exceptions->emplace( noHyphens, std::move( breaks ) ); } /** @@ -225,7 +222,7 @@ bool Hyphenator::isCharPartOfActualWord (char *s) int *Hyphenator::hyphenateWord(core::Platform *platform, const char *word, int *numBreaks) { - if ((trie == NULL && exceptions == NULL) || !isHyphenationCandidate (word)) { + if ((trie == NULL && not exceptions.has_value()) || !isHyphenationCandidate (word)) { *numBreaks = 0; return NULL; } @@ -286,13 +283,13 @@ void Hyphenator::hyphenateSingleWord(core::Platform *platform, SimpleVector *breakPos) { // If the word is an exception, get the stored points. - Vector *exceptionalBreaks; - ConstString key (wordLc); - if (exceptions != NULL && (exceptionalBreaks = exceptions->get (&key))) { - for (int i = 0; i < exceptionalBreaks->size(); i++) { + std::string key= wordLc; + if (exceptions.has_value() && exceptions.value().contains( key ) ) + { + auto exceptionalBreaks= exceptions.value().at( key ); + for (int i = 0; i < exceptionalBreaks.size(); i++) { breakPos->increase (); - breakPos->set (breakPos->size() - 1, - exceptionalBreaks->get(i)->getValue() + offset); + breakPos->set (breakPos->size() - 1, exceptionalBreaks.at( i ) + offset); } return; } diff --git a/dw/hyphenator.hh b/dw/hyphenator.hh index 8926f40..ad77b4f 100644 --- a/dw/hyphenator.hh +++ b/dw/hyphenator.hh @@ -89,9 +89,9 @@ class Hyphenator: public lout::object::Object *hyphenators; Trie *trie; - lout::container::typed::HashTable > *exceptions; + // Only instantiated when needed. + std::optional< std::map< std::string, std::vector< int > > > exceptions; + void insertPattern (TrieBuilder *trieBuilder, char *s); void insertException (char *s);