Changeset 1241 for trunk/java-utils/src/main/java/de/ugoe
- Timestamp:
- 06/28/13 13:26:30 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-utils/src/main/java/de/ugoe/cs/util/StringTools.java
r927 r1241 25 25 final public class StringTools { 26 26 27 28 29 30 31 32 27 /** 28 * <p> 29 * Private constructor to prevent initializing of the class. 30 * </p> 31 */ 32 private StringTools() { 33 33 34 34 } 35 35 36 37 38 39 40 41 36 /** 37 * <p> 38 * Simplifies use of operation system specific line separators. 39 * </p> 40 */ 41 public final static String ENDLINE = System.getProperty("line.separator"); 42 42 43 /** 44 * <p> 45 * Replaces all occurrences of {@literal &, <, >, ', and "} with their 46 * respective XML entities {@literal &, <, >, ', and "} 47 * without destroying already existing entities. 48 * </p> 49 * 50 * @param str 51 * String where the XML entities are to be replaced 52 * @return new String, where the XML entities are used instead of the 53 * literals 54 */ 55 public static String xmlEntityReplacement(String str) { 56 String result = str; 57 if (result != null && !"".equals(result)) { 58 result = result 59 .replaceAll("&(?!(?:lt|gt|apos|quot|amp);)", "&"); 60 result = result.replaceAll("<", "<"); 61 result = result.replaceAll(">", ">"); 62 result = result.replaceAll("'", "'"); 63 result = result.replaceAll("\"", """); 64 } 65 return result; 66 } 43 /** 44 * <p> 45 * Replaces all occurrences of {@literal &, <, >, ', and "} with their respective XML entities 46 * {@literal &, <, >, ', and "} without destroying already existing 47 * entities. 48 * </p> 49 * 50 * @param str 51 * String where the XML entities are to be replaced 52 * @return new String, where the XML entities are used instead of the literals 53 */ 54 public static String xmlEntityReplacement(String str) { 55 String result = str; 56 if (result != null && !"".equals(result)) { 57 result = result.replaceAll("&(?!(?:lt|gt|apos|quot|amp);)", "&"); 58 result = result.replaceAll("<", "<"); 59 result = result.replaceAll(">", ">"); 60 result = result.replaceAll("'", "'"); 61 result = result.replaceAll("\"", """); 62 } 63 return result; 64 } 67 65 }
Note: See TracChangeset
for help on using the changeset viewer.