MCPcopy Create free account
hub / github.com/SquirrelJME/SquirrelJME / main

Method main

utils-dev/GitHubWikiReformat.java:33–117  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 14

getMethod · 0.95
getParentMethod · 0.95
appendMethod · 0.95
toStringMethod · 0.95
substringMethod · 0.95
toStringMethod · 0.95
findMethod · 0.80
endMethod · 0.80
replaceAllMethod · 0.80
readMethod · 0.65
startMethod · 0.65
printfMethod · 0.45

Tested by

no test coverage detected