Search in sources :

Example 1 with LineBreaker

use of org.opengrok.indexer.util.LineBreaker in project OpenGrok by OpenGrok.

the class DefinitionsTokenStream method initialize.

/**
 * Initializes the stream by merging {@code defs} with cross-referenced
 * line offsets read from {@code src}.
 * @param defs a defined instance
 * @param src a defined instance
 * @param wrapper an optional instance
 * @throws IOException if I/O error occurs
 */
public void initialize(Definitions defs, StreamSource src, ReaderWrapper wrapper) throws IOException {
    if (defs == null) {
        throw new IllegalArgumentException("`defs' is null");
    }
    if (src == null) {
        throw new IllegalArgumentException("`src' is null");
    }
    events.clear();
    offset = 0;
    LineBreaker brk = new LineBreaker();
    brk.reset(src, wrapper);
    createTokens(defs, brk);
}
Also used : LineBreaker(org.opengrok.indexer.util.LineBreaker)

Example 2 with LineBreaker

use of org.opengrok.indexer.util.LineBreaker in project OpenGrok by OpenGrok.

the class PageConfig method evaluateMatchOffset.

/**
 * Determines whether a match offset from a search result has been
 * indicated, and if so tries to calculate a translated xref fragment
 * identifier.
 * @return {@code true} if a xref fragment identifier was calculated by the call to this method
 */
public boolean evaluateMatchOffset() {
    if (fragmentIdentifier == null) {
        int matchOffset = getIntParam(QueryParameters.MATCH_OFFSET_PARAM, -1);
        if (matchOffset >= 0) {
            File resourceFile = getResourceFile();
            if (resourceFile.isFile()) {
                LineBreaker breaker = new LineBreaker();
                StreamSource streamSource = StreamSource.fromFile(resourceFile);
                try {
                    breaker.reset(streamSource, in -> ExpandTabsReader.wrap(in, getProject()));
                    int matchLine = breaker.findLineIndex(matchOffset);
                    if (matchLine >= 0) {
                        // Convert to 1-based offset to accord with OpenGrok line number.
                        fragmentIdentifier = String.valueOf(matchLine + 1);
                        return true;
                    }
                } catch (IOException e) {
                    LOGGER.log(Level.WARNING, String.format("Failed to evaluate match offset for %s", resourceFile), e);
                }
            }
        }
    }
    return false;
}
Also used : StreamSource(org.opengrok.indexer.analysis.StreamSource) LineBreaker(org.opengrok.indexer.util.LineBreaker) IOException(java.io.IOException) File(java.io.File)

Aggregations

LineBreaker (org.opengrok.indexer.util.LineBreaker)2 File (java.io.File)1 IOException (java.io.IOException)1 StreamSource (org.opengrok.indexer.analysis.StreamSource)1