Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Using the Unicode Names package: http://www.rust-ci.org/huonw/unicode_names/doc/unicode_names/#cargo-enabled
//require macros...
// in Cargo.toml looks like this:
// [dependencies.unicode_names_macros]
// git = "https://github.com/huonw/unicode_names"
#![feature(phase)]
#[phase(plugin)] extern crate unicode_names_macros;
//require functions...
// in Cargo.toml looks like this:
// [dependencies.unicode_names]
// git = "https://github.com/huonw/unicode_names"
extern crate unicode_names;
fn main() {
// USE MACROS
let x: char = named_char!("snowman");
assert_eq!(x, '☃');
let y: &str = named!("foo bar \\N{BLACK STAR} baz qux");
assert_eq!(y, "foo bar ★ baz qux");
// USE FUNCTIONS
println!("☃ is called {}", unicode_names::name('☃'));
println!("{} is happy", unicode_names::character("white smiling face"));
// Tesing a copy paste from firefox wikipeida page on greek alphabet
println!("λ is called {}", unicode_names::name('λ'));
println!("{} is STAFF OF AESCULAPIUS", unicode_names::character("AESCULAPIUS, STAFF OF"));
}
/* ->
☃ is called Some(SNOWMAN)
λ is called Some(GREEK SMALL LETTER LAMDA)
Some(☺) is happy
Some(⚕) is STAFF OF AESCULAPIUS
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.