Example usage for java.lang Character isLowSurrogate

List of usage examples for java.lang Character isLowSurrogate

Introduction

In this page you can find the example usage for java.lang Character isLowSurrogate.

Prototype

public static boolean isLowSurrogate(char ch) 

Source Link

Document

Determines if the given char value is a <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit"> Unicode low-surrogate code unit</a> (also known as <i>trailing-surrogate code unit</i>).

Usage

From source file:it.geosdi.era.server.servlet.HTTPProxy.java

public static int escapeHtmlFull(int ch) {
    if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9') {
        // safe//from  ww w .j  a v a 2s .c o m
        return ch;
    } else if (Character.isWhitespace(ch)) {
        if (ch != '\n' && ch != '\r' && ch != '\t')
            // safe
            return ch;
    } else if (Character.isDefined(ch)) {
        // safe
        return ch;
    } else if (Character.isISOControl(ch)) {
        // paranoid version:isISOControl which are not isWhitespace
        // removed !
        // do nothing do not include in output !
        return -1;
    } else if (Character.isHighSurrogate((char) ch)) {
        // do nothing do not include in output !
        return -1;
    } else if (Character.isLowSurrogate((char) ch)) {
        // wrong char[] sequence, //TODO: LOG !!!
        return -1;
    }

    return -1;
}

From source file:adept.io.Reader.java

/**
 * Removes surrogate pairs//from  w ww .j av a 2 s.c  om
 *
 * @param text
 * @return
 */
public static String checkSurrogates(String text) {
    StringBuffer buffer = new StringBuffer();
    char[] chars = text.toCharArray();
    for (Character c : chars) {
        if (Character.isHighSurrogate(c) || Character.isLowSurrogate(c)) {
            System.out.println("WARNING -- invalid xml character " + c + " removed");
        } else {
            buffer.append(c);
        }
    }

    return buffer.toString();
}