Skip to content

Commit 0919b0e

Browse files
bitroncmaglie
authored andcommitted
Moved countLines() and loadFile() from Base to BaseNoGui.
1 parent b0d8a50 commit 0919b0e

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

app/src/processing/app/Base.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,11 +2478,7 @@ static public InputStream getLibStream(String filename) throws IOException {
24782478
* characters inside a String (and adding 1).
24792479
*/
24802480
static public int countLines(String what) {
2481-
int count = 1;
2482-
for (char c : what.toCharArray()) {
2483-
if (c == '\n') count++;
2484-
}
2485-
return count;
2481+
return BaseNoGui.countLines(what);
24862482
}
24872483

24882484

@@ -2560,10 +2556,8 @@ static public void copyFile(File sourceFile,
25602556
* Grab the contents of a file as a string.
25612557
*/
25622558
static public String loadFile(File file) throws IOException {
2563-
String[] contents = PApplet.loadStrings(file);
2564-
if (contents == null) return null;
2565-
return PApplet.join(contents, "\n");
2566-
}
2559+
return BaseNoGui.loadFile(file);
2560+
}
25672561

25682562

25692563
/**

app/src/processing/app/BaseNoGui.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ static public File absoluteFile(String path) {
7575
return file;
7676
}
7777

78+
/**
79+
* Get the number of lines in a file by counting the number of newline
80+
* characters inside a String (and adding 1).
81+
*/
82+
static public int countLines(String what) {
83+
int count = 1;
84+
for (char c : what.toCharArray()) {
85+
if (c == '\n') count++;
86+
}
87+
return count;
88+
}
89+
7890
static public String getAvrBasePath() {
7991
String path = getHardwarePath() + File.separator + "tools" +
8092
File.separator + "avr" + File.separator + "bin" + File.separator;
@@ -349,6 +361,15 @@ static protected void loadHardware(File folder) {
349361
}
350362
}
351363

364+
/**
365+
* Grab the contents of a file as a string.
366+
*/
367+
static public String loadFile(File file) throws IOException {
368+
String[] contents = PApplet.loadStrings(file);
369+
if (contents == null) return null;
370+
return PApplet.join(contents, "\n");
371+
}
372+
352373
static public void populateImportToLibraryTable() {
353374
// Populate importToLibraryTable
354375
importToLibraryTable = new HashMap<String, Library>();

app/src/processing/app/SketchCode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected boolean renameTo(File what) {
114114

115115

116116
protected void copyTo(File dest) throws IOException {
117-
Base.saveFile(program, dest);
117+
BaseNoGui.saveFile(program, dest);
118118
}
119119

120120

@@ -148,7 +148,7 @@ public void setProgram(String replacement) {
148148

149149

150150
public int getLineCount() {
151-
return Base.countLines(program);
151+
return BaseNoGui.countLines(program);
152152
}
153153

154154

@@ -184,7 +184,7 @@ public void addPreprocOffset(int extra) {
184184
* Load this piece of code from a file.
185185
*/
186186
public void load() throws IOException {
187-
program = Base.loadFile(file);
187+
program = BaseNoGui.loadFile(file);
188188

189189
if (program.indexOf('\uFFFD') != -1) {
190190
System.err.println(
@@ -212,7 +212,7 @@ public void save() throws IOException {
212212
// TODO re-enable history
213213
//history.record(s, SketchHistory.SAVE);
214214

215-
Base.saveFile(program, file);
215+
BaseNoGui.saveFile(program, file);
216216
setModified(false);
217217
}
218218

@@ -221,6 +221,6 @@ public void save() throws IOException {
221221
* Save this file to another location, used by Sketch.saveAs()
222222
*/
223223
public void saveAs(File newFile) throws IOException {
224-
Base.saveFile(program, newFile);
224+
BaseNoGui.saveFile(program, newFile);
225225
}
226226
}

0 commit comments

Comments
 (0)