Skip to content

Commit b876486

Browse files
committed
Eliminate hasPrefix usage
1 parent 99d1c41 commit b876486

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Sources/HTTPTypes/HTTPFieldName.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extension HTTPField {
6161
return nil
6262
}
6363
let token: Substring
64-
if name.hasPrefix(":") {
64+
if name.utf8.first == UInt8(ascii: ":") {
6565
token = name.dropFirst()
6666
} else {
6767
token = Substring(name)
@@ -90,7 +90,7 @@ extension HTTPField {
9090
}
9191

9292
var isPseudo: Bool {
93-
self.rawName.hasPrefix(":")
93+
self.rawName.utf8.first == UInt8(ascii: ":")
9494
}
9595
}
9696
}
@@ -126,7 +126,7 @@ extension HTTPField.Name: Codable {
126126
public init(from decoder: Decoder) throws {
127127
let container = try decoder.singleValueContainer()
128128
let nameString = try container.decode(String.self)
129-
if nameString.hasPrefix(":") {
129+
if nameString.utf8.first == UInt8(ascii: ":")
130130
guard nameString.lowercased() == nameString,
131131
HTTPField.isValidToken(nameString.dropFirst())
132132
else {

Sources/HTTPTypes/HTTPRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ extension HTTPRequest.PseudoHeaderFields: Codable {
298298
}
299299
extendedConnectProtocol = field
300300
default:
301-
guard field.name.rawName.hasPrefix(":") else {
301+
guard field.name.rawName.utf8.first == UInt8(ascii: ":") else {
302302
throw DecodingError.dataCorruptedError(
303303
in: container,
304304
debugDescription: "\"\(field)\" is not a pseudo header field"

Sources/HTTPTypes/HTTPResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ extension HTTPResponse.PseudoHeaderFields: Codable {
239239
}
240240
status = field
241241
default:
242-
guard field.name.rawName.hasPrefix(":") else {
242+
guard field.name.rawName.utf8.first == UInt8(ascii: ":") else {
243243
throw DecodingError.dataCorruptedError(
244244
in: container,
245245
debugDescription: "\"\(field)\" is not a pseudo header field"

0 commit comments

Comments
 (0)