[sword-devel] getKeyText() doesn't always return keys.
Troy A. Griffitts
coptotvmr at gmail.com
Thu Mar 28 14:11:19 EDT 2024
Hi David,
The weirdness you might be running into is the behavior that SWLex
modules 'snap' their key to the nearest entry upon renderText (or
stripText, as you are calling).
I know this doesn't seem completely intuitive, but I would try calling
stripText BEFORE calling getKeyText(). I wouldn't recommend using
setPersist. This will force the module to use the same external key and
let you manage cleaning up that key memory when you are finished, rather
than letting the module manage its own internal key.
I hope this helps.
Troy
On 3/26/24 10:01, David "Judah's Shadow" Blue wrote:
> On Monday, March 25, 2024 4:06:19 PM EDT David "Judah's Shadow" Blue wrote:
>> On Monday, March 25, 2024 1:52:40 PM EDT David "Judah's Shadow" Blue wrote:
>>> I've noticed a problem with lexicons not always getting a value from
>>> getKeyText(). It's intermittent, and I can't quite nail down why I would
>>> be
>>> getting empty strings when I call it sometimes.
>> Investigating further, it appears to happen on the first usage of
>> getKeyText() but only for lexicon based modules, bibles and commentaries
>> show keytext correctly.
> In further weirdness, I sometimes get what I have entered previously as the
> key. Here's an example function I use to retrieve a lexicon entry.
>
> std::string Lexicon::getEntry(std::string entry) {
> std::string lexEntry;
> sword::SWModule *module;
>
> std::transform(entry.begin(), entry.end(), entry.begin(),
> [](unsigned char c) {return std::toupper(c);});
>
>
> module = this->swordLibrary->getModule(this->lexiDict.c_str());
> module->setKeyText(entry.c_str());
>
> lexEntry = module->getKeyText();
> lexEntry += " ";
> lexEntry += module->stripText();
>
> return lexEntry;
> }
>
> I am uncertain what I could be doing wrong here.
>
>
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
More information about the sword-devel
mailing list