From b2524e39ce848415c02f80030283d94741ca6960 Mon Sep 17 00:00:00 2001 From: Altai-man Date: Thu, 17 May 2018 17:56:24 +0300 Subject: [PATCH] Simplify regexes more --- .../main/java/org/tap4j/model/Patterns.java | 12 +++++------ .../org/tap4j/model/TapElementFactory.java | 20 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tap4j/src/main/java/org/tap4j/model/Patterns.java b/tap4j/src/main/java/org/tap4j/model/Patterns.java index 118231e2..0da783cb 100644 --- a/tap4j/src/main/java/org/tap4j/model/Patterns.java +++ b/tap4j/src/main/java/org/tap4j/model/Patterns.java @@ -42,17 +42,17 @@ private Patterns() { // hidden as this is a final utility class /** * TAP Text Regex. */ - static final String REGEX_TEXT = "((\\s|\\t)*)(.*)"; + static final String REGEX_TEXT = "(\\s*)(.*)"; /** * TAP Header Regex. */ - static final String REGEX_HEADER = "((\\s|\\t)*)?TAP\\s*version\\s*(\\d+)\\s*(#\\s*(.*))?"; + static final String REGEX_HEADER = "(\\s*)TAP\\s*version\\s*(\\d+)\\s*(#\\s*(.*))?"; /** * TAP Plan Regex. */ - static final String REGEX_PLAN = "((\\s|\\t)*)?(\\d+)(\\.{2})(\\d+)" + static final String REGEX_PLAN = "(\\s*)(\\d+)(\\.{2})(\\d+)" + "\\s*(#\\s*(SKIP|skip)\\s*([^#]+))?\\s*(#\\s*(.*))?"; /** @@ -64,17 +64,17 @@ private Patterns() { // hidden as this is a final utility class /** * TAP Bail Out! Regex. */ - static final String REGEX_BAIL_OUT = "((\\s|\\t)*)?Bail out!\\s*([^#]+)?\\s*(#\\s*(.*))?"; + static final String REGEX_BAIL_OUT = "(\\s*)Bail out!\\s*([^#]+)?\\s*(#\\s*(.*))?"; /** * TAP Comment Regex. */ - static final String REGEX_COMMENT = "((\\s|\\t)*)?#\\s*(.*)"; + static final String REGEX_COMMENT = "(\\s*)#\\s*(.*)"; /** * TAP Footer Regex. */ - static final String REGEX_FOOTER = "((\\s|\\t)*)?TAP\\s*([^#]*)?\\s*(#\\s*(.*))?"; + static final String REGEX_FOOTER = "(\\s*)TAP\\s*([^#]*)?\\s*(#\\s*(.*))?"; /* -- Patterns -- */ diff --git a/tap4j/src/main/java/org/tap4j/model/TapElementFactory.java b/tap4j/src/main/java/org/tap4j/model/TapElementFactory.java index f40dac6a..bb4a92b4 100644 --- a/tap4j/src/main/java/org/tap4j/model/TapElementFactory.java +++ b/tap4j/src/main/java/org/tap4j/model/TapElementFactory.java @@ -71,33 +71,33 @@ public static TapElement createTapElement(String tapLine) { m = Patterns.COMMENT_PATTERN.matcher(tapLine); if (m.matches()) { - Comment comment = new Comment(m.group(3), false); + Comment comment = new Comment(m.group(2), false); comment.indentation = m.group(1).length(); return comment; } m = Patterns.HEADER_PATTERN.matcher(tapLine); if (m.matches()) { - Header header = new Header(Integer.parseInt(m.group(3))); + Header header = new Header(Integer.parseInt(m.group(2))); header.indentation = m.group(1).length(); - addComment(header, m.group(5)); + addComment(header, m.group(4)); return header; } m = Patterns.FOOTER_PATTERN.matcher(tapLine); if (m.matches()) { - Footer footer = new Footer(m.group(3)); - addComment(footer, m.group(5)); + Footer footer = new Footer(m.group(2)); + addComment(footer, m.group(4)); footer.indentation = m.group(1).length(); return footer; } m = Patterns.PLAN_PATTERN.matcher(tapLine); if (m.matches()) { - String skip = m.group(8); - String comment = m.group(10); + String skip = m.group(7); + String comment = m.group(9); SkipPlan skipPlan = skip != null && skip.trim().length() > 0 ? new SkipPlan(skip) : null; - Plan plan = new Plan(Integer.parseInt(m.group(3)), Integer.parseInt(m.group(5)), skipPlan); + Plan plan = new Plan(Integer.parseInt(m.group(2)), Integer.parseInt(m.group(4)), skipPlan); addComment(plan, comment); plan.indentation = m.group(1).length(); return plan; @@ -105,8 +105,8 @@ public static TapElement createTapElement(String tapLine) { m = Patterns.BAIL_OUT_PATTERN.matcher(tapLine); if (m.matches()) { - String reason = m.group(3); - String comment = m.group(5); + String reason = m.group(2); + String comment = m.group(4); BailOut bailOut = new BailOut(reason); addComment(bailOut, comment); bailOut.indentation = m.group(1).length();