MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / replace

Method replace

src/main/java/wycc/util/TextFile.java:63–78  ·  view source on GitHub ↗

Replace a number of lines in this text file with some other number of lines. The number being replaced could be smaller, equal or greater than those being replaced with giving different effects. @param start First line to replace (starting from one) @param end Last line to replace (exclusive). @par

(int start, int end, String... newLines)

Source from the content-addressed store, hash-verified

61 * @return
62 */
63 public TextFile replace(int start, int end, String... newLines) {
64 start = start - 1;
65 end = end - 1;
66 int delta = (end - start) - newLines.length;
67 String[] nlines = Arrays.copyOf(lines, lines.length - delta);
68 // Copy over new lines
69 for (int i = 0; i < newLines.length; ++i) {
70 nlines[i + start] = newLines[i];
71 }
72 // Copy over what comes after
73 for(int i = end;i < lines.length; ++i) {
74 nlines[i - delta] = lines[i];
75 }
76 // Done
77 return new TextFile(nlines);
78 }
79
80 public String getLine(int line) {
81 return lines[line-1];

Callers 1

applyMethod · 0.95

Calls

no outgoing calls

Tested by 1

applyMethod · 0.76