-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid type casting by using a type erasure
- Loading branch information
1 parent
7948b65
commit 9017033
Showing
4 changed files
with
99 additions
and
46 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
Sources/HTMLKit/Framework/Localization/InterpolationArgument.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Foundation | ||
|
||
/// An enum that represents the data types of arguments used in interpolation. | ||
/// | ||
/// Each case corresponds to a specific data type and provides a placeholder | ||
/// that can be used for replacing values in the localized string. | ||
@_documentation(visibility: internal) | ||
public enum InterpolationArgument { | ||
|
||
/// Holds an integer value | ||
case int(Int) | ||
|
||
/// Holds a string value | ||
case string(String) | ||
|
||
/// Holds a double value | ||
case double(Double) | ||
|
||
/// Holds a float value | ||
case float(Float) | ||
|
||
/// Holds a date value | ||
case date(Date) | ||
|
||
/// The placeholder used for string interpolation | ||
internal var placeholder: String { | ||
switch self { | ||
case .int(_): | ||
return "%in" | ||
|
||
case .string(_): | ||
return "%st" | ||
|
||
case .double(_): | ||
return "%do" | ||
|
||
case .float(_): | ||
return "%do" | ||
|
||
case .date(_): | ||
return "%dt" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters