package de.ugoe.cs.util; /** *

* Helper class that provides methods to simplify working with {@link String}s. *

* * @author Steffen Herbold * @version 1.0 */ final public class StringTools { /** *

* Simplifies use of operation system specific line separators. *

*/ public final static String ENDLINE = System.getProperty("line.separator"); /** *

* Replaces all occurrences of {@literal &, <, >, ', and "} with their * respective XML entities {@literal &, <, >, ', and "} * without destroying already existing entities. *

* * @param str * String where the XML entities are to be replaced * @return new String, where the XML entities are used instead of the * literals */ public static String xmlEntityReplacement(String str) { String result = str; result = result.replaceAll("&(?!(?:lt|gt|apos|quot|amp);)", "&"); result = result.replaceAll("<", "<"); result = result.replaceAll(">", ">"); result = result.replaceAll("'", "'"); result = result.replaceAll("\"", """); return result; } }