* of the GNU Lesser General Public License.
*/
-#include "lib/lib.h"
-#include "lib/unicode.h"
-#include "lib/unaligned.h"
-#include "charset/charconv.h"
-#include "charset/chartable.h"
+#include <ucw/lib.h>
+#include <ucw/unicode.h>
+#include <ucw/unaligned.h>
+#include <charset/charconv.h>
+#include <charset/chartable.h>
void
conv_init(struct conv_context *c)
}
if (c->code >= 0x10000)
c->code = 0xfffd;
+got_char:
c->source = s;
c->state = 0;
return -1;
{
void *p = &c->code;
c->string_at = p;
- if (c->code < 0xd800 || c->code - 0xe000 < 0x2000)
+ uint code = c->code;
+ c->string_at = p;
+ if (code < 0xd800 || code - 0xe000 < 0x2000)
{}
- else if ((c->code -= 0x10000) < 0x100000)
+ else if ((code -= 0x10000) < 0x100000)
{
- put_u16_be(p, 0xd800 | (c->code >> 10));
- put_u16_be(p + 2, 0xdc00 | (c->code & 0x3ff));
+ put_u16_be(p, 0xd800 | (code >> 10));
+ put_u16_be(p + 2, 0xdc00 | (code & 0x3ff));
c->remains = 4;
+ c->state = SEQ_WRITE;
goto seq;
}
else
- c->code = UNI_REPLACEMENT;
- put_u16_be(p, c->code);
+ code = UNI_REPLACEMENT;
+ put_u16_be(p, code);
c->remains = 2;
+ c->state = SEQ_WRITE;
goto seq;
}
{
void *p = &c->code;
c->string_at = p;
- if (c->code < 0xd800 || c->code - 0xe000 < 0x2000)
+ uint code = c->code;
+ c->string_at = p;
+ if (code < 0xd800 || code - 0xe000 < 0x2000)
{}
- else if ((c->code -= 0x10000) < 0x100000)
+ else if ((code -= 0x10000) < 0x100000)
{
- put_u16_le(p, 0xd800 | (c->code >> 10));
- put_u16_le(p + 2, 0xdc00 | (c->code & 0x3ff));
+ put_u16_le(p, 0xd800 | (code >> 10));
+ put_u16_le(p + 2, 0xdc00 | (code & 0x3ff));
c->remains = 4;
+ c->state = SEQ_WRITE;
}
else
- c->code = UNI_REPLACEMENT;
- put_u16_le(p, c->code);
+ code = UNI_REPLACEMENT;
+ put_u16_le(p, code);
c->remains = 2;
+ c->state = SEQ_WRITE;
goto seq;
}
goto cse;
c->code = (c->code << 8) | *s++;
if (c->code - 0xd800 >= 0x800)
- break;
+ goto got_char;
c->code = (c->code - 0xd800) << 10;
c->state = UTF16_BE_READ_2;
/* fall-thru */
else
c->code = UNI_REPLACEMENT;
s++;
- break;
+ goto got_char;
/* Reading of UTF16-LE */
case UTF16_LE_READ:
goto cse;
c->code |= *s++ << 8;
if (c->code - 0xd800 >= 0x800)
- break;
+ goto got_char;
c->code = (c->code - 0xd800) << 10;
c->state = UTF16_LE_READ_2;
/* fall-thru */
else
c->code = UNI_REPLACEMENT;
s++;
- break;
+ goto got_char;
default:
ASSERT(0);
{
#define CONV_READ_STD
#define CONV_WRITE_UTF8
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_UTF8
#define CONV_WRITE_STD
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_STD
#define CONV_WRITE_UTF16_BE
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_UTF16_BE
#define CONV_WRITE_STD
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_STD
#define CONV_WRITE_UTF16_LE
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_UTF16_LE
#define CONV_WRITE_STD
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_UTF8
#define CONV_WRITE_UTF16_BE
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_UTF16_BE
#define CONV_WRITE_UTF8
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_UTF8
#define CONV_WRITE_UTF16_LE
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_UTF16_LE
#define CONV_WRITE_UTF8
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
{
#define CONV_READ_UTF16_BE
#define CONV_WRITE_UTF16_LE
-#include "charset/charconv-gen.h"
+#include <charset/charconv-gen.h>
}
static int
unsigned short *x_to_out = c->x_to_out;
const unsigned char *s, *se;
unsigned char *d, *de, *k;
- unsigned int len, e;
+ uint len, e;
if (unlikely(c->state))
goto slow;
de = c->dest_end;
while (s < se)
{
- unsigned int code = x_to_out[in_to_x[*s]];
+ uint code = x_to_out[in_to_x[*s]];
if (code < 0x100)
{
if (unlikely(d >= de))
c->source_charset = src;
c->dest_charset = dest;
if (src == dest)
- c->convert = conv_none;
+ {
+ c->convert = conv_none;
+ c->in_to_x = NULL;
+ c->x_to_out = NULL;
+ }
else
{
- static uns lookup[] = {
+ static uint lookup[] = {
[CONV_CHARSET_UTF8] = 1,
[CONV_CHARSET_UTF16_BE] = 2,
[CONV_CHARSET_UTF16_LE] = 3,
{ conv_utf16_be_to_std, conv_utf16_be_to_utf8, conv_none, conv_utf16_be_to_utf16_le },
{ conv_utf16_le_to_std, conv_utf16_le_to_utf8, conv_utf16_be_to_utf16_le, conv_none },
};
- uns src_idx = ((uns)src < ARRAY_SIZE(lookup)) ? lookup[src] : 0;
- uns dest_idx = ((uns)dest < ARRAY_SIZE(lookup)) ? lookup[dest] : 0;
+ uint src_idx = ((uint)src < ARRAY_SIZE(lookup)) ? lookup[src] : 0;
+ uint dest_idx = ((uint)dest < ARRAY_SIZE(lookup)) ? lookup[dest] : 0;
c->convert = tab[src_idx][dest_idx];
- if (!src_idx)
- c->in_to_x = input_to_x[src];
- if (!dest_idx)
- c->x_to_out = x_to_output[dest];
+ c->in_to_x = src_idx ? NULL : input_to_x[src];
+ c->x_to_out = dest_idx ? NULL : x_to_output[dest];
}
c->state = 0;
}
-unsigned int
-conv_x_to_ucs(unsigned int x)
+uint
+conv_x_to_ucs(uint x)
{
return x_to_uni[x];
}
-unsigned int
-conv_ucs_to_x(unsigned int ucs)
+uint
+conv_ucs_to_x(uint ucs)
{
return uni_to_x[ucs >> 8U][ucs & 0xff];
}
-unsigned int
+uint
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)
+conv_in_to_ucs(struct conv_context *c, uint y)
{
return x_to_uni[c->in_to_x[y]];
}
-int conv_ucs_to_out(struct conv_context *c, unsigned int ucs)
+int conv_ucs_to_out(struct conv_context *c, uint ucs)
{
- uns x = uni_to_x[ucs >> 8U][ucs & 0xff];
+ uint x = uni_to_x[ucs >> 8U][ucs & 0xff];
if (x == 256 || c->x_to_out[x] >= 256)
return -1;
else