mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	remove marshal/gtk/kconv
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									210367ec88
								
							
						
					
					
						commit
						0a64817fb8
					
				
					 124 changed files with 14604 additions and 10219 deletions
				
			
		
							
								
								
									
										7
									
								
								ext/nkf/MANIFEST
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								ext/nkf/MANIFEST
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
MANIFEST
 | 
			
		||||
depend
 | 
			
		||||
extconf.rb
 | 
			
		||||
lib/kconv.rb
 | 
			
		||||
nkf.c
 | 
			
		||||
nkf1.7/nkf.c
 | 
			
		||||
test.rb
 | 
			
		||||
							
								
								
									
										1
									
								
								ext/nkf/depend
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								ext/nkf/depend
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
nkf.o : nkf.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h nkf1.7/nkf.c
 | 
			
		||||
							
								
								
									
										2
									
								
								ext/nkf/extconf.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								ext/nkf/extconf.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
require 'mkmf'
 | 
			
		||||
create_makefile('nkf')
 | 
			
		||||
							
								
								
									
										58
									
								
								ext/nkf/lib/kconv.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								ext/nkf/lib/kconv.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,58 @@
 | 
			
		|||
require 'nkf'
 | 
			
		||||
 | 
			
		||||
module Kconv
 | 
			
		||||
  AUTO = NKF::AUTO
 | 
			
		||||
  JIS = NKF::JIS
 | 
			
		||||
  EUC = NKF::EUC
 | 
			
		||||
  SJIS = NKF::SJIS
 | 
			
		||||
  BINARY = NKF::BINARY
 | 
			
		||||
  NOCONV = NKF::NOCONV
 | 
			
		||||
  UNKNOWN = NKF::UNKNOWN
 | 
			
		||||
  def kconv(str, out_code, in_code = AUTO)
 | 
			
		||||
    opt = '-'
 | 
			
		||||
    case in_code
 | 
			
		||||
    when NKF::JIS
 | 
			
		||||
      opt << 'J'
 | 
			
		||||
    when NKF::EUC
 | 
			
		||||
      opt << 'E'
 | 
			
		||||
    when NKF::SJIS
 | 
			
		||||
      opt << 'S'
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    case out_code
 | 
			
		||||
    when NKF::JIS
 | 
			
		||||
      opt << 'j'
 | 
			
		||||
    when NKF::EUC
 | 
			
		||||
      opt << 'e'
 | 
			
		||||
    when NKF::SJIS
 | 
			
		||||
      opt << 's'
 | 
			
		||||
    when NKF::NOCONV
 | 
			
		||||
      return str
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    opt = '' if opt == '-'
 | 
			
		||||
 | 
			
		||||
    NKF::nkf(opt, str)
 | 
			
		||||
  end
 | 
			
		||||
  module_function :kconv
 | 
			
		||||
 | 
			
		||||
  def tojis(str)
 | 
			
		||||
    NKF::nkf('-j', str)
 | 
			
		||||
  end
 | 
			
		||||
  module_function :tojis
 | 
			
		||||
 | 
			
		||||
  def toeuc(str)
 | 
			
		||||
    NKF::nkf('-e', str)
 | 
			
		||||
  end
 | 
			
		||||
  module_function :toeuc
 | 
			
		||||
 | 
			
		||||
  def tosjis(str)
 | 
			
		||||
    NKF::nkf('-s', str)
 | 
			
		||||
  end
 | 
			
		||||
  module_function :tosjis
 | 
			
		||||
 | 
			
		||||
  def guess(str)
 | 
			
		||||
    NKF::guess(str)
 | 
			
		||||
  end
 | 
			
		||||
  module_function :guess
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										206
									
								
								ext/nkf/nkf.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										206
									
								
								ext/nkf/nkf.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,206 @@
 | 
			
		|||
#include "ruby.h"
 | 
			
		||||
 | 
			
		||||
#define	_AUTO		0
 | 
			
		||||
#define	_JIS		1
 | 
			
		||||
#define	_EUC		2
 | 
			
		||||
#define	_SJIS		3
 | 
			
		||||
#define	_BINARY		4
 | 
			
		||||
#define	_NOCONV		4
 | 
			
		||||
#define	_UNKNOWN	_AUTO
 | 
			
		||||
 | 
			
		||||
#undef getc
 | 
			
		||||
#undef ungetc
 | 
			
		||||
#define getc(f)   	(input_ctr>i_len?-1:input[input_ctr++])
 | 
			
		||||
#define ungetc(c,f)	input_ctr--
 | 
			
		||||
 | 
			
		||||
#undef putchar
 | 
			
		||||
#define putchar(c)	rb_nkf_putchar(c)
 | 
			
		||||
 | 
			
		||||
#define INCSIZE		32
 | 
			
		||||
static int incsize;
 | 
			
		||||
 | 
			
		||||
static unsigned char *input, *output;
 | 
			
		||||
