public static int getSingleCodePoint ( CharSequence s ) { if ( s == null || s . length ( ) == 0 ) { return - 1 ; } else if ( s . length ( ) == 1 ) { return s . charAt ( 0 ) ; } else if ( s . length ( ) > 2 ) { return - 1 ; } // at this point, len = 2 int cp = Character . codePointAt ( s , 0 ) ; if ( cp > 0xFFFF ) { // is surrogate pair return cp ; } return - 1 ; }
Utility for getting a code point from a CharSequence that contains exactly one code point .