use of org.opensolaris.opengrok.analysis.StreamSource in project OpenGrok by OpenGrok.
the class SourceSplitterTest method shouldHandleStreamedDocsOfLongerLength.
@Test
public void shouldHandleStreamedDocsOfLongerLength() throws IOException {
// 0 0
// 0-- - 5-- - -1--- - 5--- - 2-
final String INPUT = "ab\r\ncde\r\nefgh\r\nijk\r\nlm";
StreamSource src = StreamSource.fromString(INPUT);
SourceSplitter splitter = new SourceSplitter();
splitter.reset(src);
assertEquals("split count", 5, splitter.count());
assertEquals("split position", 0, splitter.getPosition(0));
assertEquals("split position", 4, splitter.getPosition(1));
assertEquals("split position", 9, splitter.getPosition(2));
assertEquals("split position", 15, splitter.getPosition(3));
assertEquals("split position", 20, splitter.getPosition(4));
assertEquals("split position", 22, splitter.getPosition(5));
/*
* Test findLineOffset() for every character with an alternate
* computation that counts every LFs.
*/
for (int i = 0; i < splitter.originalLength(); ++i) {
char c = INPUT.charAt(i);
int off = splitter.findLineOffset(i);
long numLF = INPUT.substring(0, i + 1).chars().filter(ch -> ch == '\n').count();
long exp = numLF - (c == '\n' ? 1 : 0);
assertEquals("split find-offset of " + i, exp, off);
}
}
use of org.opensolaris.opengrok.analysis.StreamSource in project OpenGrok by OpenGrok.
the class StreamUtils method readTagsFromResource.
public static Definitions readTagsFromResource(String tagsResourceName, String rawResourceName, int tabSize) throws IOException {
InputStream res = StreamUtils.class.getClassLoader().getResourceAsStream(tagsResourceName);
assertNotNull(tagsResourceName + " as resource", res);
BufferedReader in = new BufferedReader(new InputStreamReader(res, "UTF-8"));
CtagsReader rdr = new CtagsReader();
rdr.setTabSize(tabSize);
if (rawResourceName != null) {
rdr.setSplitterSupplier(() -> {
/**
* This should return truly raw content, as the CtagsReader will
* expand tabs according to its setting.
*/
SourceSplitter splitter = new SourceSplitter();
StreamSource src = sourceFromEmbedded(rawResourceName);
try {
splitter.reset(src);
} catch (IOException ex) {
System.err.println(ex.toString());
return null;
}
return splitter;
});
}
String line;
while ((line = in.readLine()) != null) {
rdr.readLine(line);
}
return rdr.getDefinitions();
}
Aggregations