mirror of https://github.com/Corewala/Buran
Compare commits
2 Commits
f89f41ae14
...
eac1adb0cb
Author | SHA1 | Date |
---|---|---|
Corewala | eac1adb0cb | |
Corewala | eee109bb28 |
|
@ -6,6 +6,7 @@ const val GEMSCHEME = "gemini://"
|
||||||
const val TRAVERSE = "../"
|
const val TRAVERSE = "../"
|
||||||
const val SOLIDUS = "/"
|
const val SOLIDUS = "/"
|
||||||
const val DIREND = "/"
|
const val DIREND = "/"
|
||||||
|
const val QUERY = "?"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -44,9 +45,18 @@ class OppenURI constructor(private var ouri: String) {
|
||||||
val traversalCount = reference.split(TRAVERSE).size - 1
|
val traversalCount = reference.split(TRAVERSE).size - 1
|
||||||
ouri = traverse(traversalCount) + reference.replace(TRAVERSE, "")
|
ouri = traverse(traversalCount) + reference.replace(TRAVERSE, "")
|
||||||
}
|
}
|
||||||
|
reference.startsWith(QUERY) -> {
|
||||||
|
ouri = if(reference.contains(QUERY)){
|
||||||
|
ouri.substringBefore(QUERY) + reference
|
||||||
|
}else{
|
||||||
|
ouri + reference
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
ouri = when {
|
ouri = when {
|
||||||
ouri.endsWith(DIREND) -> "${ouri}$reference"
|
ouri.endsWith(DIREND) -> {
|
||||||
|
"${ouri}$reference"
|
||||||
|
}
|
||||||
else -> "${ouri.substring(0, ouri.lastIndexOf("/"))}/$reference"
|
else -> "${ouri.substring(0, ouri.lastIndexOf("/"))}/$reference"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,34 +64,6 @@ class OppenURI constructor(private var ouri: String) {
|
||||||
return ouri
|
return ouri
|
||||||
}
|
}
|
||||||
|
|
||||||
fun traverse(): OppenURI{
|
|
||||||
val path = ouri.removePrefix("$GEMSCHEME$host")
|
|
||||||
val segments = path.split(SOLIDUS).filter { it.isNotEmpty() }
|
|
||||||
|
|
||||||
var nouri = "$GEMSCHEME$host"
|
|
||||||
|
|
||||||
when (ouri) {
|
|
||||||
"" -> {
|
|
||||||
}
|
|
||||||
GEMSCHEME -> ouri = ""
|
|
||||||
"$nouri/" -> ouri = GEMSCHEME
|
|
||||||
else -> {
|
|
||||||
when {
|
|
||||||
segments.isNotEmpty() -> {
|
|
||||||
val remaining = segments.dropLast(1)
|
|
||||||
remaining.forEach { segment ->
|
|
||||||
nouri += "/$segment"
|
|
||||||
}
|
|
||||||
ouri = "$nouri/"
|
|
||||||
}
|
|
||||||
else -> ouri = "$nouri/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun traverse(count: Int): String{
|
private fun traverse(count: Int): String{
|
||||||
val path = ouri.removePrefix("$GEMSCHEME$host")
|
val path = ouri.removePrefix("$GEMSCHEME$host")
|
||||||
val segments = path.split(SOLIDUS).filter { it.isNotEmpty() }
|
val segments = path.split(SOLIDUS).filter { it.isNotEmpty() }
|
||||||
|
|
Loading…
Reference in New Issue