JLChen
2021-08-02 38f4fb064df09f344fc3237409c76a9fba2a8a9e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*****************************************************************************
 * 
 * Copyright (c) 2008-2010, CoreCodec, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of CoreCodec, Inc. nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY CoreCodec, Inc. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL CoreCodec, Inc. BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ****************************************************************************/
 
#ifndef __CHARCONVERT_H
#define __CHARCONVERT_H
 
#include "corec/corec.h"
 
#ifdef __cplusplus
extern "C" {
#endif
 
#if defined(CHARCONVERT_EXPORTS)
#define CHARCONVERT_DLL DLLEXPORT
#elif defined(CHARCONVERT_IMPORTS)
#define CHARCONVERT_DLL DLLIMPORT
#else
#define CHARCONVERT_DLL
#endif
 
typedef struct charconv charconv;
 
#define MAX_CHARSET_NAME    16
 
#define CHARSET_DEFAULT    T("")
#if defined(TARGET_WIN)
#define CHARSET_WCHAR    T("UCS-2")
#elif SIZEOF_WCHAR==4
#define CHARSET_WCHAR    T("UTF-32")
#elif SIZEOF_WCHAR==2
#define CHARSET_WCHAR    T("UTF-16")
#else
#error unsupported wchar_t size!
#endif
#define CHARSET_UTF8    T("UTF-8")
#define CHARSET_UTF16    T("UTF-16")
 
CHARCONVERT_DLL void CharConvDefault(tchar_t* Out, size_t OutLen);
CHARCONVERT_DLL charconv* CharConvOpen(const tchar_t* From, const tchar_t* To);
CHARCONVERT_DLL void CharConvClose(charconv*);
CHARCONVERT_DLL void CharConvSS(charconv*, char* Out,    size_t OutLen, const char* In);
CHARCONVERT_DLL void CharConvWS(charconv*, wchar_t* Out, size_t OutLen, const char* In);
CHARCONVERT_DLL void CharConvSW(charconv*, char* Out,    size_t OutLen, const wchar_t* In);
CHARCONVERT_DLL void CharConvWW(charconv*, wchar_t* Out, size_t OutLen, const wchar_t* In);
 
#if SIZEOF_WCHAR==2
#define CharConvUS CharConvWS
#define CharConvSU CharConvSW
#define CharConvUW CharConvWW
#define CharConvWU CharConvWW
#else
CHARCONVERT_DLL void CharConvUS(charconv*, utf16_t* Out, size_t OutLen, const char* In);
CHARCONVERT_DLL void CharConvSU(charconv*, char* Out,    size_t OutLen, const utf16_t* In);
CHARCONVERT_DLL void CharConvUW(charconv*, utf16_t* Out, size_t OutLen, const wchar_t* In);
CHARCONVERT_DLL void CharConvWU(charconv*, wchar_t* Out, size_t OutLen, const utf16_t* In);
#endif
 
#ifdef UNICODE
#define CharConvTS CharConvWS
#define CharConvTW CharConvWW
#define CharConvST CharConvSW
#define CharConvWT CharConvWW
#define CharConvTU CharConvWU
#define CharConvUT CharConvUW
#else
#define CharConvTS CharConvSS
#define CharConvTW CharConvSW
#define CharConvST CharConvSS
#define CharConvWT CharConvWS
#define CharConvTU CharConvSU
#define CharConvUT CharConvUS
#endif
 
#ifdef __cplusplus
}
#endif
 
#endif