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");
if (excF) {
exceptions = new HashTable <ConstString, Vector <Integer> > (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<Integer> *breaks = new Vector<Integer> (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 <int> *breakPos)
{
// If the word is an exception, get the stored points.
Vector <Integer> *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;
}

View File

@ -89,9 +89,9 @@ class Hyphenator: public lout::object::Object
<lout::object::String, Hyphenator> *hyphenators;
Trie *trie;
lout::container::typed::HashTable <lout::object::ConstString,
lout::container::typed::Vector
<lout::object::Integer> > *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);