https://kotlinlang.org logo
Title
u

4ntoine

08/05/2019, 7:40 AM
Hey, guys. Does Ktor support punycode (googled a bit but found nothing)? Looking for some util methods to convert ascii <-> unicode
b

Big Chungus

08/05/2019, 7:40 AM
Bit of a dense question, but what's puny code? 😄
u

4ntoine

08/05/2019, 7:41 AM
https://en.wikipedia.org/wiki/Punycode domains written with national characters
👍 1
g

gildor

08/05/2019, 7:42 AM
what kind support of punycode is required? Isn’t it designed to work using existing standards and do not require special support
u

4ntoine

08/05/2019, 7:43 AM
So it does converting somewhere behind the scenes?
g

gildor

08/05/2019, 7:43 AM
Ah, see, you just want to use util method
So it does converting somewhere behind the scenes?
I don’t think so. And why would ktor encode/decode it?
encoded punycode is real address, unicode representation just for humans and should be supported by browser only
u

4ntoine

08/05/2019, 7:45 AM
let’s say i want to get url content of `президент.рф`(eg. send GET request to that url) . So i guess this should be supported, right?
g

gildor

08/05/2019, 7:46 AM
okay, it’s more complicated, it should be supported by HTTP client
but where would you get such url? User input?
u

4ntoine

08/05/2019, 7:47 AM
from browser app textbox, let’s say i’m working on a browser app
So i guess browser app should convert it into “xn-- ..” and pass to ktor
g

gildor

08/05/2019, 7:47 AM
than it depend on your http client
u

4ntoine

08/05/2019, 7:47 AM
and ktor (or underlying http client) should convert it to utf, right?
g

gildor

08/05/2019, 7:47 AM
it should convert it to Punycode ascii from utf
u

4ntoine

08/05/2019, 7:49 AM
ok, thanks for the explanation. But are you aware of any kind of `expect`ed methods in
common
in ktor that any particular http client provides as
actual
?
g

gildor

08/05/2019, 7:50 AM
I don’t know any MPP implementation
u

4ntoine

08/05/2019, 7:50 AM
ok, thanks anyway
g

gildor

08/05/2019, 7:52 AM
I mean Ktor probably does nothing about Punycode, it delegates to platform http client
u

4ntoine

08/05/2019, 7:52 AM
yup, i got it
g

gildor

08/05/2019, 7:53 AM
anyway, if you implementing Browser, than you need a way to encode and decode Punycode, for example browsers has own set of rules what should be decoded and what shouldn’t to avoid fishing etc
u

4ntoine

08/05/2019, 7:53 AM
that’s exactly what i’m looking for (though i don’t work on browser itself)
g

gildor

08/05/2019, 7:54 AM
just port some existing implementation to Kotlin
u

4ntoine

08/05/2019, 7:55 AM
yeah, before doing that i just wanted to find smth existing. BTW jvm provides it in
java.net.IDN
so it should not be a problem to implement it for native (what i originally needed) i guess
g

gildor

08/05/2019, 7:56 AM
not be a problem to implement it for native
How Java implementation related to native?
u

4ntoine

08/05/2019, 7:57 AM
one can write mpp implementation using java’s code as an example
and i need both java and native impl
for some mpp project
g

gildor

08/05/2019, 7:57 AM
for Native I would just use some existing library probably
u

4ntoine

08/05/2019, 7:58 AM
i’d love to find/adapt one or even mpp impl
g

gildor

08/05/2019, 7:58 AM
one can write mpp implementation using java’s code as an example
Java delegates to native code. But there is also ICU4J implementation (which is used also for modern Android)
👍 1
y

yschimke

08/05/2019, 11:29 AM
The rules are non trivial if you want to implement it properly. e.g. not mixing different charsets, outside the valid combinations. It's probably best to find good implementation on each platform.
b

Big Chungus

08/05/2019, 11:55 AM
You would be better off writing a wrapper MPP library. For instance to have MPP json parser i could write an expect class in common module and then use say Gson for JVM and JS JSON for js as actual implementations.
This way you're free to use any platform-specific libraries for your MPP library