Here you can find the source of sanitize(CharSequence string)
Parameter | Description |
---|---|
string | string to clean |
public static String sanitize(CharSequence string)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w .j a va 2 s . co m*/ * Clean strings from illegal XML 1.0 characters. * See <a href="http://www.w3.org/TR/2006/REC-xml-20060816/#charsets">XML charset</a> * * @param string string to clean * @return the cleaned string */ public static String sanitize(CharSequence string) { StringBuilder sb = new StringBuilder(); for (int i = 0, len = string.length(); i < len; i++) { char c = string.charAt(i); boolean legal = c == '\u0009' || c == '\n' || c == '\r' || (c >= '\u0020' && c <= '\uD7FF') || (c >= '\uE000' && c <= '\uFFFD'); if (legal) { sb.append(c); } } return sb.toString(); } }