The second thing I don't really understand is how to correctly pull
out text for a verse key.
Some code is following, sorry for that.
Well, to correctly pull out text for a VerseKey, you should be able to
just use 'VerseKey::getText()' If you have enable unicode in sword,
then you will be using the UTF8 locales which should always return UTF8
and not Latin1.
If you have a crash bug please let me know and I will try to hunt things
down before this next release. Can you give me a small example of code
that crashes? e.g.
VerseKey key = "jn.1.1";
key.Persist(true);
ntOnlyModule.setKey(key);
ntOnlyModule.RenderText();
Does this crash? It shouldn't. Hope we can get things working well for
you. I need a new laptop and considering buying a Mac! :)
-Troy.
In MacSword I have implemented the code like this:
-----------------------
// needed to check for UTF8 string
MSStringMgr *strMgr = new MSStringMgr();
// incoming reference
const char *cref = [reference UTF8String];
sword::VerseKey vk;
sword::ListKey listkey = vk.ParseVerseList(cref, vk, true);
// for the duration of this query be want the key to persist
listkey.Persist(true);
swModule->setKey(listkey);
// iterate through keys
for ((*swModule) = sword::TOP; !swModule->Error(); (*swModule)++) {
const char *keyCStr = swModule->getKeyText();
const char *txtCStr = swModule->RenderText();
NSMutableDictionary *dict = [NSMutableDictionary
dictionaryWithCapacity:2];
NSString *key = @"";
NSString *txt = @"";
if(strMgr->isUtf8(txtCStr)) {
txt = [NSString stringWithUTF8String:txtCStr];
} else {
txt = [NSString stringWithCString:txtCStr
encoding:NSISOLatin1StringEncoding];
}
if([self isUnicode]) {
key = [NSString stringWithUTF8String:keyCStr];
} else {
key = [NSString stringWithCString:keyCStr
encoding:NSISOLatin1StringEncoding];
}
// add to dict
[dict setObject:txt forKey:SW_OUTPUT_TEXT_KEY];
[dict setObject:key forKey:SW_OUTPUT_REF_KEY];
// add to array
[ret addObject:dict];
}
// remove persitent key
swModule->setKey("gen.1.1");
------------------------
The above code still crashes for references that doesn't exist while the
below code works everywhere and always.
This actually works but due to the problem with the locale and Umlauts
it crashes somewhere in the library in the head of the for loop
((*swModule) = sword::TOP).
I have some older code lying around (which actually is used in
MacSword 1.4.3 done by William) which I to be honest don't understand:
--------------------------
sword::VerseKey vk;
int lastIndex;
((sword::VerseKey*)(swModule->getKey()))->Headings(1);
sword::ListKey listkey = vk.ParseVerseList(toUTF8(reference),
"Gen1", true);
for (int i = 0; i < listkey.Count(); i++) {
sword::VerseKey *element = My_SWDYNAMIC_CAST(VerseKey,
listkey.GetElement(i));
// is it a chapter or book - not atomic
if(element) {
swModule->Key(element->LowerBound());
// find the upper bound
vk = element->UpperBound();
vk.Headings(true);
} else {
// set it up
swModule->Key(*listkey.GetElement(i));
}
// while not past the upper bound
do {
//add verse index to dictionary
char *ctxt = (char *)swModule->RenderText();
int clen = strlen(ctxt);
NSString *text = fromUTF8(ctxt);
NSString *verse = fromUTF8(swModule->Key().getText());
// add to dict
NSMutableDictionary *dict = [NSMutableDictionary
dictionaryWithCapacity:2];
[dict setObject:text forKey:SW_OUTPUT_TEXT_KEY];
[dict setObject:verse forKey:SW_OUTPUT_REF_KEY];
// add to array
[ret addObject:dict];
lastIndex = (swModule->Key()).Index();
(*swModule)++;
if(lastIndex == (swModule->Key()).Index())
break;
}while (element && swModule->Key() <= vk);
}
---------------------
This code also has the locale problem but it doesn't crash.
The problem is however that I don't know the right way of pulling out
text and I don't really understand some portions of the above code.
These two loops really confuse me. I would be happy if someone could
tell me line by line what happens here.
I had the impression that actually the code above, which crashes, is
correct. But it seems, it is not.
Regards,
Manfred
_______________________________________________
sword-devel mailing list: [email protected]
http://www.crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page
_______________________________________________
sword-devel mailing list: [email protected]
http://www.crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page
_______________________________________________
sword-devel mailing list: [email protected]
http://www.crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page