org.nocrala.tools.utils.TextEncoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of text-table-formatter Show documentation
Show all versions of text-table-formatter Show documentation
Java Text Table Formatter is a Java library that renders tables made of characters.
The user add cells and can add format characteristics like predefined/custom table styles, text alignment, abbreviation, column width, border types, colspan, etc.
The newest version!
package org.nocrala.tools.utils;
public class TextEncoder {
public static String escapeXml(final String txt) {
if (txt == null) {
return null;
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < txt.length(); i++) {
char c = txt.charAt(i);
if (c < 32 || c > 127 || c == '<' || c == '>' || c == '&' || c == '\''
|| c == '\"') {
sb.append("" + (int) c + ";");
} else {
sb.append(c);
}
}
return sb.toString();
}
}