napperley
10/06/2023, 1:22 AMin
operator. Below is some sample code from a prototype which doesn't work as expected if the dataType
argument contains one or more space characters (eg " kotlin.String "):
fun processDataType(dataType: String): String {
val kotlinBaseTypes = setOf("<http://kotlin.Int|kotlin.Int>", "kotlin.String", "kotlin.UInt")
return if (dataType in kotlinBaseTypes) dataType.trim().replace("kotlin.", "")
else dataType.trim()
}
I'm wondering if the issue is limited to Kotlin Native or if it affects other Kotlin platforms. Replacing
return if (dataType in kotlinBaseTypes) dataType.trim().replace("kotlin.", "")
with
return if (dataType.trim() in kotlinBaseTypes) dataType.trim().replace("kotlin.", "")
works around the issue.ephemient
10/06/2023, 2:18 AMribesg
10/06/2023, 10:37 AM"kotlin.String"
and " kotlin.String "
are not the same strings, there's no bug herenapperley
10/09/2023, 8:32 PMin
operator have to match the entire String? Positional matches should be covered by the in
operator. Provided the text being matched exists in the String, the position shouldn't matter.ephemient
10/09/2023, 8:33 PMx in container
is equivalent to
container.contains(x)
that always means
container.any { it == x }
not
container.any { it.contains(x) }
container
could be any type of container, such as List<Int>
, and int
Int
definitely doesn't have a `in`/`contains`napperley
10/09/2023, 8:35 PMin
operator doesn't behave the same way as the contains
function.ephemient
10/09/2023, 8:36 PMin
operator behaves the exact same way as the contains
function, the order of arguments is just reversednapperley
10/09/2023, 8:39 PMephemient
10/09/2023, 8:39 PMkotlinBaseTypes.any { it in dataType }
then just do thatSet
though