mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
2833d9f95d
from_utf8 field removed. * tool/transcode-tblgen.rb: generate offsets range. follow rb_transcoder change. * transcode.c (transcode_loop): don't use from_utf8. make invalid region from_unit_length wise. * enc/trans/iso2022.erb.c: follow rb_transcoder and transcode_generate_node change. * enc/trans/utf_16_32.erb.c: follow rb_transcoder and transcode_generate_node change. explicit :invalid map removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
89 lines
3.6 KiB
C
89 lines
3.6 KiB
C
/**********************************************************************
|
|
|
|
transcode_data.h -
|
|
|
|
$Author$
|
|
created at: Mon 10 Dec 2007 14:01:47 JST 2007
|
|
|
|
Copyright (C) 2007 Martin Duerst
|
|
|
|
**********************************************************************/
|
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#ifndef RUBY_TRANSCODE_DATA_H
|
|
#define RUBY_TRANSCODE_DATA_H 1
|
|
|
|
typedef unsigned char base_element;
|
|
|
|
typedef struct byte_lookup {
|
|
const base_element *base;
|
|
const struct byte_lookup *const *info;
|
|
} BYTE_LOOKUP;
|
|
|
|
#ifndef PType
|
|
/* data file needs to treat this as a pointer, to remove warnings */
|
|
#define PType (const BYTE_LOOKUP *)
|
|
#endif
|
|
|
|
#define NOMAP (PType 0x01) /* single byte direct map */
|
|
#define ONEbt (0x02) /* one byte payload */
|
|
#define TWObt (0x03) /* two bytes payload */
|
|
#define THREEbt (0x05) /* three bytes payload */
|
|
#define FOURbt (0x06) /* four bytes payload, UTF-8 only, macros start at getBT0 */
|
|
#define INVALID (PType 0x07) /* invalid byte sequence */
|
|
#define UNDEF (PType 0x09) /* legal but undefined */
|
|
#define ZERObt (PType 0x0A) /* zero bytes of payload, i.e. remove */
|
|
#define FUNii (PType 0x0B) /* function from info to info */
|
|
#define FUNsi (PType 0x0D) /* function from start to info */
|
|
#define FUNio (PType 0x0E) /* function from info to output */
|
|
#define FUNso (PType 0x0F) /* function from start to output */
|
|
|
|
#define o1(b1) (PType((((unsigned char)(b1))<<8)|ONEbt))
|
|
#define o2(b1,b2) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|TWObt))
|
|
#define o3(b1,b2,b3) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|(((unsigned char)(b3))<<24)|THREEbt))
|
|
#define o4(b0,b1,b2,b3) (PType((((unsigned char)(b1))<< 8)|(((unsigned char)(b2))<<16)|(((unsigned char)(b3))<<24)|((((unsigned char)(b0))&0x07)<<5)|FOURbt))
|
|
|
|
#define getBT1(a) (((a)>> 8)&0xFF)
|
|
#define getBT2(a) (((a)>>16)&0xFF)
|
|
#define getBT3(a) (((a)>>24)&0xFF)
|
|
#define getBT0(a) ((((a)>> 5)&0x07)|0xF0) /* for UTF-8 only!!! */
|
|
|
|
#define o2FUNii(b1,b2) (PType((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|FUNii))
|
|
|
|
/* do we need these??? maybe not, can be done with simple tables */
|
|
#define ONETRAIL /* legal but undefined if one more trailing UTF-8 */
|
|
#define TWOTRAIL /* legal but undefined if two more trailing UTF-8 */
|
|
#define THREETRAIL /* legal but undefined if three more trailing UTF-8 */
|
|
|
|
/* dynamic structure, one per conversion (similar to iconv_t) */
|
|
/* may carry conversion state (e.g. for iso-2022-jp) */
|
|
typedef struct rb_transcoding {
|
|
const struct rb_transcoder *transcoder;
|
|
VALUE ruby_string_dest; /* the String used as the conversion destination,
|
|
or NULL if something else is being converted */
|
|
unsigned char *(*flush_func)(struct rb_transcoding*, int, int);
|
|
|
|
unsigned char stateful[256]; /* opaque data for stateful encoding */
|
|
} rb_transcoding;
|
|
|
|
/* static structure, one per supported encoding pair */
|
|
typedef struct rb_transcoder {
|
|
const char *from_encoding;
|
|
const char *to_encoding;
|
|
const BYTE_LOOKUP *conv_tree_start;
|
|
int from_unit_length;
|
|
int max_output;
|
|
VALUE (*func_ii)(rb_transcoding*, VALUE); /* info -> info */
|
|
VALUE (*func_si)(rb_transcoding*, const unsigned char*, size_t); /* start -> info */
|
|
int (*func_io)(rb_transcoding*, VALUE, const unsigned char*); /* info -> output */
|
|
int (*func_so)(rb_transcoding*, const unsigned char*, size_t, unsigned char*); /* start -> output */
|
|
int (*finish_func)(rb_transcoding*, unsigned char*); /* -> output */
|
|
} rb_transcoder;
|
|
|
|
void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib);
|
|
void rb_register_transcoder(const rb_transcoder *);
|
|
|
|
#define TRANSCODE_ERROR rb_eRuntimeError /*change exception*/
|
|
|
|
#endif /* RUBY_TRANSCODE_DATA_H */
|