1 /*$
2  Copyright (C) 2013-2020 Azel.
3 
4  This file is part of AzPainter.
5 
6  AzPainter is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  AzPainter 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
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 $*/
19 
20 #ifndef MLIB_UTIL_CHARCODE_H
21 #define MLIB_UTIL_CHARCODE_H
22 
23 #include <stddef.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /* UTF-8 */
30 
31 int mUTF8CharWidth(const char *p);
32 int mUTF8ToUCS4Char(const char *src,int maxlen,uint32_t *dst,const char **ppnext);
33 int mUTF8ToUCS4(const char *src,int srclen,uint32_t *dst,int dstlen);
34 uint32_t *mUTF8ToUCS4_alloc(const char *src,int srclen,int *retlen);
35 int mUTF8ToWide(const char *src,int srclen,wchar_t *dst,int dstlen);
36 wchar_t *mUTF8ToWide_alloc(const char *src,int srclen,int *retlen);
37 int mUTF8ToLocal(const char *src,int srclen,char *dst,int dstlen);
38 char *mUTF8ToLocal_alloc(const char *src,int srclen,int *retlen);
39 
40 /* WideChar */
41 
42 int mWideToUTF8(const wchar_t *src,int srclen,char *dst,int dstlen);
43 char *mWideToUTF8_alloc(const wchar_t *src,int srclen,int *retlen);
44 
45 /* Locale */
46 
47 int mLocalToWide(const char *src,int srclen,wchar_t *dst,int dstlen);
48 wchar_t *mLocalToWide_alloc(const char *src,int srclen,int *retlen);
49 char *mLocalToUTF8_alloc(const char *src,int srclen,int *retlen);
50 
51 /* UCS-4 */
52 
53 int mUCS4Len(const uint32_t *p);
54 uint32_t *mUCS4StrDup(const uint32_t *src);
55 int mUCS4ToUTF8Char(uint32_t ucs,char *dst);
56 int mUCS4ToUTF8(const uint32_t *src,int srclen,char *dst,int dstlen);
57 char *mUCS4ToUTF8_alloc(const uint32_t *ucs,int srclen,int *retlen);
58 wchar_t *mUCS4ToWide_alloc(const uint32_t *src,int srclen,int *retlen);
59 int mUCS4ToFloatInt(const uint32_t *text,int dig);
60 int mUCS4Compare(const uint32_t *text1,const uint32_t *text2);
61 
62 /* UTF-16 */
63 
64 int mUTF16Len(const uint16_t *p);
65 int mUTF16ToUCS4Char(const uint16_t *src,uint32_t *dst,const uint16_t **ppnext);
66 int mUTF16ToUTF8(const uint16_t *src,int srclen,char *dst,int dstlen);
67 char *mUTF16ToUTF8_alloc(const uint16_t *src,int srclen,int *retlen);
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 #endif
74