wctomb.c revision 4b9d6701570cb98fd36e209314239d104ec584d3
/*
* WideCharToMultiByte implementation
*
* Copyright 2000 Alexandre Julliard
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Oracle elects to use only
* the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
* a choice of LGPL license versions is made available with the language indicating
* that LGPLv2 or any later version may be used, or where a choice of which version
* of the LGPL is applied is otherwise unspecified.
*/
#include "config.h"
#include <string.h>
/* search for a character in the unicode_compose_table; helper for compose() */
{
extern const WCHAR unicode_compose_table[];
{
{
continue;
}
{
continue;
}
return pos;
}
return -1;
}
/* return the result of the composition of two Unicode chars, or 0 if none */
{
extern const WCHAR unicode_compose_table[];
extern const unsigned int unicode_compose_table_size;
for (;;)
{
if (pos == -1) return 0;
}
}
/****************************************************************/
/* sbcs support */
/* check if 'ch' is an acceptable sbcs mapping for 'wch' */
{
return 1;
}
/* query necessary dst length for src string */
{
*used = 0;
{
unsigned char ch;
{
/* now check if we can use the composed char */
{
/* we have a good mapping, use it */
src++;
srclen--;
continue;
}
/* no mapping for the composed char, check the other flags */
{
*used = 1;
src++; /* skip the non-spacing char */
srclen--;
continue;
}
{
src++;
srclen--;
}
/* WC_SEPCHARS is the default */
}
if (!*used)
{
}
}
return ret;
}
/* wcstombs for single-byte code page */
{
{
/* buffer too small: fill it up to dstlen and return error */
ret = -1;
}
while (srclen >= 16)
{
src += 16;
dst += 16;
srclen -= 16;
}
/* now handle remaining characters */
switch(srclen)
{
case 0: break;
}
return ret;
}
/* slow version of wcstombs_sbcs that handles the various flags */
{
unsigned char def;
unsigned int len;
int tmp;
if (!defchar)
else
*used = 0;
{
{
/* now check if we can use the composed char */
{
/* we have a good mapping, use it */
src++;
srclen--;
continue;
}
/* no mapping for the composed char, check the other flags */
{
*used = 1;
src++; /* skip the non-spacing char */
srclen--;
continue;
}
{
src++;
srclen--;
}
/* WC_SEPCHARS is the default */
}
{
*used = 1;
}
}
}
/****************************************************************/
/* dbcs support */
/* check if 'ch' is an acceptable dbcs mapping for 'wch' */
{
{
/* check if char maps back to the same Unicode value */
if (ch & 0xff00)
{
}
}
return 1;
}
/* query necessary dst length for src string */
{
{
{
}
return len;
}
*used = 0;
{
unsigned short res;
{
/* now check if we can use the composed char */
{
/* we have a good mapping for the composed char, use it */
src++;
srclen--;
continue;
}
/* no mapping for the composed char, check the other flags */
{
*used = 1;
src++; /* skip the non-spacing char */
srclen--;
continue;
}
{
src++;
srclen--;
}
/* WC_SEPCHARS is the default */
}
{
res = defchar_value;
*used = 1;
}
}
return len;
}
/* wcstombs for double-byte code page */
{
int len;
{
if (res & 0xff00)
{
len--;
}
}
}
/* slow version of wcstombs_dbcs that handles the various flags */
{
*used = 0;
{
unsigned short res;
{
/* now check if we can use the composed char */
{
/* we have a good mapping for the composed char, use it */
src++;
srclen--;
goto output_char;
}
/* no mapping for the composed char, check the other flags */
{
res = defchar_value;
*used = 1;
src++; /* skip the non-spacing char */
srclen--;
goto output_char;
}
{
src++;
srclen--;
}
/* WC_SEPCHARS is the default */
}
{
res = defchar_value;
*used = 1;
}
if (res & 0xff00)
{
len--;
}
}
}
/* wide char to multi byte string conversion */
/* return -1 on dst buffer overflow */
{
{
{
}
}
else /* mbcs */
{
}
}
/* CP_SYMBOL implementation */
/* return -1 on dst buffer overflow, -2 on invalid character */
{
int len, i;
for( i = 0; i < len; i++)
{
if( w < 0x20 )
dst[i] = w;
else if( w >= 0xf020 && w < 0xf100)
dst[i] = w - 0xf000;
else
return -2;
}
return len;
}