Last change
on this file since 250 was
175,
checked in by sherbold, 13 years ago
|
- code documentation and formatting
|
File size:
1.1 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>
|
---|
| 15 | * Simplifies use of operation system specific line separators.
|
---|
| 16 | * </p>
|
---|
| 17 | */
|
---|
[1] | 18 | public final static String ENDLINE = System.getProperty("line.separator");
|
---|
[175] | 19 |
|
---|
[1] | 20 | /**
|
---|
| 21 | * <p>
|
---|
[175] | 22 | * Replaces all occurrences of {@literal &, <, >, ', and "} with their
|
---|
| 23 | * respective XML entities {@literal &, <, >, ', and "}
|
---|
[1] | 24 | * without destroying already existing entities.
|
---|
| 25 | * </p>
|
---|
| 26 | *
|
---|
| 27 | * @param str
|
---|
[175] | 28 | * String where the XML entities are to be replaced
|
---|
| 29 | * @return new String, where the XML entities are used instead of the
|
---|
[1] | 30 | * literals
|
---|
| 31 | */
|
---|
| 32 | public static String xmlEntityReplacement(String str) {
|
---|
| 33 | String result = str;
|
---|
| 34 | result = result.replaceAll("&(?!(?:lt|gt|apos|quot|amp);)", "&");
|
---|
| 35 | result = result.replaceAll("<", "<");
|
---|
| 36 | result = result.replaceAll(">", ">");
|
---|
| 37 | result = result.replaceAll("'", "'");
|
---|
| 38 | result = result.replaceAll("\"", """);
|
---|
| 39 | return result;
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.