Example usage for org.eclipse.jgit.util StringUtils replaceLineBreaksWithSpace

List of usage examples for org.eclipse.jgit.util StringUtils replaceLineBreaksWithSpace

Introduction

In this page you can find the example usage for org.eclipse.jgit.util StringUtils replaceLineBreaksWithSpace.

Prototype

public static String replaceLineBreaksWithSpace(String in) 

Source Link

Document

Replace CRLF, CR or LF with a single space.

Usage

From source file:playRepository.GitCommit.java

License:Apache License

/**
 * Parse the commit message and return the first "line" of it.
 * <p>//from w w  w . j  a v a2s  .c  om
 * The first line is everything up to the first pair of LFs. This is the
 * "oneline" format, suitable for output in a single line display.
 * <p>
 * This method parses and returns the message portion of the commit buffer,
 * after taking the commit's character set into account and decoding the
 * buffer using that character set. This method is a fairly expensive
 * operation and produces a new string on each invocation.
 *
 * @return decoded commit message as a string. Never null. The returned
 *         string does not contain any LFs, even if the first paragraph
 *         spanned multiple lines. Embedded LFs are converted to spaces.
 */
@Override
public String getShortMessage() {
    if (shortMessage == null) {
        final byte[] raw = revCommit.getRawBuffer();
        final int msgB = RawParseUtils.commitMessage(raw, 0);
        if (msgB < 0)
            return ""; //$NON-NLS-1$

        final Charset enc = parseEncoding(raw, Charset.defaultCharset());
        final int msgE = RawParseUtils.endOfParagraph(raw, msgB);
        String str = RawParseUtils.decode(enc, raw, msgB, msgE);
        if (hasLF(raw, msgB, msgE))
            str = StringUtils.replaceLineBreaksWithSpace(str);
        shortMessage = str;
    }

    return shortMessage;
}