-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstring_formatting_helper.dart
More file actions
27 lines (25 loc) · 945 Bytes
/
Copy pathstring_formatting_helper.dart
File metadata and controls
27 lines (25 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// Helper class for string formatting utilities
///
/// Provides common string formatting functions used throughout the app.
class StringFormattingHelper {
StringFormattingHelper._();
/// Capitalize the first letter of a string
///
/// Returns the string with the first character uppercased.
/// Returns empty string if input is empty.
///
/// Example: 'cask' -> 'Cask', 'keg' -> 'Keg'
static String capitalizeFirst(String text) {
if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1);
}
/// Format a drink count with the correctly pluralised noun.
///
/// Used in screen-reader labels, where an inlined `count == 1 ? ... : ...`
/// ternary has twice been forgotten and announced '1 drinks' (#506, #513).
///
/// Example: 0 -> '0 drinks', 1 -> '1 drink', 2 -> '2 drinks'
static String drinkCountLabel(int count) {
return '$count ${count == 1 ? 'drink' : 'drinks'}';
}
}