From 24cf6d7d7d3b465de06664ad4f847e80109c5250 Mon Sep 17 00:00:00 2001 From: Jared Burce Date: Wed, 17 Jun 2020 11:19:49 -0700 Subject: [PATCH] Initial commit --- .gitignore | 1 + Cargo.lock | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 12 ++++ src/main.rs | 68 +++++++++++++++++++ 4 files changed, 266 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..3ce6d7c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,185 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "libc" +version = "0.2.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" + +[[package]] +name = "phf" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" +dependencies = [ + "phf_macros", + "phf_shared", + "proc-macro-hack", +] + +[[package]] +name = "phf_generator" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6fde18ff429ffc8fe78e2bf7f8b7a5a5a6e2a8b58bc5a9ac69198bbda9189c" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" +dependencies = [ + "siphasher", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" + +[[package]] +name = "proc-macro-hack" +version = "0.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4" + +[[package]] +name = "proc-macro2" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", + "rand_pcg", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_pcg" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" +dependencies = [ + "rand_core", +] + +[[package]] +name = "runic" +version = "0.1.0" +dependencies = [ + "phf", +] + +[[package]] +name = "siphasher" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" + +[[package]] +name = "syn" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5547066 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "runic" +version = "0.1.0" +authors = ["Jared Burce "] +edition = "2018" + +[profile.release] +panic = "abort" +strip = "symbols" + +[dependencies] +phf = { version = "0.8.0", features = ["macros"] } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4a89559 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,68 @@ +use phf::phf_map; + +static DIGRAPHS: phf::Map = phf_map! { + 'e' => &[('a', 'ᛠ'), ('e', 'ᛝ')], // EA, EE + 'n' => &[('g', 'ᛟ')], // NG + 's' => &[('t', 'ᛥ')], // ST + 't' => &[('h', 'ᚦ')], // TH +}; + +static MONOGRAPHS: phf::Map = phf_map! { + 'a' => 'ᚨ', + 'b' => 'ᛒ', + 'c' => 'ᚳ', + 'd' => 'ᛞ', + 'e' => 'ᛖ', + 'f' => 'ᚠ', + 'g' => 'ᚷ', + 'h' => 'ᚹ', + 'i' => 'ᛁ', + 'j' => 'ᛳ', + 'k' => 'ᛱ', + 'l' => 'ᛚ', + 'm' => 'ᛗ', + 'n' => 'ᚾ', + 'o' => 'ᚩ', + 'p' => 'ᛈ', + 'q' => 'ᚴ', + 'r' => 'ᚱ', + 's' => 'ᛋ', + 't' => 'ᛏ', + 'u' => 'ᚢ', + 'v' => 'Λ', // Greek Lambda + 'w' => 'ᚻ', + 'x' => 'ᛣ', + 'y' => 'ᚥ', + 'z' => 'ᛉ', +}; + +fn main() { + for arg in std::env::args().skip(1).map(to_runic) { + println!("{}", arg); + } +} + +fn monograph(latin: char) -> char { + *MONOGRAPHS.get(&latin.to_ascii_lowercase()).unwrap_or(&latin) +} + +fn to_runic(latin: String) -> String { + let mut chars = latin.chars().peekable(); + let mut out = String::with_capacity(latin.len()); + while let Some(c) = chars.next() { + if let Some(digraphs) = DIGRAPHS.get(&c) { + if let Some((_, rune)) = digraphs.iter().find(|(second, _)| match chars.peek() { + Some(peeked) => second == peeked, // unstable: chars.peek().contains(&second) + None => false, + }) { + chars.next(); + out.push(*rune); + } else { + out.push(monograph(c)); + } + } else { + out.push(monograph(c)); + } + } + out +}