1/* 2 * unicode.h 3 * 4 * $Id: unicode.h,v 1.2 2006/01/20 15:58:35 source Exp $ 5 * 6 * ODBC unicode support 7 * 8 * The iODBC driver manager. 9 * 10 * Copyright (C) 1996-2006 by OpenLink Software <iodbc@openlinksw.com> 11 * All Rights Reserved. 12 * 13 * This software is released under the terms of either of the following 14 * licenses: 15 * 16 * - GNU Library General Public License (see LICENSE.LGPL) 17 * - The BSD License (see LICENSE.BSD). 18 * 19 * Note that the only valid version of the LGPL license as far as this 20 * project is concerned is the original GNU Library General Public License 21 * Version 2, dated June 1991. 22 * 23 * While not mandated by the BSD license, any patches you make to the 24 * iODBC source code may be contributed back into the iODBC project 25 * at your discretion. Contributions will benefit the Open Source and 26 * Data Access community as a whole. Submissions may be made at: 27 * 28 * http://www.iodbc.org 29 * 30 * 31 * GNU Library Generic Public License Version 2 32 * ============================================ 33 * This library is free software; you can redistribute it and/or 34 * modify it under the terms of the GNU Library General Public 35 * License as published by the Free Software Foundation; only 36 * Version 2 of the License dated June 1991. 37 * 38 * This library is distributed in the hope that it will be useful, 39 * but WITHOUT ANY WARRANTY; without even the implied warranty of 40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 41 * Library General Public License for more details. 42 * 43 * You should have received a copy of the GNU Library General Public 44 * License along with this library; if not, write to the Free 45 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 46 * 47 * 48 * The BSD License 49 * =============== 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 54 * 1. Redistributions of source code must retain the above copyright 55 * notice, this list of conditions and the following disclaimer. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in 58 * the documentation and/or other materials provided with the 59 * distribution. 60 * 3. Neither the name of OpenLink Software Inc. nor the names of its 61 * contributors may be used to endorse or promote products derived 62 * from this software without specific prior written permission. 63 * 64 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 65 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 66 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 67 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR 68 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 69 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 70 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 71 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 72 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 73 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 74 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 75 */ 76 77#ifndef _UNICODE_H 78#define _UNICODE_H 79 80#if HAVE_WCHAR_H 81#include <wchar.h> 82#endif 83 84 85/* 86 * Max length of a UTF-8 encoded character sequence 87 */ 88#define UTF8_MAX_CHAR_LEN 4 89 90/* 91 * Function Prototypes 92 */ 93SQLCHAR *dm_SQL_W2A (SQLWCHAR * inStr, ssize_t size); 94SQLCHAR *dm_SQL_WtoU8 (SQLWCHAR * inStr, ssize_t size); 95SQLCHAR *dm_strcpy_W2A (SQLCHAR * destStr, SQLWCHAR * sourStr); 96 97SQLWCHAR *dm_SQL_A2W (SQLCHAR * inStr, ssize_t size); 98SQLWCHAR *dm_SQL_U8toW (SQLCHAR * inStr, SQLSMALLINT size); 99SQLWCHAR *dm_strcpy_A2W (SQLWCHAR * destStr, SQLCHAR * sourStr); 100 101int dm_StrCopyOut2_A2W (SQLCHAR * inStr, SQLWCHAR * outStr, SQLSMALLINT size, 102 SQLSMALLINT * result); 103int dm_StrCopyOut2_U8toW (SQLCHAR * inStr, SQLWCHAR * outStr, size_t size, 104 u_short * result); 105int dm_StrCopyOut2_W2A (SQLWCHAR * inStr, SQLCHAR * outStr, SQLSMALLINT size, 106 SQLSMALLINT * result); 107 108 109# ifdef WIN32 110#define OPL_W2A(w, a, cb) \ 111 WideCharToMultiByte(CP_ACP, 0, w, cb, a, cb, NULL, NULL) 112 113#define OPL_A2W(a, w, cb) \ 114 MultiByteToWideChar(CP_ACP, 0, a, cb, w, cb) 115 116# else 117#define OPL_W2A(XW, XA, SIZE) wcstombs((char *) XA, (wchar_t *) XW, SIZE) 118#define OPL_A2W(XA, XW, SIZE) mbstowcs((wchar_t *) XW, (char *) XA, SIZE) 119# endif 120 121#if MACOSX >= 103 122#define HAVE_WCHAR_H 123#define HAVE_WCSLEN 124#define HAVE_WCSCPY 125#define HAVE_WCSNCPY 126#define HAVE_WCSCHR 127#define HAVE_WCSCAT 128#define HAVE_WCSCMP 129#define HAVE_TOWLOWER 130#endif 131 132/* 133 * Replacement functions 134 */ 135#if !defined(HAVE_WCSLEN) 136size_t wcslen (const wchar_t * wcs); 137#endif 138#if !defined(HAVE_WCSCPY) 139wchar_t * wcscpy (wchar_t * wcd, const wchar_t * wcs); 140#endif 141#if !defined(HAVE_WCSNCPY) 142wchar_t * wcsncpy (wchar_t * wcd, const wchar_t * wcs, size_t n); 143#endif 144#if !defined(HAVE_WCSCHR) 145wchar_t* wcschr(const wchar_t *wcs, const wchar_t wc); 146#endif 147#if !defined(HAVE_WCSCAT) 148wchar_t* wcscat(wchar_t *dest, const wchar_t *src); 149#endif 150#if !defined(HAVE_WCSCMP) 151int wcscmp (const wchar_t* s1, const wchar_t* s2); 152#endif 153#if !defined(HAVE_WCSNCASECMP) 154int wcsncasecmp (wchar_t* s1, wchar_t* s2, size_t n); 155#endif 156 157#endif /* _UNICODE_H */ 158