e$B$J$+$@$G$9!#e(B
enc/trans/utf_16_32.ce$B$N7Y9p$r>C$9%Q%C%A$G$9!#<+F0@8@.$H$$$&$3$He(B
e$B$J$N$G!"@8@.85$K$*4j$$$7$^$9!#e(B
e$B$A$J$_$K!“4X?tItJ,$O<j$G=q$$$?$N$G$O$J$$$+$H;W$o$l$k$N$G$9$,!”$Ie(B
e$B$N$h$&$J07$$$K$J$C$F$$$k$N$G$7$g$&$+!#e(B
Index: enc/trans/utf_16_32.c
— enc/trans/utf_16_32.c (revision 15146)
+++ enc/trans/utf_16_32.c (working copy)
@@ -5,27 +5,30 @@
static int
-fun_so_from_utf_16be(const unsigned char* s, unsigned char* o)
+fun_so_from_utf_16be(const char* s, char* o, struct rb_transcoding *td)
{
- if (!s[0] && s[1]<0x80) {
-
o[0] = s[1];
- unsigned char s0 = s[0], s1 = s[1];
- if (!s0 && s1<0x80) {
-
}o[0] = s1; return 1;
- else if (s[0]<0x08) {
-
o[0] = 0xC0 | (s[0]<<2) | (s[1]>>6);
-
o[1] = 0x80 | s[1]&0x3F;
- else if (s0<0x08) {
-
o[0] = 0xC0 | (s0<<2) | (s1>>6);
-
}o[1] = 0x80 | (s1&0x3F); return 2;
- else if ((s[0]&0xF8)!=0xD8) {
-
o[0] = 0xE0 | s[0]>>4;
-
o[1] = 0x80 | ((s[0]&0x0F)<<2) | (s[1]>>6);
-
o[2] = 0x80 | s[1]&0x3F;
- else if ((s0&0xF8)!=0xD8) {
-
o[0] = 0xE0 | s0>>4;
-
o[1] = 0x80 | ((s0&0x0F)<<2) | (s1>>6);
-
}o[2] = 0x80 | (s1&0x3F); return 3;
else {
-
unsigned int u = (((s[0]&0x03)<<2)|(s[1]>>6)) + 1;
-
o[0] = 0xF0 | u>>2;
-
o[1] = 0x80 | ((u&0x03)<<4) | (s[1]>>2)&0x0F;
-
o[2] = 0x80 | ((s[1]&0x03)<<4) | ((s[2]&0x03)<<2) | (s[3]>>6);
-
o[3] = 0x80 | s[3]&0x3F;
- unsigned char s2 = s[2], s3 = s[3];
-
unsigned int u = (((s0&0x03)<<2)|(s1>>6)) + 1;
-
o[0] = 0xF0 | (u>>2);
-
o[1] = 0x80 | ((u&0x03)<<4) | ((s1>>2)&0x0F);
-
o[2] = 0x80 | ((s1&0x03)<<4) | ((s2&0x03)<<2) | (s3>>6);
-
}o[3] = 0x80 | (s3&0x3F); return 4;
@@ -33,27 +36,32 @@ fun_so_from_utf_16be(const unsigned char
static int
-fun_so_to_utf_16be(const unsigned char* s, unsigned char* o)
+fun_so_to_utf_16be(const char* s, char* o, struct rb_transcoding *td)
{
- if (!(s[0]&0x80)) {
- unsigned char s0 = s[0], s1, s2, s3;
- if (!(s0&0x80)) {
o[0] = 0x00;
-
o[1] = s[0];
-
}o[1] = s0; return 2;
- else if ((s[0]&0xE0)==0xC0) {
-
o[0] = (s[0]>>2)&0x07;
-
o[1] = ((s[0]&0x03)<<6) | s[1]&0x3F;
- s1 = s[1];
- if ((s0&0xE0)==0xC0) {
-
o[0] = (s0>>2)&0x07;
-
}o[1] = ((s0&0x03)<<6) | (s1&0x3F); return 2;
- else if ((s[0]&0xF0)==0xE0) {
-
o[0] = (s[0]<<4) | (s[1]>>2)^0x20;
-
o[1] = (s[1]<<6) | s[2]^0x80;
- s2 = s[2];
- if ((s0&0xF0)==0xE0) {
-
o[0] = (s0<<4) | ((s1>>2)^0x20);
-
}o[1] = (s1<<6) | (s2^0x80); return 2;
- else {
-
int w = (((s[0]&0x07)<<2) | (s[1]>>4)&0x03) - 1;
- s3 = s[3];
- {
-
int w = (((s0&0x07)<<2) | ((s1>>4)&0x03)) - 1; o[0] = 0xD8 | (w>>2);
-
o[1] = (w<<6) | ((s[1]&0x0F)<<2) | ((s[2]>>4)-8);
-
o[2] = 0xDC | ((s[2]>>2)&0x03);
-
o[3] = (s[2]<<6) | (s[3]&~0x80);
-
o[1] = (w<<6) | ((s1&0x0F)<<2) | ((s2>>4)-8);
-
o[2] = 0xDC | ((s2>>2)&0x03);
-
}o[3] = (s2<<6) | (s3&~0x80); return 4;
@@ -61,27 +69,30 @@ fun_so_to_utf_16be(const unsigned char*
static int
-fun_so_from_utf_16le(const unsigned char* s, unsigned char* o)
+fun_so_from_utf_16le(const char* s, char* o, struct rb_transcoding *td)
{
- if (!s[1] && s[0]<0x80) {
-
o[0] = s[0];
- unsigned char s0 = s[0], s1 = s[1];
- if (!s1 && s0<0x80) {
-
}o[0] = s0; return 1;
- else if (s[1]<0x08) {
-
o[0] = 0xC0 | (s[1]<<2) | (s[0]>>6);
-
o[1] = 0x80 | s[0]&0x3F;
- else if (s1<0x08) {
-
o[0] = 0xC0 | (s1<<2) | (s0>>6);
-
}o[1] = 0x80 | (s0&0x3F); return 2;
- else if ((s[1]&0xF8)!=0xD8) {
-
o[0] = 0xE0 | s[1]>>4;
-
o[1] = 0x80 | ((s[1]&0x0F)<<2) | (s[0]>>6);
-
o[2] = 0x80 | s[0]&0x3F;
- else if ((s1&0xF8)!=0xD8) {
-
o[0] = 0xE0 | s1>>4;
-
o[1] = 0x80 | ((s1&0x0F)<<2) | (s0>>6);
-
}o[2] = 0x80 | (s0&0x3F); return 3;
else {
-
unsigned int u = (((s[1]&0x03)<<2)|(s[0]>>6)) + 1;
-
o[0] = 0xF0 | u>>2;
-
o[1] = 0x80 | ((u&0x03)<<4) | (s[0]>>2)&0x0F;
-
o[2] = 0x80 | ((s[0]&0x03)<<4) | ((s[3]&0x03)<<2) | (s[2]>>6);
-
o[3] = 0x80 | s[2]&0x3F;
- unsigned char s2 = s[2], s3 = s[3];
-
unsigned int u = (((s1&0x03)<<2)|(s0>>6)) + 1;
-
o[0] = 0xF0 | (u>>2);
-
o[1] = 0x80 | ((u&0x03)<<4) | ((s0>>2)&0x0F);
-
o[2] = 0x80 | ((s0&0x03)<<4) | ((s3&0x03)<<2) | (s2>>6);
-
}o[3] = 0x80 | (s2&0x3F); return 4;
@@ -89,27 +100,32 @@ fun_so_from_utf_16le(const unsigned char
static int
-fun_so_to_utf_16le(const unsigned char* s, unsigned char* o)
+fun_so_to_utf_16le(const char* s, char* o, struct rb_transcoding *td)
{
- if (!(s[0]&0x80)) {
- unsigned char s0 = s[0], s1, s2, s3;
- if (!(s0&0x80)) {
o[1] = 0x00;
-
o[0] = s[0];
-
}o[0] = s0; return 2;
- else if ((s[0]&0xE0)==0xC0) {
-
o[1] = (s[0]>>2)&0x07;
-
o[0] = ((s[0]&0x03)<<6) | s[1]&0x3F;
- s1 = s[1];
- if ((s0&0xE0)==0xC0) {
-
o[1] = (s0>>2)&0x07;
-
}o[0] = ((s0&0x03)<<6) | (s1&0x3F); return 2;
- else if ((s[0]&0xF0)==0xE0) {
-
o[1] = (s[0]<<4) | (s[1]>>2)^0x20;
-
o[0] = (s[1]<<6) | s[2]^0x80;
- s2 = s[2];
- if ((s0&0xF0)==0xE0) {
-
o[1] = (s0<<4) | ((s1>>2)^0x20);
-
}o[0] = (s1<<6) | (s2^0x80); return 2;
- else {
-
int w = (((s[0]&0x07)<<2) | (s[1]>>4)&0x03) - 1;
- s3 = s[3];
- {
-
int w = (((s0&0x07)<<2) | ((s1>>4)&0x03)) - 1; o[1] = 0xD8 | (w>>2);
-
o[0] = (w<<6) | ((s[1]&0x0F)<<2) | ((s[2]>>4)-8);
-
o[3] = 0xDC | ((s[2]>>2)&0x03);
-
o[2] = (s[2]<<6) | (s[3]&~0x80);
-
o[0] = (w<<6) | ((s1&0x0F)<<2) | ((s2>>4)-8);
-
o[3] = 0xDC | ((s2>>2)&0x03);
-
}o[2] = (s2<<6) | (s3&~0x80); return 4;
@@ -238,5 +254,5 @@ from_UTF_16BE = {
};
-static rb_transcoder
+static const rb_transcoder
rb_from_UTF_16BE = {
“UTF-16BE”, “UTF-8”, &from_UTF_16BE, 4, 0,
@@ -403,5 +419,5 @@ to_UTF_16BE = {
};
-static rb_transcoder
+static const rb_transcoder
rb_to_UTF_16BE = {
“UTF-8”, “UTF-16BE”, &to_UTF_16BE, 4, 1,
@@ -450,5 +466,5 @@ from_UTF_16LE = {
};
-static rb_transcoder
+static const rb_transcoder
rb_from_UTF_16LE = {
“UTF-16LE”, “UTF-8”, &from_UTF_16LE, 4, 0,
@@ -456,5 +472,5 @@ rb_from_UTF_16LE = {
};
-static rb_transcoder
+static const rb_transcoder
rb_to_UTF_16LE = {
“UTF-8”, “UTF-16LE”, &to_UTF_16BE, 4, 1,