@@ -21,13 +21,12 @@ extension ProgressReporter {
2121 // Outlines the options available to format ProgressReporter
2222 internal struct Option : Sendable , Codable , Hashable , Equatable {
2323
24- #if FOUNDATION_FRAMEWORK
2524 /// Option specifying`fractionCompleted`.
2625 ///
2726 /// For example, 20% completed.
2827 /// - Parameter style: A `FloatingPointFormatStyle<Double>.Percent` instance that should be used to format `fractionCompleted`.
2928 /// - Returns: A `LocalizedStringResource` for formatted `fractionCompleted`.
30- internal static func fractionCompleted( format style: Foundation . FloatingPointFormatStyle < Double > . Percent = Foundation . FloatingPointFormatStyle< Double> . Percent( )
29+ internal static func fractionCompleted( format style: FloatingPointFormatStyle < Double > . Percent = FloatingPointFormatStyle< Double> . Percent( )
3130 ) -> Option {
3231 return Option ( . fractionCompleted( style) )
3332 }
@@ -37,33 +36,11 @@ extension ProgressReporter {
3736 /// For example, 5 of 10.
3837 /// - Parameter style: An `IntegerFormatStyle<Int>` instance that should be used to format `completedCount` and `totalCount`.
3938 /// - Returns: A `LocalizedStringResource` for formatted `completedCount` / `totalCount`.
40- internal static func count( format style: Foundation . IntegerFormatStyle < Int > = Foundation . IntegerFormatStyle < Int > ( )
39+ internal static func count( format style: IntegerFormatStyle < Int > = IntegerFormatStyle < Int > ( )
4140 ) -> Option {
4241 return Option ( . count( style) )
4342 }
44- #else
45- /// Option specifying`fractionCompleted`.
46- ///
47- /// For example, 20% completed.
48- /// - Parameter style: A `FloatingPointFormatStyle<Double>.Percent` instance that should be used to format `fractionCompleted`.
49- /// - Returns: A `LocalizedStringResource` for formatted `fractionCompleted`.
50- internal static func fractionCompleted( format style: FoundationInternationalization . FloatingPointFormatStyle < Double > . Percent = FoundationInternationalization . FloatingPointFormatStyle< Double> . Percent( )
51- ) -> Option {
52- return Option ( . fractionCompleted( style) )
53- }
54-
55- /// Option specifying `completedCount` / `totalCount`.
56- ///
57- /// For example, 5 of 10.
58- /// - Parameter style: An `IntegerFormatStyle<Int>` instance that should be used to format `completedCount` and `totalCount`.
59- /// - Returns: A `LocalizedStringResource` for formatted `completedCount` / `totalCount`.
60- internal static func count( format style: FoundationInternationalization . IntegerFormatStyle < Int > = FoundationInternationalization . IntegerFormatStyle < Int > ( )
61- ) -> Option {
62- return Option ( . count( style) )
63- }
64- #endif // FOUNDATION_FRAMEWORK
65-
66-
43+
6744 fileprivate enum RawOption : Codable , Hashable , Equatable {
6845 case count( IntegerFormatStyle < Int > )
6946 case fractionCompleted( FloatingPointFormatStyle < Double > . Percent )
@@ -99,12 +76,20 @@ extension ProgressReporter.FormatStyle: FormatStyle {
9976 let count = reporter. withProperties { p in
10077 return ( p. completedCount, p. totalCount)
10178 }
79+ #if FOUNDATION_FRAMEWORK
10280 let countLSR = LocalizedStringResource ( " \( count. 0 , format: countStyle) of \( count. 1 ?? 0 , format: countStyle) " , locale: self . locale, bundle: . forClass( ProgressReporter . self) )
10381 return String ( localized: countLSR)
82+ #else
83+ return " \( count. 0 . formatted ( countStyle. locale ( self . locale) ) ) / \( ( count. 1 ?? 0 ) . formatted ( countStyle. locale ( self . locale) ) ) "
84+ #endif
10485
10586 case . fractionCompleted( let fractionStyle) :
87+ #if FOUNDATION_FRAMEWORK
10688 let fractionLSR = LocalizedStringResource ( " \( reporter. fractionCompleted, format: fractionStyle) completed " , locale: self . locale, bundle: . forClass( ProgressReporter . self) )
10789 return String ( localized: fractionLSR)
90+ #else
91+ return " \( reporter. fractionCompleted. formatted ( fractionStyle. locale ( self . locale) ) ) "
92+ #endif
10893 }
10994 }
11095}
@@ -123,7 +108,6 @@ extension ProgressReporter {
123108 }
124109#endif // FOUNDATION_FRAMEWORK
125110
126-
127111 public func formatted( ) -> String {
128112 self . formatted ( . fractionCompleted( ) )
129113 }
@@ -133,31 +117,15 @@ extension ProgressReporter {
133117@available ( FoundationPreview 6 . 2 , * )
134118extension FormatStyle where Self == ProgressReporter . FormatStyle {
135119
136- #if FOUNDATION_FRAMEWORK
137- public static func fractionCompleted(
138- format: Foundation . FloatingPointFormatStyle < Double > . Percent = Foundation . FloatingPointFormatStyle< Double> . Percent( )
139- ) -> Self {
140- . init( . fractionCompleted( format: format) )
141- }
142-
143- public static func count(
144- format: Foundation . IntegerFormatStyle < Int > = Foundation . IntegerFormatStyle < Int > ( )
145- ) -> Self {
146- . init( . count( format: format) )
147- }
148- #else
149120 public static func fractionCompleted(
150- format: FoundationInternationalization . FloatingPointFormatStyle < Double > . Percent = FoundationInternationalization . FloatingPointFormatStyle< Double> . Percent( )
121+ format: FloatingPointFormatStyle < Double > . Percent = FloatingPointFormatStyle< Double> . Percent( )
151122 ) -> Self {
152123 . init( . fractionCompleted( format: format) )
153124 }
154125
155126 public static func count(
156- format: FoundationInternationalization . IntegerFormatStyle < Int > = FoundationInternationalization . IntegerFormatStyle < Int > ( )
127+ format: IntegerFormatStyle < Int > = IntegerFormatStyle < Int > ( )
157128 ) -> Self {
158129 . init( . count( format: format) )
159130 }
160- #endif
161-
162-
163131}
0 commit comments