diff options
| author | campbeb <bpcampbell@gmail.com> | 2013-01-19 10:34:39 -1000 |
|---|---|---|
| committer | campbeb <bpcampbell@gmail.com> | 2013-01-19 10:34:39 -1000 |
| commit | ea13018cc48c97125e25668f5bea67135f5df9ee (patch) | |
| tree | 318a84b94b33c2c9774bcc8a64a660ff248b6203 /main/src/cgeo/geocaching/utils | |
| parent | 9073a540aa3e76f77777c991464f2811dbe780b6 (diff) | |
| download | cgeo-ea13018cc48c97125e25668f5bea67135f5df9ee.zip cgeo-ea13018cc48c97125e25668f5bea67135f5df9ee.tar.gz cgeo-ea13018cc48c97125e25668f5bea67135f5df9ee.tar.bz2 | |
Convert non-Latin characters in uploaded text to HTML equivalents
Add new HtmlUtil function for this as it needs to occur in multiple places
Diffstat (limited to 'main/src/cgeo/geocaching/utils')
| -rw-r--r-- | main/src/cgeo/geocaching/utils/HtmlUtils.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/HtmlUtils.java b/main/src/cgeo/geocaching/utils/HtmlUtils.java index a54ba57..9b627ac 100644 --- a/main/src/cgeo/geocaching/utils/HtmlUtils.java +++ b/main/src/cgeo/geocaching/utils/HtmlUtils.java @@ -53,4 +53,29 @@ public class HtmlUtils { return StringUtils.replace(result, "<br />", "\n").trim(); } + /** + * Convert any non-Latin characters into their HTML escaped equivalents + * + * @param input + * String + * @return output String + */ + public static String convertNonLatinCharactersToHTML(final String input) { + final int inputLen = input.length(); + final StringBuilder output = new StringBuilder(); + + for (int i = 0; i < inputLen; i++) { + char c = input.charAt(i); + + if (c > 300) { + output.append("&#"); + output.append(Integer.toString(c)); + output.append(';'); + } else { + output.append(c); + } + } + + return output.toString(); + } } |
