Changeset 8017 for trunk/gtk/util.c


Ignore:
Timestamp:
Mar 4, 2009, 4:16:02 PM (13 years ago)
Author:
charles
Message:

(trunk) #1881: promote tr_strratio() to libtransmission, so that its code doesn't have to be repeated in all the clients

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/util.c

    r8015 r8017  
    4949#include "util.h"
    5050
    51 static void
    52 printf_double_without_rounding( char * buf, int buflen, double d, int places )
    53 {
    54     char * pch;
    55     char tmp[128];
    56     int len;
    57     g_snprintf( tmp, sizeof( tmp ), "%'.64f", d );
    58     pch = strchr( tmp, '.' );
    59     pch += places + 1;
    60     len = MIN( buflen - 1, pch - tmp );
    61     memcpy( buf, tmp, len );
    62     buf[len] = '\0';
    63 }
    64 
    6551char*
    6652tr_strlratio( char * buf, double ratio, size_t buflen )
    6753{
    68     if( (int)ratio == TR_RATIO_NA )
    69         g_strlcpy( buf, _( "None" ), buflen );
    70     else if( (int)ratio == TR_RATIO_INF )
    71         g_strlcpy( buf, "\xE2\x88\x9E", buflen );
    72     else if( ratio < 10.0 )
    73         printf_double_without_rounding( buf, buflen, ratio, 2 );
    74     else if( ratio < 100.0 )
    75         printf_double_without_rounding( buf, buflen, ratio, 1 );
    76     else
    77         g_snprintf( buf, buflen, "%'.0f", ratio );
    78     return buf;
     54    tr_strratio( buf, buflen, ratio, "\xE2\x88\x9E" );
    7955}
    8056
Note: See TracChangeset for help on using the changeset viewer.