Skip to content

Commit

Permalink
lib-charset: Move non-iconv UTF-8 only translation code to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Feb 19, 2018
1 parent f0fc31c commit d51c657
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/lib-charset/Makefile.am
Expand Up @@ -7,7 +7,8 @@ AM_CPPFLAGS = \
libcharset_la_LIBADD = $(LTLIBICONV)
libcharset_la_SOURCES = \
charset-iconv.c \
charset-utf8.c
charset-utf8.c \
charset-utf8-only.c

headers = \
charset-utf8.h
Expand Down
47 changes: 47 additions & 0 deletions src/lib-charset/charset-utf8-only.c
@@ -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
43 changes: 0 additions & 43 deletions src/lib-charset/charset-utf8.c
Expand Up @@ -42,49 +42,6 @@ charset_utf8_to_utf8_begin(normalizer_func_t *normalizer)
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)
Expand Down

0 comments on commit d51c657

Please sign in to comment.