Merge branch '2121_dir_symlink'
[kaloumi3.git] / src / ecs.h
blob7910a9ae5ef30ae42e68b716fb67cf1383078f03
1 /*
2 Basic support for extended character sets.
4 Written by:
5 Roland Illig <roland.illig@gmx.de>, 2005.
7 This file is part of the Midnight Commander.
9 The Midnight Commander is free software; you can redistribute it
10 and/or modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
14 The Midnight Commander is distributed in the hope that it will be
15 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
16 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 MA 02110-1301, USA.
25 /** \file ecs.h
26 * \brief Header: basic support for extended character sets
29 #ifndef MC_ECS_H
30 #define MC_ECS_H
33 * This header provides string processing functions for extended
34 * character sets (ECS), as well as for the traditional one-to-one
35 * byte-to-character encoding.
38 #include <sys/types.h> /* size_t */
40 #include "lib/global.h" /* include <glib.h> */
42 /* Use the macros ECS_CHAR and ECS_STR to bring character and string
43 * literals to the correct form required by the C compiler. */
44 #ifdef EXTCHARSET_ENABLED
45 # include <stdlib.h>
46 typedef wchar_t ecs_char;
47 # define ECS_CHAR(c) (L##c)
48 # define ECS_STR(s) (L##s)
49 #else
50 typedef char ecs_char;
51 # define ECS_CHAR(c) (c)
52 # define ECS_STR(s) (s)
53 #endif
56 * String conversion functions between the wide character encoding and
57 * the multibyte encoding. The returned strings should be freed using
58 * g_free after use. The return value is TRUE if the string is valid
59 * and has been converted, FALSE otherwise.
62 extern gboolean ecs_mbstr_to_str(ecs_char **ret_str, const char *);
63 extern gboolean ecs_str_to_mbstr(char **ret_str, const ecs_char *);
66 * Replacements for the ISO C90 <ctype.h> functions.
69 extern gboolean ecs_isalnum(ecs_char);
70 extern gboolean ecs_isalpha(ecs_char);
71 extern gboolean ecs_iscntrl(ecs_char);
72 extern gboolean ecs_isdigit(ecs_char);
73 extern gboolean ecs_isgraph(ecs_char);
74 extern gboolean ecs_islower(ecs_char);
75 extern gboolean ecs_isprint(ecs_char);
76 extern gboolean ecs_ispunct(ecs_char);
77 extern gboolean ecs_isspace(ecs_char);
78 extern gboolean ecs_isupper(ecs_char);
79 extern gboolean ecs_isxdigit(ecs_char);
82 * Replacements for the ISO C90 <string.h> functions.
85 /* left out: ecs_strcpy */
86 /* left out: ecs_strncpy */
87 /* left out: ecs_strcat */
88 /* left out: ecs_strncat */
89 extern int ecs_strcmp(const ecs_char *, const ecs_char *);
90 /* left out: ecs_strcoll */
91 /* left out: ecs_strncmp */
92 /* left out: ecs_strxfrm */
93 extern ecs_char *ecs_strchr(const ecs_char *, ecs_char);
94 extern size_t ecs_strcspn(const ecs_char *, const ecs_char *);
95 /* left out: ecs_strpbrk */
96 extern ecs_char *ecs_strrchr(const ecs_char *, ecs_char);
97 extern size_t ecs_strspn(const ecs_char *, const ecs_char *);
98 extern ecs_char *ecs_strstr(const ecs_char *, const ecs_char *);
99 /* left out: ecs_strtok */
100 extern size_t ecs_strlen(const ecs_char *);
103 * Other string functions.
106 /* allocates a copy of the string. Never returns NULL. */
107 extern ecs_char *ecs_xstrdup(const ecs_char *);
109 extern size_t ecs_strlcpy(ecs_char *, const ecs_char *, size_t);
110 extern size_t ecs_strlcat(ecs_char *, const ecs_char *, size_t);
112 /* calculates the bounds of the box that the string would occupy when
113 * displayed on screen. Returns TRUE if all characters in the string are
114 * either '\n' or printable, according to the current locale. If the
115 * return value is FALSE, ''width'' and ''height'' are not modified. */
116 extern gboolean ecs_strbox(const ecs_char *, size_t *ret_width,
117 size_t *ret_height);
119 #endif