Skip to content

Commit 4664361

Browse files
committed
Fix compilation for Swift <5.4
1 parent 01dab9d commit 4664361

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

Sources/CLTLogger.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ private extension CLTLogger {
404404
Merge the logger’s metadata, the provider’s metadata and the given explicit metadata and return the new metadata.
405405
If the provider’s metadata and the explicit metadata are `nil`, returns `nil` to signify the current `flatMetadataCache` can be used. */
406406
func mergedMetadata(with explicit: Logger.Metadata?) -> Logger.Metadata? {
407-
var metadata = metadata
407+
var metadata = self.metadata /* The self is required for Swift 5.3-. */
408408
let provided = metadataProvider?.get() ?? [:]
409409

410410
guard !provided.isEmpty || !((explicit ?? [:]).isEmpty) else {

Sources/String+Utils.swift

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,20 @@ internal extension String {
3838

3939
case .escapeScalars(_, let octothorpLevel?, _, true):
4040
let octothorps = String(repeating: "#", count: Int(octothorpLevel))
41-
return (octothorpLevel, octothorps + #"""#, #"""# + octothorps)
41+
//#if swift(>=5.4)
42+
// return (octothorpLevel, octothorps + #"""#, #"""# + octothorps)
43+
//#else
44+
return (octothorpLevel, octothorps + "\"", "\"" + octothorps)
45+
//#endif
4246

4347
case .escapeScalars(_, nil, _, let showQuotes):
4448
/* We must determine the octothorp level. */
4549
var level = UInt(0)
46-
var (sepOpen, sepClose) = (#"""#, #"""#)
50+
//#if swift(>=5.4)
51+
// var (sepOpen, sepClose) = (#"""#, #"""#)
52+
//#else
53+
var (sepOpen, sepClose) = ("\"", "\"")
54+
//#endif
4755
while str.contains(sepClose) {
4856
level += 1
4957
sepOpen = "#" + sepOpen
@@ -75,7 +83,11 @@ internal extension String {
7583
if curSpecial.1 == octothorpLevel - 1 {
7684
/* We have now reached the number of octothorp needed to build an actual “special char” (closing quote, backslash, etc.); we must escape it. */
7785
specialCharState = nil
78-
return #"\"# + octothorps + String(curSpecial.0) + octothorps
86+
//#if swift(>=5.4)
87+
// return #"\"# + octothorps + String(curSpecial.0) + octothorps
88+
//#else
89+
return "\\" + octothorps + String(curSpecial.0) + octothorps
90+
//#endif
7991
}
8092
specialCharState = (curSpecial.0, curSpecial.1 + 1)
8193
return ""
@@ -112,7 +124,11 @@ internal extension String {
112124
return prefix + ""
113125
}
114126
let escaped = scalar.escaped(asASCII: asASCII)
115-
return prefix + (octothorpLevel == 0 ? escaped : escaped.replacingOccurrences(of: #"\"#, with: #"\"# + octothorps, options: .literal))
127+
//#if swift(>=5.4)
128+
// return prefix + (octothorpLevel == 0 ? escaped : escaped.replacingOccurrences(of: #"\"#, with: #"\"# + octothorps, options: .literal))
129+
//#else
130+
return prefix + (octothorpLevel == 0 ? escaped : escaped.replacingOccurrences(of: "\\", with: "\\" + octothorps, options: .literal))
131+
//#endif
116132
}
117133
}
118134
let asciiJoined = ascii.joined(separator: "")
@@ -121,6 +137,10 @@ internal extension String {
121137
}
122138

123139
private static let newLines = CharacterSet.newlines
124-
private static let specialChars = CharacterSet(charactersIn: #""\"#)
125-
140+
//#if swift(>=5.4)
141+
// private static let specialChars = CharacterSet(charactersIn: #""\"#)
142+
//#else
143+
private static let specialChars = CharacterSet(charactersIn: "\"\\")
144+
//#endif
145+
126146
}

0 commit comments

Comments
 (0)