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
|
Line | |
---|
1 | package de.ugoe.cs.util;
|
---|
2 |
|
---|
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 | */
|
---|
11 | final public class StringTools {
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * <p>
|
---|
15 | * Private constructor to prevent initializing of the class.
|
---|
16 | * </p>
|
---|
17 | */
|
---|
18 | private StringTools() {
|
---|
19 |
|
---|
20 | }
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * <p>
|
---|
24 | * Simplifies use of operation system specific line separators.
|
---|
25 | * </p>
|
---|
26 | */
|
---|
27 | public final static String ENDLINE = System.getProperty("line.separator");
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * <p>
|
---|
31 | * Replaces all occurrences of {@literal &, <, >, ', and "} with their
|
---|
32 | * respective XML entities {@literal &, <, >, ', and "}
|
---|
33 | * without destroying already existing entities.
|
---|
34 | * </p>
|
---|
35 | *
|
---|
36 | * @param str
|
---|
37 | * String where the XML entities are to be replaced
|
---|
38 | * @return new String, where the XML entities are used instead of the
|
---|
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.