{"id":733,"date":"2008-01-23T00:07:02","date_gmt":"2008-01-22T15:07:02","guid":{"rendered":"http:\/\/terzeron.com\/?p=733"},"modified":"2008-01-23T00:07:02","modified_gmt":"2008-01-22T15:07:02","slug":"cp949%eb%a5%bc-ucs4%eb%a1%9c-%ec%95%88%ec%a0%84%ed%95%98%ea%b2%8c-%eb%b3%80%ed%99%98%ed%95%98%eb%8a%94-c-%ea%b8%b0%eb%b2%95","status":"publish","type":"post","link":"https:\/\/terzeron.com\/?p=733","title":{"rendered":"CP949(UHC)\ub97c UCS4\ub85c \uc548\uc804\ud558\uac8c \ubcc0\ud658\ud558\ub294 C++ \uae30\ubc95"},"content":{"rendered":"<pre class=\"brush: c++\">#include <iostream>\n#include <stdio.h>\n#include <locale>\n\nusing namespace std;\ntypedef __enc_traits enc_type;\ntypedef codecvt<wchar_t, char, enc_type> unicode_codecvt;\ntypedef codecvt_base::result result;\ntypedef wchar_t int_type;\ntypedef char ext_type;\ntypedef __gnu_cxx::char_traits<int_type> int_traits;\n\nint main(void)\n{\nlocale loc(locale::classic(), new unicode_codecvt);\nif (!has_facet<unicode_codecvt>(loc)) {\ncerr << \"don't have facet\" << endl;\nreturn -1;\n}\nconst unicode_codecvt* cvt = &#038;use_facet<unicode_codecvt>(loc);\nunicode_codecvt::state_type state01(\"UCS4\", \"UHC\");\nif (state01._M_good() == false) {\ncerr << \"can't make state\" << endl;\nreturn -1;\n}\nstate01._M_init();\n\nconst ext_type* e_lit = \"\uc49d \uc28c \uaf4c\";\nconst ext_type* e_lit2 = \"\uc2dc\ub0c7\ubb3c \ucc98\uc878 \ub0c7\";\nconst ext_type* efrom_next;\nint_type* i_arr = new int_type[1024];\nint_type* ito_next;\nresult r1;\n\nint size = strlen(e_lit);\nint size2 = strlen(e_lit2);\n\nr1 = cvt->in(state01, e_lit, e_lit + size, efrom_next,\ni_arr, i_arr + size, ito_next);\nif (r1 != codecvt_base::ok)\nreturn -1;\nfor (int i = 0; i < size &#038;&#038; i_arr[i]; ++i) {\nif (i_arr[i] == 0x20000000) {\nprintf(\"\\n\");\n} else {\nprintf(\"0x%08X\\n\", i_arr[i]);\n}\n}\ncout << endl;\n\nr1 = cvt->in(state01, e_lit2, e_lit2 + size2, efrom_next,\ni_arr, i_arr + size2, ito_next);\nif (r1 != codecvt_base::ok)\nreturn -1;\nfor (int i = 0; i < size2 &#038;&#038; i_arr[i]; ++i) {\nif (i_arr[i] == 0x20000000) {\nprintf(\"\\n\");\n} else {\nprintf(\"0x%08X\\n\", i_arr[i]);\n}\n}\ncout << endl;\n\nreturn 0;\n}<\/pre>\n<p>\uc2e4\ud589 \uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4. \uac01\uac01\uc758 \uae00\uc790\uac00 \uc81c\ub300\ub85c \ub41c UCS4 \uc6cc\ub4dc\uac12\uc744 \uac00\uc9c0\uace0 \uc788\uc74c\uc744 \ubcfc \uc218 \uc788\ub2e4.<\/p>\n<blockquote><p>0x9DC40000 \/\/ \uc49d<\/p>\n<p>0x8CC20000 \/\/ \uc28c<\/p>\n<p>0x4CAF0000 \/\/ \uaf4c<\/p>\n<p>0xDCC20000 \/\/ \uc2dc<br \/>\n0xC7B00000 \/\/ \ub0c7<br \/>\n0x3CBB0000 \/\/ \ubb3c<\/p>\n<p>0x98CC0000 \/\/ \ucc98<br \/>\n0x78C80000 \/\/ \uc878<\/p>\n<p>0xC7B00000 \/\/ \ub0c7<\/p><\/blockquote>\n<p>codecvt \ub300\uc2e0\uc5d0 mbstowcs()\ub97c \uc0ac\uc6a9\ud558\uac8c \ub418\uba74 \uc644\uc131\ud615 \ubb38\uc790\uc9d1\ud569\uc758 \ubc94\uc704\ub97c \ub118\uc5b4\uc11c\ub294 \ud655\uc7a5\uc644\uc131\ud615 \ucf54\ub4dc\uc758 \uacbd\uc6b0 '?'\ub85c \ubcc0\ud658\ub418\uc5b4 '\uc49d', '\uc28c', '\uaf4c' \ub4f1\uc758 \uae00\uc790\uac00 \ubaa8\ub450 \uac19\uc740 \uc6cc\ub4dc\uac12\uc744 \uac00\uc9c0\uac8c \ub418\ub294 \ubb38\uc81c\uc810\uc774 \ub098\ud0c0\ub09c\ub2e4.<\/p>\n<p>\ub2e4\ub9cc \uc704 \uc18c\uc2a4\ucf54\ub4dc\uc758 \ud55c \uac00\uc9c0 \uc544\uc26c\uc6b4 \uc810\uc740 locale \uc124\uc815, codecvt \uc0dd\uc131, state \uc0dd\uc131\uc744 \ucd08\uae30\ud654\ud558\ub294 \ubcc4\uac1c \ud568\uc218\ub85c \ubd84\ub9ac\ud560 \uc218 \uc5c6\ub2e4\ub294 \uc810\uc774\ub2e4. state\ub97c \ud3ec\uc778\ud130\ub098 \ub808\ud37c\ub7f0\uc2a4\ub85c \ub118\uae30\uac8c \ub418\uba74 cvt\uc758 in() \uba54\uc3d8\ub4dc\ub97c \ud638\ucd9c\ud560 \ub54c \ub0b4\ubd80\uc5d0\uc11c segmentation fault\uac00 \ubc1c\uc0dd\ud55c\ub2e4. \uc544\uc9c1 \ud574\uacb0\ucc45\uc744 \ucc3e\uc9c0 \ubabb\ud558\uace0 \uac19\uc740 \ud568\uc218\uc5d0\uc11c \uc0ac\uc6a9\ud558\ub294 \ubc29\ubc95\uc744 \uc0ac\uc6a9\ud558\uace0 \uc788\ub2e4.<\/p>\n<p>* 2009\/08\/20\uc5d0 \ucd94\uac00<br \/>\nGCC 4.3.3\uc5d0\uc11c \ud14c\uc2a4\ud2b8\ud574\ubcf4\ub2c8 \uc704\uc758 \uc608\uc81c\uac00 header dependency \ubb38\uc81c\ub85c \uc778\ud558\uc5ec \uc81c\ub300\ub85c \ucef4\ud30c\uc77c\ub418\uc9c0 \uc54a\ub294 \ubb38\uc81c\uac00 \uc788\uc5b4\uc11c GCC 4.3.3\uc5d0\uc11c \ucef4\ud30c\uc77c\ub418\ub294 \ub2e4\ub978 \uc608\uc81c\ub97c \uc791\uc131\ud574\ubcf4\uc558\ub2e4.<\/p>\n<p>\uc774 \uc608\uc81c\ub294 UTF-8 \ubb38\uc790\uc5f4\uc744 codecvt\ub97c \uc774\uc6a9\ud558\uc5ec UCS4\ub85c \ubcc0\ud658\ud558\ub294 \uae30\ub2a5\uc744 \uc218\ud589\ud55c\ub2e4. \ubb3c\ub860 \uc774 \uae30\ub2a5\uc740 mbstowcs() \ud568\uc218\ub97c \uc774\uc6a9\ud558\uc5ec \uc544\uc8fc \uac04\ub2e8\ud558\uac8c \uc791\uc131\ud560 \uc218\ub3c4 \uc788\uc73c\ub098 codecvt\ub97c \uc0ac\uc6a9\ud558\ub294 \ubcf5\uc7a1\ud55c \ucf54\ub4dc\ub97c \uc774\ud574\ud560 \uc218 \uc788\ub294 \uc608\uc81c\ub85c \uc18c\uac1c\ud55c\ub2e4.<\/p>\n<pre class=\"brush: c++\">#include <iostream>\n#include <locale>\n#include <cwchar>\n#include <string.h>\n#include <sys\/types.h>\n#include <netinet\/in.h>\n#include <ext\/codecvt_specializations.h>\n\n\nusing namespace std;\n\ntypedef encoding_state state_type;\ntypedef codecvt<wchar_t, char, state_type> unicode_codecvt;\n\n\nint main(void)\n{\nlocale loc(locale::classic(), new unicode_codecvt);\nif (!has_facet<unicode_codecvt>(loc)) {\ncerr << \"don't havve facet\" << endl;\nreturn -1;\n}\nconst unicode_codecvt* cvt = &#038;use_facet<unicode_codecvt>(loc);\nunicode_codecvt::state_type state01(\"UCS4\", \"UTF8\");\n\nconst char* text = \"\ud55c\uae00\";\nconst char* efrom_next;\nwchar_t* i_arr = new wchar_t[1024];\nwchar_t* ito_next;\ncodecvt_base::result r1;\n\nint size = strlen(text);\nr1 = cvt->in(state01, text, text + size, efrom_next,\ni_arr, i_arr + size, ito_next);\nif (r1 != codecvt_base::ok)\nreturn -1;\n\nfor (uint i = 0; i_arr[i] != 0x00000000 ; ++i) {\nif (i_arr[i] == 0x20000000) {\ncout << endl;\n} else {\ncout << \"0x\" << hex << htonl(i_arr[i]) << dec << endl;\n}\n}\ncout << endl;\n\nreturn 0;\n}<\/pre>\n<p>\uc560\ucd08\uc758 \ubaa9\uc801\uc774\uc5c8\ub358 CP949\ub97c UCS4\ub85c \ubcc0\ud654\ud558\ub294 \uac83\uc740 \uc774 \uae00\uc744 \uc77d\uc740 \ub3c5\uc790\uc758 \ubaab\uc73c\ub85c \ub0a8\uaca8\ub454\ub2e4. \uc704\uc758 \ub450 \uac00\uc9c0 \uc608\uc81c\ub97c \ucc38\uace0\ud558\uba74 \uc544\uc8fc \uac04\ub2e8\ud558\ub2e4.<\/p>\n<div class=\"fb-background-color\">\n\t\t\t  <div \n\t\t\t  \tclass = \"fb-comments\" \n\t\t\t  \tdata-href = \"https:\/\/terzeron.com\/?p=733\"\n\t\t\t  \tdata-numposts = \"100\"\n\t\t\t  \tdata-lazy = \"true\"\n\t\t\t\tdata-colorscheme = \"light\"\n\t\t\t\tdata-order-by = \"time\"\n\t\t\t\tdata-mobile=true>\n\t\t\t  <\/div><\/div>\n\t\t  <style>\n\t\t    .fb-background-color {\n\t\t\t\tbackground: #ffffff !important;\n\t\t\t}\n\t\t\t.fb_iframe_widget_fluid_desktop iframe {\n\t\t\t    width: 100% !important;\n\t\t\t}\n\t\t  <\/style>\n\t\t  ","protected":false},"excerpt":{"rendered":"<p>#include #include #include using namespace std; typedef __enc_traits enc_type; typedef codecvt unicode_codecvt; typedef codecvt_base::result result; typedef wchar_t int_type; typedef char ext_type; typedef __gnu_cxx::char_traits int_traits; int main(void) { locale loc(locale::classic(), new unicode_codecvt); if (!has_facet(loc)) { cerr<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_sitemap_exclude":false,"_sitemap_priority":"","_sitemap_frequency":"","footnotes":""},"categories":[13,9],"tags":[],"class_list":["post-733","post","type-post","status-publish","format-standard","hentry","category-programming","category-9"],"_links":{"self":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/posts\/733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=733"}],"version-history":[{"count":0,"href":"https:\/\/terzeron.com\/index.php?rest_route=\/wp\/v2\/posts\/733\/revisions"}],"wp:attachment":[{"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/terzeron.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}