NeoMutt  2024-10-02-37-gfa9146
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 <stddef.h>
30#include <stdint.h>
31#include <wchar.h>
32
33struct Buffer;
34struct Slist;
35
36extern bool CharsetIsUtf8;
37extern wchar_t ReplacementChar;
38
43{
44 FILE *fp;
45 iconv_t cd;
46 char bufi[512];
47 char bufo[512];
48 char *p;
49 char *ob;
50 char *ib;
51 size_t ibl;
52 const char **inrepls;
53};
54
59{
60 FILE *fp;
61 iconv_t cd;
62};
63
68{
71};
72
73#define MUTT_ICONV_NO_FLAGS 0
74#define MUTT_ICONV_HOOK_FROM 1
75
76void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name);
77const char * mutt_ch_charset_lookup(const char *chs);
78int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to);
79bool mutt_ch_check_charset(const char *cs, bool strict);
80char * mutt_ch_choose(const char *fromcode, const struct Slist *charsets, const char *u, size_t ulen, char **d, size_t *dlen);
81bool mutt_ch_chscmp(const char *cs1, const char *cs2);
82int mutt_ch_convert_nonmime_string(const struct Slist *const assumed_charset, const char *charset, char **ps);
83int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags);
84int mutt_ch_fgetconv(struct FgetConv *fc);
85void mutt_ch_fgetconv_close(struct FgetConv **ptr);
86struct FgetConv *mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags);
87char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc);
88const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset);
90size_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);
91const char * mutt_ch_iconv_lookup(const char *chs);
92iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags);
93bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);
94void mutt_ch_lookup_remove(void);
95void mutt_ch_set_charset(const char *charset);
96void mutt_ch_cache_cleanup(void);
97
98#define mutt_ch_is_utf8(str) mutt_ch_chscmp(str, "utf-8")
99#define mutt_ch_is_us_ascii(str) mutt_ch_chscmp(str, "us-ascii")
100
102#define ICONV_T_INVALID ((iconv_t) -1)
103
105#define ICONV_ILLEGAL_SEQ ((size_t) -1)
107#define ICONV_BUF_TOO_SMALL ((size_t) -2)
108
114static inline bool iconv_t_valid(const iconv_t cd)
115{
116 return cd != ICONV_T_INVALID;
117}
118
119#endif /* MUTT_MUTT_CHARSET_H */
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition: charset.c:894
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:697
void mutt_ch_lookup_remove(void)
Remove all the character set lookups.
Definition: charset.c:541
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:1111
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:102
char * mutt_ch_get_langinfo_charset(void)
Get the user's choice of character set.
Definition: charset.c:486
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:509
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:1178
const char * mutt_ch_iconv_lookup(const char *chs)
Look for a replacement character set.
Definition: charset.c:781
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition: charset.c:831
LookupType
Types of character set lookups.
Definition: charset.h:68
@ MUTT_LOOKUP_ICONV
Character set conversion.
Definition: charset.h:70
@ MUTT_LOOKUP_CHARSET
Alias for another character set.
Definition: charset.h:69
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Definition: charset.c:1078
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:796
const char * mutt_ch_charset_lookup(const char *chs)
Look for a replacement character set.
Definition: charset.c:562
int mutt_ch_fgetconv(struct FgetConv *fc)
Convert a file's character set.
Definition: charset.c:983
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:933
char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc)
Convert a file's charset into a string buffer.
Definition: charset.c:1045
bool mutt_ch_chscmp(const char *cs1, const char *cs2)
Are the names of two character sets equivalent?
Definition: charset.c:442
void mutt_ch_fgetconv_close(struct FgetConv **ptr)
Close an fgetconv handle.
Definition: charset.c:965
iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags)
Set up iconv for conversions.
Definition: charset.c:594
const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset)
Get the default character set.
Definition: charset.c:465
static bool iconv_t_valid(const iconv_t cd)
Is the conversion descriptor valid?
Definition: charset.h:114
String manipulation buffer.
Definition: buffer.h:36
A dummy converter.
Definition: charset.h:59
FILE * fp
Definition: charset.h:60
iconv_t cd
iconv conversion descriptor
Definition: charset.h:61
Cursor for converting a file's encoding.
Definition: charset.h:43
char bufi[512]
Definition: charset.h:46
iconv_t cd
iconv conversion descriptor
Definition: charset.h:45
char bufo[512]
Definition: charset.h:47
size_t ibl
Definition: charset.h:51
FILE * fp
Definition: charset.h:44
char * p
Definition: charset.h:48
const char ** inrepls
Definition: charset.h:52
char * ib
Definition: charset.h:50
char * ob
Definition: charset.h:49
String list.
Definition: slist.h:37