@@ -25,6 +25,40 @@ extension Doclink
25
25
{
26
26
self . absolute ? self . path. first : nil
27
27
}
28
+
29
+ @inlinable public
30
+ var page : String
31
+ {
32
+ var first : Bool = true
33
+ var text : String = self . absolute ? " // " : " "
34
+ for component : String in self . path
35
+ {
36
+ if first
37
+ {
38
+ first = false
39
+ }
40
+ else
41
+ {
42
+ text. append ( " / " )
43
+ }
44
+
45
+ text. append ( component)
46
+ }
47
+ return text
48
+ }
49
+
50
+ @inlinable public
51
+ var value : String
52
+ {
53
+ var text : String = self . page
54
+ if let fragment: String = self . fragment
55
+ {
56
+ text. append ( " # " )
57
+ text. append ( fragment)
58
+ }
59
+ return text
60
+ }
61
+
28
62
/// Returns the string value of the doclink, without the `doc:` prefix, percent-encoding any
29
63
/// special characters as needed.
30
64
@inlinable public
@@ -53,6 +87,7 @@ extension Doclink
53
87
return text
54
88
}
55
89
}
90
+ @available ( * , deprecated)
56
91
extension Doclink : CustomStringConvertible
57
92
{
58
93
@inlinable public
@@ -113,11 +148,19 @@ extension Doclink
113
148
end = uri. endIndex
114
149
}
115
150
116
- if let path: URI . Path = . init( relative: uri [ start ..< end] )
151
+ /// The URI path parser doesn’t know how to handle optionals due to the
152
+ /// question character so we need to manually split it off and append
153
+ /// it to the last path component.
154
+ let question : String . Index ? = uri [ start ..< end] . firstIndex ( of: " ? " )
155
+ if let path: URI . Path = . init( relative: uri [ start ..< ( question ?? end) ] )
117
156
{
118
- self . init ( absolute: slashes >= 2 ,
119
- path: path. normalized ( ) ,
120
- fragment: fragment? . decoded)
157
+ var path : [ String ] = path. normalized ( )
158
+ if let question: String . Index ,
159
+ let i: Int = path. indices. last
160
+ {
161
+ path [ i] += uri [ question... ]
162
+ }
163
+ self . init ( absolute: slashes >= 2 , path: path, fragment: fragment? . decoded)
121
164
}
122
165
else
123
166
{
0 commit comments