-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97f71fe
commit 76e02f8
Showing
3 changed files
with
35 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |