GSMCharset extends BaseCharset { static public boolean canRepresent(CharSequence str0) { if (str0 == null) { return true; } int len = str0.length(); for (int i = 0; i < len; i++) { char c = str0.charAt(i); if ((c >= ' ' && c <= '_') || (c >= 'a' && c <= '~')) { continue; } else { switch (c) { case '\u00A3': case '\u00A5': case '\u00E8': case '\u00E9': case '\u00F9': case '\u00EC': case '\u00F2': case '\u00C7': case '\n': case '\u00D8': case '\u00F8': case '\r': case '\u000c': case '\u00C5': case '\u00E5': case '\u0394': case '\u03A6': case '\u0393': case '\u039B': case '\u03A9': case '\u03A0': case '\u03A8': case '\u03A3': case '\u0398': case '\u039E': case '\u00C6': case '\u00E6': case '\u00DF': case '\u00C9': case '\u00A4': case '\u00A1': case '\u00C4': case '\u00D6': case '\u00D1': case '\u00DC': case '\u00A7': case '\u00BF': case '\u00E4': case '\u00F6': case '\u00F1': case '\u00FC': case '\u00E0': case '\u20AC': continue; default: return false; } } } return true; }  static boolean canRepresent(CharSequence str0); @Override int estimateEncodeByteLength(CharSequence str0); @Override byte[] encode(CharSequence str0); @Override int estimateDecodeCharLength(byte[] bytes); @Override void decode(byte[] bytes, StringBuilder buffer); static final int EXTENDED_ESCAPE; static final int PAGE_BREAK; static final char[] CHAR_TABLE; static final char[] EXT_CHAR_TABLE; }
@Test public void canRepresent() throws Exception { Assert.assertEquals(true, GSMCharset.canRepresent(null)); Assert.assertEquals(true, GSMCharset.canRepresent(" ")); Assert.assertEquals(true, GSMCharset.canRepresent("\n\r")); Assert.assertEquals(true, GSMCharset.canRepresent("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")); Assert.assertEquals(true, GSMCharset.canRepresent("Hello @ World")); Assert.assertEquals(true, GSMCharset.canRepresent("{}[]$")); Assert.assertEquals(true, GSMCharset.canRepresent("\u20ac")); Assert.assertEquals(false, GSMCharset.canRepresent("\u0623")); Assert.assertEquals(false, GSMCharset.canRepresent("`")); Assert.assertEquals(true, GSMCharset.canRepresent("[\\]^_")); Assert.assertEquals(true, GSMCharset.canRepresent("\f")); StringBuilder s = new StringBuilder(); for (int i = 0; i < GSMCharset.CHAR_TABLE.length; i++) { char c = GSMCharset.CHAR_TABLE[i]; if (c > 0) { s.append(c); } } for (int i = 0; i < GSMCharset.EXT_CHAR_TABLE.length; i++) { char c = GSMCharset.EXT_CHAR_TABLE[i]; if (c > 0) { s.append(c); } } Assert.assertEquals(true, GSMCharset.canRepresent(s.toString())); }