NeoMutt  2024-03-23-142-g2b2e76
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
charset.h
Go to the documentation of this file.
1
24#ifndef MUTT_MUTT_CHARSET_H
25#define MUTT_MUTT_CHARSET_H
26
27#include <iconv.h>
28#include <stdbool.h>
29#include <stdint.h>
30#include <wchar.h>
31
32struct Buffer;
33struct Slist;
34
35extern bool CharsetIsUtf8;
36extern wchar_t ReplacementChar;
37
42{
43 FILE *fp;
44 iconv_t cd;
45 char bufi[512];
46 char bufo[512];
47 char *p;
48 char *ob;
49 char *ib;
50 size_t ibl;
51 const char **inrepls;
52};
53
58{
59 FILE *fp;
60 iconv_t cd;
61};
62
67{
70};
71
72#define MUTT_ICONV_NO_FLAGS 0
73#define MUTT_ICONV_HOOK_FROM 1
74
75void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name);
76const char * mutt_ch_charset_lookup(const char *chs);
77int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to);
78bool mutt_ch_check_charset(const char *cs, bool strict);
79char * mutt_ch_choose(const char *fromcode, const struct Slist *charsets, const char *u, size_t ulen, char **d, size_t *dlen);
80bool mutt_ch_chscmp(const char *cs1, const char *cs2);
81int mutt_ch_convert_nonmime_string(const struct Slist *const assumed_charset, const char *charset, char **ps);
82int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags);
83int mutt_ch_fgetconv(struct FgetConv *fc);
84void mutt_ch_fgetconv_close(struct FgetConv **ptr);
85struct FgetConv *mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags);
86char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc);
87const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset);
89size_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);
90const char * mutt_ch_iconv_lookup(const char *chs);
91iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags);
92bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);
93void mutt_ch_lookup_remove(void);
94void mutt_ch_set_charset(const char *charset);
95void mutt_ch_cache_cleanup(void);
96
97#define mutt_ch_is_utf8(str) mutt_ch_chscmp(str, "utf-8")
98#define mutt_ch_is_us_ascii(str) mutt_ch_chscmp(str, "us-ascii")
99
101#define ICONV_T_INVALID ((iconv_t) -1)
102
104#define ICONV_ILLEGAL_SEQ ((size_t) -1)
106#define ICONV_BUF_TOO_SMALL ((size_t) -2)
107
113static inline bool iconv_t_valid(const iconv_t cd)
114{
115 return cd != ICONV_T_INVALID;
116}
117
118#endif /* MUTT_MUTT_CHARSET_H */
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition: charset.c:893
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:696
void mutt_ch_lookup_remove(void)
Remove all the character set lookups.
Definition: charset.c:540
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:1110
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:331
#define ICONV_T_INVALID
Error value for iconv functions.
Definition: charset.h:101
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
Definition: charset.c:485
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:508
void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
Canonicalise the charset of a string.
Definition: charset.c:374
void mutt_ch_cache_cleanup(void)
Clean up the cached iconv handles and charset strings.
Definition: charset.c:1177
const char * mutt_ch_iconv_lookup(const char *chs)
Look for a replacement character set.
Definition: charset.c:780
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition: charset.c:830
LookupType
Types of character set lookups.
Definition: charset.h:67
@ MUTT_LOOKUP_ICONV
Character set conversion.
Definition: charset.h:69
@ MUTT_LOOKUP_CHARSET
Alias for another character set.
Definition: charset.h:68
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Definition: charset.c:1077
bool CharsetIsUtf8
Is the user's current character set utf-8?
Definition: charset.c:66
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:795
const char * mutt_ch_charset_lookup(const char *chs)
Look for a replacement character set.
Definition: charset.c:561
int mutt_ch_fgetconv(struct FgetConv *fc)
Convert a file's character set.
Definition: charset.c:982
wchar_t ReplacementChar
When a Unicode character can't be displayed, use this instead.
Definition: charset.c:61
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:932
char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc)
Convert a file's charset into a string buffer.
Definition: charset.c:1044
bool mutt_ch_chscmp(const char *cs1, const char *cs2)
Are the names of two character sets equivalent?
Definition: charset.c:441
void mutt_ch_fgetconv_close(struct FgetConv **ptr)
Close an fgetconv handle.
Definition: charset.c:964
iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags)
Set up iconv for conversions.
Definition: charset.c:593
const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset)
Get the default character set.
Definition: charset.c:464
static bool iconv_t_valid(const iconv_t cd)
Is the conversion descriptor valid?
Definition: charset.h:113
String manipulation buffer.
Definition: buffer.h:36
A dummy converter.
Definition: charset.h:58
FILE * fp
Definition: charset.h:59
iconv_t cd
iconv conversion descriptor
Definition: charset.h:60
Cursor for converting a file's encoding.
Definition: charset.h:42
char bufi[512]
Definition: charset.h:45
iconv_t cd
iconv conversion descriptor
Definition: charset.h:44
char bufo[512]
Definition: charset.h:46
size_t ibl
Definition: charset.h:50
FILE * fp
Definition: charset.h:43
char * p
Definition: charset.h:47
const char ** inrepls
Definition: charset.h:51
char * ib
Definition: charset.h:49
char * ob
Definition: charset.h:48
String list.
Definition: slist.h:37