X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=charset%2Fcharconv.c;h=fcd8680c438af7d7b847089149db4cf82657737b;hb=859769b129993a67598d61bb36d72d268082276b;hp=ed07f2f96e4adeb1a54958c592614caa26b3485e;hpb=fece0021c9d669b6e0175906d0137a857b4bf4a9;p=libucw.git diff --git a/charset/charconv.c b/charset/charconv.c index ed07f2f9..fcd8680c 100644 --- a/charset/charconv.c +++ b/charset/charconv.c @@ -97,6 +97,7 @@ conv_slow(struct conv_context *c) c->code <<= 4; c->remains = 2; } + c->code &= 0xffff; c->state = UTF8_WRITE_CONT; /* fall-thru */ case UTF8_WRITE_CONT: @@ -208,7 +209,6 @@ main: 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 @@ -219,17 +219,18 @@ send_utf: 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_char: c->state = SINGLE_WRITE; c->code = code; - goto go_slow; go_slow: c->source = s; c->dest = d; @@ -302,7 +303,7 @@ dend: return CONV_DEST_END; dend_utf: - c->source = s; + c->source = s+1; 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]); } + +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]; +}