Exemple #1
0
rb_encoding* rb_nkf_enc_get(const char *name)
{
#if 0
    int idx = rb_enc_find_index(name);
    if (idx < 0) {
	nkf_encoding *nkf_enc = nkf_enc_find(name);
	idx = rb_enc_find_index(nkf_enc_name(nkf_enc_to_base_encoding(nkf_enc)));
	if (idx < 0) {
	    idx = rb_define_dummy_encoding(name);
	} else {
	    rb_encoding *rb_enc = rb_enc_from_index(idx);
	    idx = rb_enc_replicate(name, rb_enc);
	}
    }
    return rb_enc_from_index(idx);
#else
	struct nkf_osx_name_enc_table { 
	  const char*      name; 
	  CFStringEncoding enc;
	};

	static struct nkf_osx_name_enc_table table[] = {
	  { "BINARY",      kCFStringEncodingNonLossyASCII },
	  { "US-ASCII",    kCFStringEncodingASCII  	},
	  { "ISO-2022-JP", kCFStringEncodingISO_2022_JP  	},
	  { "ISO-2022-JP-1", kCFStringEncodingISO_2022_JP_1  	},
	  { "ISO-2022-JP-2", kCFStringEncodingISO_2022_JP_2  	},
	  { "ISO-2022-JP-3", kCFStringEncodingISO_2022_JP_3  	},
	  { "EUC-JP",      kCFStringEncodingEUC_JP },
	  { "Shift_JIS",   kCFStringEncodingShiftJIS 	},
	  { "UTF-8",       kCFStringEncodingUTF8   	},
	  { "UTF-16",      kCFStringEncodingUTF16   },
	  { "UTF-16BE",    kCFStringEncodingUTF16BE },
	  { "UTF-16LE",    kCFStringEncodingUTF16LE },
	  { "UTF-32",      kCFStringEncodingUTF32   },
	  { "UTF-32BE",    kCFStringEncodingUTF32BE },
	  { "UTF-32LE",    kCFStringEncodingUTF32LE },
	  { NULL,          kCFStringEncodingNonLossyASCII }
	};

	struct nkf_osx_name_enc_table* ptr = table;
	while (ptr->name) {
	  if (strcmp(name, ptr->name) == 0)
		return &(ptr->enc);
	  ptr++;
	}
	return &(ptr->enc);
#endif
}
Exemple #2
0
rb_encoding* rb_nkf_enc_get(const char *name)
{
    int idx = rb_enc_find_index(name);
    if (idx < 0) {
	nkf_encoding *nkf_enc = nkf_enc_find(name);
	idx = rb_enc_find_index(nkf_enc_name(nkf_enc_to_base_encoding(nkf_enc)));
	if (idx < 0) {
	    idx = rb_define_dummy_encoding(name);
	} else {
	    rb_encoding *rb_enc = rb_enc_from_index(idx);
	    idx = rb_enc_replicate(name, rb_enc);
	}
    }
    return rb_enc_from_index(idx);
}