11/*
2- This source file is part of the Swift.org open source project
2+ This source file is part doccof the Swift.org open source project
33
44 Copyright (c) 2024 Apple Inc. and the Swift project authors
55 Licensed under Apache License v2.0 with Runtime Library Exception
@@ -36,7 +36,9 @@ extension Docc.ProcessArchive {
3636 " \( frameworkName. localizedCapitalized) _ChangeLog.md " : """
3737 # \( frameworkName. localizedCapitalized) Updates
3838
39- @Metadata { @PageColor(yellow) }
39+ @Metadata {
40+ @PageColor(yellow)
41+ }
4042
4143 Learn about important changes to \( frameworkName. localizedCapitalized) .
4244
@@ -222,6 +224,48 @@ extension Docc.ProcessArchive {
222224 }
223225 }
224226
227+ // TODO: CONTINUE
228+ // func findPageType(symbolPath: URL) throws -> URL? {
229+ // struct ContainerWithPageType: Codable {
230+ // var pageType: NavigatorIndex.PageType
231+ // }
232+ //
233+ // let renderJSONData = try Data(contentsOf: symbolPath)
234+ // let decoder = RenderJSONDecoder.makeDecoder()
235+ //
236+ // do {
237+ // let identifier = try decoder.decode(NavigatorIndex.self, from: renderJSONData).
238+ // return identifier.url
239+ // } catch {
240+ // return nil
241+ // }
242+ // }
243+
244+ func findClassName( symbolPath: URL ) -> String {
245+ return symbolPath. lastPathComponent
246+ }
247+
248+ // func findClassName(symbolPath: URL) throws -> [[String]]? {
249+ // struct ContainerWithRenderHierarchy: Codable {
250+ // var hierarchy: RenderHierarchy
251+ // }
252+ //
253+ // let renderJSONData = try Data(contentsOf: symbolPath)
254+ // let decoder = RenderJSONDecoder.makeDecoder()
255+ //
256+ // do {
257+ // let hierarchy = try decoder.decode(ContainerWithRenderHierarchy.self, from: renderJSONData).hierarchy
258+ //
259+ // if hierarchy != nil {
260+ // return hierarchy.paths
261+ // }
262+ //
263+ // return identifier.url
264+ // } catch {
265+ // return nil
266+ // }
267+ // }
268+
225269 /// Process lists of symbols to group them according to the highest level path component, split by spaces.
226270 func groupSymbols( symbolLinks: Set < URL > , frameworkName: String ) -> String {
227271 // Sort list alphabetically
@@ -239,7 +283,7 @@ extension Docc.ProcessArchive {
239283
240284 // If there are no common path components, add a space. Then reset the first to find the next parent.
241285 if parent. localizedLowercase. hasSuffix ( frameworkName + " / " ) {
242- links. append ( " \n \n " )
286+ links. append ( " \n \n " )
243287 first = symbol
244288 }
245289
@@ -248,6 +292,37 @@ extension Docc.ProcessArchive {
248292
249293 return links
250294 }
295+
296+ func addClassNames( allSymbolsString: String ) -> String {
297+ // let processedString = ""
298+
299+ // Split string into string array on a double newline
300+ return longestCommonPrefix ( of: allSymbolsString)
301+ }
302+
303+ func longestCommonPrefix( of string: String ) -> String {
304+
305+ let words = string. split ( separator: " " )
306+ // let words = string.split(separator: "\n\n")
307+ guard let first = words. first else {
308+ return " "
309+ }
310+
311+ var ( minWord, maxWord) = ( first, first)
312+ for word in words. dropFirst ( ) {
313+ if word < minWord {
314+ print ( word)
315+ print ( maxWord)
316+ minWord = word
317+ } else if word > maxWord {
318+ print ( word)
319+ print ( maxWord)
320+ maxWord = word
321+ }
322+ }
323+
324+ return minWord. commonPrefix ( with: maxWord)
325+ }
251326
252327 }
253328}
0 commit comments