From 0d8e37403f698eb0b9edd68d455eac5e6d25bb88 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Thu, 15 Mar 2007 12:46:51 +0000 Subject: [PATCH] return "error" when requesting a speed or ratio string for speed/ratio less then 0 --- macosx/StringAdditions.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/macosx/StringAdditions.m b/macosx/StringAdditions.m index b1eb13420..ceb9d3b22 100644 --- a/macosx/StringAdditions.m +++ b/macosx/StringAdditions.m @@ -79,12 +79,18 @@ + (NSString *) stringForSpeed: (float) speed { + if (speed < 0) + return NSLocalizedString(@"error", "Transfer speed invalid"); + return [[self stringForSpeedAbbrev: speed] stringByAppendingString: NSLocalizedString(@"B/s", "Transfer speed (Bytes per second)")]; } + (NSString *) stringForSpeedAbbrev: (float) speed { + if (speed < 0) + return NSLocalizedString(@"error", "Transfer speed invalid"); + if (speed < 1000.0) //0.0 K to 999.9 K return [NSString stringWithFormat: @"%.1f K", speed]; else if (speed < 102400.0) //0.98 M to 99.99 M @@ -101,7 +107,10 @@ return NSLocalizedString(@"N/A", "No Ratio"); else if (ratio == TR_RATIO_INF) return [NSString stringWithUTF8String: "\xE2\x88\x9E"]; - else if (ratio < 10.0) + else if (ratio < 0) + return NSLocalizedString(@"error", "Ratio invalid"); + + if (ratio < 10.0) return [NSString stringWithFormat: @"%.2f", ratio]; else if (ratio < 100.0) return [NSString stringWithFormat: @"%.1f", ratio];