Freeciv-3.1: /fast/freeciv/nightly/S3_1/utility/fc_utf8.h Source File

Freeciv-3.1

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)
35 fc__attribute((nonnull (1)));
36const char *fc_utf8_find_next_char(const char *utf8_char)
37 fc__attribute((nonnull (1)));
38 const 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)
47 fc__attribute((nonnull (1)));
48bool fc_utf8_validate_len(const char *utf8_string, size_t byte_len,
49 const char **end)
50 fc__attribute((nonnull (1)));
51
52char *fc_utf8_validate_trunc(char *utf8_string)
53 fc__attribute((nonnull (1)));
54char *fc_utf8_validate_trunc_len(char *utf8_string, size_t byte_len)
55 fc__attribute((nonnull (1)));
56char *fc_utf8_validate_trunc_dup(const char *utf8_string)
57 fc__attribute((nonnull (1)))
58 fc__attribute((warn_unused_result));
59
60char *fc_utf8_validate_rep_len(char *utf8_string, size_t byte_len)
61 fc__attribute((nonnull (1)));
62char *fc_utf8_validate_rep_dup(const char *utf8_string)
63 fc__attribute((nonnull (1)))
64 fc__attribute((warn_unused_result));
65
66size_t fc_utf8_strlen(const char *utf8_string)
67 fc__attribute((nonnull (1)));
68
69/* UTF-8-safe replacements of some string utilities. See also functions
70 * defined in "support.[ch]". */
71 size_t fc_utf8_strlcpy_trunc(char *dest, const char *src, size_t n)
72 fc__attribute((nonnull (1, 2)));
73 size_t fc_utf8_strlcpy_rep(char *dest, const char *src, size_t n)
74 fc__attribute((nonnull (1, 2)));
75 size_t fc_utf8_strlcat_trunc(char *dest, const char *src, size_t n)
76 fc__attribute((nonnull (1, 2)));
77 size_t fc_utf8_strlcat_rep(char *dest, const char *src, size_t n)
78 fc__attribute((nonnull (1, 2)));
79
80 int fc_utf8_snprintf_trunc(char *str, size_t n, const char *format, ...)
81 fc__attribute((__format__ (__printf__, 3, 4)))
82 fc__attribute((nonnull (1, 3)));
83 int fc_utf8_snprintf_rep(char *str, size_t n, const char *format, ...)
84 fc__attribute((__format__ (__printf__, 3, 4)))
85 fc__attribute((nonnull (1, 3)));
86 int fc_utf8_vsnprintf_trunc(char *str, size_t n, const char *format,
87 va_list args)
88 fc__attribute((nonnull (1, 3)));
89 int fc_utf8_vsnprintf_rep(char *str, size_t n, const char *format,
90 va_list args)
91 fc__attribute((nonnull (1, 3)));
92 int cat_utf8_snprintf_trunc(char *str, size_t n, const char *format, ...)
93 fc__attribute((__format__ (__printf__, 3, 4)))
94 fc__attribute((nonnull (1, 3)));
95 int cat_utf8_snprintf_rep(char *str, size_t n, const char *format, ...)
96 fc__attribute((__format__ (__printf__, 3, 4)))
97 fc__attribute((nonnull (1, 3)));
98
99#ifdef __cplusplus
100}
101#endif /* __cplusplus */
102
103#endif /* FC__FC_UTF8_H */
str
#define str
Definition astring.c:76
n
#define n
Definition astring.c:77
fc_utf8_validate_trunc_dup
char * fc_utf8_validate_trunc_dup(const char *utf8_string) fc__attribute((nonnull(1))) fc__attribute((warn_unused_result))
Definition fc_utf8.c:345
cat_utf8_snprintf_trunc
int int int cat_utf8_snprintf_trunc(char *str, size_t n, const char *format,...) fc__attribute((__format__(__printf__
fc_utf8_validate_trunc_len
char * fc_utf8_validate_trunc_len(char *utf8_string, size_t byte_len) fc__attribute((nonnull(1)))
Definition fc_utf8.c:327
cat_utf8_snprintf_rep
int cat_utf8_snprintf_rep(char *str, size_t n, const char *format,...) fc__attribute((__format__(__printf__
fc_utf8_validate
bool fc_utf8_validate(const char *utf8_string, const char **end) fc__attribute((nonnull(1)))
Definition fc_utf8.c:239
fc_utf8_find_prev_char
const char * fc_utf8_find_prev_char(const char *utf8_char, const char *utf8_string) fc__attribute((nonnull(1
fc_utf8_find_next_char
const char * fc_utf8_find_next_char(const char *utf8_char) fc__attribute((nonnull(1)))
Definition fc_utf8.c:204
fc_utf8_validate_len
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
fc_utf8_snprintf_rep
int fc_utf8_snprintf_rep(char *str, size_t n, const char *format,...) fc__attribute((__format__(__printf__
fc_utf8_strlcat_trunc
size_t size_t size_t fc_utf8_strlcat_trunc(char *dest, const char *src, size_t n) fc__attribute((nonnull(1
fc_utf8_validate_rep_len
char * fc_utf8_validate_rep_len(char *utf8_string, size_t byte_len) fc__attribute((nonnull(1)))
Definition fc_utf8.c:368
fc_utf8_strlen
size_t fc_utf8_strlen(const char *utf8_string) fc__attribute((nonnull(1)))
Definition fc_utf8.c:425
fc_utf8_char_validate
bool fc_utf8_char_validate(const char *utf8_char) fc__attribute((nonnull(1)))
Definition fc_utf8.c:193
fc_utf8_vsnprintf_rep
int int fc_utf8_vsnprintf_rep(char *str, size_t n, const char *format, va_list args) fc__attribute((nonnull(1
fc_utf8_snprintf_trunc
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__
fc_utf8_vsnprintf_trunc
int fc_utf8_vsnprintf_trunc(char *str, size_t n, const char *format, va_list args) fc__attribute((nonnull(1
fc_utf8_strlcat_rep
size_t size_t size_t size_t fc_utf8_strlcat_rep(char *dest, const char *src, size_t n) fc__attribute((nonnull(1
fc_utf8_strlcpy_trunc
size_t fc_utf8_strlcpy_trunc(char *dest, const char *src, size_t n) fc__attribute((nonnull(1
fc_utf8_validate_trunc
char * fc_utf8_validate_trunc(char *utf8_string) fc__attribute((nonnull(1)))
Definition fc_utf8.c:309
fc_utf8_validate_rep_dup
char * fc_utf8_validate_rep_dup(const char *utf8_string) fc__attribute((nonnull(1))) fc__attribute((warn_unused_result))
Definition fc_utf8.c:386
fc_utf8_skip
const char fc_utf8_skip[256]
Definition fc_utf8.c:31
fc_utf8_strlcpy_rep
size_t size_t fc_utf8_strlcpy_rep(char *dest, const char *src, size_t n) fc__attribute((nonnull(1
utf8_char
Definition widget_edit.c:36
fc__attribute
#define fc__attribute(x)
Definition support.h:89