All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nocrala.tools.utils.TextEncoder Maven / Gradle / Ivy

Go to download

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();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy