-
Notifications
You must be signed in to change notification settings - Fork 0
/
rust.rs
27 lines (24 loc) · 689 Bytes
/
rust.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::fmt::Write;
use std::env;
// https://doc.rust-lang.org/std/string/struct.String.html
pub fn to_utf8_unicode_point_string(arg: String) -> String {
let mut res = String::new();
if arg.len() == 0 {
return res;
}
write!(&mut res, "U+").expect("Cannot create hexstring");
for &byte in arg.as_bytes() {
write!(&mut res, "{:x}", byte).expect("Unable to create hex representation");
}
return res;
}
fn main() {
let mut arg = String::from("hi ルーカスǃ");
for (i, a) in env::args().enumerate() {
if i == 1 {
arg = a;
}
}
let res = to_utf8_unicode_point_string(arg);
println!("{}", res);
}