Blender  V2.93
utfconv.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2012 Blender Foundation.
17  * All rights reserved.
18  *
19  */
20 
21 #ifndef __UTFCONV_H__
22 #define __UTFCONV_H__
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <wchar.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
37 size_t count_utf_8_from_16(const wchar_t *string16);
38 
44 size_t count_utf_16_from_8(const char *string8);
45 
46 /*
47  * conv_utf_*** errors
48  */
49 
51 #define UTF_ERROR_NULL_IN (1 << 0)
53 #define UTF_ERROR_ILLCHAR (1 << 1)
55 #define UTF_ERROR_SMALL (1 << 2)
57 #define UTF_ERROR_ILLSEQ (1 << 3)
58 
66 int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8);
67 
75 int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16);
76 
83 char *alloc_utf_8_from_16(const wchar_t *in16, size_t add);
84 
92 wchar_t *alloc_utf16_from_8(const char *in8, size_t add);
93 
94 /* Easy allocation and conversion of new utf-16 string. New string has _16 suffix.
95  * Must be deallocated with UTF16_UN_ENCODE in right order. */
96 #define UTF16_ENCODE(in8str) \
97  if (1) { \
98  wchar_t *in8str##_16 = alloc_utf16_from_8((const char *)in8str, 0)
99 
100 #define UTF16_UN_ENCODE(in8str) \
101  free(in8str##_16); \
102  } \
103  (void)0
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* __UTFCONV_H__ */
static void add(GHash *messages, MemArena *memarena, const Message *msg)
Definition: msgfmt.c:268
size_t count_utf_8_from_16(const wchar_t *string16)
Definition: utfconv.c:23
wchar_t * alloc_utf16_from_8(const char *in8, size_t add)
Definition: utfconv.c:296
int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16)
Definition: utfconv.c:189
char * alloc_utf_8_from_16(const wchar_t *in16, size_t add)
Definition: utfconv.c:285
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)
Definition: utfconv.c:127
size_t count_utf_16_from_8(const char *string8)
Definition: utfconv.c:70