]> mj.ucw.cz Git - libucw.git/blobdiff - charset/charconv.c
hashtables: fixed combination of HASH_GIVE_ALLOC and HASH_TABLE_ALLOC
[libucw.git] / charset / charconv.c
index ed07f2f96e4adeb1a54958c592614caa26b3485e..fcd8680c438af7d7b847089149db4cf82657737b 100644 (file)
@@ -97,6 +97,7 @@ conv_slow(struct conv_context *c)
          c->code <<= 4;
          c->remains = 2;
        }
          c->code <<= 4;
          c->remains = 2;
        }
+      c->code &= 0xffff;
       c->state = UTF8_WRITE_CONT;
       /* fall-thru */
     case UTF8_WRITE_CONT:
       c->state = UTF8_WRITE_CONT;
       /* fall-thru */
     case UTF8_WRITE_CONT:
@@ -208,7 +209,6 @@ main:
   return CONV_SOURCE_END;
 
 send_utf:
   return CONV_SOURCE_END;
 
 send_utf:
-  c->state = UTF8_WRITE_START;
   if (cc < 0xe0)               { c->code = cc & 0x1f; c->remains = 1; }
   else if (cc < 0xf0)          { c->code = cc & 0x0f; c->remains = 2; }
   else
   if (cc < 0xe0)               { c->code = cc & 0x1f; c->remains = 1; }
   else if (cc < 0xf0)          { c->code = cc & 0x0f; c->remains = 2; }
   else
@@ -219,17 +219,18 @@ send_utf:
       else if (cc < 0xfe)      c->remains = 5;
       else goto nocode;
     }
       else if (cc < 0xfe)      c->remains = 5;
       else goto nocode;
     }
+  c->state = UTF8_READ;
   goto go_slow;
 
 dend_str:
   c->state = SEQ_WRITE;
   c->string_at = k;
   c->remains = len;
   goto go_slow;
 
 dend_str:
   c->state = SEQ_WRITE;
   c->string_at = k;
   c->remains = len;
+  goto go_slow;
 
 dend_char:
   c->state = SINGLE_WRITE;
   c->code = code;
 
 dend_char:
   c->state = SINGLE_WRITE;
   c->code = code;
-  goto go_slow;
 go_slow:
   c->source = s;
   c->dest = d;
 go_slow:
   c->source = s;
   c->dest = d;
@@ -302,7 +303,7 @@ dend:
   return CONV_DEST_END;
 
 dend_utf:
   return CONV_DEST_END;
 
 dend_utf:
-  c->source = s;
+  c->source = s+1;
   c->dest = d;
   c->state = UTF8_WRITE_START;
   c->code = code;
   c->dest = d;
   c->state = UTF8_WRITE_START;
   c->code = code;
@@ -411,3 +412,18 @@ conv_x_count(void)
 {
   return sizeof(x_to_uni) / sizeof(x_to_uni[0]);
 }
 {
   return sizeof(x_to_uni) / sizeof(x_to_uni[0]);
 }
+
+int
+conv_in_to_ucs(struct conv_context *c, unsigned int y)
+{
+  return x_to_uni[c->in_to_x[y]];
+}
+
+int conv_ucs_to_out(struct conv_context *c, unsigned int ucs)
+{
+  uns x = uni_to_x[ucs >> 8U][ucs & 0xff];
+  if (x == 256 || c->x_to_out[x] >= 256)
+    return -1;
+  else
+    return c->x_to_out[x];
+}