Skip to content

Commit

Permalink
Add cases for %u, %x and %o to produce UInt arguments (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger authored Nov 28, 2023
1 parent 7ca4764 commit e73c640
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/StringExtractor/PlaceholderType.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/SwiftGen/SwiftGen/blob/stable/Sources/SwiftGenKit/Parsers/Strings/PlaceholderType.swift
enum PlaceholderType {
case object, float, int, char, cString, pointer
case object, float, int, uint, char, cString, pointer

/// Create an instance using a formatSpecifier
init?(formatSpecifier: some StringProtocol) {
Expand All @@ -10,8 +10,10 @@ enum PlaceholderType {
self = .object
case "a", "e", "f", "g":
self = .float
case "d", "i", "o", "u", "x":
case "d", "i":
self = .int
case "u", "x", "X", "o":
self = .uint
case "c":
self = .char
case "s":
Expand All @@ -28,6 +30,7 @@ enum PlaceholderType {
case .object: "String"
case .float: "Double"
case .int: "Int"
case .uint: "UInt"
case .char: "CChar"
case .cString: "UnsafePointer<CChar>"
case .pointer: "UnsafeRawPointer"
Expand Down
36 changes: 36 additions & 0 deletions Tests/XCStringsToolTests/__Fixtures__/FormatSpecifiers.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@
}
}
},
"o" : {
"comment" : "%o should convert to a UInt argument",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Test %o"
}
}
}
},
"p" : {
"comment" : "%p should convert to an UnsafeRawPointer argument",
"extractionState" : "manual",
Expand All @@ -108,6 +120,30 @@
}
}
}
},
"u" : {
"comment" : "%u should convert to a UInt argument",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Test %u"
}
}
}
},
"x" : {
"comment" : "%x should convert to a UInt argument",
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Test %x"
}
}
}
}
},
"version" : "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ extension LocalizedStringResource {
)
}

/// %o should convert to a UInt argument
internal func o(_ arg1: UInt) -> LocalizedStringResource {
LocalizedStringResource(
"o",
defaultValue: ###"Test \###(arg1)"###,
table: "FormatSpecifiers",
bundle: .current
)
}

/// %p should convert to an UnsafeRawPointer argument
internal func p(_ arg1: UnsafeRawPointer) -> LocalizedStringResource {
LocalizedStringResource(
Expand All @@ -103,6 +113,26 @@ extension LocalizedStringResource {
bundle: .current
)
}

/// %u should convert to a UInt argument
internal func u(_ arg1: UInt) -> LocalizedStringResource {
LocalizedStringResource(
"u",
defaultValue: ###"Test \###(arg1)"###,
table: "FormatSpecifiers",
bundle: .current
)
}

/// %x should convert to a UInt argument
internal func x(_ arg1: UInt) -> LocalizedStringResource {
LocalizedStringResource(
"x",
defaultValue: ###"Test \###(arg1)"###,
table: "FormatSpecifiers",
bundle: .current
)
}
}

/// Constant values for the FormatSpecifiers Strings Catalog
Expand Down

0 comments on commit e73c640

Please sign in to comment.