Java String Sanitize sanitizeString(String input)

Here you can find the source of sanitizeString(String input)

Description

sanitize String

License

Apache License

Declaration

public static String sanitizeString(String input) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String sanitizeString(String input) {
        // sanitize the content
        // get document text
        if (input != null) {
            char[] docCharArray = input.toCharArray();
            replaceInvalidXmlChars(docCharArray);
            return String.valueOf(docCharArray);
        }/* w  w w  . j a  va2 s  . co  m*/
        return input;
    }

    private static void replaceInvalidXmlChars(char[] aChars) {
        for (int i = 0; i < aChars.length; i++) {
            if ((aChars[i] < 0x20 && aChars[i] != 0x09 && aChars[i] != 0x0A && aChars[i] != 0x0D)
                    || (aChars[i] > 0xD7FF && aChars[i] < 0xE000) || aChars[i] == 0xFFFE || aChars[i] == 0xFFFF) {
                // System.out.println("Found invalid XML character: " + (int)aChars[i] + " at position " +
                // i); //temp
                aChars[i] = ' ';
            }
        }
    }
}

Related

  1. sanitizeResource(String resource)
  2. sanitizeSAMHeader(String samString)
  3. sanitizeSingleQuotesInAlbumItemValues(String value)
  4. sanitizeString(final String s)
  5. sanitizeString(String dirtyString)
  6. sanitizeString(String s)
  7. sanitizeString(String s)
  8. sanitizeString(String s)
  9. sanitizeString(String str)