Main entry point. @param __args The first argument is the file being looked at, a relative path from the root. @throws Throwable On any exception. @since 2018/09/02
(String... __args)
| 31 | * @since 2018/09/02 |
| 32 | */ |
| 33 | public static void main(String... __args) |
| 34 | throws Throwable |
| 35 | { |
| 36 | if (__args == null || __args.length != 1 || __args[0] == null) |
| 37 | throw new IllegalArgumentException("Expected path specifying " + |
| 38 | "the file being modified."); |
| 39 | |
| 40 | // Turn it into a path, make root to simplify it |
| 41 | Path file = Paths.get("/", __args[0]), |
| 42 | parent = file.getParent(); |
| 43 | System.err.printf("Reformatting %s (in %s)...%n", file, parent); |
| 44 | |
| 45 | // Read original file into string |
| 46 | String original; |
| 47 | try (Reader r = new InputStreamReader(System.in, "utf-8")) |
| 48 | { |
| 49 | StringBuilder sb = new StringBuilder(); |
| 50 | |
| 51 | for (;;) |
| 52 | { |
| 53 | int c = r.read(); |
| 54 | |
| 55 | if (c < 0) |
| 56 | break; |
| 57 | |
| 58 | sb.append((char)c); |
| 59 | } |
| 60 | |
| 61 | original = sb.toString(); |
| 62 | } |
| 63 | |
| 64 | // Pattern used to search for file sequences |
| 65 | Pattern want = Pattern.compile("\\([^)]*\\.mkd\\)"); |
| 66 | |
| 67 | // Output result |
| 68 | StringBuilder out = new StringBuilder(); |
| 69 | |
| 70 | // Replace patterns |
| 71 | Matcher match = want.matcher(original); |
| 72 | for (int lastdx = 0;;) |
| 73 | { |
| 74 | // Try to find it |
| 75 | if (!match.find()) |
| 76 | { |
| 77 | // Add everything from the last match to the end |
| 78 | out.append(original.substring(lastdx)); |
| 79 | |
| 80 | // Stop |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | // Starting and end points, used to sub-sequence |
| 85 | int start = match.start(), |
| 86 | end = match.end(); |
| 87 | |
| 88 | // Add everything from the last index to this match |
| 89 | out.append(original.substring(lastdx, start)); |
| 90 |
nothing calls this directly
no test coverage detected