-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
f85f514
commit ddc63c8
Showing
132 changed files
with
1,144 additions
and
911 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 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 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 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 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 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 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
67 changes: 67 additions & 0 deletions
67
Sources/SwiftDocC/Infrastructure/DocumentationBundle+Identifier.swift
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,67 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Foundation | ||
|
||
extension DocumentationBundle { | ||
/// A stable and locally unique identifier for a collection of documentation inputs. | ||
public struct Identifier: RawRepresentable { | ||
public let rawValue: String | ||
|
||
public init(rawValue: String) { | ||
// To ensure that the identifier can be used as a valid "host" component of a resolved topic reference's url, | ||
// replace any consecutive sequence of unsupported characters with a "-". | ||
self.rawValue = rawValue | ||
.components(separatedBy: Self.charactersToReplace) | ||
.filter { !$0.isEmpty } | ||
.joined(separator: "-") | ||
} | ||
|
||
private static let charactersToReplace = CharacterSet.urlHostAllowed.inverted | ||
} | ||
} | ||
|
||
extension DocumentationBundle.Identifier: Hashable {} | ||
extension DocumentationBundle.Identifier: Sendable {} | ||
|
||
// Support creating an identifier from a string literal. | ||
extension DocumentationBundle.Identifier: ExpressibleByStringLiteral { | ||
public init(stringLiteral value: StringLiteralType) { | ||
self.init(rawValue: value) | ||
} | ||
} | ||
|
||
// Sort identifiers based on their raw string value. | ||
extension DocumentationBundle.Identifier: Comparable { | ||
public static func < (lhs: Self, rhs: Self) -> Bool { | ||
lhs.rawValue < rhs.rawValue | ||
} | ||
} | ||
|
||
// Print as a single string value | ||
extension DocumentationBundle.Identifier: CustomStringConvertible { | ||
public var description: String { | ||
rawValue | ||
} | ||
} | ||
|
||
// Encode and decode the identifier as a single string value. | ||
extension DocumentationBundle.Identifier: Codable { | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let rawValue = try container.decode(String.self) | ||
self.init(rawValue: rawValue) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
try container.encode(rawValue) | ||
} | ||
} |
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
Oops, something went wrong.