Blender  V3.3
utfconv.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2012 Blender Foundation. All rights reserved. */
3 
8 #ifndef __UTFCONV_H__
9 #define __UTFCONV_H__
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <wchar.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
24 size_t count_utf_8_from_16(const wchar_t *string16);
25 
31 size_t count_utf_16_from_8(const char *string8);
32 
33 /*
34  * conv_utf_*** errors
35  */
36 
38 #define UTF_ERROR_NULL_IN (1 << 0)
40 #define UTF_ERROR_ILLCHAR (1 << 1)
42 #define UTF_ERROR_SMALL (1 << 2)
44 #define UTF_ERROR_ILLSEQ (1 << 3)
45 
53 int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8);
54 
62 int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16);
63 
70 char *alloc_utf_8_from_16(const wchar_t *in16, size_t add);
71 
79 wchar_t *alloc_utf16_from_8(const char *in8, size_t add);
80 
81 /* Easy allocation and conversion of new utf-16 string. New string has _16 suffix.
82  * Must be deallocated with UTF16_UN_ENCODE in right order. */
83 #define UTF16_ENCODE(in8str) \
84  if (1) { \
85  wchar_t *in8str##_16 = alloc_utf16_from_8((const char *)in8str, 0)
86 
87 #define UTF16_UN_ENCODE(in8str) \
88  free(in8str##_16); \
89  } \
90  (void)0
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif /* __UTFCONV_H__ */
bool add(void *owner, const AttributeIDRef &attribute_id, eAttrDomain domain, eCustomDataType data_type, const AttributeInit &initializer)
size_t count_utf_8_from_16(const wchar_t *string16)
Definition: utfconv.c:10
wchar_t * alloc_utf16_from_8(const char *in8, size_t add)
Definition: utfconv.c:291
int conv_utf_8_to_16(const char *in8, wchar_t *out16, size_t size16)
Definition: utfconv.c:181
char * alloc_utf_8_from_16(const wchar_t *in16, size_t add)
Definition: utfconv.c:279
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)
Definition: utfconv.c:115
size_t count_utf_16_from_8(const char *string8)
Definition: utfconv.c:57