XviImporter extends Importer { public static String getBlockContents(String text, String command) throws Exception { outer: for (int i = 0; i < text.length(); i++) { for (int j = 0; j < command.length(); j++) { char text_current = text.charAt(i + j); char command_current = command.charAt(j); if (text_current != command_current) { continue outer; } } i += command.length(); while (Character.isWhitespace(text.charAt(i))) { i++; } if (text.charAt(i) == '{') { i++; } else { continue outer; } int openBraces = 1; int startOfContent = i; for(; i < text.length(); i++) { if (text.charAt(i) == '{') { openBraces++; } else if (text.charAt(i) == '}') { openBraces--; } if (openBraces == 0) { int endOfContent = i; String content = text.substring(startOfContent, endOfContent); return content; } } throw new Exception("Malformed text: could not match braces"); } throw new Exception("Could not match command in text"); }  Survey toSurvey(File file); static Sketch getSketch(File file); boolean canHandleFile(File file); Grid parseGrid(String contents); static Set<PathDetail> parseSketchlineBlock(double scale, String contents); static List<String> parseBlockEntries(String content); static PathDetail parseSketchEntry(double scale, String entry); static String getBlockContents(String text, String command);  }
@Test public void testGetEmptyBlockContents() throws Exception { String simpleText = "set Command{}"; String contents = XviImporter.getBlockContents(simpleText, "set Command"); Assert.assertEquals("", contents); }
@Test public void testGetEmptyBlockContentsWithWhitespace() throws Exception { String simpleText = "set Command {}"; String contents = XviImporter.getBlockContents(simpleText, "set Command"); Assert.assertEquals("", contents); }
@Test public void testGetSimpleBlockContents() throws Exception { String simpleText = "set Command {foo}"; String contents = XviImporter.getBlockContents(simpleText, "set Command"); Assert.assertEquals("foo", contents); }
@Test public void testGetNestedBlockContents() throws Exception { String simpleText = "set Command {{foo}}"; String contents = XviImporter.getBlockContents(simpleText, "set Command"); Assert.assertEquals("{foo}", contents); }
@Test(expected=Exception.class) public void testBadlyNestedBlockContentsRaiseError() throws Exception { String simpleText = "set Command {{foo}"; String contents = XviImporter.getBlockContents(simpleText, "set Command"); Assert.assertEquals("{foo}", contents); }
@Test(expected=Exception.class) public void testNoCommandMatchRaiseError() throws Exception { String simpleText = "set Commandx {foo}"; String contents = XviImporter.getBlockContents(simpleText, "set Command"); }