Skip to content

Commit

Permalink
bank.NullableIBAN.NormalizedOrNull
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed Aug 22, 2024
1 parent b48dbf4 commit bb4e5c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bank/iban.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ func (iban IBAN) NormalizedOrNull() NullableIBAN {

// NormalizedWithSpaces returns the iban in normalized form with spaces every 4 characters,
// or an error if the format can't be detected.
// Returns the IBAN unchanged in case of an error.
func (iban IBAN) NormalizedWithSpaces() (IBAN, error) {
norm, err := iban.Normalized()
if err != nil {
return "", err
return iban, err
}
var b strings.Builder
normLen := len(norm)
Expand Down
16 changes: 8 additions & 8 deletions bank/nullableiban.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,36 @@ func (iban NullableIBAN) CountryCode() country.Code {

// Normalized returns the iban in normalized form,
// or an error if the format can't be detected.
// Returns the NullableIBAN unchanged in case of an error.
func (iban NullableIBAN) Normalized() (NullableIBAN, error) {
if iban.IsNull() {
return "", nil
return iban, nil
}
normalized, err := IBAN(iban).Normalized()
if err != nil {
return "", err
return iban, err
}
return NullableIBAN(normalized), nil
}

// NormalizedOrUnchanged returns the iban in normalized form,
// or unchanged if the format has an error.
func (iban NullableIBAN) NormalizedOrUnchanged() NullableIBAN {
func (iban NullableIBAN) NormalizedOrNull() NullableIBAN {
normalized, err := iban.Normalized()
if err != nil {
return iban
return IBANNull
}
return normalized
}

// NormalizedWithSpaces returns the iban in normalized form with spaces every 4 characters,
// or an error if the format can't be detected.
// Returns the NullableIBAN unchanged in case of an error.
func (iban NullableIBAN) NormalizedWithSpaces() (NullableIBAN, error) {
if iban.IsNull() {
return "", nil
return iban, nil
}
normalized, err := IBAN(iban).NormalizedWithSpaces()
if err != nil {
return "", err
return iban, err
}
return NullableIBAN(normalized), nil
}
Expand Down

0 comments on commit bb4e5c4

Please sign in to comment.