Skip to content

Commit 897d5c9

Browse files
committed
Show units for fmt-like string format
Extract the unit from fmt-like string formats. This improves the user experience, but avoids a full fmt integration.
1 parent 95c5a4f commit 897d5c9

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

XBMC Remote/SettingsValuesViewController.m

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,25 @@ - (NSString*)getFormatString:(NSString*)format {
367367
// Default format does not provide any units
368368
NSString *defaultFormat = settingValueType == SettingValueTypeNumber ? @"%.2f" : @"%i";
369369

370-
// Workaround!! Before Kodi 18.x an older format ("%i ms") was used. The new format ("{0:d} ms") needs
371-
// an updated parser. Until this is implemented just display the value itself, without the unit.
372-
if (format.length > 0 && AppDelegate.instance.serverVersion < 18) {
373-
return format;
370+
// Identify fmt-like format string
371+
if (format.length && [format rangeOfString:@"{"].location != NSNotFound && [format rangeOfString:@"}"].location != NSNotFound) {
372+
// Gather range for unit which is added after "}"
373+
NSRange range;
374+
range.location = [format rangeOfString:@"}"].location + 1;
375+
range.length = format.length - range.location;
376+
377+
// Extract unit and make percent character is formatted correctly
378+
NSString *unit = [format substringWithRange:range];
379+
unit = [unit stringByReplacingOccurrencesOfString:@"%" withString:@"%%"];
380+
381+
// Build std format string, appending the fmt format string's unit
382+
format = [defaultFormat stringByAppendingString:unit];
383+
}
384+
// Fallback to default in case no format is defined or we missed to identify fmt-style format (which is used for Kodi 18 and later)
385+
else if (!format.length || AppDelegate.instance.serverVersion >= 18) {
386+
format = defaultFormat;
374387
}
375-
return defaultFormat;
388+
return format;
376389
}
377390

378391
- (NSString*)getStringForSliderItem:(id)item value:(float)value {

0 commit comments

Comments
 (0)