Ignore:
Timestamp:
Jul 16, 2003, 8:07:01 PM (22 years ago)
Author:
sandervl
Message:

KOM: Added functions to query length after ascii or unicode conversion; Changed the destination length parameter name of lstrcpynWtoA() and lstrcpynAtoW()

File:
1 edited

Legend:

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

    r9975 r10176  
    1 /* $Id: heapstring.cpp,v 1.52 2003-04-02 12:58:29 sandervl Exp $ */
     1/* $Id: heapstring.cpp,v 1.53 2003-07-16 18:07:01 sandervl Exp $ */
    22/*
    33 * Project Odin Software License can be found in LICENSE.TXT
     
    410410     */
    411411    if (!dst || !src) {
    412         SetLastError(ERROR_INVALID_PARAMETER);
    413         return 0;
     412        SetLastError(ERROR_INVALID_PARAMETER);
     413    return 0;
    414414    }
    415415    while ((n-- > 1) && *src) *p++ = *src++;
     
    462462{
    463463  if (!str1 || !str2) {
    464    
     464
    465465    SetLastError(ERROR_INVALID_PARAMETER);
    466466    return 0;
     
    495495//lstrcpynWtoA and lstrcpynAtoW must zero-terminate the string
    496496//because Wine code depends on this behaviour (i.e. comdlg32)
    497 int WIN32API lstrcpynAtoW(LPWSTR unicode, LPCSTR ascii, int asciilen)
     497int WIN32API lstrcpynAtoW(LPWSTR unicode, LPCSTR ascii, int unilen)
    498498{
    499499 int ret;
    500500
    501     ret = MultiByteToWideChar(CP_ACP, 0, ascii, -1, unicode, asciilen);
     501    ret = MultiByteToWideChar(CP_ACP, 0, ascii, -1, unicode, unilen );
    502502    if(ret == 0) {
    503503         SetLastError(ERROR_SUCCESS); //MultiByteToWideChar sets it to ERROR_INSUFFICIENT_BUFFER
    504          ret = asciilen;
     504         ret = unilen;
    505505    }
    506506
     
    508508    //string size to apis that use this function (i.e. GetMenuStringW (Notes))
    509509    //-> overwrites stack
    510     if(ret == asciilen) {
    511          unicode[asciilen-1] = 0;
     510    if(ret == unilen) {
     511         unicode[unilen-1] = 0;
    512512    }
    513513    else unicode[ret] = 0;
    514514    return ret;
    515 
    516 
    517515}
    518516
     
    547545    lstrcpynWtoA(ascii,
    548546               unicode,
    549                lstrlenW(unicode)+1); //end included
     547               WideCharToMultiByte( CP_ACP, 0, unicode, -1, 0, 0, 0, 0 )); //end included
    550548
    551549    return ascii;
     
    582580
    583581    /* forward to call with length parameter */
    584     lstrcpynAtoW(unicode, ascii, strlen(ascii)+1); //end included
     582    lstrcpynAtoW(unicode, ascii, MultiByteToWideChar( CP_ACP, 0, ascii, -1, 0, 0 )); //end included
    585583    return (unicode);
    586584}
    587585
    588 
    589 
     586/*****************************************************************************
     587 * NAME
     588 *      lstrlenWtoA
     589 *
     590 * PURPOSE
     591 *      calculate the length of string when unicode string was converted to
     592 *      ansi string.
     593 *
     594 * PARAMETERS
     595 *      ustring - unicode string
     596 *      ulen - length of ustring
     597 *
     598 * RESULT
     599 *   Success
     600 *      if ulen < 0, length of null-terminated unicode string NOT including
     601 *      null-terminator.
     602 *      otherwise, length of string when first ulen characters of ustring
     603 *      converted to ansi string.
     604 *
     605 *   Failure
     606 *      return 0.
     607 *
     608 * REMARK
     609 *      this function is not Win32 API but helper for convenient.
     610 *
     611 * AUTHOR    : KO Myung-Hun
     612 *****************************************************************************/
     613
     614int WIN32API lstrlenWtoA( LPCWSTR ustring, int ulen )
     615{
     616    int ret;
     617
     618    if( ulen < 0 )
     619        ulen = lstrlenW( ustring );
     620
     621    ret = WideCharToMultiByte( CP_ACP, 0, ustring, ulen, 0, 0, 0, 0 );
     622    if(ret == 0) {
     623         SetLastError(ERROR_SUCCESS); //WideCharToMultiByte sets it to ERROR_INSUFFICIENT_BUFFER
     624         return 0;
     625    }
     626
     627    return ret;
     628}
     629
     630/*****************************************************************************
     631 * NAME
     632 *      lstrlenAtoW
     633 *
     634 * PURPOSE
     635 *      return the length of string when ansi string was converted to
     636 *      unicode string.
     637 *
     638 * PARAMETERS
     639 *      astring - ansi string
     640 *      alen - length of astring
     641 *
     642 * RESULT
     643 *   Success
     644 *      if alen < 0, length of null-terminated ansi string NOT including
     645 *      null-terminator.
     646 *      otherwise, length of string when first alen characters of astring
     647 *      converted to unicode string.
     648 *
     649 *   Failure
     650 *      return 0.
     651 *
     652 * REMARK
     653 *      this function is not Win32 API but helper for convenient.
     654 *
     655 * AUTHOR    : KO Myung-Hun
     656 *****************************************************************************/
     657
     658int WIN32API lstrlenAtoW( LPCSTR astring, int alen )
     659{
     660    int ret;
     661
     662    if( alen < 0 )
     663        alen = strlen( astring );
     664
     665    ret = MultiByteToWideChar( CP_ACP, 0, astring, alen, 0, 0 );
     666    if(ret == 0) {
     667         SetLastError(ERROR_SUCCESS); //MultiByteToWideChar sets it to ERROR_INSUFFICIENT_BUFFER
     668         return 0;
     669    }
     670
     671    return ret;
     672}
    590673
    591674/*****************************************************************************
Note: See TracChangeset for help on using the changeset viewer.