This is just text encoding, unaware of domain names. For domain names, prepend xn--, and remove any invalid chars, like whitespace and punctuation.