diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-12-09 13:13:14 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-12-09 13:13:14 +0100 |
commit | 5df24b640c4f1471eb6d7a38160e9d9330fbdc67 (patch) | |
tree | 2605c8f6206822531f8fb1c9ea08e89814f81823 /dw/hyphenator.cc | |
parent | 7a47cd331d30a780e7437b77aeb994c8ed2061b8 (diff) |
share hyphenators between windows/tabs
Diffstat (limited to 'dw/hyphenator.cc')
-rw-r--r-- | dw/hyphenator.cc | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/dw/hyphenator.cc b/dw/hyphenator.cc index cec5a9d8..4fe9433b 100644 --- a/dw/hyphenator.cc +++ b/dw/hyphenator.cc @@ -19,15 +19,11 @@ using namespace lout::misc; namespace dw { -HashTable <TypedPair <TypedPointer <core::Platform>, ConstString>, - Hyphenator> *Hyphenator::hyphenators = - new HashTable <TypedPair <TypedPointer <core::Platform>, ConstString>, - Hyphenator> (true, true); +HashTable <String, Hyphenator> *Hyphenator::hyphenators = + new HashTable <String, Hyphenator> (true, true); -Hyphenator::Hyphenator (core::Platform *platform, - const char *patFile, const char *excFile, int pack) +Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack) { - this->platform = platform; trie = NULL; // As long we are not sure whether a pattern file can be read. char buf[PATH_MAX + 1]; @@ -91,20 +87,13 @@ Hyphenator::~Hyphenator () delete exceptions; } -Hyphenator *Hyphenator::getHyphenator (core::Platform *platform, - const char *lang) +Hyphenator *Hyphenator::getHyphenator (const char *lang) { - // TODO Not very efficient. Other key than TypedPair? - // (Keeping the parts of the pair on the stack does not help, since - // ~TypedPair deletes them, so they have to be kept on the heap.) - TypedPair <TypedPointer <core::Platform>, ConstString> *pair = - new TypedPair <TypedPointer <core::Platform>, - ConstString> (new TypedPointer <core::Platform> (platform), - new String (lang)); - - Hyphenator *hyphenator = hyphenators->get (pair); + String *langString = new String (lang); + + Hyphenator *hyphenator = hyphenators->get (langString); if (hyphenator) - delete pair; + delete langString; else { char patFile [PATH_MAX]; snprintf (patFile, sizeof (patFile), "%s/hyphenation/%s.pat", @@ -116,8 +105,8 @@ Hyphenator *Hyphenator::getHyphenator (core::Platform *platform, //printf ("Loading hyphenation patterns for language '%s' from '%s' and " // "exceptions from '%s' ...\n", lang, patFile, excFile); - hyphenator = new Hyphenator (platform, patFile, excFile); - hyphenators->put (pair, hyphenator); + hyphenator = new Hyphenator (patFile, excFile); + hyphenators->put (langString, hyphenator); } //lout::misc::StringBuffer sb; @@ -221,7 +210,8 @@ bool Hyphenator::isCharPartOfActualWord (char *s) /** * Given a word, returns a list of the possible hyphenation points. */ -int *Hyphenator::hyphenateWord(const char *word, int *numBreaks) +int *Hyphenator::hyphenateWord(core::Platform *platform, + const char *word, int *numBreaks) { if ((trie == NULL && exceptions ==NULL) || !isHyphenationCandidate (word)) { *numBreaks = 0; @@ -261,7 +251,7 @@ int *Hyphenator::hyphenateWord(const char *word, int *numBreaks) } else nextStart = end; - hyphenateSingleWord (wordLc + start, start, &breakPos); + hyphenateSingleWord (platform, wordLc + start, start, &breakPos); start = nextStart; } @@ -279,8 +269,9 @@ int *Hyphenator::hyphenateWord(const char *word, int *numBreaks) * Hyphenate a single word, which only consists of lowercase * characters. Store break positions + "offset" in "breakPos". */ -void Hyphenator::hyphenateSingleWord(char *wordLc, int offset, - SimpleVector <int> *breakPos) +void Hyphenator::hyphenateSingleWord(core::Platform *platform, + char *wordLc, int offset, + SimpleVector <int> *breakPos) { // If the word is an exception, get the stored points. Vector <Integer> *exceptionalBreaks; |