1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/iconv/iconv.c (map_charset): use lower case keys.

* ext/iconv/iconv.c (iconv_fail): just yield error and return the
  result if a block is given.

* ext/iconv/iconv.c (iconv_convert): yield error and append the
  result if a block is given.

* ext/iconv/charset_alias.rb (charset_alias): optional third
  argument.

* ext/iconv/charset_alias.rb (charset_alias): use CP932 instead of
  SHIFT_JIS on cygwin.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-09-01 15:41:31 +00:00
parent 6f8f0a86f5
commit 26fcfd1bb5
3 changed files with 57 additions and 12 deletions

View file

@ -1,3 +1,19 @@
Tue Sep 2 00:41:27 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/iconv/iconv.c (map_charset): use lower case keys.
* ext/iconv/iconv.c (iconv_fail): just yield error and return the
result if a block is given.
* ext/iconv/iconv.c (iconv_convert): yield error and append the
result if a block is given.
* ext/iconv/charset_alias.rb (charset_alias): optional third
argument.
* ext/iconv/charset_alias.rb (charset_alias): use CP932 instead of
SHIFT_JIS on cygwin.
Mon Sep 1 18:34:25 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Sep 1 18:34:25 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_eval): make tail recursion in ELSE clause of * eval.c (rb_eval): make tail recursion in ELSE clause of

View file

@ -1,16 +1,16 @@
#! /usr/bin/ruby #! /usr/bin/ruby
require 'rbconfig' require 'rbconfig'
# http://www.ctan.org/tex-archive/macros/texinfo/texinfo/intl/config.charset' # http://www.ctan.org/tex-archive/macros/texinfo/texinfo/intl/config.charset
# Fri, 30 May 2003 00:09:00 GMT' # Fri, 30 May 2003 00:09:00 GMT'
OS = Config::CONFIG["target"] OS = Config::CONFIG["target"]
SHELL = Config::CONFIG['SHELL'] SHELL = Config::CONFIG['SHELL']
def charset_alias(config_charset, mapfile) def charset_alias(config_charset, mapfile, target = OS)
map = {} map = {}
comments = [] comments = []
IO.foreach("|#{SHELL} #{config_charset} #{OS}") do |list| IO.foreach("|#{SHELL} #{config_charset} #{target}") do |list|
next comments << list if /^\#/ =~ list next comments << list if /^\#/ =~ list
next unless /^(\S+)\s+(\S+)$/ =~ list next unless /^(\S+)\s+(\S+)$/ =~ list
sys, can = $1, $2 sys, can = $1, $2
@ -18,9 +18,12 @@ def charset_alias(config_charset, mapfile)
next if can.downcase! and sys == can next if can.downcase! and sys == can
map[can] = sys map[can] = sys
end end
case OS case target
when /linux|-gnu/ when /linux|-gnu/
map.delete('ascii') map.delete('ascii')
when /cygwin/
# get rid of tilde/yen problem.
map['shift_jis'] = 'cp932'
end end
open(mapfile, "w") do |f| open(mapfile, "w") do |f|
f.puts("require 'iconv.so'") f.puts("require 'iconv.so'")
@ -32,5 +35,5 @@ def charset_alias(config_charset, mapfile)
end end
end end
ARGV.size == 2 or abort "usage: #$0 config.status map.rb" (2..3) === ARGV.size or abort "usage: #$0 config.status map.rb [target]"
charset_alias(*ARGV) charset_alias(*ARGV)

View file

@ -59,6 +59,7 @@ static VALUE rb_eIconvOutOfRange;
static ID rb_inserter; static ID rb_inserter;
static ID rb_success, rb_failed, rb_mesg; static ID rb_success, rb_failed, rb_mesg;
static VALUE iconv_fail _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env));
static VALUE iconv_failure_initialize _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env)); static VALUE iconv_failure_initialize _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env));
static VALUE iconv_failure_success _((VALUE self)); static VALUE iconv_failure_success _((VALUE self));
static VALUE iconv_failure_failed _((VALUE self)); static VALUE iconv_failure_failed _((VALUE self));
@ -108,13 +109,17 @@ map_charset
{ {
VALUE val = *code; VALUE val = *code;
StringValuePtr(val);
if (RHASH(charset_map)->tbl && RHASH(charset_map)->tbl->num_entries) { if (RHASH(charset_map)->tbl && RHASH(charset_map)->tbl->num_entries) {
val = rb_funcall2(val, rb_intern("downcase"), 0, 0);
StringValuePtr(val);
if (st_lookup(RHASH(charset_map)->tbl, val, &val)) { if (st_lookup(RHASH(charset_map)->tbl, val, &val)) {
StringValuePtr(val); StringValuePtr(val);
*code = val; *code = val;
} }
} }
else {
StringValuePtr(val);
}
return RSTRING(val)->ptr; return RSTRING(val)->ptr;
} }
@ -231,9 +236,6 @@ iconv_try
return Qfalse; return Qfalse;
} }
#define iconv_fail(error, success, failed, env) \
rb_exc_raise(iconv_failure_initialize(error, success, failed, env))
#define FAILED_MAXLEN 16 #define FAILED_MAXLEN 16
static VALUE static VALUE
@ -270,6 +272,21 @@ iconv_failure_initialize
return error; return error;
} }
static VALUE
iconv_fail
#ifdef HAVE_PROTOTYPES
(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env)
#else /* HAVE_PROTOTYPES */
(error, success, failed, env)
VALUE error, success, failed;
struct iconv_env_t *env;
#endif /* HAVE_PROTOTYPES */
{
error = iconv_failure_initialize(error, success, failed, env);
if (!rb_block_given_p()) rb_exc_raise(error);
return rb_yield(error);
}
static VALUE static VALUE
rb_str_derive rb_str_derive
#ifdef HAVE_PROTOTYPES #ifdef HAVE_PROTOTYPES
@ -327,8 +344,17 @@ iconv_convert
outptr = buffer; outptr = buffer;
outlen = sizeof(buffer); outlen = sizeof(buffer);
error = iconv_try(cd, &inptr, &inlen, &outptr, &outlen); error = iconv_try(cd, &inptr, &inlen, &outptr, &outlen);
if (error) if (error) {
iconv_fail(error, Qnil, Qnil, env); unsigned int i;
str = iconv_fail(error, Qnil, Qnil, env);
if (FIXNUM_P(str) && (i = FIX2INT(str)) <= 0xff) {
char c = i;
str = rb_str_new(&c, 1);
}
else if (!NIL_P(str)) {
StringValue(str);
}
}
inptr = NULL; inptr = NULL;
length = 0; length = 0;
@ -395,7 +421,7 @@ iconv_convert
if (!ret) if (!ret)
ret = rb_str_derive(str, instart, inptr - instart); ret = rb_str_derive(str, instart, inptr - instart);
str = rb_str_derive(str, inptr, inlen); str = rb_str_derive(str, inptr, inlen);
iconv_fail(error, ret, str, env); rb_str_concat(str, iconv_fail(error, ret, str, env));
} }
} while (inlen > 0); } while (inlen > 0);