SafDocumentPath.android.kt
composeApp/src/androidMain/kotlin/eu/friedcutlet/yokan/services/files/SafDocumentPath.android.kt
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