Last change
on this file since 331 was
330,
checked in by sherbold, 13 years ago
|
- added private constructors to helper classes de.ugoe.cs.util.ArrayTools?, de.ugoe.cs.util.FileTools?, and de.ugoe.cs.util.StringTools? to prevent initialization of the classes (they only provide static methods)
|
File size:
1.3 KB
|
Rev | Line | |
---|
[1] | 1 | package de.ugoe.cs.util;
|
---|
| 2 |
|
---|
[175] | 3 | /**
|
---|
| 4 | * <p>
|
---|
| 5 | * Helper class that provides methods to simplify working with {@link String}s.
|
---|
| 6 | * </p>
|
---|
| 7 | *
|
---|
| 8 | * @author Steffen Herbold
|
---|
| 9 | * @version 1.0
|
---|
| 10 | */
|
---|
[1] | 11 | final public class StringTools {
|
---|
| 12 |
|
---|
[175] | 13 | /**
|
---|
| 14 | * <p>
|
---|
[330] | 15 | * Private constructor to prevent initializing of the class.
|
---|
| 16 | * </p>
|
---|
| 17 | */
|
---|
| 18 | private StringTools() {
|
---|
| 19 |
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | /**
|
---|
| 23 | * <p>
|
---|
[175] | 24 | * Simplifies use of operation system specific line separators.
|
---|
| 25 | * </p>
|
---|
| 26 | */
|
---|
[1] | 27 | public final static String ENDLINE = System.getProperty("line.separator");
|
---|
[175] | 28 |
|
---|
[1] | 29 | /**
|
---|
| 30 | * <p>
|
---|
[175] | 31 | * Replaces all occurrences of {@literal &, <, >, ', and "} with their
|
---|
| 32 | * respective XML entities {@literal &, <, >, ', and "}
|
---|
[1] | 33 | * without destroying already existing entities.
|
---|
| 34 | * </p>
|
---|
| 35 | *
|
---|
| 36 | * @param str
|
---|
[175] | 37 | * String where the XML entities are to be replaced
|
---|
| 38 | * @return new String, where the XML entities are used instead of the
|
---|
[1] | 39 | * literals
|
---|
| 40 | */
|
---|
| 41 | public static String xmlEntityReplacement(String str) {
|
---|
| 42 | String result = str;
|
---|
| 43 | result = result.replaceAll("&(?!(?:lt|gt|apos|quot|amp);)", "&");
|
---|
| 44 | result = result.replaceAll("<", "<");
|
---|
| 45 | result = result.replaceAll(">", ">");
|
---|
| 46 | result = result.replaceAll("'", "'");
|
---|
| 47 | result = result.replaceAll("\"", """);
|
---|
| 48 | return result;
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.