NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
charset.h
Go to the documentation of this file.
1
23#ifndef MUTT_MUTT_CHARSET_H
24#define MUTT_MUTT_CHARSET_H
25
26#include <iconv.h>
27#include <stdbool.h>
28#include <stdint.h>
29#include <wchar.h>
30
31struct Buffer;
32struct Slist;
33
34extern bool CharsetIsUtf8;
35extern wchar_t ReplacementChar;
36
41{
42 FILE *fp;
43 iconv_t cd;
44 char bufi[512];
45 char bufo[512];
46 char *p;
47 char *ob;
48 char *ib;
49 size_t ibl;
50 const char **inrepls;
51};
52
57{
58 FILE *fp;
59 iconv_t cd;
60};
61
66{
69};
70
71#define MUTT_ICONV_NO_FLAGS 0
72#define MUTT_ICONV_HOOK_FROM 1
73
74void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name);
75const char * mutt_ch_charset_lookup(const char *chs);
76int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to);
77bool mutt_ch_check_charset(const char *cs, bool strict);
78char * mutt_ch_choose(const char *fromcode, const struct Slist *charsets, const char *u, size_t ulen, char **d, size_t *dlen);
79bool mutt_ch_chscmp(const char *cs1, const char *cs2);
80int mutt_ch_convert_nonmime_string(const struct Slist *const assumed_charset, const char *charset, char **ps);
81int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags);
82int mutt_ch_fgetconv(struct FgetConv *fc);
83void mutt_ch_fgetconv_close(struct FgetConv **fc);
84struct FgetConv *mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags);
85char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc);
86const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset);
88size_t mutt_ch_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, const char **inrepls, const char *outrepl, int *iconverrno);
89const char * mutt_ch_iconv_lookup(const char *chs);
90iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags);
91bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);
92void mutt_ch_lookup_remove(void);
93void mutt_ch_set_charset(const char *charset);
94void mutt_ch_cache_cleanup(void);
95
96#define mutt_ch_is_utf8(str) mutt_ch_chscmp(str, "utf-8")
97#define mutt_ch_is_us_ascii(str) mutt_ch_chscmp(str, "us-ascii")
98
100#define ICONV_T_INVALID ((iconv_t) -1)
101
103#define ICONV_ILLEGAL_SEQ ((size_t) -1)
105#define ICONV_BUF_TOO_SMALL ((size_t) -2)
106
112static inline bool iconv_t_valid(const iconv_t cd)
113{
114 return cd != ICONV_T_INVALID;
115}
116
117#endif /* MUTT_MUTT_CHARSET_H */
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition: charset.c:885
void mutt_ch_fgetconv_close(struct FgetConv **fc)
Close an fgetconv handle.
Definition: charset.c:956
size_t mutt_ch_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, const char **inrepls, const char *outrepl, int *iconverrno)
Change the encoding of a string.
Definition: charset.c:688
void mutt_ch_lookup_remove(void)
Remove all the character set lookups.
Definition: charset.c:532
char * mutt_ch_choose(const char *fromcode, const struct Slist *charsets, const char *u, size_t ulen, char **d, size_t *dlen)
Figure the best charset to encode a string.
Definition: charset.c:1102
int mutt_ch_convert_nonmime_string(const struct Slist *const assumed_charset, const char *charset, char **ps)
Try to convert a string using a list of character sets.
Definition: charset.c:324
#define ICONV_T_INVALID
Error value for iconv functions.
Definition: charset.h:100
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
Definition: charset.c:477
bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err)
Add a new character set lookup.
Definition: charset.c:500
void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
Canonicalise the charset of a string.
Definition: charset.c:367
void mutt_ch_cache_cleanup(void)
Clean up the cached iconv handles and charset strings.
Definition: charset.c:1169
const char * mutt_ch_iconv_lookup(const char *chs)
Look for a replacement character set.
Definition: charset.c:772
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition: charset.c:822
LookupType
Types of character set lookups.
Definition: charset.h:66
@ MUTT_LOOKUP_ICONV
Character set conversion.
Definition: charset.h:68
@ MUTT_LOOKUP_CHARSET
Alias for another character set.
Definition: charset.h:67
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Definition: charset.c:1069
bool CharsetIsUtf8
Is the user's current character set utf-8?
Definition: charset.c:59
int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to)
Check whether a string can be converted between encodings.
Definition: charset.c:787
const char * mutt_ch_charset_lookup(const char *chs)
Look for a replacement character set.
Definition: charset.c:553
int mutt_ch_fgetconv(struct FgetConv *fc)
Convert a file's character set.
Definition: charset.c:974
wchar_t ReplacementChar
When a Unicode character can't be displayed, use this instead.
Definition: charset.c:54
struct FgetConv * mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags)
Prepare a file for charset conversion.
Definition: charset.c:924
char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc)
Convert a file's charset into a string buffer.
Definition: charset.c:1036
bool mutt_ch_chscmp(const char *cs1, const char *cs2)
Are the names of two character sets equivalent?
Definition: charset.c:433
iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags)
Set up iconv for conversions.
Definition: charset.c:585
const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset)
Get the default character set.
Definition: charset.c:456
static bool iconv_t_valid(const iconv_t cd)
Is the conversion descriptor valid?
Definition: charset.h:112
String manipulation buffer.
Definition: buffer.h:34
A dummy converter.
Definition: charset.h:57
FILE * fp
Definition: charset.h:58
iconv_t cd
iconv conversion descriptor
Definition: charset.h:59
Cursor for converting a file's encoding.
Definition: charset.h:41
char bufi[512]
Definition: charset.h:44
iconv_t cd
iconv conversion descriptor
Definition: charset.h:43
char bufo[512]
Definition: charset.h:45
size_t ibl
Definition: charset.h:49
FILE * fp
Definition: charset.h:42
char * p
Definition: charset.h:46
const char ** inrepls
Definition: charset.h:50
char * ib
Definition: charset.h:48
char * ob
Definition: charset.h:47
String list.
Definition: slist.h:47