NeoMutt  2024-12-12-14-g7b49f7
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 <stdio.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{
62};
63
64#define MUTT_ICONV_NO_FLAGS 0
65#define MUTT_ICONV_HOOK_FROM 1
66
67void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name);
68const char * mutt_ch_charset_lookup(const char *chs);
69int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to);
70bool mutt_ch_check_charset(const char *cs, bool strict);
71char * mutt_ch_choose(const char *fromcode, const struct Slist *charsets, const char *u, size_t ulen, char **d, size_t *dlen);
72bool mutt_ch_chscmp(const char *cs1, const char *cs2);
73int mutt_ch_convert_nonmime_string(const struct Slist *const assumed_charset, const char *charset, char **ps);
74int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags);
75int mutt_ch_fgetconv(struct FgetConv *fc);
76void mutt_ch_fgetconv_close(struct FgetConv **ptr);
77struct FgetConv *mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags);
78char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc);
79const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset);
81size_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);
82const char * mutt_ch_iconv_lookup(const char *chs);
83iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags);
84bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);
85void mutt_ch_lookup_remove(void);
86void mutt_ch_set_charset(const char *charset);
87void mutt_ch_cache_cleanup(void);
88
89#define mutt_ch_is_utf8(str) mutt_ch_chscmp(str, "utf-8")
90#define mutt_ch_is_us_ascii(str) mutt_ch_chscmp(str, "us-ascii")
91
93#define ICONV_T_INVALID ((iconv_t) -1)
94
96#define ICONV_ILLEGAL_SEQ ((size_t) -1)
98#define ICONV_BUF_TOO_SMALL ((size_t) -2)
99
105static inline bool iconv_t_valid(const iconv_t cd)
106{
107 return cd != ICONV_T_INVALID;
108}
109
110#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:1108
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:93
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:1175
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:59
@ MUTT_LOOKUP_ICONV
Character set conversion.
Definition: charset.h:61
@ MUTT_LOOKUP_CHARSET
Alias for another character set.
Definition: charset.h:60
void mutt_ch_set_charset(const char *charset)
Update the records for a new character set.
Definition: charset.c:1075
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:980
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:1042
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:962
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:105
String manipulation buffer.
Definition: buffer.h:36
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