Changeset 10844


Ignore:
Timestamp:
Jun 25, 2010, 1:13:35 AM (12 years ago)
Author:
charles
Message:

(trunk) #3311 "MingW build of Transmission" -- modify tr_strip_positional_args() to strip out the ' printf flag. Platforms not supporting $ tend to not support ' either

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils-test.c

    r10239 r10844  
    104104
    105105static int
     106test_strip_positional_args( void )
     107{
     108    const char * in;
     109    const char * out;
     110    const char * expected;
     111
     112    in = "Hello %1$s foo %2$.*f";
     113    expected = "Hello %s foo %.*f";
     114    out = tr_strip_positional_args( in );
     115    check( out != NULL )
     116    check( !strcmp( out, expected ) )
     117
     118    in = "Hello %1$'d foo %2$'f";
     119    expected = "Hello %d foo %f";
     120    out = tr_strip_positional_args( in );
     121    check( out != NULL )
     122    check( !strcmp( out, expected ) )
     123
     124    return 0;
     125}
     126
     127static int
    106128test_strstrip( void )
    107129{
     
    393415    if( ( i = test_lowerbound( ) ) )
    394416        return i;
     417    if( ( i = test_strip_positional_args( ) ) )
     418        return i;
    395419    if( ( i = test_strstrip( ) ) )
    396420        return i;
  • trunk/libtransmission/utils.c

    r10837 r10844  
    405405***/
    406406
    407 #ifdef DISABLE_GETTEXT
    408 
    409407const char*
    410408tr_strip_positional_args( const char* str )
     
    425423    {
    426424        *out++ = *str;
     425
    427426        if( ( *str == '%' ) && isdigit( str[1] ) )
    428427        {
     
    430429            while( isdigit( *tmp ) )
    431430                ++tmp;
    432 
    433431            if( *tmp == '$' )
    434                 str = tmp;
     432                str = tmp[1]=='\'' ? tmp+1 : tmp;
    435433        }
     434
     435        if( ( *str == '%' ) && ( str[1] == '\'' ) )
     436            str = str + 1;
     437 
    436438    }
    437439    *out = '\0';
     
    439441    return strcmp( buf, in ) ? buf : in;
    440442}
    441 
    442 #endif
    443443
    444444/**
  • trunk/libtransmission/utils.h

    r10822 r10844  
    8989***/
    9090
     91const char * tr_strip_positional_args( const char * fmt );
     92
    9193#if !defined( _ )
    9294 #if defined( HAVE_LIBINTL_H ) && !defined( SYS_DARWIN )
     
    105107#endif
    106108#ifdef DISABLE_GETTEXT
    107  const char * tr_strip_positional_args( const char * fmt );
    108109 #undef _
    109110 #define _( a ) tr_strip_positional_args( a )
Note: See TracChangeset for help on using the changeset viewer.