/** * Automatically finds and sets an appropriate implicit title for the * document. Will include the first line token as part of the covered range, * so it's easy to detect if a line is part of a title, by checking for the * annotation. * * If the title has been explicitly set, does nothing. * * @param doc */ public static <N, E extends N, T extends N> void maybeFindAndSetImplicitTitle( final MutableDocument<N, E, T> doc) { if (hasExplicitTitle(doc)) { // Explicit title is set - do not touch return; } Range range = findImplicitTitle(doc); if (range != null) { setImplicitTitle(doc, range.getStart(), range.getEnd()); } }
public void testFindImplicitTitle() { getDoc("<body><line/>Some text.<line/>Some more text</body>"); Range range = TitleHelper.findImplicitTitle(doc); assertTrue(range.getEnd() > range.getStart()); getDoc("<body></body>"); range = TitleHelper.findImplicitTitle(doc); assertNull(range); getDoc(""); range = TitleHelper.findImplicitTitle(doc); assertNull(range); }
public void testFindImplicitTitle() { getDoc("<body><line/>Some text.<line/>Some more text</body>"); Range range = TitleHelper.findImplicitTitle(doc); assertTrue(range.getEnd() > range.getStart()); getDoc("<body></body>"); range = TitleHelper.findImplicitTitle(doc); assertNull(range); getDoc(""); range = TitleHelper.findImplicitTitle(doc); assertNull(range); }
/** Tests that the complexity is not, say, exponential */ public void testFindImplicitTitleComplexity() { getDoc("<body><line/>a!xa!!!!!!!!!!!!!!!!!!!!!!!!!!!!xxxxxxxxxxxxxxxxxxxxxxx<line/>foo</body>"); // Should not time out: Range r = TitleHelper.findImplicitTitle(doc); // Just a sanity check. assertTrue(r.getEnd() > r.getStart()); }
/** Tests that the complexity is not, say, exponential */ public void testFindImplicitTitleComplexity() { getDoc("<body><line/>a!xa!!!!!!!!!!!!!!!!!!!!!!!!!!!!xxxxxxxxxxxxxxxxxxxxxxx<line/>foo</body>"); // Should not time out: Range r = TitleHelper.findImplicitTitle(doc); // Just a sanity check. assertTrue(r.getEnd() > r.getStart()); }