[dovecot-cvs] dovecot/src/lib-charset charset-utf8.c,NONE,1.1 Makefile.am,1.1,1.2 charset-iconv.c,1.3,1.4 charset-ascii.c,1.4,NONE
cras at procontrol.fi
cras at procontrol.fi
Wed Nov 13 15:48:02 EET 2002
Update of /home/cvs/dovecot/src/lib-charset
In directory danu:/tmp/cvs-serv9130
Modified Files:
Makefile.am charset-iconv.c
Added Files:
charset-utf8.c
Removed Files:
charset-ascii.c
Log Message:
We can support UTF-8 charset too without any translations.
--- NEW FILE: charset-utf8.c ---
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "charset-utf8.h"
#ifndef HAVE_ICONV_H
#include <ctype.h>
struct _CharsetTranslation {
int dummy;
};
static CharsetTranslation ascii_translation, utf8_translation;
CharsetTranslation *charset_to_utf8_begin(const char *charset,
int *unknown_charset)
{
if (unknown_charset != NULL)
*unknown_charset = FALSE;
if (strcasecmp(charset, "us-ascii") == 0 ||
strcasecmp(charset, "ascii") == 0)
return &ascii_translation;
if (strcasecmp(charset, "UTF-8") == 0 ||
strcasecmp(charset, "UTF8") == 0)
return &utf8_translation;
/* no support for charsets that need translation */
if (unknown_charset != NULL)
*unknown_charset = TRUE;
return NULL;
}
void charset_to_utf8_end(CharsetTranslation *t __attr_unused__)
{
}
void charset_to_utf8_reset(CharsetTranslation *t __attr_unused__)
{
}
int charset_to_ucase_utf8(CharsetTranslation *t __attr_unused__,
const unsigned char **inbuf, size_t *insize,
unsigned char *outbuf, size_t *outsize)
{
size_t max_size, i;
max_size = I_MIN(*insize, *outsize);
for (i = 0; i < max_size; i++)
outbuf[i] = i_toupper((*inbuf)[i]); /* FIXME: utf8 */
*insize = 0;
*outsize = max_size;
return TRUE;
}
const char *
charset_to_ucase_utf8_string(const char *charset, int *unknown_charset,
const unsigned char *buf,
size_t *size __attr_unused__)
{
if (charset == NULL || strcasecmp(charset, "us-ascii") == 0 ||
strcasecmp(charset, "ascii") == 0 ||
strcasecmp(charset, "UTF-8") == 0 ||
strcasecmp(charset, "UTF8") == 0)
return str_ucase(t_strdup_noconst(buf)); /* FIXME: utf8 */
if (unknown_charset != NULL)
*unknown_charset = TRUE;
return NULL;
}
#endif
Index: Makefile.am
===================================================================
RCS file: /home/cvs/dovecot/src/lib-charset/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am 3 Nov 2002 08:39:43 -0000 1.1
+++ Makefile.am 13 Nov 2002 13:47:59 -0000 1.2
@@ -4,8 +4,8 @@
-I$(top_srcdir)/src/lib
libcharset_a_SOURCES = \
- charset-ascii.c \
- charset-iconv.c
+ charset-iconv.c \
+ charset-utf8.c
noinst_HEADERS = \
charset-utf8.h
Index: charset-iconv.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-charset/charset-iconv.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- charset-iconv.c 13 Nov 2002 11:08:18 -0000 1.3
+++ charset-iconv.c 13 Nov 2002 13:47:59 -0000 1.4
@@ -10,6 +10,7 @@
struct _CharsetTranslation {
iconv_t cd;
+ int ascii;
};
CharsetTranslation *charset_to_utf8_begin(const char *charset,
@@ -17,16 +18,22 @@
{
CharsetTranslation *t;
iconv_t cd;
+ int ascii;
if (unknown_charset != NULL)
*unknown_charset = FALSE;
if (strcasecmp(charset, "us-ascii") == 0 ||
strcasecmp(charset, "ascii") == 0) {
- /* no need to do any actual translation */
cd = NULL;
+ ascii = TRUE;
+ } else if (strcasecmp(charset, "UTF-8") == 0 ||
+ strcasecmp(charset, "UTF8") == 0) {
+ cd = NULL;
+ ascii = FALSE;
} else {
- cd = iconv_open("UTF8", charset);
+ ascii = FALSE;
+ cd = iconv_open("UTF-8", charset);
if (cd == (iconv_t)-1) {
if (unknown_charset != NULL)
*unknown_charset = TRUE;
@@ -36,6 +43,7 @@
t = i_new(CharsetTranslation, 1);
t->cd = cd;
+ t->ascii = ascii;
return t;
}
@@ -60,10 +68,10 @@
size_t outleft, max_size, i;
if (t->cd == NULL) {
- /* ascii - just copy it to outbuf uppercased */
+ /* no translation needed - just copy it to outbuf uppercased */
max_size = I_MIN(*insize, *outsize);
for (i = 0; i < max_size; i++)
- outbuf[i] = i_toupper((*inbuf)[i]);
+ outbuf[i] = i_toupper((*inbuf)[i]); /* FIXME: utf8 */
*insize = 0;
*outsize = max_size;
return TRUE;
@@ -86,7 +94,7 @@
max_size = *outsize;
for (i = 0; i < max_size; i++)
- outbuf[i] = i_toupper(outbuf[i]);
+ outbuf[i] = i_toupper(outbuf[i]); /* FIXME: utf8 */
return TRUE;
}
@@ -103,7 +111,7 @@
strcasecmp(charset, "ascii") == 0)
return str_ucase(t_strdup_noconst(buf));
- cd = iconv_open("UTF8", charset);
+ cd = iconv_open("UTF-8", charset);
if (cd == (iconv_t)-1) {
if (unknown_charset != NULL)
*unknown_charset = TRUE;
@@ -139,8 +147,7 @@
*outpos++ = '\0';
t_buffer_alloc(*size + 1);
- /* FIXME: this works only for ASCII */
- str_ucase(outbuf);
+ str_ucase(outbuf); /* FIXME: utf8 */
iconv_close(cd);
return outbuf;
--- charset-ascii.c DELETED ---
More information about the dovecot-cvs
mailing list