aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-09 10:14:06 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-09 10:14:06 -0800
commitf1b1d1ca7526dd9797b9f406e2351b8a9fbacbdf (patch)
treecf66553a9f65b0a1d6b758e7de59f12f49da8aee /common.cpp
parente5bba2294dfd0d56ee5b1c7ac4b9060873b8b03a (diff)
Get rid of some string buffer
Diffstat (limited to 'common.cpp')
-rw-r--r--common.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/common.cpp b/common.cpp
index 6564a7ac..0cab244d 100644
--- a/common.cpp
+++ b/common.cpp
@@ -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()