1 /* Message list character set conversion.
2    Copyright (C) 2001-2003, 2005-2006, 2009 Free Software Foundation, Inc.
3    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
4 
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17 
18 #ifndef _MSGL_ICONV_H
19 #define _MSGL_ICONV_H
20 
21 #include <stdbool.h>
22 #if HAVE_ICONV
23 #include <iconv.h>
24 #endif
25 
26 #include "message.h"
27 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 
34 #if HAVE_ICONV
35 
36 /* A context, used for accurate error messages.  */
37 struct conversion_context
38 {
39   const char *from_code;     /* canonicalized encoding name for input */
40   const char *to_code;       /* canonicalized encoding name for output */
41   const char *from_filename; /* file name where the input comes from */
42   const message_ty *message; /* message being converted, or NULL */
43 };
44 
45 /* Converts the STRING through the conversion descriptor CD.
46    Assumes that either FROM_CODE or TO_CODE is UTF-8.  */
47 extern char *convert_string_directly (iconv_t cd, const char *string,
48                                       const struct conversion_context* context);
49 
50 #endif
51 
52 /* Converts the message list MLP to the (already canonicalized) encoding
53    CANON_TO_CODE.  The (already canonicalized) encoding before conversion
54    can be passed as CANON_FROM_CODE; if NULL is passed instead, the
55    encoding is looked up in the header entry.  Returns true if and only if
56    some msgctxt or msgid changed due to the conversion.  */
57 extern bool
58        iconv_message_list (message_list_ty *mlp,
59                            const char *canon_from_code,
60                            const char *canon_to_code,
61                            const char *from_filename);
62 
63 /* Converts all the message lists in MDLP to the encoding TO_CODE.
64    UPDATE_HEADER specifies whether to update the "charset=..." specification
65    in the header; it should normally be true.  */
66 extern msgdomain_list_ty *
67        iconv_msgdomain_list (msgdomain_list_ty *mdlp,
68                              const char *to_code,
69                              bool update_header,
70                              const char *from_filename);
71 
72 /* Tests whether the message list MLP could be converted to CANON_TO_CODE.
73    The (already canonicalized) encoding before conversion can be passed as
74    CANON_FROM_CODE; if NULL is passed instead, the encoding is looked up
75    in the header entry.  */
76 extern bool
77        is_message_list_iconvable (message_list_ty *mlp,
78                                   const char *canon_from_code,
79                                   const char *canon_to_code);
80 
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 
87 #endif /* _MSGL_ICONV_H */
88