Skip to content

Commit 76e02f8

Browse files
committed
swift-nio-utf8
1 parent 97f71fe commit 76e02f8

File tree

3 files changed

+35
-129
lines changed

3 files changed

+35
-129
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let package = Package(
1616
dependencies: [
1717
.package(url: "https://github.com/apple/swift-http-types.git", from: "1.0.0"),
1818
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.0"),
19-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.62.0"),
19+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.77.0"),
2020
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.22.0"),
2121
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.5.0"),
2222
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.20.0"),

Sources/WSCore/ByteBuffer+validatingString.swift

Lines changed: 0 additions & 128 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Hummingbird server framework project
4+
//
5+
// Copyright (c) 2024 the Hummingbird authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import NIOCore
16+
17+
extension String {
18+
init?(buffer: ByteBuffer, validateUTF8: Bool) {
19+
#if compiler(>=6)
20+
if #available(macOS 15, iOS 18, tvOS 18, watchOS 11, *), validateUTF8 {
21+
do {
22+
var buffer = buffer
23+
self = try buffer.readUTF8ValidatedString(length: buffer.readableBytes)!
24+
} catch {
25+
return nil
26+
}
27+
} else {
28+
self = .init(buffer: buffer)
29+
}
30+
#else
31+
self = .init(buffer: buffer)
32+
#endif // compiler(>=6)
33+
}
34+
}

0 commit comments

Comments
 (0)