Skip to content

Commit

Permalink
swift-nio-utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Nov 27, 2024
1 parent 97f71fe commit 76e02f8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 129 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-http-types.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.62.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.77.0"),
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.22.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.5.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.20.0"),
Expand Down
128 changes: 0 additions & 128 deletions Sources/WSCore/ByteBuffer+validatingString.swift

This file was deleted.

34 changes: 34 additions & 0 deletions Sources/WSCore/String+validatingString.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2024 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import NIOCore

extension String {
init?(buffer: ByteBuffer, validateUTF8: Bool) {
#if compiler(>=6)
if #available(macOS 15, iOS 18, tvOS 18, watchOS 11, *), validateUTF8 {
do {
var buffer = buffer
self = try buffer.readUTF8ValidatedString(length: buffer.readableBytes)!
} catch {
return nil
}
} else {
self = .init(buffer: buffer)
}
#else
self = .init(buffer: buffer)
#endif // compiler(>=6)
}
}

0 comments on commit 76e02f8

Please sign in to comment.