Skip to content

Instantly share code, notes, and snippets.

@jbowles
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbowles/6c04470bd334713bf96a to your computer and use it in GitHub Desktop.
Save jbowles/6c04470bd334713bf96a to your computer and use it in GitHub Desktop.
// 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