1/* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
25 */
26
27#ifndef __G_CONVERT_H__
28#define __G_CONVERT_H__
29
30#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
31#error "Only <glib.h> can be included directly."
32#endif
33
34#include <glib/gerror.h>
35
36G_BEGIN_DECLS
37
38/**
39 * GConvertError:
40 * @G_CONVERT_ERROR_NO_CONVERSION: Conversion between the requested character
41 * sets is not supported.
42 * @G_CONVERT_ERROR_ILLEGAL_SEQUENCE: Invalid byte sequence in conversion input;
43 * or the character sequence could not be represented in the target
44 * character set.
45 * @G_CONVERT_ERROR_FAILED: Conversion failed for some reason.
46 * @G_CONVERT_ERROR_PARTIAL_INPUT: Partial character sequence at end of input.
47 * @G_CONVERT_ERROR_BAD_URI: URI is invalid.
48 * @G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: Pathname is not an absolute path.
49 * @G_CONVERT_ERROR_NO_MEMORY: No memory available. Since: 2.40
50 * @G_CONVERT_ERROR_EMBEDDED_NUL: An embedded NUL character is present in
51 * conversion output where a NUL-terminated string is expected.
52 * Since: 2.56
53 *
54 * Error codes returned by character set conversion routines.
55 */
56typedef enum
57{
58 G_CONVERT_ERROR_NO_CONVERSION,
59 G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
60 G_CONVERT_ERROR_FAILED,
61 G_CONVERT_ERROR_PARTIAL_INPUT,
62 G_CONVERT_ERROR_BAD_URI,
63 G_CONVERT_ERROR_NOT_ABSOLUTE_PATH,
64 G_CONVERT_ERROR_NO_MEMORY,
65 G_CONVERT_ERROR_EMBEDDED_NUL
66} GConvertError;
67
68/**
69 * G_CONVERT_ERROR:
70 *
71 * Error domain for character set conversions. Errors in this domain will
72 * be from the #GConvertError enumeration. See #GError for information on
73 * error domains.
74 */
75#define G_CONVERT_ERROR g_convert_error_quark()
76GLIB_AVAILABLE_IN_ALL
77GQuark g_convert_error_quark (void);
78
79/**
80 * GIConv: (skip)
81 *
82 * The GIConv struct wraps an iconv() conversion descriptor. It contains
83 * private data and should only be accessed using the following functions.
84 */
85typedef struct _GIConv *GIConv;
86
87GLIB_AVAILABLE_IN_ALL
88GIConv g_iconv_open (const gchar *to_codeset,
89 const gchar *from_codeset);
90GLIB_AVAILABLE_IN_ALL
91gsize g_iconv (GIConv converter,
92 gchar **inbuf,
93 gsize *inbytes_left,
94 gchar **outbuf,
95 gsize *outbytes_left);
96GLIB_AVAILABLE_IN_ALL
97gint g_iconv_close (GIConv converter);
98
99
100GLIB_AVAILABLE_IN_ALL
101gchar* g_convert (const gchar *str,
102 gssize len,
103 const gchar *to_codeset,
104 const gchar *from_codeset,
105 gsize *bytes_read,
106 gsize *bytes_written,
107 GError **error) G_GNUC_MALLOC;
108GLIB_AVAILABLE_IN_ALL
109gchar* g_convert_with_iconv (const gchar *str,
110 gssize len,
111 GIConv converter,
112 gsize *bytes_read,
113 gsize *bytes_written,
114 GError **error) G_GNUC_MALLOC;
115GLIB_AVAILABLE_IN_ALL
116gchar* g_convert_with_fallback (const gchar *str,
117 gssize len,
118 const gchar *to_codeset,
119 const gchar *from_codeset,
120 const gchar *fallback,
121 gsize *bytes_read,
122 gsize *bytes_written,
123 GError **error) G_GNUC_MALLOC;
124
125
126/* Convert between libc's idea of strings and UTF-8.
127 */
128GLIB_AVAILABLE_IN_ALL
129gchar* g_locale_to_utf8 (const gchar *opsysstring,
130 gssize len,
131 gsize *bytes_read,
132 gsize *bytes_written,
133 GError **error) G_GNUC_MALLOC;
134GLIB_AVAILABLE_IN_ALL
135gchar* g_locale_from_utf8 (const gchar *utf8string,
136 gssize len,
137 gsize *bytes_read,
138 gsize *bytes_written,
139 GError **error) G_GNUC_MALLOC;
140
141/* Convert between the operating system (or C runtime)
142 * representation of file names and UTF-8.
143 */
144GLIB_AVAILABLE_IN_ALL
145gchar* g_filename_to_utf8 (const gchar *opsysstring,
146 gssize len,
147 gsize *bytes_read,
148 gsize *bytes_written,
149 GError **error) G_GNUC_MALLOC;
150GLIB_AVAILABLE_IN_ALL
151gchar* g_filename_from_utf8 (const gchar *utf8string,
152 gssize len,
153 gsize *bytes_read,
154 gsize *bytes_written,
155 GError **error) G_GNUC_MALLOC;
156
157GLIB_AVAILABLE_IN_ALL
158gchar *g_filename_from_uri (const gchar *uri,
159 gchar **hostname,
160 GError **error) G_GNUC_MALLOC;
161
162GLIB_AVAILABLE_IN_ALL
163gchar *g_filename_to_uri (const gchar *filename,
164 const gchar *hostname,
165 GError **error) G_GNUC_MALLOC;
166GLIB_AVAILABLE_IN_ALL
167gchar *g_filename_display_name (const gchar *filename) G_GNUC_MALLOC;
168GLIB_AVAILABLE_IN_ALL
169gboolean g_get_filename_charsets (const gchar ***filename_charsets);
170
171GLIB_AVAILABLE_IN_ALL
172gchar *g_filename_display_basename (const gchar *filename) G_GNUC_MALLOC;
173
174GLIB_AVAILABLE_IN_ALL
175gchar **g_uri_list_extract_uris (const gchar *uri_list);
176
177G_END_DECLS
178
179#endif /* __G_CONVERT_H__ */
180