Ignore:
Timestamp:
Jun 9, 1999, 3:12:20 PM (26 years ago)
Author:
achimha
Message:

Added unicode/ascii functions to convert n characters, old ones wrap to new functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/unicode.cpp

    r46 r68  
    109109//******************************************************************************
    110110//******************************************************************************
    111 int WIN32API UnicodeToAscii(WCHAR *ustring, char *astring)
    112 {
    113   int ulen, i;
     111int WIN32API UnicodeToAsciiN(WCHAR *ustring, char *astring, int unilen)
     112{
     113  int i;
    114114  int rc;
    115115  size_t uni_chars_left;
     
    122122    return(NULL);
    123123
    124 //  dprintf(("KERNEL32: UnicodeToAscii\n"));
    125   ulen = UniStrlen((UniChar*)ustring);
    126   if ( getUconvObject() )
    127   {
    128     uni_chars_left = ulen + 1;
     124//  dprintf(("KERNEL32: UnicodeToAsciiN\n"));
     125  if (getUconvObject())
     126  {
     127    uni_chars_left = unilen + 1;
    129128    out_bytes_left = uni_chars_left;
    130129    in_buf  = (UniChar*)ustring;
    131130    out_buf = astring;
    132     rc = UniUconvFromUcs( uconv_object,
    133                           &in_buf, &uni_chars_left,
    134                           (void**)&out_buf, &out_bytes_left,
    135                           &num_subs );
    136 //    dprintf(("KERNEL32: UnicodeToAscii(%d) '%s'\n", rc, astring ));
     131    rc = UniUconvFromUcs(uconv_object,
     132                         &in_buf, &uni_chars_left,
     133                         (void**)&out_buf, &out_bytes_left,
     134                         &num_subs);
     135//    dprintf(("KERNEL32: UnicodeToAsciiN(%d) '%s'\n", rc, astring ));
    137136  }
    138137  else
    139138  {
    140    for(i=0;i<ulen;i++) {
     139   for(i = 0; i < unilen; i++) {
    141140        astring[i] = (char)ustring[i];
    142141   }
    143    astring[ulen] = 0;
    144   }
    145   return(ulen);
     142   astring[unilen] = 0;
     143  }
     144  return(unilen);
     145}
     146//******************************************************************************
     147//******************************************************************************
     148int WIN32API UnicodeToAscii(WCHAR *ustring, char *astring)
     149{
     150  /* forward to function with len parameter */
     151  return UnicodeToAsciiN(ustring, astring, UniStrlen((UniChar*)ustring));
    146152}
    147153//******************************************************************************
     
    167173//******************************************************************************
    168174//******************************************************************************
    169 void WIN32API AsciiToUnicode(char *ascii, WCHAR *unicode)
     175void WIN32API AsciiToUnicodeN(char *ascii, WCHAR *unicode, int asciilen)
    170176{
    171177  int rc;
    172   int i, len;
     178  int i;
    173179  size_t uni_chars_left;
    174180  size_t in_bytes_left;
     
    178184
    179185
    180   dprintf(("KERNEL32: AsciiToUnicode(%s,%08xh)\n",
     186  dprintf(("KERNEL32: AsciiToUnicodeN(%s,%08xh)\n",
    181187           ascii,
    182188           unicode));
     
    187193    return;
    188194
    189   /* determine length of ascii string */
    190   len = strlen(ascii);
    191 
    192 //  dprintf(("KERNEL32: AsciiToUnicode %s\n", ascii));
    193   if ( getUconvObject() )
     195//  dprintf(("KERNEL32: AsciiToUnicodeN %s\n", ascii));
     196  if (getUconvObject())
    194197  {
    195198    in_buf        = ascii;
    196     in_bytes_left = len;
     199    in_bytes_left = asciilen;
    197200    out_buf = (UniChar*)unicode;
    198201
     
    208211  {
    209212    for(i=0;
    210         i<len;
     213        i < asciilen;
    211214        i++)
    212215      unicode[i] = ascii[i];
    213216  }
    214217
    215   unicode[len] = 0;
     218  unicode[asciilen] = 0;
    216219//SvL: Messes up the heap
    217220//  unicode[len+1] = 0; /* @@@PH 98/06/07 */
     221}
     222//******************************************************************************
     223//******************************************************************************
     224void WIN32API AsciiToUnicode(char *ascii, WCHAR *unicode)
     225{
     226  /* achimha for security, strlen might trap if garbage in */
     227  /* @@@PH 98/06/07 */
     228  if ( (ascii   == NULL) ||                     /* garbage in, garbage out ! */
     229       (unicode == NULL) )
     230    return;
     231  /* forward to call with length parameter */
     232  AsciiToUnicodeN(ascii, unicode, strlen(ascii));
    218233}
    219234//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.