@Test public void simplePageRange() { PageRange pr = PageParser.parse("10-20"); assertEquals("10-20", pr.getLiteral()); assertEquals("10", pr.getPageFirst()); assertEquals(Integer.valueOf(11), pr.getNumberOfPages()); assertTrue(pr.isMultiplePages()); pr = PageParser.parse("10 - 20"); assertEquals("10-20", pr.getLiteral()); assertEquals("10", pr.getPageFirst()); assertEquals(Integer.valueOf(11), pr.getNumberOfPages()); assertTrue(pr.isMultiplePages()); pr = PageParser.parse("10--20"); assertEquals("10-20", pr.getLiteral()); assertEquals("10", pr.getPageFirst()); assertEquals(Integer.valueOf(11), pr.getNumberOfPages()); assertTrue(pr.isMultiplePages()); pr = PageParser.parse("10---20"); assertEquals("10-20", pr.getLiteral()); assertEquals("10", pr.getPageFirst()); assertEquals(Integer.valueOf(11), pr.getNumberOfPages()); assertTrue(pr.isMultiplePages()); pr = PageParser.parse("10\u201320"); assertEquals("10-20", pr.getLiteral()); assertEquals("10", pr.getPageFirst()); assertEquals(Integer.valueOf(11), pr.getNumberOfPages()); assertTrue(pr.isMultiplePages()); }
public static PageRange parse(String pages) { CharStream cs = CharStreams.fromString(pages); InternalPageLexer lexer = new InternalPageLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalPageParser parser = new InternalPageParser(tokens); parser.removeErrorListeners(); PagesContext ctx = parser.pages(); if (ctx.literal == null || ctx.literal.isEmpty() || ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0) { return new PageRange(pages, null, null, false); } return new PageRange(ctx.literal, ctx.pageFrom, ctx.numberOfPages, ctx.multiplePages); }
PageParser { public static PageRange parse(String pages) { CharStream cs = CharStreams.fromString(pages); InternalPageLexer lexer = new InternalPageLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalPageParser parser = new InternalPageParser(tokens); parser.removeErrorListeners(); PagesContext ctx = parser.pages(); if (ctx.literal == null || ctx.literal.isEmpty() || ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0) { return new PageRange(pages, null, null, false); } return new PageRange(ctx.literal, ctx.pageFrom, ctx.numberOfPages, ctx.multiplePages); } }
PageParser { public static PageRange parse(String pages) { CharStream cs = CharStreams.fromString(pages); InternalPageLexer lexer = new InternalPageLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalPageParser parser = new InternalPageParser(tokens); parser.removeErrorListeners(); PagesContext ctx = parser.pages(); if (ctx.literal == null || ctx.literal.isEmpty() || ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0) { return new PageRange(pages, null, null, false); } return new PageRange(ctx.literal, ctx.pageFrom, ctx.numberOfPages, ctx.multiplePages); }  }
PageParser { public static PageRange parse(String pages) { CharStream cs = CharStreams.fromString(pages); InternalPageLexer lexer = new InternalPageLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalPageParser parser = new InternalPageParser(tokens); parser.removeErrorListeners(); PagesContext ctx = parser.pages(); if (ctx.literal == null || ctx.literal.isEmpty() || ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0) { return new PageRange(pages, null, null, false); } return new PageRange(ctx.literal, ctx.pageFrom, ctx.numberOfPages, ctx.multiplePages); }  static PageRange parse(String pages); }
PageParser { public static PageRange parse(String pages) { CharStream cs = CharStreams.fromString(pages); InternalPageLexer lexer = new InternalPageLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalPageParser parser = new InternalPageParser(tokens); parser.removeErrorListeners(); PagesContext ctx = parser.pages(); if (ctx.literal == null || ctx.literal.isEmpty() || ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0) { return new PageRange(pages, null, null, false); } return new PageRange(ctx.literal, ctx.pageFrom, ctx.numberOfPages, ctx.multiplePages); }  static PageRange parse(String pages);  }