static int input_ctr, i_len;
 | 
			
		||||
static int output_ctr, o_len;
 | 
			
		||||
 | 
			
		||||
static VALUE dst;
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
rb_nkf_putchar(c)
 | 
			
		||||
     unsigned int c;
 | 
			
		||||
{
 | 
			
		||||
  if (output_ctr >= o_len) {
 | 
			
		||||
    o_len += incsize;
 | 
			
		||||
    rb_str_cat(dst, "", incsize);
 | 
			
		||||
    incsize *= 2;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  output[output_ctr++] = c;
 | 
			
		||||
/*
 | 
			
		||||
printf("[[%c][%c][%d]]\n", c, output[output_ctr - 1], output_ctr);
 | 
			
		||||
*/
 | 
			
		||||
  return c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define PERL_XS 1
 | 
			
		||||
#include "nkf1.7/nkf.c"
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
rb_nkf_kconv(obj, opt, src)
 | 
			
		||||
     VALUE obj, opt, src;
 | 
			
		||||
{
 | 
			
		||||
  int i;
 | 
			
		||||
  char *opt_ptr, *opt_end;
 | 
			
		||||
 | 
			
		||||
  reinit();
 | 
			
		||||
  opt_ptr = str2cstr(opt, &i);
 | 
			
		||||
  opt_end = opt_ptr + i;
 | 
			
		||||
  for (; opt_ptr < opt_end; opt_ptr++) {
 | 
			
		||||
    if (*opt_ptr != '-') {
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
    arguments(opt_ptr);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  incsize = INCSIZE;
 | 
			
		||||
 | 
			
		||||
  input_ctr = 0; 
 | 
			
		||||
  input     = str2cstr(src, &i_len);
 | 
			
		||||
  dst = rb_str_new(0, i_len*3 + 10); /* large enough? */
 | 
			
		||||
 | 
			
		||||
  output_ctr = 0;
 | 
			
		||||
  output     = RSTRING(dst)->ptr;
 | 
			
		||||
  o_len      = RSTRING(dst)->len;
 | 
			
		||||
  *output    = '\0';
 | 
			
		||||
 | 
			
		||||
  if(iso8859_f && (oconv != j_oconv || !x0201_f )) {
 | 
			
		||||
    iso8859_f = FALSE;
 | 
			
		||||
  } 
 | 
			
		||||
 | 
			
		||||
  kanji_convert(NULL);
 | 
			
		||||
  if (output_ctr > 0) output_ctr--;
 | 
			
		||||
  if (output[output_ctr] == '\0') {
 | 
			
		||||
/*
 | 
			
		||||
printf("([%c][%d])\n", output[output_ctr], output_ctr);
 | 
			
		||||
*/
 | 
			
		||||
    RSTRING(dst)->len = output_ctr;
 | 
			
		||||
  } else {
 | 
			
		||||
/*
 | 
			
		||||
printf("<[%c][%d]>\n", output[output_ctr], output_ctr);
 | 
			
		||||
*/
 | 
			
		||||
    RSTRING(dst)->len = output_ctr + 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return dst;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Character code detection - Algorithm described in:
 | 
			
		||||
 * Ken Lunde. `Understanding Japanese Information Processing'
 | 
			
		||||
 * Sebastopol, CA: O'Reilly & Associates.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
rb_nkf_guess(obj, src)
 | 
			
		||||
     VALUE obj, src;
 | 
			
		||||
{
 | 
			
		||||
  unsigned char *p;
 | 
			
		||||
  unsigned char *pend;
 | 
			
		||||
  int plen;
 | 
			
		||||
  int sequence_counter = 0;
 | 
			
		||||
 | 
			
		||||
  Check_Type(src, T_STRING);
 | 
			
		||||
 | 
			
		||||
  p = str2cstr(src, &plen);
 | 
			
		||||
  pend = p + plen;
 | 
			
		||||
 | 
			
		||||
#define INCR do {\
 | 
			
		||||
    p++;\
 | 
			
		||||
    if (p==pend) return INT2FIX(_UNKNOWN);\
 | 
			
		||||
    sequence_counter++;\
 | 
			
		||||
    if (sequence_counter % 2 == 1 && *p != 0xa4)\
 | 
			
		||||
	sequence_counter = 0;\
 | 
			
		||||
    if (6 <= sequence_counter) {\
 | 
			
		||||
	sequence_counter = 0;\
 | 
			
		||||
	return INT2FIX(_EUC);\
 | 
			
		||||
    }\
 | 
			
		||||
} while (0)
 | 
			
		||||
 | 
			
		||||
  if (*p == 0xa4)
 | 
			
		||||
    sequence_counter = 1;
 | 
			
		||||
 | 
			
		||||
  while (p<pend) {
 | 
			
		||||
    if (*p == '\033') {
 | 
			
		||||
      return INT2FIX(_JIS);
 | 
			
		||||
    }
 | 
			
		||||
    if (*p < '\006' || *p == 0x7f || *p == 0xff) {
 | 
			
		||||
      return INT2FIX(_BINARY);
 | 
			
		||||
    }
 | 
			
		||||
    if (0x81 <= *p && *p <= 0x8d) {
 | 
			
		||||
      return INT2FIX(_SJIS);
 | 
			
		||||
    }
 | 
			
		||||
    if (0x8f <= *p && *p <= 0x9f) {
 | 
			
		||||
      return INT2FIX(_SJIS);
 | 
			
		||||
    }
 | 
			
		||||
    if (*p == 0x8e) {	/* SS2 */
 | 
			
		||||
      INCR;
 | 
			
		||||
      if ((0x40 <= *p && *p <= 0x7e) ||
 | 
			
		||||
	  (0x80 <= *p && *p <= 0xa0) ||
 | 
			
		||||
	  (0xe0 <= *p && *p <= 0xfc))
 | 
			
		||||
	return INT2FIX(_SJIS);
 | 
			
		||||
    }
 | 
			
		||||
    else if (0xa1 <= *p && *p <= 0xdf) {
 | 
			
		||||
      INCR;
 | 
			
		||||
      if (0xf0 <= *p && *p <= 0xfe)
 | 
			
		||||
	return INT2FIX(_EUC);
 | 
			
		||||
      if (0xe0 <= *p && *p <= 0xef) {
 | 
			
		||||
	while (p < pend && *p >= 0x40) {
 | 
			
		||||
	  if (*p >= 0x81) {
 | 
			
		||||
	    if (*p <= 0x8d || (0x8f <= *p && *p <= 0x9f)) {
 | 
			
		||||
	      return INT2FIX(_SJIS);
 | 
			
		||||
	    }
 | 
			
		||||
	    else if (0xfd <= *p && *p <= 0xfe) {
 | 
			
		||||
	      return INT2FIX(_EUC);
 | 
			
		||||
	    }
 | 
			
		||||
	  }
 | 
			
		||||
	  INCR;
 | 
			
		||||
	}
 | 
			
		||||
      }
 | 
			
		||||
      else if (*p <= 0x9f) {
 | 
			
		||||
	return INT2FIX(_SJIS);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else if (0xf0 <= *p && *p <= 0xfe) {
 | 
			
		||||
      return INT2FIX(_EUC);
 | 
			
		||||
    }
 | 
			
		||||
    else if (0xe0 <= *p && *p <= 0xef) {
 | 
			
		||||
      INCR;
 | 
			
		||||
      if ((0x40 <= *p && *p <= 0x7e) ||
 | 
			
		||||
	  (0x80 <= *p && *p <= 0xa0)) {
 | 
			
		||||
	return INT2FIX(_SJIS);
 | 
			
		||||
      }
 | 
			
		||||
      if (0xfd <= *p && *p <= 0xfe) {
 | 
			
		||||
	return INT2FIX(_EUC);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    INCR;
 | 
			
		||||
  }
 | 
			
		||||
  return INT2FIX(_UNKNOWN);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
Init_nkf()
 | 
			
		||||
{
 | 
			
		||||
    VALUE mKconv = rb_define_module("NKF");
 | 
			
		||||
 | 
			
		||||
    rb_define_module_function(mKconv, "nkf", rb_nkf_kconv, 2);
 | 
			
		||||
    rb_define_module_function(mKconv, "guess", rb_nkf_guess, 1);
 | 
			
		||||
 | 
			
		||||
    rb_define_const(mKconv, "AUTO", INT2FIX(_AUTO));
 | 
			
		||||
    rb_define_const(mKconv, "JIS", INT2FIX(_JIS));
 | 
			
		||||
    rb_define_const(mKconv, "EUC", INT2FIX(_EUC));
 | 
			
		||||
    rb_define_const(mKconv, "SJIS", INT2FIX(_SJIS));
 | 
			
		||||
    rb_define_const(mKconv, "BINARY", INT2FIX(_BINARY));
 | 
			
		||||
    rb_define_const(mKconv, "NOCONV", INT2FIX(_NOCONV));
 | 
			
		||||
    rb_define_const(mKconv, "UNKNOWN", INT2FIX(_UNKNOWN));
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1899
									
								
								ext/nkf/nkf1.7/nkf.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1899
									
								
								ext/nkf/nkf1.7/nkf.c
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										318
									
								
								ext/nkf/test.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										318
									
								
								ext/nkf/test.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,318 @@
 | 
			
		|||
$counter = 0
 | 
			
		||||
def result(result, message = nil)
 | 
			
		||||
  $counter += 1
 | 
			
		||||
  printf("%s %d%s\n",
 | 
			
		||||
	 result ? 'ok' : 'no', 
 | 
			
		||||
	 $counter, 
 | 
			
		||||
	 message ? ' ... ' + message : '')
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
begin
 | 
			
		||||
  require 'nkf'
 | 
			
		||||
  include NKF
 | 
			
		||||
rescue LoadError
 | 
			
		||||
  result(false)
 | 
			
		||||
end
 | 
			
		||||
result(true)
 | 
			
		||||
 | 
			
		||||
if nkf('-me', '1')
 | 
			
		||||
  result(true);
 | 
			
		||||
else
 | 
			
		||||
  result(false);
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
output = nkf('-e', "\033\$@#1#3#2%B")
 | 
			
		||||
if output
 | 
			
		||||
  # print output, "\n"
 | 
			
		||||
  result(true, output)
 | 
			
		||||
else
 | 
			
		||||
  result(false)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
output = nkf('-Zj', "\033\$@#1#3#2%B")
 | 
			
		||||
if output
 | 
			
		||||
  # print output, "\n"
 | 
			
		||||
  result(true, output)
 | 
			
		||||
else
 | 
			
		||||
  result(false)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
output = "\244\306 " * 1024
 | 
			
		||||
old =  output.length
 | 
			
		||||
output = nkf("-j", output)
 | 
			
		||||
if output
 | 
			
		||||
  # print output, "\n"
 | 
			
		||||
  result(true, "#{old} #{output.length}")
 | 
			
		||||
else
 | 
			
		||||
    result(false)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
$detail = false
 | 
			
		||||
def test(opt, input, expect)
 | 
			
		||||
  print "\nINPUT:\n", input if $detail
 | 
			
		||||
  print "\nEXPECT:\n", expect if $detail
 | 
			
		||||
  result = nkf(opt, input)
 | 
			
		||||
  print "\nGOT:\n", result if $detail
 | 
			
		||||
 | 
			
		||||
  print result == expect ? "Ok\n" : "Fail\n"
 | 
			
		||||
  return result
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
# Basic Conversion
 | 
			
		||||
print "\nBasic Conversion test\n\n"
 | 
			
		||||
 | 
			
		||||
example = {}
 | 
			
		||||
example['jis'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M1FER<W0@4W1A9V4@&R1"(3DQ(3%^2R%+?D]3&RA"(%-E8V]N9"!3=&%G92`;
 | 
			
		||||
M)$)0)TU:&RA"($AI<F%G86YA(!LD0B0B)"0D)B0H)"HD;R1R)',;*$(*2V%T
 | 
			
		||||
M86MA;F$@&R1")2(E)"4F)2@E*B5O)7(E<QLH0B!+:6=O=2`;)$(A)B%G(S`C
 | 
			
		||||
/029!)E@G(B=!*$`;*$(*
 | 
			
		||||
eofeof
 | 
			
		||||
#'
 | 
			
		||||
 | 
			
		||||
example['sjis'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M1FER<W0@4W1A9V4@@5B)0(F>ED"6GIAR(%-E8V]N9"!3=&%G92"8I9=Y($AI
 | 
			
		||||
M<F%G86YA((*@@J*"I(*F@JB"[8+P@O$*2V%T86MA;F$@@T�X-%@T>#28./
 | 
			
		||||
>@Y*#DR!+:6=O=2"!18&'@D^"8(._@]:$081@A+X*
 | 
			
		||||
eofeof
 | 
			
		||||
#'
 | 
			
		||||
 | 
			
		||||
example['euc'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M1FER<W0@4W1A9V4@H;FQH;'^RZ'+_L_3(%-E8V]N9"!3=&%G92#0I\W:($AI
 | 
			
		||||
M<F%G86YA(*2BI*2DIJ2HI*JD[Z3RI/,*2V%T86MA;F$@I:*EI*6FI:BEJJ7O
 | 
			
		||||
>I?*E\R!+:6=O=2"AIJ'GH["CP:;!IMBGHJ?!J,`*
 | 
			
		||||
eofeof
 | 
			
		||||
#'
 | 
			
		||||
 | 
			
		||||
example['amb'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
MI<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<*PL:7"L+&E
 | 
			
		||||
MPK"QI<*PL:7"L+&EPK"QI<(*I<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<*P
 | 
			
		||||
ML:7"L+&EPK"QI<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<(*I<*PL:7"L+&E
 | 
			
		||||
MPK"QI<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<*PL:7"
 | 
			
		||||
ML+&EPK"QI<(*I<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"Q
 | 
			
		||||
MI<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<(*I<*PL:7"L+&EPK"QI<*PL:7"
 | 
			
		||||
ML+&EPK"QI<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<*PL:7"L+&EPK"QI<(*
 | 
			
		||||
eofeof
 | 
			
		||||
 | 
			
		||||
example['amb.euc'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&R1")4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25"
 | 
			
		||||
M,#$E0C`Q)4(P,25",#$E0C`Q)4(;*$(*&R1")4(P,25",#$E0C`Q)4(P,25"
 | 
			
		||||
M,#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(;
 | 
			
		||||
M*$(*&R1")4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P
 | 
			
		||||
M,25",#$E0C`Q)4(P,25",#$E0C`Q)4(;*$(*&R1")4(P,25",#$E0C`Q)4(P
 | 
			
		||||
M,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q
 | 
			
		||||
M)4(;*$(*&R1")4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q
 | 
			
		||||
>)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(;*$(*
 | 
			
		||||
eofeof
 | 
			
		||||
 | 
			
		||||
example['amb.sjis'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&RA))4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25"
 | 
			
		||||
M,#$E0C`Q)4(P,25",#$E0C`Q)4(;*$(*&RA))4(P,25",#$E0C`Q)4(P,25"
 | 
			
		||||
M,#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(;
 | 
			
		||||
M*$(*&RA))4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P
 | 
			
		||||
M,25",#$E0C`Q)4(P,25",#$E0C`Q)4(;*$(*&RA))4(P,25",#$E0C`Q)4(P
 | 
			
		||||
M,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q
 | 
			
		||||
M)4(;*$(*&RA))4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q
 | 
			
		||||
>)4(P,25",#$E0C`Q)4(P,25",#$E0C`Q)4(;*$(*
 | 
			
		||||
eofeof
 | 
			
		||||
 | 
			
		||||
example['x0201.sjis'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
MD5.*<(-*@TR#3H-0@U*#2X--@T^#48-3"I%3B7""8()A@F*"8X)D@F6"9H*!
 | 
			
		||||
M@H*"@X*$@H6"AH*'"I%3BTR-AH%)@9>!E(&0@9.!3X&5@9:!:8%J@7R!>X&!
 | 
			
		||||
M@6V!;H%O@7"!CPJ4O(IPMK>X/;FZMMZWWKC>N=ZZWH+&"I2\BG#*W\O?S-_-
 | 
			
		||||
MW\[?M]^QW@K*W\O?S`IH86YK86MU(,K?R]_,I`K*W\O?S-VA"I2\BG""S(SC
 | 
			
		||||
!"@!"
 | 
			
		||||
eofeof
 | 
			
		||||
#'
 | 
			
		||||
 | 
			
		||||
example['x0201.euc'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
MP;2ST:6KI:VEKZ6QI;.EK*6NI;"ELJ6T"L&TL=&CP:/"H\.CQ*/%H\:CQZ/A
 | 
			
		||||
MH^*CXZ/DH^6CYJ/G"L&TM:VYYJ&JH?>A]*'PH?.AL*'UH?:ARJ'+H=VAW*'A
 | 
			
		||||
MH<ZASZ'0H=&A[PK(OK/1CK:.MXZX/8ZYCKJ.MH[>CK>.WHZXCMZ.N8[>CKJ.
 | 
			
		||||
MWJ3("LB^L]&.RH[?CLN.WX[,CM^.S8[?CLZ.WXZWCM^.L8[>"H[*CM^.RX[?
 | 
			
		||||
MCLP*:&%N:V%K=2".RH[?CLN.WX[,CJ0*CLJ.WX[+CM^.S([=CJ$*R+ZST:3.
 | 
			
		||||
#N.4*
 | 
			
		||||
eofeof
 | 
			
		||||
#'
 | 
			
		||||
 | 
			
		||||
example['x0201.jis'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&R1"030S424K)2TE+R4Q)3,E+"4N)3`E,B4T&RA""ALD0D$T,5$C02-"(T,C
 | 
			
		||||
M1"-%(T8C1R-A(V(C8R-D(V4C9B-G&RA""ALD0D$T-2TY9B$J(7<A="%P(7,A
 | 
			
		||||
M,"%U(78A2B%+(5TA7"%A(4XA3R%0(5$A;QLH0@H;)$)(/C-1&RA)-C<X&RA"
 | 
			
		||||
M/1LH23DZ-EXW7CA>.5XZ7ALD0B1(&RA""ALD0D@^,U$;*$E*7TM?3%]-7TY?
 | 
			
		||||
M-U\Q7ALH0@H;*$E*7TM?3!LH0@IH86YK86MU(!LH24I?2U],)!LH0@H;*$E*
 | 
			
		||||
97TM?3%TA&RA""ALD0D@^,U$D3CAE&RA""@``
 | 
			
		||||
eofeof
 | 
			
		||||
#`
 | 
			
		||||
 | 
			
		||||
example['x0201.sosi'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&R1"030S424K)2TE+R4Q)3,E+"4N)3`E,B4T&RA*"ALD0D$T,5$C02-"(T,C
 | 
			
		||||
M1"-%(T8C1R-A(V(C8R-D(V4C9B-G&RA*"ALD0D$T-2TY9B$J(7<A="%P(7,A
 | 
			
		||||
M,"%U(78A2B%+(5TA7"%A(4XA3R%0(5$A;QLH2@H;)$)(/C-1&RA*#C8W.`\;
 | 
			
		||||
M*$H]#CDZ-EXW7CA>.5XZ7@\;)$(D2!LH2@H;)$)(/C-1&RA*#DI?2U],7TU?
 | 
			
		||||
M3E\W7S%>#PH.2E]+7TP/&RA*"FAA;FMA:W4@#DI?2U],)`\;*$H*#DI?2U],
 | 
			
		||||
672$/&RA*"ALD0D@^,U$D3CAE&RA""@``
 | 
			
		||||
eofeof
 | 
			
		||||
#"
 | 
			
		||||
 | 
			
		||||
example['x0201.x0208'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&R1"030S424K)2TE+R4Q)3,E+"4N)3`E,B4T&RA""ALD0D$T,5$;*$)!0D-$
 | 
			
		||||
M149'86)C9&5F9PH;)$)!-#4M.68;*$(A0",D)5XF*B@I+2L]6UU[?1LD0B%O
 | 
			
		||||
M&RA""ALD0D@^,U$E*R4M)2\;*$(]&R1")3$E,R4L)2XE,"4R)30D2!LH0@H;
 | 
			
		||||
M)$)(/C-1)5$E5"57)5HE724M(2PE(B$K&RA""ALD0B51)50E51LH0@IH86YK
 | 
			
		||||
M86MU(!LD0B51)50E52$B&RA""ALD0B51)50E525S(2,;*$(*&R1"2#XS421.
 | 
			
		||||
&.&4;*$(*
 | 
			
		||||
eofeof
 | 
			
		||||
#`
 | 
			
		||||
 | 
			
		||||
example['mime.iso2022'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M/3])4T\M,C`R,BU*4#]"/T=Y4D%.144W96E23TI566Q/4U9)1WEH2S\]"CT_
 | 
			
		||||
M:7-O+3(P,C(M2E`_0C]'>5)!3D5%-V5I4D]*55EL3U-624=Y:$L_/0H]/VES
 | 
			
		||||
M;RTR,#(R+4I0/U$_/3%")$(D1B11/3%"*$)?96YD/ST*&R1`)#TD)B0K)$H;
 | 
			
		||||
M*$H@/3])4T\M,C`R,BU*4#]"/T=Y4D%.144W96E23U!Y:S=D:'-O4V<]/3\]
 | 
			
		||||
M(&5N9"!O9B!L:6YE"CT_25-/+3(P,C(M2E`_0C]'>5)!3D5%-V5I4D]0>6LW
 | 
			
		||||
M9&AS;U-G/3T_/2`]/TE33RTR,#(R+4I0/T(_1WE204Y%13=E:5)/4'EK-V1H
 | 
			
		||||
M<V]39ST]/ST*0G)O:V5N(&-A<V4*/3])4T\M,C`R,BU*4#]"/T=Y4D%.144W
 | 
			
		||||
M96E23U!Y:S=D"FAS;U-G/3T_/2`]/TE33RTR,`HR,BU*4#]"/T=Y4D%.144W
 | 
			
		||||
M96E23U!Y:S=D:'-O4V<]/3\]"CT_25-/+3(P,C(M2E`_0C]'>5)!3D5%-V5I
 | 
			
		||||
44D]*55EL3QM;2U-624=Y:$L_/0H_
 | 
			
		||||
eofeof
 | 
			
		||||
#'
 | 
			
		||||
 | 
			
		||||
example['mime.ans.strict'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&R1"-$$[>B1.)48E.25(&RA""ALD0C1!.WHD3B5&)3DE2!LH0@H;)$(D1B11
 | 
			
		||||
M&RA"(&5N9`H;)$(D/20F)"LD2ALH0B`;)$(T03MZ)$X_*3MV&RA"96YD(&]F
 | 
			
		||||
M(&QI;F4*&R1"-$$[>B1./RD[=C1!.WHD3C\I.W8;*$(*0G)O:V5N(&-A<V4*
 | 
			
		||||
M/3])4T\M,C`R,BU*4#]"/T=Y4D%.144W96E23U!Y:S=D"FAS;U-G/3T_/2`]
 | 
			
		||||
M/TE33RTR,`HR,BU*4#]"/T=Y4D%.144W96E23U!Y:S=D:'-O4V<]/3\]"CT_
 | 
			
		||||
L25-/+3(P,C(M2E`_0C]'>5)!3D5%-V5I4D]*55EL3QM;2U-624=Y:$L_/0H_
 | 
			
		||||
eofeof
 | 
			
		||||
#'
 | 
			
		||||
 | 
			
		||||
example['mime.unbuf.strict'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&R1"-$$[>B1.)48E.25(&RA""ALD0C1!.WHD3B5&)3DE2!LH0@H;)$(D1B11
 | 
			
		||||
M&RA"(&5N9`H;)$(D/20F)"LD2ALH0B`;)$(T03MZ)$X_*3MV&RA"96YD(&]F
 | 
			
		||||
M(&QI;F4*&R1"-$$[>B1./RD[=C1!.WHD3C\I.W8;*$(*0G)O:V5N(&-A<V4*
 | 
			
		||||
M&R1"-$$[>B1./RD;*$)H<V]39ST]/ST@/3])4T\M,C`*,C(M2E`_0C]'>5)!
 | 
			
		||||
M3D5%-V5I4D]0>6LW9&AS;U-G/3T_/0H;)$(T03MZ)$XE1ALH0EM+4U9)1WEH
 | 
			
		||||
$2S\]"F5I
 | 
			
		||||
eofeof
 | 
			
		||||
 | 
			
		||||
example['mime.ans'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&R1"-$$[>B1.)48E.25(&RA""ALD0C1!.WHD3B5&)3DE2!LH0@H;)$(D1B11
 | 
			
		||||
M&RA"(&5N9`H;)$(D/20F)"LD2ALH0B`;)$(T03MZ)$X_*3MV&RA"96YD(&]F
 | 
			
		||||
M(&QI;F4*&R1"-$$[>B1./RD[=C1!.WHD3C\I.W8;*$(*0G)O:V5N(&-A<V4*
 | 
			
		||||
M&R1"-$$[>B1./RD;*$)H<V]39ST]/ST@&R1"-$$[>B1./RD[=ALH0@H;)$(T
 | 
			
		||||
603MZ)$XE1ALH0EM+4U9)1WEH2S\]"@`*
 | 
			
		||||
eofeof
 | 
			
		||||
#"
 | 
			
		||||
 | 
			
		||||
example['mime.unbuf'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&R1"-$$[>B1.)48E.25(&RA""ALD0C1!.WHD3B5&)3DE2!LH0@H;)$(D1B11
 | 
			
		||||
M&RA"(&5N9`H;)$(D/20F)"LD2ALH0B`;)$(T03MZ)$X_*3MV&RA"96YD(&]F
 | 
			
		||||
M(&QI;F4*&R1"-$$[>B1./RD[=C1!.WHD3C\I.W8;*$(*0G)O:V5N(&-A<V4*
 | 
			
		||||
M&R1"-$$[>B1./RD;*$)H<V]39ST]/ST@&R1"-$$[>B1./RD[=ALH0@H;)$(T
 | 
			
		||||
603MZ)$XE1ALH0EM+4U9)1WEH2S\]"@`*
 | 
			
		||||
eofeof
 | 
			
		||||
#"
 | 
			
		||||
 | 
			
		||||
example['mime.base64'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M9W-M5"])3&YG<FU#>$I+-&=Q=4,S24LS9W%Q0E%:3TUI-39,,S0Q-&=S5T)1
 | 
			
		||||
M43!+9VUA1%9O3T@*9S)+1%1O3'=K8C)1;$E+;V=Q2T-X24MG9W5M0W%*3EEG
 | 
			
		||||
<<T=#>$E+9V=U;4,X64Q&9W)70S592VMG<6U""F=Q
 | 
			
		||||
eofeof
 | 
			
		||||
#"
 | 
			
		||||
 | 
			
		||||
example['mime.base64.ans'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M&R1")$M&?B1I)#LD1D0Z)"TD7B0Y)"PA(D5L-7XV83E9)$<A(ALH0@T*&R1"
 | 
			
		||||
M(T<E-R5G)4,E+R1R0C\_="0J)"0D1B0B)&LD*D4Y)$,D1B0B)&LD<R1')#<D
 | 
			
		||||
(9R0F)"L;*$(E
 | 
			
		||||
eofeof
 | 
			
		||||
#'
 | 
			
		||||
 | 
			
		||||
example['mime.is8859'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M/3])4T\M.#@U.2TQ/U$_*CU#-V%V83\_/2`*4&5E<B!4]G)N9W)E;@I,87-S
 | 
			
		||||
M92!(:6QL97+X92!0971E<G-E;B`@7"`B36EN(&MA97!H97-T(&AA<B!F86%E
 | 
			
		||||
M="!E="!F;V5L(2(*06%R:'5S(%5N:79E<G-I='DL($1%3DU!4DL@(%P@(DUI
 | 
			
		||||
<;B!KYG!H97-T(&AA<B!FY65T(&5T(&;X;"$B"@!K
 | 
			
		||||
eofeof
 | 
			
		||||
 | 
			
		||||
example['mime.is8859.ans'] = <<'eofeof'.unpack('u')[0]
 | 
			
		||||
M*L=A=F$_(`I0965R(%3V<FYG<F5N"DQA<W-E($AI;&QE<OAE(%!E=&5R<V5N
 | 
			
		||||
M("!<(")-:6X@:V%E<&AE<W0@:&%R(&9A865T(&5T(&9O96PA(@I!87)H=7,@
 | 
			
		||||
M56YI=F5R<VET>2P@1$5.34%22R`@7"`B36EN(&OF<&AE<W0@:&%R(&;E970@
 | 
			
		||||
)970@9OAL(2(*
 | 
			
		||||
eofeof
 | 
			
		||||
#"
 | 
			
		||||
 | 
			
		||||
print 'JIS  to JIS ... '; test('  ', example['jis'], example['jis'])
 | 
			
		||||
print 'JIS  to SJIS... '; test('-s', example['jis'], example['sjis'])
 | 
			
		||||
print 'JIS  to EUC ... '; test('-e', example['jis'], example['euc'])
 | 
			
		||||
 | 
			
		||||
print 'SJIS to JIS ... '; test('-j', example['sjis'], example['jis'])
 | 
			
		||||
print 'SJIS to SJIS... '; test('-s', example['sjis'], example['sjis'])
 | 
			
		||||
print 'SJIS to EUC ... '; test('-e', example['sjis'], example['euc'])
 | 
			
		||||
 | 
			
		||||
print 'EUC  to JIS ... '; test('  ', example['euc'], example['jis'])
 | 
			
		||||
print 'EUC  to SJIS... '; test('-s', example['euc'], example['sjis'])
 | 
			
		||||
print 'EUC  to EUC ... '; test('-e', example['euc'], example['euc'])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Ambigous Case
 | 
			
		||||
print 'Ambiguous Case. '; test(''  , example['amb'], example['amb.euc'])
 | 
			
		||||
 | 
			
		||||
# Input assumption
 | 
			
		||||
print 'SJIS  Input assumption '
 | 
			
		||||
test('-Sx', example['amb'], example['amb.sjis'])
 | 
			
		||||
 | 
			
		||||
# X0201 ²¾Ì¾
 | 
			
		||||
# X0201->X0208 conversion
 | 
			
		||||
# X0208 aphabet -> ASCII
 | 
			
		||||
# X0201 Áê¸ßÊÑ´¹
 | 
			
		||||
 | 
			
		||||
print "\nX0201 test\n\n"
 | 
			
		||||
 | 
			
		||||
# -X is necessary to allow X0201 in SJIS
 | 
			
		||||
# -Z convert X0208 alphabet to ASCII
 | 
			
		||||
print 'X0201 conversion: SJIS '
 | 
			
		||||
test('-XZ', example['x0201.sjis'], example['x0201.x0208'])
 | 
			
		||||
print 'X0201 conversion: JIS  '
 | 
			
		||||
test('-Z',  example['x0201.jis'],  example['x0201.x0208'])
 | 
			
		||||
print 'X0201 conversion:SI/SO '
 | 
			
		||||
test('-Z',  example['x0201.sosi'], example['x0201.x0208'])
 | 
			
		||||
print 'X0201 conversion: EUC  '
 | 
			
		||||
test('-Z',  example['x0201.euc'],  example['x0201.x0208'])
 | 
			
		||||
# -x means X0201 output
 | 
			
		||||
print 'X0201 output: SJIS     '
 | 
			
		||||
test('-xs', example['x0201.euc'],  example['x0201.sjis'])
 | 
			
		||||
print 'X0201 output: JIS      '
 | 
			
		||||
test('-xj', example['x0201.sjis'], example['x0201.jis'])
 | 
			
		||||
print 'X0201 output: EUC      '
 | 
			
		||||
test('-xe', example['x0201.jis'],  example['x0201.euc'])
 | 
			
		||||
 | 
			
		||||
# MIME decode
 | 
			
		||||
 | 
			
		||||
print "\nMIME test\n\n"
 | 
			
		||||
 | 
			
		||||
# MIME ISO-2022-JP
 | 
			
		||||
 | 
			
		||||
print "Next test is expeced to Fail.\n"
 | 
			
		||||
 | 
			
		||||
print 'MIME decode (strict)   '
 | 
			
		||||
tmp = test('-m', example['mime.iso2022'], example['mime.ans.strict'])
 | 
			
		||||
print 'MIME decode (nonstrict)'
 | 
			
		||||
tmp = test('-m', example['mime.iso2022'], example['mime.ans'])
 | 
			
		||||
#    open(OUT,'>tmp1');print OUT pack('u',$tmp);close(OUT);
 | 
			
		||||
# unbuf mode implies more pessimistic decode
 | 
			
		||||
print 'MIME decode (unbuf)    '
 | 
			
		||||
test('-mu', example['mime.iso2022'], example['mime.unbuf'])
 | 
			
		||||
print 'MIME decode (base64)   '
 | 
			
		||||
t = test('-mB', example['mime.base64'],  example['mime.base64.ans'])
 | 
			
		||||
 | 
			
		||||
# MIME ISO-8859-1
 | 
			
		||||
 | 
			
		||||
# Without -l, ISO-8859-1 was handled as X0201.
 | 
			
		||||
 | 
			
		||||
print 'MIME ISO-8859-1 (Q)    '
 | 
			
		||||
test('-ml', example['mime.is8859'], example['mime.is8859.ans'])
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue