Author: aschnell Date: Tue Apr 1 21:41:01 2008 New Revision: 45945 URL: http://svn.opensuse.org/viewcvs/yast?rev=45945&view=rev Log: - fixed String::FormatSizeWithPrecision to return a unit for small values Modified: trunk/yast2/library/types/src/String.ycp trunk/yast2/library/types/testsuite/tests/String.out trunk/yast2/package/yast2.changes Modified: trunk/yast2/library/types/src/String.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/yast2/library/types/src/String.ycp?rev=45945&r1=45944&r2=45945&view=diff ============================================================================== --- trunk/yast2/library/types/src/String.ycp (original) +++ trunk/yast2/library/types/src/String.ycp Tue Apr 1 21:41:01 2008 @@ -79,7 +79,7 @@ * Return a pretty description of a byte count * * Return a pretty description of a byte count with required precision - * and using kB, MB, GB or TB as unit as appropriate. + * and using B, kB, MB, GB or TB as unit as appropriate. * * @param bytes size (e.g. free diskspace, memory size) in Bytes * @param precision number of fraction digits in output @@ -87,6 +87,7 @@ * (usefull for memory size - 128 MB RAM looks better than 128.00 MB RAM) * @return formatted string * + * @example FormatSizeWithPrecision(128, 2, true) -> "128 B" * @example FormatSizeWithPrecision(4096, 2, true) -> "4 kB" * @example FormatSizeWithPrecision(4096, 2, false) -> "4.00 kB" * @example FormatSizeWithPrecision(1024*1024, 2, true) -> "1 MB" @@ -95,8 +96,9 @@ if(bytes == nil) return ""; - string unit = ""; - list units = [ + const list units = [ + /* Byte abbreviated */ + _("B"), /* KiloByte abbreviated */ _("kB"), /* MegaByte abbreviated */ @@ -106,12 +108,12 @@ /* TeraByte abbreviated */ _("TB"), ]; + integer index = 0; float whole = tofloat(bytes); - while((whole >= 1024.0 || whole <= -1024.0) && index < size(units)) { + while((whole >= 1024.0 || whole <= -1024.0) && index + 1 < size(units)) { whole = whole / 1024.0; - unit = units[index]:""; index = index + 1; } @@ -120,14 +122,14 @@ precision = 0; } - return tostring(whole, precision) + " " + unit; + return tostring(whole, precision) + " " + units[index]:""; } /** * Return a pretty description of a byte count * * Return a pretty description of a byte count, with two fraction digits - * and using KB, MB or GB as unit as appropriate. + * and using B, kB, MB, GB or TB as unit as appropriate. * * @param bytes size (e.g. free diskspace) in Bytes * @return formatted string @@ -142,7 +144,7 @@ * Return a pretty description of a download rate * * Return a pretty description of a download rate, with two fraction digits - * and using KB/s, MB/s or GB/s as unit as appropriate. + * and using B/s, kB/s, MB/s, GB/s or TB/s as unit as appropriate. * * @param bytes_per_second download rate (in B/s) * @return formatted string @@ -154,7 +156,7 @@ global string FormatRate(integer bytes_per_second) { // covert a number to download rate string - // %1 is string - size in bytes, kB, MB or GB + // %1 is string - size in bytes, B, kB, MB, GB or TB return sformat(_("%1/s"), FormatSize(bytes_per_second)); } Modified: trunk/yast2/library/types/testsuite/tests/String.out URL: http://svn.opensuse.org/viewcvs/yast/trunk/yast2/library/types/testsuite/tests/String.out?rev=45945&r1=45944&r2=45945&view=diff ============================================================================== --- trunk/yast2/library/types/testsuite/tests/String.out (original) +++ trunk/yast2/library/types/testsuite/tests/String.out Tue Apr 1 21:41:01 2008 @@ -12,8 +12,8 @@ Return a'b'c Dump String::FormatSize Return -Return 0.00 -Return 1.00 +Return 0.00 B +Return 1.00 B Return 1.00 kB Return 1.00 MB Return 1.00 GB @@ -21,8 +21,8 @@ Return 1024.09 TB Dump String::FormatSizeWithPrecision Return -Return 0 -Return 1.00 +Return 0 B +Return 1.00 B Return 1.001 kB Return 1 MB Return 1.00 MB @@ -34,7 +34,7 @@ Return 4.00 kB Return 4.00 kB Return 8 GB -Return 15.00000 +Return 15.00000 B Return 21.846 GB Dump String::CutBlanks Return Modified: trunk/yast2/package/yast2.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/yast2/package/yast2.changes?rev=45945&r1=45944&r2=45945&view=diff ============================================================================== --- trunk/yast2/package/yast2.changes (original) +++ trunk/yast2/package/yast2.changes Tue Apr 1 21:41:01 2008 @@ -3,6 +3,8 @@ - let String::FormatSizeWithPrecision return "1 MB" instead of "1024 kB" and alike +- fixed String::FormatSizeWithPrecision to return a unit for small + values ------------------------------------------------------------------- Tue Apr 1 09:46:44 CEST 2008 - jsrain@suse.cz -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org