90 static char *dict_utf8_check_fold(
DICT *dict,
const char *
string,
100 *err =
"malformed UTF-8 or invalid codepoint";
113 return ((
char *)
string);
122 *err =
"malformed UTF-8 or invalid codepoint";
130 static const char *dict_utf8_lookup(
DICT *dict,
const char *key)
133 const char *utf8_err;
134 const char *fold_res;
141 if ((fold_res = dict_utf8_check_fold(dict, key, &utf8_err)) == 0) {
142 msg_warn(
"%s:%s: non-UTF-8 key \"%s\": %s",
143 dict->
type, dict->
name, key, utf8_err);
154 value = backup->
lookup(dict, fold_res);
155 dict->
flags |= saved_flags;
160 if (value != 0 && dict_utf8_check(value, &utf8_err) == 0) {
161 msg_warn(
"%s:%s: key \"%s\": non-UTF-8 value \"%s\": %s",
162 dict->
type, dict->
name, key, value, utf8_err);
172 static int dict_utf8_update(
DICT *dict,
const char *key,
const char *value)
175 const char *utf8_err;
176 const char *fold_res;
183 if ((fold_res = dict_utf8_check_fold(dict, key, &utf8_err)) == 0) {
184 msg_warn(
"%s:%s: non-UTF-8 key \"%s\": %s",
185 dict->
type, dict->
name, key, utf8_err);
193 else if (dict_utf8_check(value, &utf8_err) == 0) {
194 msg_warn(
"%s:%s: key \"%s\": non-UTF-8 value \"%s\": %s",
195 dict->
type, dict->
name, key, value, utf8_err);
207 status = backup->
update(dict, fold_res, value);
208 dict->
flags |= saved_flags;
215 static int dict_utf8_delete(
DICT *dict,
const char *key)
218 const char *utf8_err;
219 const char *fold_res;
226 if ((fold_res = dict_utf8_check_fold(dict, key, &utf8_err)) == 0) {
227 msg_warn(
"%s:%s: non-UTF-8 key \"%s\": %s",
228 dict->
type, dict->
name, key, utf8_err);
240 status = backup->
delete(dict, fold_res);
241 dict->
flags |= saved_flags;
250 const char myname[] =
"dict_utf8_activate";
257 msg_panic(
"%s: Unicode support is not available", myname);
259 msg_panic(
"%s: %s:%s does not request Unicode support",
262 msg_panic(
"%s: %s:%s Unicode support is already activated",
284 dict->
lookup = dict_utf8_lookup;
285 dict->
update = dict_utf8_update;
286 dict->
delete = dict_utf8_delete;
#define DICT_FLAG_FOLD_ANY
int(* delete)(struct DICT *, const char *)
NORETURN msg_panic(const char *fmt,...)
int(* delete)(struct DICT *, const char *)
int valid_utf8_string(const char *, ssize_t)
int(* update)(struct DICT *, const char *, const char *)
#define DICT_FLAG_UTF8_REQUEST
#define DICT_FLAG_FOLD_FIX
#define casefold(dst, src)
int(* update)(struct DICT *, const char *, const char *)
#define DICT_STAT_SUCCESS
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
const char *(* lookup)(struct DICT *, const char *)
struct DICT_UTF8_BACKUP * utf8_backup
DICT * dict_utf8_activate(DICT *dict)
#define DICT_FLAG_FOLD_MUL
const char *(* lookup)(struct DICT *, const char *)
const char * CONST_CHAR_STAR
#define DICT_FLAG_UTF8_ACTIVE
void * mymalloc(ssize_t len)