Skip to content

Commit 3b5606b

Browse files
committed
Fixes for ObjC literal output
1 parent ddc05b5 commit 3b5606b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

Sources/plutil/PLUContext.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,14 @@ extension NSNumber {
294294
}
295295
}
296296

297-
/// This number formatted for raw, Swift, or ObjC output (all are the same).
298-
func propertyListFormatted() throws -> String {
297+
/// This number formatted for raw, Swift, or ObjC output. Raw and Swift output are the same.
298+
func propertyListFormatted(objCStyle: Bool) throws -> String {
299299
// For now, use the Objective-C based formatting API for consistency with pre-Swift plutil.
300-
return switch betterSwiftType {
300+
let formatted = switch betterSwiftType {
301301
case .true:
302-
"true"
302+
objCStyle ? "YES" : "true"
303303
case .false:
304-
"false"
304+
objCStyle ? "NO" : "false"
305305
case .signed:
306306
String(format: "%lld", int64Value)
307307
case .unsigned:
@@ -314,6 +314,12 @@ extension NSNumber {
314314
case .other:
315315
throw PLUContextError.invalidPropertyListObject("Incorrect numeric type for literal \(objCType)")
316316
}
317+
318+
if objCStyle {
319+
return "@\(formatted)"
320+
} else {
321+
return formatted
322+
}
317323
}
318324
}
319325

@@ -1097,7 +1103,7 @@ func propertyListIsValidForRawFormat(_ propertyList: Any) -> Bool {
10971103
/// Output the property list in "raw" string format. Does not descend into collections like array or dictionary.
10981104
func rawStringWithPropertyList(_ propertyList: Any) throws -> String {
10991105
if let num = propertyList as? NSNumber {
1100-
return try num.propertyListFormatted()
1106+
return try num.propertyListFormatted(objCStyle: false)
11011107
} else if let string = propertyList as? String {
11021108
return string
11031109
} else if let array = propertyList as? [Any] {

Sources/plutil/PLULiteralOutput.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private func _objcLiteralDataWithPropertyList(_ plist: Any, depth: Int, indent:
118118
}
119119

120120
if let num = plist as? NSNumber {
121-
return result.appending(try num.propertyListFormatted())
121+
return result.appending(try num.propertyListFormatted(objCStyle: true))
122122
} else if let string = plist as? String {
123123
return result.appending("@\"\(string.escapedForQuotesAndEscapes)\"")
124124
} else if let array = plist as? [Any] {
@@ -243,7 +243,7 @@ private func _swiftLiteralDataWithPropertyList(_ plist: Any, depth: Int, indent:
243243
}
244244

245245
if let num = plist as? NSNumber {
246-
result.append(try num.propertyListFormatted())
246+
result.append(try num.propertyListFormatted(objCStyle: false))
247247
} else if let string = plist as? String {
248248
// FEATURE: Support triple-quote when string is multi-line.
249249
// For now, do one simpler thing and replace newlines with literal \n

0 commit comments

Comments
 (0)