MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / countLines

Method countLines

ij/src/main/java/ij/plugin/TextReader.java:105–142  ·  view source on GitHub ↗
(Reader r)

Source from the content-addressed store, hash-verified

103 }
104
105 void countLines(Reader r) throws IOException {
106 StreamTokenizer tok = new StreamTokenizer(r);
107 int wordsPerLine=0, wordsInPreviousLine=0;
108 tok.resetSyntax();
109 tok.wordChars(43, 43);
110 tok.wordChars(45, 127);
111 tok.whitespaceChars(0, 42);
112 tok.whitespaceChars(44, 44);
113 //tok.wordChars(33, 127);
114 //tok.whitespaceChars(0, ' ');
115 tok.whitespaceChars(128, 255);
116 tok.eolIsSignificant(true);
117
118 while (tok.nextToken() != StreamTokenizer.TT_EOF) {
119 switch (tok.ttype) {
120 case StreamTokenizer.TT_EOL:
121 lines++;
122 if (wordsPerLine==0)
123 lines--; // ignore empty lines
124 if (lines==1 && wordsPerLine>0)
125 width = wordsPerLine;
126 if (lines>1 && wordsPerLine!=0 && wordsPerLine!=wordsInPreviousLine)
127 throw new IOException("Line "+lines+ " is not the same length as the first line.");
128 if (wordsPerLine!=0)
129 wordsInPreviousLine = wordsPerLine;
130 wordsPerLine = 0;
131 if (lines%20==0 && width>1 && lines<=width)
132 IJ.showProgress(((double)lines/width)/2.0);
133 break;
134 case StreamTokenizer.TT_WORD:
135 words++;
136 wordsPerLine++;
137 break;
138 }
139 }
140 if (wordsPerLine==width)
141 lines++; // last line does not end with EOL
142 }
143
144 void read(Reader r, int size, float[] pixels) throws IOException {
145 StreamTokenizer tok = new StreamTokenizer(r);

Callers 1

openMethod · 0.95

Calls 2

showProgressMethod · 0.95
nextTokenMethod · 0.45

Tested by

no test coverage detected