{"id":172964,"date":"2020-03-06T09:37:47","date_gmt":"2020-03-06T01:37:47","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=172964"},"modified":"2020-02-24T09:39:18","modified_gmt":"2020-02-24T01:39:18","slug":"java-implementation-chinese","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/java-implementation-chinese.html","title":{"rendered":"Java\u5b9e\u73b0\u8fc7\u6ee4\u4e2d\u6587\u4e71\u7801"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6700\u8fd1\u5728\u65e5\u5fd7\u6570\u636e\u6e05\u6d17\u65f6\u9047\u5230\u4e2d\u6587\u4e71\u7801\uff0c\u5982\u679c\u53ea\u8981\u6709\u975e\u4e2d\u6587\u5b57\u7b26\u5c31\u5c06\u8be5\u5b57\u7b26\u4e32\u8fc7\u6ee4\u6389\uff0c\u8fd9\u79cd\u65b9\u6cd5\u867d\u7b80\u5355\u4f46\u5e76\u4e0d\u53ef\u53d6\uff0c\u56e0\u4e3a\u6bd4\u5982\u50cfXperia™\u4e3b\u984c\u3001\u5929\u5929\u56db\u5ddd\u9ebb\u5c06\u2161\u8fd9\u6837\u7684\u5b57\u7b26\u4e32\u4e5f\u4f1a\u88ab\u8fc7\u6ee4\u6389\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

1. Unicode\u7f16\u7801<\/strong><\/div>\n

Unicode\u7f16\u7801\u662f\u4e00\u79cd\u6db5\u76d6\u4e86\u4e16\u754c\u4e0a\u6240\u6709\u8bed\u8a00\u3001\u6807\u70b9\u7b49\u5b57\u7b26\u7684\u7f16\u7801\u65b9\u5f0f\uff0c\u7b80\u5355\u4e00\u70b9\u8bf4\uff0c\u5c31\u662f\u4e00\u79cd\u901a\u7528\u7684\u4e16\u754c\u7801\uff1b\u5176\u7f16\u7801\u8303\u56f4\uff1aU+0000 .. U+10FFFF\u3002\u6309Unicode\u786c\u7f16\u7801\u7684\u533a\u95f4\u8fdb\u884c\u5212\u5206\uff0cUnicode\u7f16\u7801\u88ab\u5206\u6210\u82e5\u5e72\u4e2ablock ( Unicode block)\uff1b\u6bcf\u4e00\u4e2aUnicode\u7f16\u7801\u4e13\u5c5e\u4e8e\u552f\u4e00\u7684Unicode block\uff0cUnicode block\u4e4b\u95f4\u4e92\u4e0d\u91cd\u53e0\u3002\u4ece\u7801\u5b57\u7684\u672c\u8eab\u7684\u5c5e\u6027\u51fa\u53d1\uff0cUnicode\u7f16\u7801\u88ab\u5206\u6210\u4e86\u82e5\u5e72script ( Unicode script)\uff1b\u6bd4\u5982\uff0c\u4e0e\u4e2d\u6587\u76f8\u5173\u7684\u5b57\u7b26\u3001\u6807\u70b9\u7684scriptHan\u5305\u62ecblock\u5982\u4e0b\uff1a<\/p>\n

    \n
  • CJK Radicals Supplement<\/li>\n
  • Kangxi Radicals<\/li>\n
  • CJK Symbols and Punctuation\u4e2d\u768415\u4e2a\u5b57\u7b26<\/li>\n
  • CJK Unified Ideographs Extension A<\/li>\n
  • CJK Unified Ideographs<\/li>\n
  • CJK Compatibility Ideographs<\/li>\n
  • CJK Unified Ideographs Extension B<\/li>\n
  • CJK Unified Ideographs Extension C<\/li>\n
  • CJK Unified Ideographs Extension D<\/li>\n
  • CJK Unified Ideographs Extension E<\/li>\n
  • CJK Compatibility Ideographs Supplement<\/li>\n<\/ul>\n

    \u5176\u4e2d\uff0c\u5e38\u89c1\u7684\u4e2d\u6587\u5b57\u7b26\u5728CJK Unified Ideographs block\uff1b\u6b64\u5916\uff0c\u8003\u8651\u7e41\u4f53\u5b57\u53ca\u4e0d\u5e38\u89c1\u5b57\u7b49\uff0cCJK\u8fd8\u6709A\u3001B\u3001C\u3001D\u3001E\u4e94\u4e2aextension\u3002Basic Latin block\u5b8c\u6574\u5730\u5305\u542b\u4e86ASCII\u7801\u7684\u63a7\u5236\u5b57\u7b26\u3001\u6807\u70b9\u5b57\u7b26\u4e0e\u82f1\u6587\u5b57\u6bcd\u5b57\u7b26\u3002<\/p>\n

    2. Java\u7684\u5b57\u7b26\u7f16\u7801<\/strong><\/div>\n

    JDK\u5b8c\u6574\u5b9e\u73b0Unicode\u7684block\u4e0escript\uff1a<\/p>\n

    Char c = '☎'\r\nCharacter.UnicodeBlock ub = Character.UnicodeBlock.of(c)\r\nCharacter.UnicodeScript uc = Character.UnicodeScript.of(c);<\/pre>\n

    Java\u4e2d\u7684\u5b57\u7b26char\u5185\u7f6e\u7684\u7f16\u7801\u65b9\u5f0f\u662fUTF-16\uff0c\u5f53char\u5f3a\u8f6c\u6210int\u7c7b\u578b\u65f6\uff0c\u5176\u8fd4\u56de\u503c\u662funicode\u7f16\u7801\u503c\uff0c\u53ea\u6709\u5f53getbyte\u65f6\u624d\u8fd4\u56de\u7684\u662futf-8\u7f16\u7801\u7684byte\uff1a<\/p>\n

    String s = \"\\u00a0\";\r\nString.format(\"\\\\u%04x\", (int) s.charAt(0)) \/\/ --> \\u00a0\r\nimport org.apache.commons.codec.binary.Hex;\r\nHex.encodeHex(s.getBytes()) \/\/ --> c2a0<\/pre>\n

    UTF-8\u662fUnicode\u5b57\u7b26\u7684\u53d8\u957f\u524d\u7f00\u7f16\u7801\u7684\u4e00\u79cd\u5b9e\u73b0\uff0c\u4e8c\u8005\u4e4b\u95f4\u7684\u5bf9\u5e94\u5173\u7cfb\u5728\u8fd9\u91cc.\u73b0\u5728\u6211\u4eec\u56de\u5230\u5f00\u7bc7\u8fc7\u6ee4\u4e2d\u6587\u4e71\u7801\u7684\u95ee\u9898\uff0c\u6709\u4e00\u4e2a\u57fa\u672c\u89e3\u51b3\u601d\u8def\uff1a<\/p>\n

      \n
    • \u53bb\u6389\u5404\u79cd\u6807\u70b9\u5b57\u7b26\u3001\u63a7\u5236\u5b57\u7b26\uff0c<\/li>\n
    • \u8ba1\u7b97\u5269\u4e0b\u5b57\u7b26\u4e2d\u975e\u4e2d\u6587\u5b57\u7b26\u6240\u5360\u7684\u6bd4\u4f8b\uff0c\u5982\u679c\u8d85\u8fc7\u9608\u503c\uff0c\u5219\u8ba4\u4e3a\u8be5\u5b57\u7b26\u4e32\u4e3a\u4e71\u7801\u4e32<\/li>\n<\/ul>\n

      \u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

      \r\npublic class ChineseUtill {\r\n     \r\n    private static boolean isChinese(char c) {\r\n        Character.UnicodeScript sc = Character.UnicodeScript.of(c);\r\n        if (sc == Character.UnicodeScript.HAN) {\r\n            return true;\r\n        }\r\n        return false;\r\n    }\r\n    \r\n    public static boolean isPunctuation(char c) {\r\n        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);\r\n        if (    \/\/ punctuation, spacing, and formatting characters\r\n                ub == Character.UnicodeBlock.GENERAL_PUNCTUATION\r\n                \/\/ symbols and punctuation in the unified Chinese, Japanese and Korean script\r\n                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION\r\n                \/\/ fullwidth character or a halfwidth character\r\n                || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS\r\n                \/\/ vertical glyph variants for east Asian compatibility\r\n                || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS\r\n                \/\/ vertical punctuation for compatibility characters with the Chinese Standard GB 18030\r\n                || ub == Character.UnicodeBlock.VERTICAL_FORMS\r\n                \/\/ ascii\r\n                || ub == Character.UnicodeBlock.BASIC_LATIN\r\n                ) {\r\n            return true;\r\n        } else {\r\n            return false;\r\n        }\r\n    }\r\n    \r\n    private static Boolean isUserDefined(char c) {\r\n        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);\r\n        if (ub == Character.UnicodeBlock.NUMBER_FORMS\r\n                || ub == Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS\r\n                || ub == Character.UnicodeBlock.LETTERLIKE_SYMBOLS\r\n                || c == '\\ufeff'\r\n                || c == '\\u00a0'\r\n                )\r\n            return true;\r\n        return false;\r\n    }\r\n    \r\n    public static Boolean isMessy(String str)  {\r\n        float chlength = 0;\r\n        float count = 0;\r\n        for(int i = 0; i < str.length(); i++) {\r\n            char c = str.charAt(i);\r\n            if(isPunctuation(c) || isUserDefined(c))\r\n                continue;\r\n            else {\r\n                if(!isChinese(c)) {\r\n                    count = count + 1;\r\n                }\r\n                chlength ++;\r\n            }\r\n        }\r\n        float result = count \/ chlength;\r\n        if(result > 0.3)\r\n            return true;\r\n        return false;\r\n    }\r\n    \r\n}\r\n<\/pre>\n

      \u4e3a\u4e86\u5f97\u5230\u66f4\u4e3a\u5b8c\u6574\u7684\u53ef\u63a5\u53d7\u7684\u5b57\u7b26\u8868\uff0c\u5b9a\u4e49isUserDefined\u65b9\u6cd5\uff08\u5177\u4f53\u5b57\u7b26\u8868\u4e0e\u65e5\u5fd7\u4e2d\u7684\u5b57\u7b26\u6709\u5173\u7cfb\uff09\uff1b\u52a0\u4e0a\u4e86Number Forms\u3001Enclosed Alphanumerics\u3001Letterlike Symbols\u8fd9\u4e09\u4e2ablock\uff0c\u4ee5\u53ca\\u00a0\uff08Non-breaking space\uff09\u5b57\u7b26\u4e0e\\ufeff\uff08ZERO WIDTH NO-BREAK SPACE\uff09\u5b57\u7b26\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

      Unicode\u7f16\u7801\u662f\u4e00\u79cd\u6db5\u76d6\u4e86\u4e16\u754c\u4e0a\u6240\u6709\u8bed\u8a00\u3001\u6807\u70b9\u7b49\u5b57\u7b26\u7684\u7f16\u7801\u65b9\u5f0f\uff0c\u7b80\u5355\u4e00\u70b9\u8bf4\uff0c\u5c31\u662f\u4e00\u79cd\u901a\u7528\u7684\u4e16\u754c\u7801\uff1b\u5176\u7f16\u7801\u8303 […]<\/p>\n","protected":false},"author":1481,"featured_media":172972,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-172964","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/172964","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=172964"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/172964\/revisions"}],"predecessor-version":[{"id":172974,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/172964\/revisions\/172974"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/172972"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=172964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=172964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=172964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}