Mercurial > dovecot > core-2.2
changeset 22848:170f155eb2b2
lib-charset: Move non-iconv UTF-8 only translation code to its own file
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 09 Nov 2017 15:12:05 +0200 |
parents | 3338a8e5976d |
children | 01666acde1a8 |
files | src/lib-charset/Makefile.am src/lib-charset/charset-utf8-only.c src/lib-charset/charset-utf8.c |
diffstat | 3 files changed, 49 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-charset/Makefile.am Fri Feb 09 23:57:29 2018 +0100 +++ b/src/lib-charset/Makefile.am Thu Nov 09 15:12:05 2017 +0200 @@ -7,7 +7,8 @@ libcharset_la_LIBADD = $(LTLIBICONV) libcharset_la_SOURCES = \ charset-iconv.c \ - charset-utf8.c + charset-utf8.c \ + charset-utf8-only.c headers = \ charset-utf8.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-charset/charset-utf8-only.c Thu Nov 09 15:12:05 2017 +0200 @@ -0,0 +1,47 @@ +/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "charset-utf8.h" + +#ifndef HAVE_ICONV + +struct charset_translation { + normalizer_func_t *normalizer; +}; + +int charset_to_utf8_begin(const char *charset, normalizer_func_t *normalizer, + struct charset_translation **t_r) +{ + struct charset_translation *t; + + if (!charset_is_utf8(charset)) { + /* no support for charsets that need translation */ + return -1; + } + + t = i_new(struct charset_translation, 1); + t->normalizer = normalizer; + *t_r = t; + return 0; +} + +void charset_to_utf8_end(struct charset_translation **_t) +{ + struct charset_translation *t = *_t; + + *_t = NULL; + i_free(t); +} + +void charset_to_utf8_reset(struct charset_translation *t ATTR_UNUSED) +{ +} + +enum charset_result +charset_to_utf8(struct charset_translation *t, + const unsigned char *src, size_t *src_size, buffer_t *dest) +{ + return charset_utf8_to_utf8(t->normalizer, src, src_size, dest); +} + +#endif
--- a/src/lib-charset/charset-utf8.c Fri Feb 09 23:57:29 2018 +0100 +++ b/src/lib-charset/charset-utf8.c Thu Nov 09 15:12:05 2017 +0200 @@ -42,49 +42,6 @@ return trans; } -#ifndef HAVE_ICONV - -struct charset_translation { - normalizer_func_t *normalizer; -}; - -int charset_to_utf8_begin(const char *charset, normalizer_func_t *normalizer, - struct charset_translation **t_r) -{ - struct charset_translation *t; - - if (!charset_is_utf8(charset)) { - /* no support for charsets that need translation */ - return -1; - } - - t = i_new(struct charset_translation, 1); - t->normalizer = normalizer; - *t_r = t; - return 0; -} - -void charset_to_utf8_end(struct charset_translation **_t) -{ - struct charset_translation *t = *_t; - - *_t = NULL; - i_free(t); -} - -void charset_to_utf8_reset(struct charset_translation *t ATTR_UNUSED) -{ -} - -enum charset_result -charset_to_utf8(struct charset_translation *t, - const unsigned char *src, size_t *src_size, buffer_t *dest) -{ - return charset_utf8_to_utf8(t->normalizer, src, src_size, dest); -} - -#endif - enum charset_result charset_utf8_to_utf8(normalizer_func_t *normalizer, const unsigned char *src, size_t *src_size, buffer_t *dest)