3 * ====================================================================
4 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
19 * @brief UTF-8 conversion routines
27 #include <apr_xlate.h>
29 #include "svn_error.h"
30 #include "svn_string.h"
34 #endif /* __cplusplus */
38 #define SVN_APR_LOCALE_CHARSET APR_LOCALE_CHARSET
39 #define SVN_APR_DEFAULT_CHARSET APR_DEFAULT_CHARSET
41 /* APR_LOCALE_CHARSET and APR_DEFAULT_CHARSET are defined as ints on
43 #define SVN_APR_LOCALE_CHARSET (const char*)APR_LOCALE_CHARSET
44 #define SVN_APR_DEFAULT_CHARSET (const char*)APR_DEFAULT_CHARSET
48 * Initialize the UTF-8 encoding/decoding routines.
49 * Allocate cached translation handles in a subpool of @a pool.
51 * @note It is optional to call this function, but if it is used, no other
52 * svn function may be in use in other threads during the call of this
53 * function or when @a pool is cleared or destroyed.
54 * Initializing the UTF-8 routines will improve performance.
58 void svn_utf_initialize(apr_pool_t
*pool
);
60 /** Set @a *dest to a utf8-encoded stringbuf from native stringbuf @a src;
61 * allocate @a *dest in @a pool.
63 svn_error_t
*svn_utf_stringbuf_to_utf8(svn_stringbuf_t
**dest
,
64 const svn_stringbuf_t
*src
,
68 /** Set @a *dest to a utf8-encoded string from native string @a src; allocate
69 * @a *dest in @a pool.
71 svn_error_t
*svn_utf_string_to_utf8(const svn_string_t
**dest
,
72 const svn_string_t
*src
,
76 /** Set @a *dest to a utf8-encoded C string from native C string @a src;
77 * allocate @a *dest in @a pool.
79 svn_error_t
*svn_utf_cstring_to_utf8(const char **dest
,
84 /** Set @a *dest to a utf8 encoded C string from @a frompage encoded C
85 * string @a src; allocate @a *dest in @a pool.
89 svn_error_t
*svn_utf_cstring_to_utf8_ex2(const char **dest
,
95 /** Like svn_utf_cstring_to_utf8_ex2() but with @a convset_key which is
98 * @deprecated Provided for backward compatibility with the 1.3 API.
100 svn_error_t
*svn_utf_cstring_to_utf8_ex(const char **dest
,
102 const char *frompage
,
103 const char *convset_key
,
107 /** Set @a *dest to a natively-encoded stringbuf from utf8 stringbuf @a src;
108 * allocate @a *dest in @a pool.
110 svn_error_t
*svn_utf_stringbuf_from_utf8(svn_stringbuf_t
**dest
,
111 const svn_stringbuf_t
*src
,
115 /** Set @a *dest to a natively-encoded string from utf8 string @a src;
116 * allocate @a *dest in @a pool.
118 svn_error_t
*svn_utf_string_from_utf8(const svn_string_t
**dest
,
119 const svn_string_t
*src
,
123 /** Set @a *dest to a natively-encoded C string from utf8 C string @a src;
124 * allocate @a *dest in @a pool.
126 svn_error_t
*svn_utf_cstring_from_utf8(const char **dest
,
131 /** Set @a *dest to a @a topage encoded C string from utf8 encoded C string
132 * @a src; allocate @a *dest in @a pool.
136 svn_error_t
*svn_utf_cstring_from_utf8_ex2(const char **dest
,
142 /** Like svn_utf_cstring_from_utf8_ex2() but with @a convset_key which is
145 * @deprecated Provided for backward compatibility with the 1.3 API.
147 svn_error_t
*svn_utf_cstring_from_utf8_ex(const char **dest
,
150 const char *convset_key
,
154 /** Return a fuzzily native-encoded C string from utf8 C string @a src,
155 * allocated in @a pool. A fuzzy recoding leaves all 7-bit ascii
156 * characters the same, and substitutes "?\\XXX" for others, where XXX
157 * is the unsigned decimal code for that character.
159 * This function cannot error; it is guaranteed to return something.
160 * First it will recode as described above and then attempt to convert
161 * the (new) 7-bit UTF-8 string to native encoding. If that fails, it
162 * will return the raw fuzzily recoded string, which may or may not be
163 * meaningful in the client's locale, but is (presumably) better than
168 * Improvement is possible, even imminent. The original problem was
169 * that if you converted a UTF-8 string (say, a log message) into a
170 * locale that couldn't represent all the characters, you'd just get a
171 * static placeholder saying "[unconvertible log message]". Then
172 * Justin Erenkrantz pointed out how on platforms that didn't support
173 * conversion at all, "svn log" would still fail completely when it
174 * encountered unconvertible data.
176 * Now for both cases, the caller can at least fall back on this
177 * function, which converts the message as best it can, substituting
178 * "?\\XXX" escape codes for the non-ascii characters.
180 * Ultimately, some callers may prefer the iconv "//TRANSLIT" option,
181 * so when we can detect that at configure time, things will change.
182 * Also, this should (?) be moved to apr/apu eventually.
184 * See http://subversion.tigris.org/issues/show_bug.cgi?id=807 for
187 const char *svn_utf_cstring_from_utf8_fuzzy(const char *src
,
191 /** Set @a *dest to a natively-encoded C string from utf8 stringbuf @a src;
192 * allocate @a *dest in @a pool.
194 svn_error_t
*svn_utf_cstring_from_utf8_stringbuf(const char **dest
,
195 const svn_stringbuf_t
*src
,
199 /** Set @a *dest to a natively-encoded C string from utf8 string @a src;
200 * allocate @a *dest in @a pool.
202 svn_error_t
*svn_utf_cstring_from_utf8_string(const char **dest
,
203 const svn_string_t
*src
,
208 #endif /* __cplusplus */
210 #endif /* SVN_UTF_H */