Skip to content

Commit

Permalink
Add support for notation to currency format styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblukas committed Mar 1, 2024
1 parent 71c3c94 commit f511980
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ extension Decimal.FormatStyle {
return new
}

public func notation(_ notation: Configuration.Notation) -> Self {
var new = self
new.collection.notation = notation
return new
}

// FormatStyle
public func format(_ value: Decimal) -> String {
if let f = ICUCurrencyNumberFormatter.create(for: self), let res = f.format(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ extension FloatingPointFormatStyle {
new.collection.presentation = p
return new
}

public func notation(_ notation: Configuration.Notation) -> Self {
var new = self
new.collection.notation = notation
return new
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ extension IntegerFormatStyle {
new.collection.presentation = p
return new
}

public func notation(_ notation: Configuration.Notation) -> Self {
var new = self
new.collection.notation = notation
return new
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public enum CurrencyFormatStyleConfiguration {
public typealias Precision = NumberFormatStyleConfiguration.Precision
public typealias DecimalSeparatorDisplayStrategy = NumberFormatStyleConfiguration.DecimalSeparatorDisplayStrategy
public typealias RoundingRule = NumberFormatStyleConfiguration.RoundingRule
public typealias Notation = NumberFormatStyleConfiguration.Notation

internal typealias RoundingIncrement = NumberFormatStyleConfiguration.RoundingIncrement
internal struct Collection : Codable, Hashable {
Expand All @@ -327,6 +328,7 @@ public enum CurrencyFormatStyleConfiguration {
var rounding: RoundingRule?
var roundingIncrement: RoundingIncrement?
var presentation: Presentation
var notation: Notation?
}

public struct SignDisplayStrategy: Codable, Hashable, Sendable {
Expand Down Expand Up @@ -846,6 +848,9 @@ extension CurrencyFormatStyleConfiguration.Collection {
if let rounding = rounding {
s += rounding.skeleton + " "
}
if let notation = notation {
s += notation.skeleton + " "
}

return s._trimmingWhitespace()
}
Expand Down

0 comments on commit f511980

Please sign in to comment.