Commits

Luke Plant committed 93a5c17

Fixed bug with infinite loop when hitting the very end of a module

  • Participants
  • Parent commits ad866b4

Comments (0)

Files changed (1)

lukeplant_me_uk/bibleverses/sword.py

 import re
 
 sword_mgr = Sword.SWMgr()
-#sword_mgr = Sword.SWMgr(None, None, True, Sword.EncodingFilterMgr(Sword.ENC_UTF8))
 sword_mgr.setGlobalOption("Footnotes", "Off")
 sword_mgr.setGlobalOption("Cross-references", "Off")
 
         e = Sword.VerseKey.castTo(lk.getElement(i))
         if e is not None:
             mod.Key(e.LowerBound())
-            while mod.Key().compare(e.UpperBound()) <= 0:
+            lastKey = None # Need this to stop infinite loops when module hits last verse.
+            while mod.Key().compare(e.UpperBound()) <= 0 and (lastKey is None or mod.Key().compare(lastKey) != 0):
                 out.append(conv(mod))
                 if not out[-1].endswith("\n") and not out[-1].endswith(" "):
                     out.append(u" ")
+                lastKey = mod.Key().clone()
                 mod.increment(1)
         else:
             mod.Key(lk.getElement(i))