dovecot: charset_to_utf8() isn't used anymore, so renamed charse...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jul 20 17:39:13 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/d86581f4a0c6
changeset: 6122:d86581f4a0c6
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jul 20 16:22:59 2007 +0300
description:
charset_to_utf8() isn't used anymore, so renamed charset_to_utf8_full() to it.

diffstat:

5 files changed, 18 insertions(+), 45 deletions(-)
src/lib-charset/charset-iconv.c      |   27 +++++++++++++--------------
src/lib-charset/charset-utf8.c       |   19 -------------------
src/lib-charset/charset-utf8.h       |    8 +-------
src/lib-mail/message-decoder.c       |    7 +++----
src/lib-mail/message-header-decode.c |    2 +-

diffs (154 lines):

diff -r 157e31742eeb -r d86581f4a0c6 src/lib-charset/charset-iconv.c
--- a/src/lib-charset/charset-iconv.c	Fri Jul 20 16:21:23 2007 +0300
+++ b/src/lib-charset/charset-iconv.c	Fri Jul 20 16:22:59 2007 +0300
@@ -57,9 +57,9 @@ void charset_to_utf8_reset(struct charse
 		(void)iconv(t->cd, NULL, NULL, NULL, NULL);
 }
 
-enum charset_result
-charset_to_utf8(struct charset_translation *t,
-		const unsigned char *src, size_t *src_size, buffer_t *dest)
+static enum charset_result
+charset_to_utf8_try(struct charset_translation *t,
+		    const unsigned char *src, size_t *src_size, buffer_t *dest)
 {
 	ICONV_CONST char *ic_srcbuf;
 	char *ic_destbuf;
@@ -67,17 +67,19 @@ charset_to_utf8(struct charset_translati
         enum charset_result ret;
 
 	destpos = dest->used;
-	destleft = buffer_get_size(dest) - destpos;
-
 	if (t->cd == (iconv_t)-1) {
 		/* no translation needed - just copy it to outbuf uppercased */
-		if (*src_size > destleft)
-			*src_size = destleft;
 		if (t->ucase)
 			charset_utf8_ucase_write(dest, destpos, src, *src_size);
 		else
-			buffer_write(dest, destpos, src, *src_size);
+			buffer_append(dest, src, *src_size);
 		return CHARSET_RET_OK;
+	}
+	destleft = buffer_get_size(dest) - destpos;
+	if (destleft < *src_size) {
+		/* The buffer is most likely too small to hold the output,
+		   so increase it at least to the input size. */
+		destleft = *src_size;
 	}
 
 	size = destleft;
@@ -106,23 +108,20 @@ charset_to_utf8(struct charset_translati
 		charset_utf8_ucase_write(dest, destpos,
 					 (unsigned char *)ic_destbuf - size,
 					 size);
-	} else {
-		buffer_write(dest, destpos, ic_destbuf - size, size);
 	}
 	return ret;
 }
 
 enum charset_result
-charset_to_utf8_full(struct charset_translation *t,
-		     const unsigned char *src, size_t *src_size,
-		     buffer_t *dest)
+charset_to_utf8(struct charset_translation *t,
+		const unsigned char *src, size_t *src_size, buffer_t *dest)
 {
 	enum charset_result ret;
 	size_t pos, used, size;
 
 	for (pos = 0;;) {
 		size = *src_size - pos;
-		ret = charset_to_utf8(t, src + pos, &size, dest);
+		ret = charset_to_utf8_try(t, src + pos, &size, dest);
 		pos += size;
 
 		if (ret != CHARSET_RET_OUTPUT_FULL) {
diff -r 157e31742eeb -r d86581f4a0c6 src/lib-charset/charset-utf8.c
--- a/src/lib-charset/charset-utf8.c	Fri Jul 20 16:21:23 2007 +0300
+++ b/src/lib-charset/charset-utf8.c	Fri Jul 20 16:22:59 2007 +0300
@@ -81,25 +81,6 @@ enum charset_result
 enum charset_result
 charset_to_utf8(struct charset_translation *t,
 		const unsigned char *src, size_t *src_size, buffer_t *dest)
-{
-	size_t destpos = dest->used, destleft;
-
-	destleft = buffer_get_size(dest) - destpos;
-	if (*src_size > destleft)
-		*src_size = destleft;
-
-	/* no translation needed - just copy it to outbuf uppercased */
-	if (t == &utf8_translation_uc || t == &ascii_translation_uc)
-		charset_utf8_ucase_write(dest, destpos, src, *src_size);
-	else
-		buffer_write(dest, destpos, src, *src_size);
-	return CHARSET_RET_OK;
-}
-
-enum charset_result
-charset_to_utf8_full(struct charset_translation *t,
-		     const unsigned char *src, size_t *src_size,
-		     buffer_t *dest)
 {
 	if (t == &utf8_translation_uc || t == &ascii_translation_uc)
 		charset_utf8_ucase_write(dest, dest->used, src, *src_size);
diff -r 157e31742eeb -r d86581f4a0c6 src/lib-charset/charset-utf8.h
--- a/src/lib-charset/charset-utf8.h	Fri Jul 20 16:21:23 2007 +0300
+++ b/src/lib-charset/charset-utf8.h	Fri Jul 20 16:22:59 2007 +0300
@@ -20,16 +20,10 @@ bool charset_is_utf8(const char *charset
 bool charset_is_utf8(const char *charset);
 
 /* Translate src to UTF-8. src_size is updated to contain the number of
-   characters actually translated from src. Note that dest buffer is used
-   only up to its current size, for growing it automatically use
-   charset_to_utf8_full(). */
+   characters actually translated from src. */
 enum charset_result
 charset_to_utf8(struct charset_translation *t,
 		const unsigned char *src, size_t *src_size, buffer_t *dest);
-enum charset_result
-charset_to_utf8_full(struct charset_translation *t,
-		     const unsigned char *src, size_t *src_size,
-		     buffer_t *dest);
 
 /* Simple wrappers for above functions. If utf8_size is non-NULL, it's set
    to same as strlen(returned data). */
diff -r 157e31742eeb -r d86581f4a0c6 src/lib-mail/message-decoder.c
--- a/src/lib-mail/message-decoder.c	Fri Jul 20 16:21:23 2007 +0300
+++ b/src/lib-mail/message-decoder.c	Fri Jul 20 16:22:59 2007 +0300
@@ -193,8 +193,7 @@ static void translation_buf_decode(struc
 	memcpy(trans_buf + ctx->translation_size, data, skip);
 
 	pos = *size;
-	(void)charset_to_utf8_full(ctx->charset_trans,
-				   *data, &pos, ctx->buf2);
+	(void)charset_to_utf8(ctx->charset_trans, *data, &pos, ctx->buf2);
 
 	i_assert(pos > ctx->translation_size);
 	skip = (ctx->translation_size + skip) - pos;
@@ -317,8 +316,8 @@ static bool message_decode_body(struct m
 			translation_buf_decode(ctx, &data, &size);
 
 		pos = size;
-		(void)charset_to_utf8_full(ctx->charset_trans,
-					   data, &pos, ctx->buf2);
+		(void)charset_to_utf8(ctx->charset_trans,
+				      data, &pos, ctx->buf2);
 		if (pos != size) {
 			ctx->translation_size = size - pos;
 			i_assert(ctx->translation_size <=
diff -r 157e31742eeb -r d86581f4a0c6 src/lib-mail/message-header-decode.c
--- a/src/lib-mail/message-header-decode.c	Fri Jul 20 16:21:23 2007 +0300
+++ b/src/lib-mail/message-header-decode.c	Fri Jul 20 16:22:59 2007 +0300
@@ -155,7 +155,7 @@ decode_utf8_callback(const unsigned char
 	}
 
 	/* ignore any errors */
-	(void)charset_to_utf8_full(t, data, &size, ctx->dest);
+	(void)charset_to_utf8(t, data, &size, ctx->dest);
 	charset_to_utf8_end(&t);
 	return TRUE;
 }


More information about the dovecot-cvs mailing list