Freeciv-3.2
Loading...
Searching...
No Matches
fc_utf8.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifndef FC__FC_UTF8_H
15#define FC__FC_UTF8_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21/****************************************************************************
22 This module provides tools to make safe operations on UTF-8 strings. All
23 functions are prefixed with fc_utf8_*. There are two main categories of
24 functions:
25 - the ones which truncate the strings at the first UTF-8 invalid
26 character. They are named *_trunc();
27 - the ones which attempts to replace the invalid characters by the
28 replacement character (U+FFFD). They are named *_rep().
29****************************************************************************/
30
31extern const char fc_utf8_skip[256];
32
33/* UTF-8 character functions. */
34bool fc_utf8_char_validate(const char *utf8_char)
36const char *fc_utf8_find_next_char(const char *utf8_char)
38const char *fc_utf8_find_prev_char(const char *utf8_char,
39 const char *utf8_string)
40 fc__attribute((nonnull (1, 2)));
41/* Jump to next UTF-8 character, assuming it is a valid UTF-8 string. */
42#define fc_ut8_next_char(utf8_char) \
43 (utf8_char + fc_utf8_skip[*(unsigned char *) utf8_char])
44
45/* UTF-8 string functions. */
46bool fc_utf8_validate(const char *utf8_string, const char **end)
48bool fc_utf8_validate_len(const char *utf8_string, size_t byte_len,
49 const char **end)
51
59
65
68
69/* UTF-8-safe replacements of some string utilities. See also functions
70 * defined in "support.[ch]". */
71size_t fc_utf8_strlcpy_trunc(char *dest, const char *src, size_t n)
72 fc__attribute((nonnull (1, 2)));
73size_t fc_utf8_strlcpy_rep(char *dest, const char *src, size_t n)
74 fc__attribute((nonnull (1, 2)));
75size_t fc_utf8_strlcat_trunc(char *dest, const char *src, size_t n)
76 fc__attribute((nonnull (1, 2)));
77size_t fc_utf8_strlcat_rep(char *dest, const char *src, size_t n)
78 fc__attribute((nonnull (1, 2)));
79
80int fc_utf8_snprintf_trunc(char *str, size_t n, const char *format, ...)
83int fc_utf8_snprintf_rep(char *str, size_t n, const char *format, ...)
85 fc__attribute((nonnull (1, 3)));
86int fc_utf8_vsnprintf_trunc(char *str, size_t n, const char *format,
87 va_list args)
88 fc__attribute((nonnull (1, 3)));
89int fc_utf8_vsnprintf_rep(char *str, size_t n, const char *format,
90 va_list args)
91 fc__attribute((nonnull (1, 3)));
92int cat_utf8_snprintf_trunc(char *str, size_t n, const char *format, ...)
94 fc__attribute((nonnull (1, 3)));
95int cat_utf8_snprintf_rep(char *str, size_t n, const char *format, ...)
97 fc__attribute((nonnull (1, 3)));
98
99#ifdef __cplusplus
100}
101#endif /* __cplusplus */
102
103#endif /* FC__FC_UTF8_H */
#define str
Definition astring.c:76
#define n
Definition astring.c:77
char * incite_cost
Definition comments.c:75
char * fc_utf8_validate_trunc_dup(const char *utf8_string) fc__attribute((nonnull(1))) fc__attribute((warn_unused_result))
Definition fc_utf8.c:345
int int int cat_utf8_snprintf_trunc(char *str, size_t n, const char *format,...) fc__attribute((__format__(__printf__
char * fc_utf8_validate_trunc_len(char *utf8_string, size_t byte_len) fc__attribute((nonnull(1)))
Definition fc_utf8.c:327
int cat_utf8_snprintf_rep(char *str, size_t n, const char *format,...) fc__attribute((__format__(__printf__
bool fc_utf8_validate(const char *utf8_string, const char **end) fc__attribute((nonnull(1)))
Definition fc_utf8.c:239
const char * fc_utf8_find_prev_char(const char *utf8_char, const char *utf8_string) fc__attribute((nonnull(1
const char * fc_utf8_find_next_char(const char *utf8_char) fc__attribute((nonnull(1)))
Definition fc_utf8.c:204
bool fc_utf8_validate_len(const char *utf8_string, size_t byte_len, const char **end) fc__attribute((nonnull(1)))
Definition fc_utf8.c:268
int fc_utf8_snprintf_rep(char *str, size_t n, const char *format,...) fc__attribute((__format__(__printf__
size_t size_t size_t fc_utf8_strlcat_trunc(char *dest, const char *src, size_t n) fc__attribute((nonnull(1
char * fc_utf8_validate_rep_len(char *utf8_string, size_t byte_len) fc__attribute((nonnull(1)))
Definition fc_utf8.c:368
size_t fc_utf8_strlen(const char *utf8_string) fc__attribute((nonnull(1)))
Definition fc_utf8.c:425
bool fc_utf8_char_validate(const char *utf8_char) fc__attribute((nonnull(1)))
Definition fc_utf8.c:193
int int fc_utf8_vsnprintf_rep(char *str, size_t n, const char *format, va_list args) fc__attribute((nonnull(1
size_t size_t size_t size_t int fc_utf8_snprintf_trunc(char *str, size_t n, const char *format,...) fc__attribute((__format__(__printf__
int fc_utf8_vsnprintf_trunc(char *str, size_t n, const char *format, va_list args) fc__attribute((nonnull(1
size_t size_t size_t size_t fc_utf8_strlcat_rep(char *dest, const char *src, size_t n) fc__attribute((nonnull(1
size_t fc_utf8_strlcpy_trunc(char *dest, const char *src, size_t n) fc__attribute((nonnull(1
char * fc_utf8_validate_trunc(char *utf8_string) fc__attribute((nonnull(1)))
Definition fc_utf8.c:309
char * fc_utf8_validate_rep_dup(const char *utf8_string) fc__attribute((nonnull(1))) fc__attribute((warn_unused_result))
Definition fc_utf8.c:386
const char fc_utf8_skip[256]
Definition fc_utf8.c:31
size_t size_t fc_utf8_strlcpy_rep(char *dest, const char *src, size_t n) fc__attribute((nonnull(1
#define fc__attribute(x)
Definition support.h:99