Switched to using codePoints in toHtmlEntities
This commit is contained in:
parent
772ffd55f4
commit
b3930804c6
3 changed files with 13 additions and 8 deletions
|
@ -44,14 +44,19 @@ public class EncodeHtmlEntities implements ValueRenderer {
|
|||
* @param text the String to convert.
|
||||
* @return the converted string.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidReassigningLoopVariables")
|
||||
public static String toHtmlEntities(String text) {
|
||||
var buff = new StringBuilder(text.length() * 6);
|
||||
|
||||
// https://stackoverflow.com/a/6766497/8356718
|
||||
var sb = new StringBuilder(text.length() * 6);
|
||||
for (var i = 0; i < text.length(); i++) {
|
||||
buff.append("&#").append((int) text.charAt(i)).append(';');
|
||||
var codePoint = text.codePointAt(i);
|
||||
// Skip over the second char in a surrogate pair
|
||||
if (codePoint > 0xffff) {
|
||||
i++;
|
||||
}
|
||||
sb.append(String.format("&#%s;", codePoint));
|
||||
}
|
||||
|
||||
return buff.toString();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,7 +33,7 @@ public final class RenderUtils {
|
|||
*
|
||||
* @param template the template
|
||||
* @param valueId the ID of the value to fetch
|
||||
* @return The fetched value.
|
||||
* @return the fetched value.
|
||||
*/
|
||||
public static String fetchValue(Template template, String valueId) {
|
||||
Object value = null;
|
||||
|
|
|
@ -37,8 +37,8 @@ public class Rot13 implements ValueRenderer {
|
|||
/**
|
||||
* Translates a String to/from ROT13.
|
||||
*
|
||||
* @param src The source String.
|
||||
* @return The translated String.
|
||||
* @param src the source String.
|
||||
* @return the translated String.
|
||||
*/
|
||||
public static String rot13(String src) {
|
||||
if (src == null || src.isEmpty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue