aboutsummaryrefslogtreecommitdiffstats
path: root/transcode_data.h
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-10 05:01:47 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-10 05:01:47 +0000
commit7ded13f54b4963f9e535d4909c9957d33f68f1ed (patch)
tree09fb1cb466a3c7a3ab950361900e2dea9354796c /transcode_data.h
parent38a24d73c80acf6b7eba4e7ad6c958fd95de2f86 (diff)
downloadruby-7ded13f54b4963f9e535d4909c9957d33f68f1ed.tar.gz
* transcode.c: new file to provide encoding conversion features.
code contributed by Martin Duerst. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14172 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode_data.h')
-rw-r--r--transcode_data.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/transcode_data.h b/transcode_data.h
new file mode 100644
index 0000000000..42e0921458
--- /dev/null
+++ b/transcode_data.h
@@ -0,0 +1,40 @@
+typedef unsigned char base_element;
+typedef const void * const info_element;
+
+typedef struct byte_lookup {
+ const base_element *base;
+ const void * const * const info;
+} BYTE_LOOKUP;
+
+#ifdef TRANSCODE_DATA
+/* data file needs to treat this as a pointer, to remove warnings */
+#define PType (const void * const)
+#else
+/* in code, this is treated as just an integer */
+#define PType (int)
+#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 ILLEGAL (PType 0x07) /* illegal byte sequence */
+#define UNDEF (PType 0x09) /* legal but undefined */
+#define ZERObt (PType 0x0A) /* zero bytes of payload, i.e. remove */
+
+#define output1(b1) ((void*)((((unsigned char)(b1))<<8)|ONEbt))
+#define output2(b1,b2) ((void*)((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|TWObt))
+#define output3(b1,b2,b3) ((void*)((((unsigned char)(b1))<<8)|(((unsigned char)(b2))<<16)|(((unsigned char)(b3))<<24)|THREEbt))
+#define output4(b0,b1,b2,b3) ((void*)((((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!!! */
+
+/* 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 */
+