Subversion
Loading...
Searching...
No Matches
svn_utf.h
Go to the documentation of this file.
1/**
2 * @copyright
3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 * ====================================================================
21 * @endcopyright
22 *
23 * @file svn_utf.h
24 * @brief UTF-8 conversion routines
25 *
26 * Whenever a conversion routine cannot convert to or from UTF-8, the
27 * error returned has code @c APR_EINVAL.
28 */
29
30
31␌
32#ifndef SVN_UTF_H
33#define SVN_UTF_H
34
35#include <apr_pools.h>
36#include <apr_xlate.h> /* for APR_*_CHARSET */
37
38#include "svn_types.h"
39#include "svn_string.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
45/**
46 * To indicate charset names of the current locale
47 */
48#define SVN_APR_LOCALE_CHARSET APR_LOCALE_CHARSET
49
50/**
51 * Indicates the charset of the sourcecode at compile time names. This is
52 * useful if there are literal strings in the source code which must
53 * be translated according to the charset of the source code.
54 */
55#define SVN_APR_DEFAULT_CHARSET APR_DEFAULT_CHARSET
56
57 /**
58 * Initialize the UTF-8 encoding/decoding routines.
59 * Allocate cached translation handles in a subpool of @a pool.
60 *
61 * If @a assume_native_utf8 is TRUE, the native character set is
62 * assumed to be UTF-8, i.e. conversion is a no-op. This is useful
63 * in contexts where the native character set is ASCII but UTF-8
64 * should be used regardless (e.g. for mod_dav_svn which runs within
65 * httpd and always uses the "C" locale).
66 *
67 * @note It is optional to call this function, but if it is used, no other
68 * svn function may be in use in other threads during the call of this
69 * function or when @a pool is cleared or destroyed.
70 * Initializing the UTF-8 routines will improve performance.
71 *
72 * @since New in 1.8.
73 */
74void
76 apr_pool_t *pool);
77
78/**
79 * Like svn_utf_initialize2() but without the ability to force the
80 * native encoding to UTF-8.
81 *
82 * @deprecated Provided for backward compatibility with the 1.7 API.
83 */
85void
86svn_utf_initialize(apr_pool_t *pool);
87
88/** Set @a *dest to a utf8-encoded stringbuf from native stringbuf @a src;
89 * allocate @a *dest in @a pool.
90 */
93 const svn_stringbuf_t *src,
94 apr_pool_t *pool);
95
96
97/** Set @a *dest to a utf8-encoded string from native string @a src; allocate
98 * @a *dest in @a pool.
99 */
102 const svn_string_t *src,
103 apr_pool_t *pool);
104
105
106/** Set @a *dest to a utf8-encoded C string from native C string @a src;
107 * allocate @a *dest in @a pool.
108 */
110svn_utf_cstring_to_utf8(const char **dest,
111 const char *src,
112 apr_pool_t *pool);
113
114
115/** Set @a *dest to a utf8 encoded C string from @a frompage encoded C
116 * string @a src; allocate @a *dest in @a pool.
117 *
118 * @since New in 1.4.
119 */
122 const char *src,
123 const char *frompage,
124 apr_pool_t *pool);
125
126
127/** Like svn_utf_cstring_to_utf8_ex2() but with @a convset_key which is
128 * ignored.
129 *
130 * @deprecated Provided for backward compatibility with the 1.3 API.
131 */
135 const char *src,
136 const char *frompage,
137 const char *convset_key,
138 apr_pool_t *pool);
139
140
141/** Set @a *dest to a natively-encoded stringbuf from utf8 stringbuf @a src;
142 * allocate @a *dest in @a pool.
143 */
146 const svn_stringbuf_t *src,
147 apr_pool_t *pool);
148
149
150/** Set @a *dest to a natively-encoded string from utf8 string @a src;
151 * allocate @a *dest in @a pool.
152 */
155 const svn_string_t *src,
156 apr_pool_t *pool);
157
158
159/** Set @a *dest to a natively-encoded C string from utf8 C string @a src;
160 * allocate @a *dest in @a pool.
161 */
164 const char *src,
165 apr_pool_t *pool);
166
167
168/** Set @a *dest to a @a topage encoded C string from utf8 encoded C string
169 * @a src; allocate @a *dest in @a pool.
170 *
171 * @since New in 1.4.
172 */
175 const char *src,
176 const char *topage,
177 apr_pool_t *pool);
178
179
180/** Like svn_utf_cstring_from_utf8_ex2() but with @a convset_key which is
181 * ignored.
182 *
183 * @deprecated Provided for backward compatibility with the 1.3 API.
184 */
188 const char *src,
189 const char *topage,
190 const char *convset_key,
191 apr_pool_t *pool);
192
193
194/** Return a fuzzily native-encoded C string from utf8 C string @a src,
195 * allocated in @a pool. A fuzzy recoding leaves all 7-bit ascii
196 * characters the same, and substitutes "?\\XXX" for others, where XXX
197 * is the unsigned decimal code for that character.
198 *
199 * This function cannot error; it is guaranteed to return something.
200 * First it will recode as described above and then attempt to convert
201 * the (new) 7-bit UTF-8 string to native encoding. If that fails, it
202 * will return the raw fuzzily recoded string, which may or may not be
203 * meaningful in the client's locale, but is (presumably) better than
204 * nothing.
205 *
206 * ### Notes:
207 *
208 * Improvement is possible, even imminent. The original problem was
209 * that if you converted a UTF-8 string (say, a log message) into a
210 * locale that couldn't represent all the characters, you'd just get a
211 * static placeholder saying "[unconvertible log message]". Then
212 * Justin Erenkrantz pointed out how on platforms that didn't support
213 * conversion at all, "svn log" would still fail completely when it
214 * encountered unconvertible data.
215 *
216 * Now for both cases, the caller can at least fall back on this
217 * function, which converts the message as best it can, substituting
218 * "?\\XXX" escape codes for the non-ascii characters.
219 *
220 * Ultimately, some callers may prefer the iconv "//TRANSLIT" option,
221 * so when we can detect that at configure time, things will change.
222 * Also, this should (?) be moved to apr/apu eventually.
223 *
224 * See https://issues.apache.org/jira/browse/SVN-807 for
225 * details.
226 */
227const char *
229 apr_pool_t *pool);
230
231
232/** Set @a *dest to a natively-encoded C string from utf8 stringbuf @a src;
233 * allocate @a *dest in @a pool.
234 */
237 const svn_stringbuf_t *src,
238 apr_pool_t *pool);
239
240
241/** Set @a *dest to a natively-encoded C string from utf8 string @a src;
242 * allocate @a *dest in @a pool.
243 */
246 const svn_string_t *src,
247 apr_pool_t *pool);
248
249/** Return the display width of UTF-8-encoded C string @a cstr.
250 * If the string is not printable or invalid UTF-8, return -1.
251 *
252 * @since New in 1.8.
253 */
254int
256
257#ifdef __cplusplus
258}
259#endif /* __cplusplus */
260
261#endif /* SVN_UTF_H */
Subversion error object.
Definition svn_types.h:177
A simple counted string.
Definition svn_string.h:97
A buffered string, capable of appending without an allocation and copy for each append.
Definition svn_string.h:105
Counted-length strings for Subversion, plus some C string goodies.
Subversion's data types.
int svn_boolean_t
YABT: Yet Another Boolean Type.
Definition svn_types.h:137
#define SVN_DEPRECATED
Macro used to mark deprecated functions.
Definition svn_types.h:62
svn_error_t * svn_utf_stringbuf_from_utf8(svn_stringbuf_t **dest, const svn_stringbuf_t *src, apr_pool_t *pool)
Set *dest to a natively-encoded stringbuf from utf8 stringbuf src; allocate *dest in pool.
svn_error_t * svn_utf_stringbuf_to_utf8(svn_stringbuf_t **dest, const svn_stringbuf_t *src, apr_pool_t *pool)
Set *dest to a utf8-encoded stringbuf from native stringbuf src; allocate *dest in pool.
svn_error_t * svn_utf_cstring_from_utf8_stringbuf(const char **dest, const svn_stringbuf_t *src, apr_pool_t *pool)
Set *dest to a natively-encoded C string from utf8 stringbuf src; allocate *dest in pool.
svn_error_t * svn_utf_cstring_from_utf8(const char **dest, const char *src, apr_pool_t *pool)
Set *dest to a natively-encoded C string from utf8 C string src; allocate *dest in pool.
svn_error_t * svn_utf_cstring_from_utf8_ex(const char **dest, const char *src, const char *topage, const char *convset_key, apr_pool_t *pool)
Like svn_utf_cstring_from_utf8_ex2() but with convset_key which is ignored.
int svn_utf_cstring_utf8_width(const char *cstr)
Return the display width of UTF-8-encoded C string cstr.
svn_error_t * svn_utf_string_from_utf8(const svn_string_t **dest, const svn_string_t *src, apr_pool_t *pool)
Set *dest to a natively-encoded string from utf8 string src; allocate *dest in pool.
svn_error_t * svn_utf_cstring_from_utf8_string(const char **dest, const svn_string_t *src, apr_pool_t *pool)
Set *dest to a natively-encoded C string from utf8 string src; allocate *dest in pool.
svn_error_t * svn_utf_string_to_utf8(const svn_string_t **dest, const svn_string_t *src, apr_pool_t *pool)
Set *dest to a utf8-encoded string from native string src; allocate *dest in pool.
svn_error_t * svn_utf_cstring_to_utf8(const char **dest, const char *src, apr_pool_t *pool)
Set *dest to a utf8-encoded C string from native C string src; allocate *dest in pool.
svn_error_t * svn_utf_cstring_to_utf8_ex(const char **dest, const char *src, const char *frompage, const char *convset_key, apr_pool_t *pool)
Like svn_utf_cstring_to_utf8_ex2() but with convset_key which is ignored.
const char * svn_utf_cstring_from_utf8_fuzzy(const char *src, apr_pool_t *pool)
Return a fuzzily native-encoded C string from utf8 C string src, allocated in pool.
void svn_utf_initialize2(svn_boolean_t assume_native_utf8, apr_pool_t *pool)
Initialize the UTF-8 encoding/decoding routines.
svn_error_t * svn_utf_cstring_from_utf8_ex2(const char **dest, const char *src, const char *topage, apr_pool_t *pool)
Set *dest to a topage encoded C string from utf8 encoded C string src; allocate *dest in pool.
void svn_utf_initialize(apr_pool_t *pool)
Like svn_utf_initialize2() but without the ability to force the native encoding to UTF-8.
svn_error_t * svn_utf_cstring_to_utf8_ex2(const char **dest, const char *src, const char *frompage, apr_pool_t *pool)
Set *dest to a utf8 encoded C string from frompage encoded C string src; allocate *dest in pool.