Skip to main content

encode_punycode

Function encode_punycode 

Source
pub fn encode_punycode<'a, T: Into<Cow<'a, str>>>(value: T) -> Cow<'a, str>
Expand description

Punycode encode, in-place if possible.

Please note that, per Appendix C of RFC 3492, this uses usizes instead of u32s.

In practice this means nothing but someone’s going to complain so I figured I’d explain myself early.

§Examples

use better_url::util::*;

assert_eq!(encode_punycode(""  ), ""   );
assert_eq!(encode_punycode("a" ), "a-" );
assert_eq!(encode_punycode("a-"), "a--");

assert_eq!(encode_punycode("ليهمابتكلموشعربي؟"                                                       ), "egbpdaj6bu4bxfgehfvwxn"                                               );
assert_eq!(encode_punycode("他们为什么不说中文"                                                      ), "ihqwcrb4cv8a8dqg056pqjye"                                             );
assert_eq!(encode_punycode("他們爲什麽不說中文"                                                      ), "ihqwctvzc91f659drss3x8bo0yb"                                          );
assert_eq!(encode_punycode("Pročprostěnemluvíčesky"                                                  ), "Proprostnemluvesky-uyb24dma41a"                                       );
assert_eq!(encode_punycode("למההםפשוטלאמדבריםעברית"                                                  ), "4dbcagdahymbxekheh6e0a7fei0b"                                         );
assert_eq!(encode_punycode("यहलोगहिन\u{94d}दीक\u{94d}यो\u{902}नही\u{902}बोलसकत\u{947}ह\u{948}\u{902}"), "i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd"                         );
assert_eq!(encode_punycode("なぜみんな日本語を話してくれないのか"                                    ), "n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa"                               );
assert_eq!(encode_punycode("세계의모든사람들이한국어를이해한다면얼마나좋을까"                        ), "989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c");
assert_eq!(encode_punycode("почемужеонинеговорятпорусски"                                            ), "b1abfaaepdrnnbgefbadotcwatmq2g4l"                                     );
assert_eq!(encode_punycode("PorquénopuedensimplementehablarenEspañol"                                ), "PorqunopuedensimplementehablarenEspaol-fmd56a"                        );
assert_eq!(encode_punycode("TạisaohọkhôngthểchỉnóitiếngViệt"                                         ), "TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g"                         );