This commit is contained in:
Freya Murphy 2024-04-18 13:26:17 -04:00
commit 125fd67c96
Signed by: freya
GPG key ID: 744AB800E383AE52
7 changed files with 678 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

303
Cargo.lock generated Normal file
View file

@ -0,0 +1,303 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
[[package]]
name = "anstyle-parse"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "clap"
version = "4.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "memchr"
version = "2.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
[[package]]
name = "proc-macro2"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
[[package]]
name = "serde"
version = "1.0.198"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.198"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "trollify"
version = "0.1.0"
dependencies = [
"clap",
"lazy_static",
"regex",
"serde",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"

12
Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "trollify"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
lazy_static = "1"
regex = "1"

9
LICENSE Normal file
View file

@ -0,0 +1,9 @@
the miit liicen2e (miit)
copyriight © 2023 freya murphy
permii22iion ii2 hereby granted, free of charge, two any per2on obtaiiniing a copy of thii2 2oftware and a22ociiated documentatiion fiile2 (the “2oftware”), two deal iin the 2oftware wiithout re2triictiion, iincludiing wiithout liimiitatiion the riight2 two u2e, copy, modiify, merge, publii2h, dii2triibute, 2ubliicen2e, and/or 2ell copiie2 of the 2oftware, and two permiit per2on2 two whom the 2oftware ii2 furnii2hed two do 2o, 2ubject two the followiing condiitiion2:
the above copyriight notiice and thii2 permii22iion notiice 2hall be iincluded iin all copiie2 or 2ub2tantiial portiion2 of the 2oftware
the 2oftware ii2 proviided “a2 ii2”, wiithout warranty of any kiind, EXPRESS or iimpliied, iincludiing but not liimiited two the warrantiie2 of merchantabiiliity, fiitne22 for a partiicular purpo2e and noniinfriingement iin no event 2hall the author2 or copyriight holder2 be liiable for any claiim, damage2 or other liiabiiliity, whether iin an actiion of contract, twort or otherwii2e, arii2iing from, out of or iin connectiion wiith the 2oftware or the u2e or other dealiing2 iin the 2oftware

14
README.md Normal file
View file

@ -0,0 +1,14 @@
## trollify
make2 your text trollii2h
#### usage
```
trollify <TROLL>
```
text ii2 read iin from 2tdiin
#### license
trolliify ii2 liicened under the miit liicen2e

313
src/lib.rs Normal file
View file

@ -0,0 +1,313 @@
use std::borrow::Cow;
use lazy_static::lazy_static;
use regex::Regex;
fn to_title_case<'a>(text: &'a str) -> Cow<'a, str> {
let mut chars = text.chars();
match chars.next() {
None => Cow::Borrowed(text),
Some(c) => Cow::Owned(
c.to_uppercase().collect::<String>() +
&chars.as_str().to_lowercase()
)
}
}
lazy_static! {
static ref FACE_RE: Regex = Regex::new(r"[:Xx][\)\]|p|P|d|D|o|O]").unwrap();
}
trait Trollify {
fn sentance_delimiter(&self) -> char {
'.'
}
fn troll_word<'w>(&self, word: &'w str) -> Cow<'w, str> {
Cow::Borrowed(word)
}
fn troll_line<'l>(&self, line: &'l str) -> Cow<'l, str> {
Cow::Borrowed(line)
}
fn troll_sentence<'s>(&self, sentence: &'s str) -> Cow<'s, str> {
Cow::Borrowed(sentence)
}
fn troll_all<'a>(&self, all: &'a str) -> Cow<'a, str> {
Cow::Borrowed(all)
}
fn troll_face<'f>(&self, face: &'f str) -> Cow<'f, str> {
Cow::Borrowed(face)
}
}
struct Araida;
impl Trollify for Araida {
fn troll_word<'w>(&self, word: &'w str) -> Cow<'w, str> {
Cow::Owned(word.to_lowercase().replace("o", "0"))
}
}
struct Tavros;
impl Trollify for Tavros {
fn sentance_delimiter(&self) -> char {
','
}
fn troll_sentence<'s>(&self, sentence: &'s str) -> Cow<'s, str> {
let mut chars = sentence.chars();
match chars.next() {
None => Cow::Borrowed(sentence),
Some(c) => Cow::Owned(
c.to_lowercase().collect::<String>() +
&chars.as_str().to_uppercase()
)
}
}
fn troll_all<'a>(&self, all: &'a str) -> Cow<'a, str> {
Cow::Owned(all
.replace(".", ",")
.replace("?", ",")
.replace("!", ",")
)
}
fn troll_face<'f>(&self, face: &'f str) -> Cow<'f, str> {
Cow::Owned(String::from("}") + face)
}
}
struct Sollux;
impl Trollify for Sollux {
fn troll_word<'w>(&self, word: &'w str) -> Cow<'w, str> {
Cow::Owned(word
.to_lowercase()
.replace("s", "2")
.replace("i", "ii")
.replace("to", "two")
)
}
}
struct Karkat;
impl Trollify for Karkat {
fn troll_all<'a>(&self, all: &'a str) -> Cow<'a, str> {
Cow::Owned(all.to_uppercase())
}
}
struct Nepeta;
impl Trollify for Nepeta {
fn troll_line<'l>(&self, line: &'l str) -> Cow<'l, str> {
Cow::Owned(
String::from(":33 < ") +
&line.to_lowercase()
)
}
}
struct Kanaya;
impl Trollify for Kanaya {
fn troll_word<'w>(&self, word: &'w str) -> Cow<'w, str> {
to_title_case(word)
}
}
struct Terezi;
impl Trollify for Terezi {
fn troll_word<'w>(&self, word: &'w str) -> Cow<'w, str> {
Cow::Owned(word
.to_uppercase()
.replace("A", "4")
.replace("I", "1")
.replace("E", "3")
)
}
fn troll_face<'f>(&self, face: &'f str) -> Cow<'f, str> {
Cow::Owned(
String::from(">") +
&face.replace(")", "]")
)
}
}
struct Vriska;
impl Trollify for Vriska {
fn troll_word<'w>(&self, word: &'w str) -> Cow<'w, str> {
Cow::Owned(word.replace("b", "8"))
}
fn troll_sentence<'s>(&self, sentence: &'s str) -> Cow<'s, str> {
to_title_case(sentence)
}
fn troll_face<'f>(&self, face: &'f str) -> Cow<'f, str> {
Cow::Owned(face
.replace(":", "::::")
.replace("X", "XXXX")
)
}
}
struct Equius;
impl Trollify for Equius {
fn troll_word<'w>(&self, word: &'w str) -> Cow<'w, str> {
Cow::Owned(word.replace("x", "%"))
}
fn troll_sentence<'s>(&self, sentence: &'s str) -> Cow<'s, str> {
to_title_case(sentence)
}
fn troll_line<'l>(&self, line: &'l str) -> Cow<'l, str> {
Cow::Owned(String::from("D --> ") + line)
}
}
struct Gamzee;
impl Trollify for Gamzee {
fn troll_all<'a>(&self, all: &'a str) -> Cow<'a, str> {
let chars = all.chars();
let mut next = true;
let mut buf = String::new();
for char in chars {
if char.is_alphabetic() {
if next {
buf += &char.to_uppercase().to_string();
} else {
buf += &char.to_lowercase().to_string();
}
next = !next;
} else {
buf.push(char);
}
}
Cow::Owned(buf)
}
fn troll_face<'f>(&self, face: &'f str) -> Cow<'f, str> {
Cow::Owned(face.replace(":", ":o"))
}
}
struct Eridan;
impl Trollify for Eridan {
fn troll_word<'w>(&self, word: &'w str) -> Cow<'w, str> {
Cow::Owned(word
.to_lowercase()
.replace("v", "vv")
.replace("w", "ww")
)
}
}
struct Feferi;
impl Trollify for Feferi {
fn troll_word<'w>(&self, word: &'w str) -> Cow<'w, str> {
Cow::Owned(word
.replace("h", ") (")
.replace("E", "-E")
)
}
fn troll_sentence<'s>(&self, sentence: &'s str) -> Cow<'s, str> {
to_title_case(sentence)
}
fn troll_face<'f>(&self, face: &'f str) -> Cow<'f, str> {
Cow::Owned(face.replace(":", "3:"))
}
}
#[derive(clap::ValueEnum, serde::Serialize, Clone, Copy, Debug)]
#[serde(rename_all = "kebab-case")]
pub enum Troll {
Araida,
Tavros,
Sollux,
Karkat,
Nepeta,
Kanaya,
Terezi,
Vriska,
Equius,
Gamzee,
Eridan,
Feferi
}
fn get_troll(troll: Troll) -> Box<dyn Trollify> {
match troll {
Troll::Araida => Box::new(Araida {}),
Troll::Tavros => Box::new(Tavros {}),
Troll::Sollux => Box::new(Sollux {}),
Troll::Karkat => Box::new(Karkat {}),
Troll::Nepeta => Box::new(Nepeta {}),
Troll::Kanaya => Box::new(Kanaya {}),
Troll::Terezi => Box::new(Terezi {}),
Troll::Vriska => Box::new(Vriska {}),
Troll::Equius => Box::new(Equius {}),
Troll::Gamzee => Box::new(Gamzee {}),
Troll::Eridan => Box::new(Eridan {}),
Troll::Feferi => Box::new(Feferi {}),
}
}
pub fn trollify<'a>(text: &'a str, troll: Troll) -> String {
let troll = get_troll(troll);
let text = troll.troll_all(text);
let sentences = text.split(troll.sentance_delimiter());
let mut buf = String::new();
for sentence in sentences {
let sentence = troll.troll_sentence(sentence);
sentence
.split(" ")
.into_iter()
.map(|word| {
match FACE_RE.is_match(word) {
true => troll.troll_face(word),
false => troll.troll_word(word)
}
})
.enumerate()
.for_each(|(idx, word)| {
if idx != 0 {
buf += " ";
}
buf += &word;
});
}
let text = buf;
let lines = text.split("\n");
let mut buf = String::new();
for (idx, line) in lines.enumerate() {
if idx != 0 {
buf.push('\n');
}
let line = troll.troll_line(line);
buf += &line;
}
let text = buf;
text
}

26
src/main.rs Normal file
View file

@ -0,0 +1,26 @@
use std::io;
use clap::Parser;
use trollify::{trollify, Troll};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
troll: Troll
}
fn main() {
let args = Args::parse();
let mut line = String::new();
loop {
match io::stdin().read_line(&mut line) {
Ok(0) => break,
Err(_) => break,
Ok(_) => {
let out = trollify(&line, args.troll);
print!("{}", out);
line.clear();
},
}
}
}