Moved renderer methods to RenderUtils
This commit is contained in:
parent
54f40eb41e
commit
b7c9695395
7 changed files with 178 additions and 175 deletions
|
@ -38,32 +38,11 @@ import rife.template.ValueRenderer;
|
|||
* @since 1.0
|
||||
*/
|
||||
public class EncodeHtmlEntities implements ValueRenderer {
|
||||
/**
|
||||
* Converts a text string to HTML decimal entities.
|
||||
*
|
||||
* @param text the String to convert.
|
||||
* @return the converted string.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidReassigningLoopVariables")
|
||||
public static String toHtmlEntities(String text) {
|
||||
// https://stackoverflow.com/a/6766497/8356718
|
||||
var sb = new StringBuilder(text.length() * 6);
|
||||
for (var i = 0; i < text.length(); i++) {
|
||||
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 sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
return toHtmlEntities(RenderUtils.fetchValue(template, differentiator));
|
||||
return RenderUtils.toHtmlEntities(RenderUtils.fetchValue(template, differentiator));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue