This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/client/src/main/java/envoy/client/util/IssueUtil.java

41 lines
1.3 KiB
Java

package envoy.client.util;
/**
* Provides methods to handle outgoing issues.
* <p>
* Project: <strong>client</strong><br>
* File: <strong>IssueUtil.java</strong><br>
* Created: <strong>20.08.2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public final class IssueUtil {
/**
*
* @since Envoy Client v0.2-beta
*/
private IssueUtil() {}
/**
* Performs actions to ensure the description of an issue will be displayed as
* intended by the user.
*
* @param rawDescription the description to sanitize
* @param username the user who submitted the issue. Should be
* {@code null} if he does not want to be named.
* @return the sanitized description
* @since Envoy Client v0.2-beta
*/
public static String sanitizeIssueDescription(String rawDescription, String username) {
// Appending the submitter name, if this option was enabled
rawDescription += username != null
? (rawDescription.endsWith("\n") || rawDescription.endsWith("<br>") ? "" : "<br>") + String.format("Submitted by user %s.", username)
: "";
// Markdown does not support "normal" line breaks. It uses "<br>"
rawDescription = rawDescription.replaceAll(System.getProperty("line.separator", "\r?\n"), "<br>");
return rawDescription;
}
}