Yokan / rebuild
Course 1 8624561

SafDocumentPath.android.kt

composeApp/src/androidMain/kotlin/eu/friedcutlet/yokan/services/files/SafDocumentPath.android.kt

implementation13 lines
1package eu.friedcutlet.yokan.services.files23internal data class SafDocumentPath(val documentId: String, val children: List<String>)45/** URI pathSegments have already decoded opaque document IDs; never split those IDs as paths. */6internal fun safDocumentPath(segments: List<String>): SafDocumentPath? {7    if (segments.getOrNull(0) != "tree" || segments.getOrNull(1).isNullOrBlank()) return null8    val explicitDocument = segments.getOrNull(2) == "document"9    val id = segments.getOrNull(if (explicitDocument) 3 else 1)?.takeIf(String::isNotBlank) ?: return null10    val children = segments.drop(if (explicitDocument) 4 else 2)11    if (children.size > 64 || children.any { it.isBlank() || it == "." || it == ".." || '/' in it || '\\' in it || '\u0000' in it }) return null12    return SafDocumentPath(id, children)13}14

Search chapters, reference and source filenames.