More non-STL containers contained.

This commit is contained in:
2025-08-09 15:31:50 -04:00
parent 80aa7cb15d
commit 9a907a0501
2 changed files with 15 additions and 18 deletions

View File

@ -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"); FILE *excF = fopen (excFile, "r");
if (excF) { if (excF) {
exceptions = new HashTable <ConstString, Vector <Integer> > (true, true); exceptions.emplace();
while (!feof (excF)) { while (!feof (excF)) {
char buf[LEN + 1]; char buf[LEN + 1];
char *s = fgets (buf, LEN, excF); char *s = fgets (buf, LEN, excF);
@ -109,7 +107,6 @@ Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack)
Hyphenator::~Hyphenator () Hyphenator::~Hyphenator ()
{ {
delete trie; delete trie;
delete exceptions;
} }
Hyphenator *Hyphenator::getHyphenator (const char *lang) Hyphenator *Hyphenator::getHyphenator (const char *lang)
@ -174,15 +171,15 @@ void Hyphenator::insertPattern (TrieBuilder *trieBuilder, char *s)
void Hyphenator::insertException (char *s) void Hyphenator::insertException (char *s)
{ {
Vector<Integer> *breaks = new Vector<Integer> (1, true); std::vector< int > breaks;
int len = strlen (s); int len = strlen (s);
for (int i = 0; i < len - 1; i++) for (int i = 0; i < len - 1; i++)
if((unsigned char)s[i] == 0xc2 && (unsigned char)s[i + 1] == 0xad) 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; std::string noHyphens;
noHyphens.resize( len - 2 * breaks->size() + 1 ); noHyphens.resize( len - 2 * breaks.size() + 1 );
int j = 0; int j = 0;
for (int i = 0; i < len; ) { for (int i = 0; i < len; ) {
if(i < len - 1 && if(i < len - 1 &&
@ -193,7 +190,7 @@ void Hyphenator::insertException (char *s)
} }
noHyphens[j] = 0; 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, int *Hyphenator::hyphenateWord(core::Platform *platform,
const char *word, int *numBreaks) const char *word, int *numBreaks)
{ {
if ((trie == NULL && exceptions == NULL) || !isHyphenationCandidate (word)) { if ((trie == NULL && not exceptions.has_value()) || !isHyphenationCandidate (word)) {
*numBreaks = 0; *numBreaks = 0;
return NULL; return NULL;
} }
@ -286,13 +283,13 @@ void Hyphenator::hyphenateSingleWord(core::Platform *platform,
SimpleVector <int> *breakPos) SimpleVector <int> *breakPos)
{ {
// If the word is an exception, get the stored points. // If the word is an exception, get the stored points.
Vector <Integer> *exceptionalBreaks; std::string key= wordLc;
ConstString key (wordLc); if (exceptions.has_value() && exceptions.value().contains( key ) )
if (exceptions != NULL && (exceptionalBreaks = exceptions->get (&key))) { {
for (int i = 0; i < exceptionalBreaks->size(); i++) { auto exceptionalBreaks= exceptions.value().at( key );
for (int i = 0; i < exceptionalBreaks.size(); i++) {
breakPos->increase (); breakPos->increase ();
breakPos->set (breakPos->size() - 1, breakPos->set (breakPos->size() - 1, exceptionalBreaks.at( i ) + offset);
exceptionalBreaks->get(i)->getValue() + offset);
} }
return; return;
} }

View File

@ -89,9 +89,9 @@ class Hyphenator: public lout::object::Object
<lout::object::String, Hyphenator> *hyphenators; <lout::object::String, Hyphenator> *hyphenators;
Trie *trie; Trie *trie;
lout::container::typed::HashTable <lout::object::ConstString, // Only instantiated when needed.
lout::container::typed::Vector std::optional< std::map< std::string, std::vector< int > > > exceptions;
<lout::object::Integer> > *exceptions;
void insertPattern (TrieBuilder *trieBuilder, char *s); void insertPattern (TrieBuilder *trieBuilder, char *s);
void insertException (char *s); void insertException (char *s);