Пример #1
0
void
wc_push_to_gb18030(Str os, wc_wchar_t cc, wc_status *st)
{
  while (1) {
    switch (WC_CCS_SET(cc.ccs)) {
    case WC_CCS_US_ASCII:
	Strcat_char(os, (char)cc.code);
	return;
    case WC_CCS_GB_2312:
	Strcat_char(os, (char)((cc.code >> 8) | 0x80));
	Strcat_char(os, (char)((cc.code & 0xff) | 0x80));
	return;
    case WC_CCS_GBK_1:
    case WC_CCS_GBK_2:
	cc = wc_cs128w_to_gbk(cc);
    case WC_CCS_GBK:
	Strcat_char(os, (char)(cc.code >> 8));
	Strcat_char(os, (char)(cc.code & 0xff));
	return;
    case WC_CCS_GBK_EXT_1:
    case WC_CCS_GBK_EXT_2:
	cc = wc_cs128w_to_gbk(cc);
    case WC_CCS_GBK_EXT:
	Strcat_char(os, (char)(cc.code >> 8));
	Strcat_char(os, (char)(cc.code & 0xff));
	return;
    case WC_CCS_GB18030:
	Strcat_char(os, (char)((cc.code >> 24) & 0xff));
	Strcat_char(os, (char)((cc.code >> 16) & 0xff));
	Strcat_char(os, (char)((cc.code >> 8)  & 0xff));
	Strcat_char(os, (char)(cc.code & 0xff));
	return;
    case WC_CCS_UNKNOWN_W:
	if (!WcOption.no_replace)
	    Strcat_charp(os, WC_REPLACE_W);
	return;
    case WC_CCS_UNKNOWN:
	if (!WcOption.no_replace)
	    Strcat_charp(os, WC_REPLACE);
	return;
    default:
#ifdef USE_UNICODE
	if (WcOption.ucs_conv)
	    cc = wc_any_to_any_ces(cc, st);
	else
#endif
	    cc.ccs = WC_CCS_IS_WIDE(cc.ccs) ? WC_CCS_UNKNOWN_W : WC_CCS_UNKNOWN;
	continue;
    }
  }
}
Пример #2
0
void
wc_push_to_viet(Str os, wc_wchar_t cc, wc_status *st)
{
    wc_ccs ccs1 = st->ces_info->gset[1].ccs;
    wc_ccs ccs2 = 0, ccs3 = 0;
    wc_uint8 *map = NULL;

    switch (st->ces_info->id) {
    case WC_CES_CP1258:
	ccs3 = st->ces_info->gset[2].ccs;
	break;
    case WC_CES_TCVN_5712:
	map = wc_c0_tcvn57122_map;
	ccs2 = st->ces_info->gset[2].ccs;
	ccs3 = st->ces_info->gset[3].ccs;
	break;
    case WC_CES_VISCII_11:
	map = wc_c0_viscii112_map;
	ccs2 = st->ces_info->gset[2].ccs;
	break;
    case WC_CES_VPS:
	map = wc_c0_vps2_map;
	ccs2 = st->ces_info->gset[2].ccs;
	break;
    }

  while (1) {
    if (cc.ccs == ccs1) {
	Strcat_char(os, (char)(cc.code | 0x80));
	return;
    } else if (cc.ccs == ccs2) {
	Strcat_char(os, (char)(cc.code & 0x7f));
	return;
    } else if (cc.ccs == ccs3) {
	Strcat_char(os, (char)((cc.code >> 8) & 0xff));
	Strcat_char(os, (char)(cc.code & 0xff));
	return;
    }
    switch (cc.ccs) {
    case WC_CCS_US_ASCII:
	if (cc.code < 0x20 && map && map[cc.code])
	    Strcat_char(os, ' ');
	else
	    Strcat_char(os, (char)cc.code);
	return;
    case WC_CCS_UNKNOWN_W:
	if (!WcOption.no_replace)
	    Strcat_charp(os, WC_REPLACE_W);
	return;
    case WC_CCS_UNKNOWN:
	if (!WcOption.no_replace)
	    Strcat_charp(os, WC_REPLACE);
	return;
    default:
#ifdef USE_UNICODE
	if (WcOption.ucs_conv)
	    cc = wc_any_to_any_ces(cc, st);
	else
#endif
	    cc.ccs = WC_CCS_IS_WIDE(cc.ccs) ? WC_CCS_UNKNOWN_W : WC_CCS_UNKNOWN;
	continue;
    }
  }
Пример #3
0
void wc_push_to_hz( Str os, wc_wchar_t cc, wc_status *st )
{
  while ( 1 )
  {
    switch ( cc.ccs )
    {
      if ( ( WcOption.ucs_conv & 255 ) != 0 )
      {
        wc_any_to_any_ces( cc, &cc.ccs/*error:'I'*/ );
      }
      else
      {
        cc.ccs = ( cc.ccs & 98304 ) == 0 ? 16384 : 49152;
      }
      break;
    default:
      break;
    case 322:
      if ( ( st->gl & 255 ) != 0 )
      {
        if ( os->area_size <= os->length + 1 )
          Strgrow( os );
        os->ptr[ os->length ] = '~';
        os->length++;
        os->ptr[ os->length ] = 0;
        if ( os->area_size <= os->length + 1 )
          Strgrow( os );
        os->ptr[ os->length ] = '}';
        os->length++;
        os->ptr[ os->length ] = 0;
        st->gl = 0;
      }
      if ( (unsigned char)( cc.code ) == '~' )
      {
        if ( os->area_size <= os->length + 1 )
          Strgrow( os );
        os->ptr[ os->length ] = '~';
        os->length++;
        os->ptr[ os->length ] = 0;
      }
      if ( os->area_size <= os->length + 1 )
        Strgrow( os );
      os->ptr[ os->length ] = cc.code;
      os->length++;
      os->ptr[ os->length ] = 0;
      break;
    case 33089:
      if ( ( st->gl & 255 ) == 0 )
      {
        if ( os->area_size <= os->length + 1 )
          Strgrow( os );
        os->ptr[ os->length ] = '~';
        os->length++;
        os->ptr[ os->length ] = 0;
        if ( os->area_size <= os->length + 1 )
          Strgrow( os );
        os->ptr[ os->length ] = '{';
        os->length++;
        os->ptr[ os->length ] = 0;
        st->gl = 1;
      }
      if ( os->area_size <= os->length + 1 )
        Strgrow( os );
      os->ptr[ os->length ] = ( cc.code >> 8 ) & 127;
      os->length++;
      os->ptr[ os->length ] = 0;
      if ( os->area_size <= os->length + 1 )
        Strgrow( os );
      os->ptr[ os->length ] = cc.code & 127;
      os->length++;
      os->ptr[ os->length ] = 0;
      break;
    case 49152:
      if ( ( WcOption.no_replace & 255 ) != 0 )
      {
      }
      else
      {
        if ( ( st->gl & 255 ) != 0 )
        {
          if ( os->area_size <= os->length + 1 )
            Strgrow( os );
          os->ptr[ os->length ] = '~';
          os->length++;
          os->ptr[ os->length ] = 0;
          if ( os->area_size <= os->length + 1 )
            Strgrow( os );
          os->ptr[ os->length ] = '}';
          os->length++;
          os->ptr[ os->length ] = 0;
          st->gl = 0;
        }
        Strcat_charp( os, WcReplaceW );
      }
      break;
    case 16384:
      if ( ( WcOption.no_replace & 255 ) != 0 )
      {
      }
      else
      {
        if ( ( st->gl & 255 ) != 0 )
        {
          if ( os->area_size <= os->length + 1 )
            Strgrow( os );
          os->ptr[ os->length ] = '~';
          os->length++;
          os->ptr[ os->length ] = 0;
          if ( os->area_size <= os->length + 1 )
            Strgrow( os );
          os->ptr[ os->length ] = '}';
          os->length++;
          os->ptr[ os->length ] = 0;
          st->gl = 0;
        }
        Strcat_charp( os, WcReplace );
      }
      break;
    }
    break;
  }
}