/********************************************************************** encoding.c - $Author: matz $ $Date: 2007-05-24 17:22:33 +0900 (Thu, 24 May 2007) $ created at: Thu May 24 17:23:27 JST 2007 Copyright (C) 2007 Yukihiro Matsumoto **********************************************************************/ #include "ruby/ruby.h" #include "ruby/encoding.h" #include "regenc.h" static ID id_encoding; struct rb_encoding_entry { const char *name; rb_encoding *enc; }; static struct rb_encoding_entry *enc_table; static int enc_table_size; void rb_enc_register(const char *name, rb_encoding *encoding) { struct rb_encoding_entry *ent; if (!enc_table) { enc_table = malloc(sizeof(struct rb_encoding_entry)); enc_table_size = 1; } else { enc_table_size++; enc_table = realloc(enc_table, sizeof(struct rb_encoding_entry)*enc_table_size); } ent = &enc_table[enc_table_size-1]; ent->name = name; ent->enc = encoding; } void rb_enc_init(void) { rb_enc_register("ascii", ONIG_ENCODING_ASCII); rb_enc_register("sjis", ONIG_ENCODING_SJIS); rb_enc_register("euc-jp", ONIG_ENCODING_EUC_JP); rb_enc_register("utf-8", ONIG_ENCODING_UTF8); } rb_encoding * rb_enc_from_index(int index) { if (!enc_table) { rb_enc_init(); } if (index < 0 || enc_table_size <= index) { return 0; } return enc_table[index].enc; } rb_encoding * rb_enc_find(const char *name) { int i; if (!enc_table) { rb_enc_init(); } for (i=0; i