diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-02-09 10:14:06 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-02-09 10:14:06 -0800 |
commit | f1b1d1ca7526dd9797b9f406e2351b8a9fbacbdf (patch) | |
tree | cf66553a9f65b0a1d6b758e7de59f12f49da8aee /common.cpp | |
parent | e5bba2294dfd0d56ee5b1c7ac4b9060873b8b03a (diff) |
Get rid of some string buffer
Diffstat (limited to 'common.cpp')
-rw-r--r-- | common.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
@@ -1935,7 +1935,50 @@ void sb_format_size( string_buffer_t *sb, sz /= 1024; } - } + } +} + +wcstring format_size(long long sz) +{ + wcstring result; + const wchar_t *sz_name[]= + { + L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", 0 + }; + + if( sz < 0 ) + { + result.append( L"unknown" ); + } + else if( sz < 1 ) + { + result.append( _( L"empty" ) ); + } + else if( sz < 1024 ) + { + result.append(format_string( L"%lldB", sz )); + } + else + { + int i; + + for( i=0; sz_name[i]; i++ ) + { + if( sz < (1024*1024) || !sz_name[i+1] ) + { + int isz = sz/1024; + if( isz > 9 ) + result.append( format_string( L"%d%ls", isz, sz_name[i] )); + else + result.append( format_string( L"%.1f%ls", (double)sz/1024, sz_name[i] )); + break; + } + sz /= 1024; + + } + } + + return result; } double timef() |