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

* ext/nkf/nkf-utf8/nkf.c (nkf_str_caseeql): added.

* ext/nkf/nkf-utf8/nkf.c (nkf_enc_find_index): use nkf_str_caseeql.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2008-05-21 21:23:51 +00:00
parent 989c8ed00a
commit 404de438af
2 changed files with 21 additions and 17 deletions

View file

@ -1,3 +1,9 @@
Thu May 22 06:21:34 2008 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/nkf-utf8/nkf.c (nkf_str_caseeql): added.
* ext/nkf/nkf-utf8/nkf.c (nkf_enc_find_index): use nkf_str_caseeql.
Thu May 22 05:45:30 2008 Yukihiro Matsumoto <matz@ruby-lang.org> Thu May 22 05:45:30 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* proc.c (proc_dup): should copy safe_level from src proc * proc.c (proc_dup): should copy safe_level from src proc

View file

@ -653,14 +653,15 @@ static int end_check;
nkf_char std_gc_buf[STD_GC_BUFSIZE]; nkf_char std_gc_buf[STD_GC_BUFSIZE];
nkf_char std_gc_ndx; nkf_char std_gc_ndx;
static void static int
nkf_str_upcase(const char *src, char *dest, size_t length) nkf_str_caseeql(const char *src, const char *target)
{ {
int i = 0; int i;
for (; i < length && src[i]; i++) { for (i = 0; src[i] && target[i]; i++) {
dest[i] = nkf_toupper(src[i]); if (nkf_toupper(src[i]) != nkf_toupper(target[i])) return FALSE;
} }
dest[i] = 0; if (src[i] || target[i]) return FALSE;
else return TRUE;
} }
static nkf_encoding* static nkf_encoding*
@ -675,14 +676,14 @@ nkf_enc_from_index(int idx)
static int static int
nkf_enc_find_index(const char *name) nkf_enc_find_index(const char *name)
{ {
int i, index = -1; int i;
if (*name == 'X' && *(name+1) == '-') name += 2; if (name[0] == 'X' && *(name+1) == '-') name += 2;
for (i = 0; encoding_name_to_id_table[i].id >= 0; i++) { for (i = 0; encoding_name_to_id_table[i].id >= 0; i++) {
if (strcasecmp(name, encoding_name_to_id_table[i].name) == 0) { if (nkf_str_caseeql(encoding_name_to_id_table[i].name, name)) {
return encoding_name_to_id_table[i].id; return encoding_name_to_id_table[i].id;
} }
} }
return index; return -1;
} }
static nkf_encoding* static nkf_encoding*
@ -914,8 +915,7 @@ get_backup_filename(const char *suffix, const char *filename)
} }
backup_filename[j] = '\0'; backup_filename[j] = '\0';
}else{ }else{
j = strlen(suffix) + filename_length; backup_filename = malloc(filename_length + strlen(suffix) + 1);
backup_filename = malloc( + 1);
strcpy(backup_filename, filename); strcpy(backup_filename, filename);
strcat(backup_filename, suffix); strcat(backup_filename, suffix);
backup_filename[j] = '\0'; backup_filename[j] = '\0';
@ -5693,7 +5693,6 @@ options(unsigned char *cp)
nkf_char i, j; nkf_char i, j;
unsigned char *p; unsigned char *p;
unsigned char *cp_back = NULL; unsigned char *cp_back = NULL;
char codeset[32];
nkf_encoding *enc; nkf_encoding *enc;
if (option_mode==1) if (option_mode==1)
@ -5733,15 +5732,13 @@ options(unsigned char *cp)
cp = (unsigned char *)long_option[i].alias; cp = (unsigned char *)long_option[i].alias;
}else{ }else{
if (strcmp(long_option[i].name, "ic=") == 0){ if (strcmp(long_option[i].name, "ic=") == 0){
nkf_str_upcase((char *)p, codeset, 32); enc = nkf_enc_find((char *)p);
enc = nkf_enc_find(codeset);
if (!enc) continue; if (!enc) continue;
input_encoding = enc; input_encoding = enc;
continue; continue;
} }
if (strcmp(long_option[i].name, "oc=") == 0){ if (strcmp(long_option[i].name, "oc=") == 0){
nkf_str_upcase((char *)p, codeset, 32); enc = nkf_enc_find((char *)p);
enc = nkf_enc_find(codeset);
if (enc <= 0) continue; if (enc <= 0) continue;
output_encoding = enc; output_encoding = enc;
continue; continue;
@ -6490,6 +6487,7 @@ main(int argc, char **argv)
fprintf(stderr, "Can't rename %s to %s\n", fprintf(stderr, "Can't rename %s to %s\n",
origfname, backup_filename); origfname, backup_filename);
} }
free(backup_filename);
}else{ }else{
#ifdef MSDOS #ifdef MSDOS
if (unlink(origfname)){ if (unlink(origfname)){