// $Id: sjis_imode.cpp,v 1.15 2002/07/04 04:52:29 hio Exp $ #include #include "Japanese.h" EXTERN_C SV* xs_sjis_imode_utf8(SV* sv_str) { if( sv_str==&PL_sv_undef ) { return newSVsv(&PL_sv_undef); } unsigned char* src = (unsigned char*)SvPV(sv_str,PL_na); int len = sv_len(sv_str); //fprintf(stderr,"Unicode::Japanese::(xs)sjis_imode_utf8[len:%d]\n",len); //bin_dump("in ",src,len); SV_Buf result(len*3/2+4); const unsigned char* src_end = src+len; while( src=src_end ) { //ECHO_U2S((stderr," no enough buffer, here is %d, need %d\n",src_end-src,utf8_len)); result.append('?'); ++src; continue; } // 2バイト目以降が正しい文字範囲か確認 bool succ = true; for( int i=1; i=4); if( ucs<0x0ff000 ) { // 知らない使用領域 result.append('?'); src += utf8_len; continue; } // 絵文字判定(imode) const unsigned char* const sjis = (unsigned char*)&g_eu2i_table[ucs - 0x0ff000]; if( sjis[1]!=0 ) { // 2バイト文字に. result.append_ch2(*reinterpret_cast(sjis)); }else if( sjis[0]!=0 ) { // 1バイト文字に. result.append(*sjis); }else { // マッピングなし result.append('?'); } src += utf8_len; continue; } if( ucs & ~0xFFFF ) { // ucs2の範囲外 (ucs4の範囲) result.append('?'); src += utf8_len; continue; } // ucs => sjis //ECHO_U2S((stderr,"ucs2 [%04x]\n",ucs)); const unsigned short sjis = g_u2s_table[ucs]; //ECHO_U2S((stderr,"sjis [%04x]\n",ntohs(sjis) )); if( sjis || !ucs ) { // 対応文字がある時とucs=='\0'の時 if( sjis & 0xff00 ) { result.append_ch2(sjis); }else { result.append((unsigned char)sjis); } }else if( ucs<=0x7F ) { result.append((unsigned char)ucs); }else { result.append('?'); } src += utf8_len; //bin_dump("now",dst_begin,dst-dst_begin); } /* for */ //ON_U2S( bin_dump("out",result.getBegin(),result.getLength()) ); result.setLength(); return result.getSv(); }