EsvXmlEnhancer { int findWordPosition(final String str, final int n) { final int start = fastForwardNonAlphaNumeric(str); boolean foundLetter = true; int count = n; int ii = start; for (ii = start; ii < str.length(); ii++) { if (!Character.isLetterOrDigit(str.charAt(ii))) { if (foundLetter) { count--; } foundLetter = false; } else { foundLetter = true; } if (count < 0) { while (ii + 1 < str.length() && !Character.isLetterOrDigit(str.charAt(ii + 1))) { ii++; } break; } } return ii; } EsvXmlEnhancer(final File tagging, final File esvText, File outputPath); static void main(final String[] args);  }
@Test public void testNthOccurrence() { final EsvXmlEnhancer esvXmlEnhancer = new EsvXmlEnhancer(null, null, null); assertEquals(3, esvXmlEnhancer.findWordPosition("the dog", 0)); assertEquals(10, esvXmlEnhancer.findWordPosition("the dog is in the garden", 2)); assertEquals(11, esvXmlEnhancer.findWordPosition(" the dog is in the garden", 2)); assertEquals(13, esvXmlEnhancer.findWordPosition(" the dog is in the garden", 2)); assertEquals(13, esvXmlEnhancer.findWordPosition("-_ the dog is in the garden", 2)); assertEquals(13, esvXmlEnhancer.findWordPosition("-_ the dog-is in the garden", 2)); assertEquals(14, esvXmlEnhancer.findWordPosition("-_ the dog-,is in the garden", 2)); assertEquals(6, esvXmlEnhancer.findWordPosition(" them, saying, ", 0)); }