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