Merge pull request #6 from sgoudham/v0.3.0

pull/8/head v0.3.0
Hamothy 3 years ago committed by GitHub
commit e3a1458f66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -154,6 +154,7 @@ jobs:
- uses: mislav/bump-homebrew-formula-action@v1 - uses: mislav/bump-homebrew-formula-action@v1
if: "!contains(github.ref, '-')" # skip prereleases if: "!contains(github.ref, '-')" # skip prereleases
with: with:
create-pullrequest: true
formula-name: ${{ env.BIN }} formula-name: ${{ env.BIN }}
formula-path: Formula/${{ env.BIN }}.rb formula-path: Formula/${{ env.BIN }}.rb
homebrew-tap: sgoudham/homebrew-tap homebrew-tap: sgoudham/homebrew-tap

@ -1,8 +1,8 @@
[package] [package]
name = "uwuifyy" name = "uwuifyy"
version = "0.2.0" version = "0.3.0"
edition = "2021" edition = "2021"
authors = ["Goudham <sgoudham@gmail.com>"] authors = ["Goudham Suresh <sgoudham@gmail.com>"]
description = "A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!" description = "A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!"
license = "MIT" license = "MIT"
readme = "README.md" readme = "README.md"
@ -31,7 +31,6 @@ linkify = "0.8.0"
rand_xoshiro = "0.6.0" rand_xoshiro = "0.6.0"
ahash = "0.7.6" ahash = "0.7.6"
memmap = "0.7.0" memmap = "0.7.0"
kaomoji-ru = "1.0.1"
[profile.release] [profile.release]
lto = "fat" lto = "fat"

@ -21,7 +21,7 @@
* [Binaries](#binaries) * [Binaries](#binaries)
+ [Windows](#windows) + [Windows](#windows)
+ [Linux \ macOS](#Linux-\-macOS) + [Linux \ macOS](#Linux-\-macOS)
+ [Rust \ Cargo](#Rust-\-Cargo) * [Rust \ Cargo](#Rust-\-Cargo)
* [Usage](#usage) * [Usage](#usage)
+ [Text Input to Text Output](#text-input-to-text-output) + [Text Input to Text Output](#text-input-to-text-output)
+ [Text Input to File Output](#text-input-to-file-output) + [Text Input to File Output](#text-input-to-file-output)
@ -138,11 +138,11 @@ $ source ~/.bash_profile
6. Verify installation 6. Verify installation
```shell ```shell
$ uwuifyy --help $ uwuifyy --version
uwuifyy 0.2.0 uwuifyy 0.3.0
``` ```
### Rust \ Cargo ## Rust \ Cargo
Alternatively, if using Rust's package manager, `Cargo`, all that is needed is Alternatively, if using Rust's package manager, `Cargo`, all that is needed is
@ -162,14 +162,16 @@ USAGE:
uwuifyy.exe [OPTIONS] <--text <TEXT>|--infile <FILE>> uwuifyy.exe [OPTIONS] <--text <TEXT>|--infile <FILE>>
OPTIONS: OPTIONS:
-t, --text <TEXT> Text to uwu'ify -t, --text <TEXT> The text to uwu'ify
-i, --infile <FILE> The file to uwu'ify -i, --infile <FILE> The file to uwu'ify
-o, --outfile <FILE> The file to output uwu'ified text -o, --outfile <FILE> The file to output uwu'ified text
--ascii-only The uwu'ified text will only include ASCII faces
--unicode-only The uwu'ified text will only include UTF-8 faces
-r, --random The flag to enable randomized uwu'ified text
-w, --words <VALUE> The modifier to determine how many words to be uwu'ified [default: 1] -w, --words <VALUE> The modifier to determine how many words to be uwu'ified [default: 1]
-f, --faces <VALUE> The modifier for uwu faces e.g hello -> hewwo [default: 0.05] -f, --faces <VALUE> The modifier for uwu faces e.g hello -> hewwo [default: 0.05]
-a, --actions <VALUE> The modifier for actions e.g *shuffles over* [default: 0.125] -a, --actions <VALUE> The modifier for actions e.g *shuffles over* [default: 0.125]
-s, --stutters <VALUE> The modifier for stutters e.g b-baka! [default: 0.225] -s, --stutters <VALUE> The modifier for stutters e.g b-baka! [default: 0.225]
-r, --random Flag to enable/disable random uwu'ifying
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
``` ```

@ -1,252 +1,204 @@
pub const FACES_SIZE: usize = 106; pub const ASCII_FACES_SIZE: usize = 33;
pub const FACES: [&[u8]; FACES_SIZE] = [ pub const ASCII_FACES: [&[u8]; ASCII_FACES_SIZE] = [
b"OwO", b"OwO ",
b"UwU", b"UwU ",
b">w<", b">w< ",
b"^w^", b"^w^ ",
b"^-^", b"^-^ ",
b":3", b":3 ",
b"x3", b"x3 ",
b"xDD", b"xDD ",
b";;w;;", b";;w;; ",
b">_<", b">_< ",
b">_>", b">_> ",
b"^.^", b"^.^ ",
b":33", b":33 ",
b"uWu", b"uWu ",
b"(o^ ^o) ",
b"(o-_-o) ",
b"(*^.^*) ",
b"(--_--) ",
b"o(>< )o ",
b"(-_-) ",
b"(T_T) ",
b"(>_<) ",
b"~(>_<~) ",
b"(x_x)V ",
b"(;;;*_*) ",
b"{{ (>_<) }} ",
b"(o_O) ",
b"(O_O;) ",
b"(O.O) ",
b"(o_O)! ",
b"(^-^*)/ ",
b"(o^ ^o)/ ",
b"( ~*-*)~ ",
];
pub const UNICODE_FACES_SIZE: usize = 66;
pub const UNICODE_FACES: [&[u8]; UNICODE_FACES_SIZE] = [
// (* ^ ω ^) // (* ^ ω ^)
kaomoji_ru::positive_emotions::JOY[0], b"(* ^ \xCF\x89 ^) ",
// (´ ∀ ` *) // (´ ∀ ` *)
kaomoji_ru::positive_emotions::JOY[1], b"(\xC2\xB4 \xE2\x88\x80 ` *) ",
// (o^▽^o) // (o^▽^o)
kaomoji_ru::positive_emotions::JOY[4], b"(o^\xE2\x96\xBD^o) ",
// (⌒▽⌒)☆ // (⌒▽⌒)☆
kaomoji_ru::positive_emotions::JOY[5], b"(\xE2\x8C\x92\xE2\x96\xBD\xE2\x8C\x92)\xE2\x98\x86 ",
// <( ̄︶ ̄)>
kaomoji_ru::positive_emotions::JOY[6],
// ヽ(・∀・)ノ // ヽ(・∀・)ノ
kaomoji_ru::positive_emotions::JOY[8], b"\xE3\x83\xBD(\xE3\x83\xBB\xE2\x88\x80\xE3\x83\xBB)\xEF\xBE\x89 ",
// (´。• ω •。`)
kaomoji_ru::positive_emotions::JOY[9],
// ( ̄ω ̄) // ( ̄ω ̄)
kaomoji_ru::positive_emotions::JOY[10], b"(\xEF\xBF\xA3\xCF\x89\xEF\xBF\xA3) ",
// (o・ω・o) // (o・ω・o)
kaomoji_ru::positive_emotions::JOY[12], b"(o\xEF\xBD\xA5\xCF\x89\xEF\xBD\xA5o) ",
// ヽ(*・ω・)ノ
kaomoji_ru::positive_emotions::JOY[14],
// (^人^) // (^人^)
kaomoji_ru::positive_emotions::JOY[16], b"(^\xE4\xBA\xBA^) ",
// (*´▽`*) // (*´▽`*)
kaomoji_ru::positive_emotions::JOY[18], b"(*\xC2\xB4\xE2\x96\xBD`*) ",
// ( ´ ω ` )
kaomoji_ru::positive_emotions::JOY[20],
// (≧◡≦) // (≧◡≦)
kaomoji_ru::positive_emotions::JOY[22], b"(\xE2\x89\xA7\xE2\x97\xA1\xE2\x89\xA6) ",
// (o´∀`o) // (o´∀`o)
kaomoji_ru::positive_emotions::JOY[23], b"(o\xC2\xB4\xE2\x88\x80`o) ",
// (´• ω •`)
kaomoji_ru::positive_emotions::JOY[24],
// (^▽^) // (^▽^)
kaomoji_ru::positive_emotions::JOY[25], b"(\xEF\xBC\xBE\xE2\x96\xBD\xEF\xBC\xBE') ",
// (⌒ω⌒) // (⌒ω⌒)
kaomoji_ru::positive_emotions::JOY[26], b"(\xE2\x8C\x92\xCF\x89\xE2\x8C\x92) ",
// ╰(▔∀▔)╯ // ╰(▔∀▔)╯
kaomoji_ru::positive_emotions::JOY[28], b"\xE2\x95\xB0(\xE2\x96\x94\xE2\x88\x80\xE2\x96\x94)\xE2\x95\xAF ",
// (*^‿^*) // (*^‿^*)
kaomoji_ru::positive_emotions::JOY[30], b"(*^\xE2\x80\xBF^*) ",
// (✯◡✯) // (✯◡✯)
kaomoji_ru::positive_emotions::JOY[32], b"(\xE2\x9C\xAF\xE2\x97\xA1\xE2\x9C\xAF) ",
// (*≧ω≦*) // (*≧ω≦*)
kaomoji_ru::positive_emotions::JOY[34], b"(*\xE2\x89\xA7\xCF\x89\xE2\x89\xA6*) ",
// (☆▽☆) // (☆▽☆)
kaomoji_ru::positive_emotions::JOY[35], b"(\xE2\x98\x86\xE2\x96\xBD\xE2\x98\x86) ",
// (≧▽≦) // (≧▽≦)
kaomoji_ru::positive_emotions::JOY[37], b"\xEF\xBC\xBC(\xE2\x89\xA7\xE2\x96\xBD\xE2\x89\xA6)\xEF\xBC\x8F ",
// ヽ(oo)
kaomoji_ru::positive_emotions::JOY[38],
// (*°▽°*) // (*°▽°*)
kaomoji_ru::positive_emotions::JOY[40], b"(*\xC2\xB0\xE2\x96\xBD\xC2\xB0*) ",
// (✧ω✧) // (✧ω✧)
kaomoji_ru::positive_emotions::JOY[42], b"(\xE2\x9C\xA7\xCF\x89\xE2\x9C\xA7) ",
// ヽ(*⌒▽⌒*)ノ
kaomoji_ru::positive_emotions::JOY[43],
// ヽ(>∀<☆) // ヽ(>∀<☆)
kaomoji_ru::positive_emotions::JOY[48], b"\xE3\x83\xBD(>\xE2\x88\x80<\xE2\x98\x86)\xE3\x83\x8E ",
// o(≧▽≦)o // o(≧▽≦)o
kaomoji_ru::positive_emotions::JOY[49], b"o(\xE2\x89\xA7\xE2\x96\xBD\xE2\x89\xA6)o ",
// (☆ω☆) // (☆ω☆)
kaomoji_ru::positive_emotions::JOY[50], b"(\xE2\x98\x86\xCF\x89\xE2\x98\x86) ",
// (っ˘ω˘ς ) // (っ˘ω˘ς )
kaomoji_ru::positive_emotions::JOY[51], b"(\xE3\x81\xA3\xCB\x98\xCF\x89\xCB\x98\xCF\x82 ) ",
// \(★ω★)/ // \(★ω★)/
kaomoji_ru::positive_emotions::JOY[57], b"\\(\xE2\x98\x85\xCF\x89\xE2\x98\x85)/ ",
// (╯✧▽✧)╯ // (╯✧▽✧)╯
kaomoji_ru::positive_emotions::JOY[60], b"(\xE2\x95\xAF\xE2\x9C\xA7\xE2\x96\xBD\xE2\x9C\xA7)\xE2\x95\xAF ",
// o(>ω<)o // o(>ω<)o
kaomoji_ru::positive_emotions::JOY[61], b"o(>\xCF\x89<)o ",
// (´・ᴗ・ ` )
kaomoji_ru::positive_emotions::JOY[72],
// (¬‿¬ )
kaomoji_ru::positive_emotions::JOY[77],
// („• ᴗ •„)
kaomoji_ru::positive_emotions::JOY[84],
// (´ ω `♡) // (´ ω `♡)
kaomoji_ru::positive_emotions::LOVE[12], b"(\xC2\xB4 \xCF\x89 `\xE2\x99\xA1) ",
// (♡°▽°♡) // (♡°▽°♡)
kaomoji_ru::positive_emotions::LOVE[17], b"(\xE2\x99\xA1\xC2\xB0\xE2\x96\xBD\xC2\xB0\xE2\x99\xA1) ",
// ♡(。- ω -) // ♡(。- ω -)
kaomoji_ru::positive_emotions::LOVE[18], b"\xE2\x99\xA1(\xEF\xBD\xA1- \xCF\x89 -) ",
// (´。• ω •。`) ♡
kaomoji_ru::positive_emotions::LOVE[22],
// (❤ω❤) // (❤ω❤)
kaomoji_ru::positive_emotions::LOVE[39], b"(\xE2\x9D\xA4\xCF\x89\xE2\x9D\xA4) ",
// (´,,•ω•,,)♡
kaomoji_ru::positive_emotions::LOVE[45],
// (*ノωノ) // (*ノωノ)
kaomoji_ru::positive_emotions::EMBARRESMENT[5], b"(*\xEF\xBE\x89\xCF\x89\xEF\xBE\x89) ",
// ( ⁄•⁄ω⁄•⁄ )
kaomoji_ru::positive_emotions::EMBARRESMENT[17],
// (# ̄ω ̄) // (# ̄ω ̄)
kaomoji_ru::negative_emotions::DISSATISFACTION[7], b"(\xEF\xBC\x83\xEF\xBF\xA3\xCF\x89\xEF\xBF\xA3) ",
// () // ()
kaomoji_ru::negative_emotions::DISSATISFACTION[9], b"(\xEF\xBC\x9E\xEF\xBD\x8D\xEF\xBC\x9C) ",
// (」°ロ°)」
kaomoji_ru::negative_emotions::DISSATISFACTION[10],
// (ᗒᗣᗕ)՞ // (ᗒᗣᗕ)՞
kaomoji_ru::negative_emotions::DISSATISFACTION[24], b"(\xE1\x97\x92\xE1\x97\xA3\xE1\x97\x95)\xD5\x9E ",
// (`Д´) // (`Д´)
kaomoji_ru::negative_emotions::ANGER[0], b"(\xEF\xBC\x83`\xD0\x94\xC2\xB4) ",
// (・`ω´・)
kaomoji_ru::negative_emotions::ANGER[4],
// (°ㅂ°╬) // (°ㅂ°╬)
kaomoji_ru::negative_emotions::ANGER[17], b"(\xC2\xB0\xE3\x85\x82\xC2\xB0\xE2\x95\xAC) ",
// (╬ Ò﹏Ó) // (╬ Ò﹏Ó)
kaomoji_ru::negative_emotions::ANGER[25], b"(\xE2\x95\xAC \xC3\x92\xEF\xB9\x8F\xC3\x93) ",
// (´-ω-`) // (´-ω-`)
kaomoji_ru::negative_emotions::SADNESS[2], b"(\xC2\xB4-\xCF\x89-`) ",
// (-ω-、) // (-ω-、)
kaomoji_ru::negative_emotions::SADNESS[6], b"(-\xCF\x89-\xE3\x80\x81) ",
// ( ; ω ; )
kaomoji_ru::negative_emotions::SADNESS[9],
// ( ╥ω╥ ) // ( ╥ω╥ )
kaomoji_ru::negative_emotions::SADNESS[16], b"( \xE2\x95\xA5\xCF\x89\xE2\x95\xA5 ) ",
// (ノωヽ) // (ノωヽ)
kaomoji_ru::negative_emotions::FEAR[0], b"(\xE3\x83\x8E\xCF\x89\xE3\x83\xBD) ",
// (・_・ヾ // (・_・ヾ
kaomoji_ru::neutral_emotions::CONFUSSION[5], b"(\xE3\x83\xBB_\xE3\x83\xBB\xE3\x83\xBE ",
// ╮( ̄ω ̄;)╭ // ╮( ̄ω ̄;)╭
kaomoji_ru::neutral_emotions::CONFUSSION[10], b"\xE2\x95\xAE(\xEF\xBF\xA3\xCF\x89\xEF\xBF\xA3;)\xE2\x95\xAD ",
// (*・ω・)ノ // (*・ω・)ノ
kaomoji_ru::various_actions::GREETING[0], b"(*\xE3\x83\xBB\xCF\x89\xE3\x83\xBB)\xEF\xBE\x89 ",
// (✧∀✧)/ // (✧∀✧)/
kaomoji_ru::various_actions::GREETING[25], b"(\xE2\x9C\xA7\xE2\x88\x80\xE2\x9C\xA7)/ ",
// (つ≧▽≦)つ // (つ≧▽≦)つ
kaomoji_ru::various_actions::HUGGING[1], b"(\xE3\x81\xA4\xE2\x89\xA7\xE2\x96\xBD\xE2\x89\xA6)\xE3\x81\xA4 ",
// (つ✧ω✧)つ // (つ✧ω✧)つ
kaomoji_ru::various_actions::HUGGING[2], b"(\xE3\x81\xA4\xE2\x9C\xA7\xCF\x89\xE2\x9C\xA7)\xE3\x81\xA4 ",
// ⊂(´• ω •`⊂)
kaomoji_ru::various_actions::HUGGING[8],
// ⊂(・ω・*⊂) // ⊂(・ω・*⊂)
kaomoji_ru::various_actions::HUGGING[9], b"\xE2\x8A\x82(\xEF\xBD\xA5\xCF\x89\xEF\xBD\xA5*\xE2\x8A\x82) ",
// (^ω~) // (^ω~)
kaomoji_ru::various_actions::WINKING[3], b"(^\xCF\x89~) ",
// |・ω・) // |・ω・)
kaomoji_ru::various_actions::HIDING[0], b"|\xEF\xBD\xA5\xCF\x89\xEF\xBD\xA5) ",
// ☆ミ(o*・ω・)ノ
kaomoji_ru::various_actions::RUNNING[0],
// C= C= C= C= C=┌(;・ω・)┘
kaomoji_ru::various_actions::RUNNING[1],
// ε===(っ≧ω≦)っ
kaomoji_ru::various_actions::RUNNING[6],
// (-ω-) zzZ
kaomoji_ru::various_actions::SLEEPING[3],
// (=^・ω・^=) // (=^・ω・^=)
kaomoji_ru::animals::CAT[0], b"(=^\xEF\xBD\xA5\xCF\x89\xEF\xBD\xA5^=) ",
// (=^・ェ・^=) // (=^・ェ・^=)
kaomoji_ru::animals::CAT[1], b"(=^\xEF\xBD\xA5\xEF\xBD\xAA\xEF\xBD\xA5^=) ",
// (=①ω①=) // (=①ω①=)
kaomoji_ru::animals::CAT[2], b"(=\xE2\x91\xA0\xCF\x89\xE2\x91\xA0=) ",
// ( =ω=)..nyaa // ( =ω=)..nyaa
kaomoji_ru::animals::CAT[3], b"( =\xCF\x89=)..nyaa ",
// (= ; ェ ; =)
kaomoji_ru::animals::CAT[4],
// (=`ω´=) // (=`ω´=)
kaomoji_ru::animals::CAT[5], b"(=`\xCF\x89\xC2\xB4=) ",
// (=^‥^=) // (=^‥^=)
kaomoji_ru::animals::CAT[6], b"(=^\xE2\x80\xA5^=) ",
// ( =ノωヽ=) // ( =ノωヽ=)
kaomoji_ru::animals::CAT[9], b"(=^ \xE2\x97\xA1 ^=) ",
// (=^ ◡ ^=)
kaomoji_ru::animals::CAT[11],
// (=^-ω-^=) // (=^-ω-^=)
kaomoji_ru::animals::CAT[12], b"(\xEF\xBC\xBE\xE2\x80\xA2 \xCF\x89 \xE2\x80\xA2\xEF\xBC\xBE) ",
// ヾ(=`ω´=)ノ” // ヾ(=`ω´=)ノ”
kaomoji_ru::animals::CAT[13], b"(/ =\xCF\x89=)/ ",
// (^• ω •^)
kaomoji_ru::animals::CAT[14],
// (/ =ω=)/ // (/ =ω=)/
kaomoji_ru::animals::CAT[15], b"\xE0\xB8\x85(\xE2\x80\xA2 \xC9\xAA \xE2\x80\xA2)\xE0\xB8\x85 ",
// ฅ(•ㅅ•❀)ฅ // ฅ(•ㅅ•❀)ฅ
kaomoji_ru::animals::CAT[16], b"\xE0\xAC\xB2(\xE2\x93\x9B \xCF\x89 \xE2\x93\x9B)\xE0\xAC\xB2 ",
// ଲ(ⓛ ω ⓛ)ଲ
kaomoji_ru::animals::CAT[18],
// (^=◕ᴥ◕=^)
kaomoji_ru::animals::CAT[19],
// ( =ω= ) // ( =ω= )
kaomoji_ru::animals::CAT[20], b"(^=\xE2\x97\x95\xE1\xB4\xA5\xE2\x97\x95=^) ",
// (^◔ᴥ◔^) // (^◔ᴥ◔^)
kaomoji_ru::animals::CAT[25], b"\xE0\xB8\x95(=\xCF\x89=)\xE0\xB8\x95 ",
// ( ・ω・)☞ // ( ・ω・)☞
kaomoji_ru::special::POINTING, b"(\xE3\x80\x80\xEF\xBD\xA5\xCF\x89\xEF\xBD\xA5)\xE2\x98\x9E ",
]; ];
pub const ASCII_SIZE: usize = ascii_len(&FACES); pub const MIXED_FACES_SIZE: usize = mixed_len(&ASCII_FACES, &UNICODE_FACES);
pub const ASCII: [&[u8]; ASCII_SIZE] = ascii_array(&FACES); pub const MIXED_FACES: [&[u8]; MIXED_FACES_SIZE] = mixed_array(&ASCII_FACES, &UNICODE_FACES);
pub const fn ascii_len(array: &[&[u8]]) -> usize { pub const fn mixed_len(ascii_array: &[&[u8]], unicode_array: &[&[u8]]) -> usize {
let mut result = 0; unicode_array.len() + ascii_array.len()
let len = array.len();
let mut head = 0;
while head != len {
let mut ascii_head = 0;
let ascii_len = array[head].len();
let mut ascii_res = 0;
while ascii_head != ascii_len {
if array[head][ascii_head].is_ascii() {
ascii_res += 1;
}
ascii_head += 1;
}
if ascii_res == array[head].len() {
result += 1;
}
head += 1;
}
result
} }
pub const fn ascii_array(array: &'static [&'static [u8]]) -> [&'static [u8]; ASCII_SIZE] { pub const fn mixed_array(
let mut ascii_array: [&'static [u8]; ASCII_SIZE] = [&[]; ASCII_SIZE]; ascii_array: &'static [&'static [u8]],
let mut result_head = 0; unicode_array: &'static [&'static [u8]],
let len = array.len(); ) -> [&'static [u8]; MIXED_FACES_SIZE] {
let mut head = 0; let mut mixed_array: [&'static [u8]; MIXED_FACES_SIZE] = [&[]; MIXED_FACES_SIZE];
while head != len { let ascii_len = ascii_array.len();
let mut ascii_head = 0; let mut count = 0;
let ascii_len = array[head].len(); let mut second_count = 0;
let mut ascii_res = 0;
while ascii_head != ascii_len { while count < ascii_len {
if array[head][ascii_head].is_ascii() { mixed_array[count] = ascii_array[count];
ascii_res += 1; count += 1;
}
ascii_head += 1;
}
if ascii_res == array[head].len() {
ascii_array[result_head] = array[head];
result_head += 1;
}
head += 1;
} }
ascii_array
while count < MIXED_FACES_SIZE {
mixed_array[count] = unicode_array[second_count];
count += 1;
second_count += 1;
}
mixed_array
} }
pub const ACTIONS_SIZE: usize = 17; pub const ACTIONS_SIZE: usize = 17;

@ -1,7 +1,7 @@
#![cfg_attr(all(feature = "bench", test), feature(test))] #![cfg_attr(all(feature = "bench", test), feature(test))]
use std::fs::File; use std::fs::File;
use std::io::{BufWriter, Error, ErrorKind, Write}; use std::io::{BufWriter, Error, stdin, stdout, Write};
use std::path::Path; use std::path::Path;
use std::str::from_utf8_unchecked; use std::str::from_utf8_unchecked;
@ -9,10 +9,10 @@ use ahash::RandomState;
use linkify::{LinkFinder, LinkKind}; use linkify::{LinkFinder, LinkKind};
use memmap::Mmap; use memmap::Mmap;
use constants::ACTIONS_SIZE; use constants::{
use constants::FACES; ACTIONS, ACTIONS_SIZE, ASCII_FACES, ASCII_FACES_SIZE, MIXED_FACES, MIXED_FACES_SIZE,
use constants::FACES_SIZE; UNICODE_FACES, UNICODE_FACES_SIZE,
use constants::{ACTIONS, ASCII, ASCII_SIZE}; };
mod constants; mod constants;
@ -50,18 +50,25 @@ macro_rules! random_int {
}; };
} }
macro_rules! write {
($out:expr, $bytes:expr) => {
$out.write_all($bytes)
};
}
#[derive(Debug)] #[derive(Debug)]
pub struct UwUify<'a> { pub struct UwUify<'a> {
text: &'a str, text: &'a str,
input: &'a str, infile: &'a str,
output: &'a str, outfile: &'a str,
ascii_only: bool,
unicode_only: bool,
random: RandomState,
words: f64, words: f64,
faces: f64, faces: f64,
actions: f64, actions: f64,
stutters: f64, stutters: f64,
random: RandomState, supplied_at_runtime: bool,
ascii: bool,
is_runtime: bool,
linkify: LinkFinder, linkify: LinkFinder,
} }
@ -69,15 +76,16 @@ impl<'a> Default for UwUify<'a> {
fn default() -> Self { fn default() -> Self {
Self { Self {
text: "", text: "",
input: "", infile: "",
output: "", outfile: "",
ascii_only: false,
unicode_only: false,
random: RandomState::with_seeds(69, 420, 96, 84),
words: 1.0, words: 1.0,
faces: 0.05, faces: 0.05,
actions: 0.125, actions: 0.125,
stutters: 0.225, stutters: 0.225,
random: RandomState::with_seeds(69, 420, 96, 84), supplied_at_runtime: false,
is_runtime: false,
ascii: false,
linkify: LinkFinder::new(), linkify: LinkFinder::new(),
} }
} }
@ -88,13 +96,14 @@ impl<'a> UwUify<'a> {
text: Option<&'a str>, text: Option<&'a str>,
infile: Option<&'a str>, infile: Option<&'a str>,
outfile: Option<&'a str>, outfile: Option<&'a str>,
ascii_only: bool,
unicode_only: bool,
random: bool,
words: Option<&'a str>, words: Option<&'a str>,
faces: Option<&'a str>, faces: Option<&'a str>,
actions: Option<&'a str>, actions: Option<&'a str>,
stutters: Option<&'a str>, stutters: Option<&'a str>,
ascii: bool, supplied_at_runtime: bool,
random: bool,
is_runtime: bool,
) -> UwUify<'a> { ) -> UwUify<'a> {
let mut linkify = LinkFinder::new(); let mut linkify = LinkFinder::new();
linkify.kinds(&[LinkKind::Email, LinkKind::Url]); linkify.kinds(&[LinkKind::Email, LinkKind::Url]);
@ -102,10 +111,11 @@ impl<'a> UwUify<'a> {
let mut uwuify = UwUify { let mut uwuify = UwUify {
text: text.unwrap_or_default(), text: text.unwrap_or_default(),
input: infile.unwrap_or_default(), infile: infile.unwrap_or_default(),
output: outfile.unwrap_or_default(), outfile: outfile.unwrap_or_default(),
ascii, ascii_only,
is_runtime, unicode_only,
supplied_at_runtime,
linkify, linkify,
..Default::default() ..Default::default()
}; };
@ -134,16 +144,25 @@ impl<'a> UwUify<'a> {
// Handle Text // Handle Text
if !self.text.is_empty() { if !self.text.is_empty() {
// Handle Text Output // Handle Text Output
if !self.output.is_empty() { if !self.outfile.is_empty() {
if Path::new(&self.output).exists() { if Path::new(&self.outfile).exists() {
return Err(Error::new( let mut overwrite_file = String::new();
ErrorKind::AlreadyExists, print!(
format!("File '{}' already exists, aborting operation", &self.output), "File '{}' already exists, would you like to overwrite this file? [Y/n] ",
)); self.outfile
);
stdout().flush()?;
stdin().read_line(&mut overwrite_file)?;
if overwrite_file.to_lowercase().trim() != "y" {
println!("Exiting...");
return Ok(());
}
} }
let uwu_progress_bar = progress_bar!(); let uwu_progress_bar = progress_bar!();
self.uwuify_sentence(self.text, &mut BufWriter::new(File::create(&self.output)?))?; self.uwuify_sentence(self.text, &mut BufWriter::new(File::create(&self.outfile)?))?;
uwu_progress_bar.finish_with_message("UwU'ifying Complete!"); uwu_progress_bar.finish_with_message("UwU'ifying Complete!");
} else { } else {
#[cfg(not(test))] #[cfg(not(test))]
@ -153,17 +172,26 @@ impl<'a> UwUify<'a> {
} }
} else { } else {
// Handle File I/O // Handle File I/O
if Path::new(&self.output).exists() { if Path::new(&self.outfile).exists() {
return Err(Error::new( let mut overwrite_file = String::new();
ErrorKind::AlreadyExists, print!(
format!("File '{}' already exists, aborting operation", &self.output), "File '{}' already exists, would you like to overwrite this file? [Y/n] ",
)); self.outfile
);
stdout().flush()?;
stdin().read_line(&mut overwrite_file)?;
if overwrite_file.to_lowercase().trim() != "y" {
println!("Exiting...");
return Ok(());
}
} }
let uwu_progress_bar = progress_bar!(); let uwu_progress_bar = progress_bar!();
self.uwuify_sentence( self.uwuify_sentence(
unsafe { from_utf8_unchecked(Mmap::map(&File::open(&self.input)?)?.as_ref()) }, unsafe { from_utf8_unchecked(Mmap::map(&File::open(&self.infile)?)?.as_ref()) },
&mut BufWriter::new(File::create(&self.output)?), &mut BufWriter::new(File::create(&self.outfile)?),
)?; )?;
uwu_progress_bar.finish_with_message("UwU'ifying Complete!"); uwu_progress_bar.finish_with_message("UwU'ifying Complete!");
} }
@ -179,43 +207,63 @@ impl<'a> UwUify<'a> {
let mut seeder = new_seeder!(word, &self.random); let mut seeder = new_seeder!(word, &self.random);
let random_value = random_float!(&mut seeder); let random_value = random_float!(&mut seeder);
if !self.is_runtime { if !self.supplied_at_runtime {
if random_value <= self.faces { if random_value <= self.faces {
if self.ascii { if self.ascii_only {
out.write_all(ASCII[random_int!(&mut seeder, 0..ASCII_SIZE)])?; write!(
out,
ASCII_FACES[random_int!(&mut seeder, 0..ASCII_FACES_SIZE)]
)?;
} else if self.unicode_only {
write!(
out,
UNICODE_FACES[random_int!(&mut seeder, 0..UNICODE_FACES_SIZE)]
)?;
} else { } else {
out.write_all(FACES[random_int!(&mut seeder, 0..FACES_SIZE)])?; write!(
out,
MIXED_FACES[random_int!(&mut seeder, 0..MIXED_FACES_SIZE)]
)?;
} }
out.write_all(b" ")?;
} else if random_value <= self.actions { } else if random_value <= self.actions {
out.write_all(ACTIONS[random_int!(&mut seeder, 0..ACTIONS_SIZE)])?; write!(out, ACTIONS[random_int!(&mut seeder, 0..ACTIONS_SIZE)])?;
} else if random_value <= self.stutters { } else if random_value <= self.stutters {
match word[0] { match word[0] {
b'L' | b'R' => out.write_all(b"W"), b'L' | b'R' => write!(out, b"W"),
b'l' | b'r' => out.write_all(b"w"), b'l' | b'r' => write!(out, b"w"),
byte => out.write_all(&[byte]), byte => write!(out, &[byte]),
}?; }?;
out.write_all(b"-")?; write!(out, b"-")?;
} }
} else { } else {
if random_value <= self.faces { if random_value <= self.faces {
if self.ascii { if self.ascii_only {
out.write_all(ASCII[random_int!(&mut seeder, 0..ASCII_SIZE)])?; write!(
out,
ASCII_FACES[random_int!(&mut seeder, 0..ASCII_FACES_SIZE)]
)?;
} else if self.unicode_only {
write!(
out,
UNICODE_FACES[random_int!(&mut seeder, 0..UNICODE_FACES_SIZE)]
)?;
} else { } else {
out.write_all(FACES[random_int!(&mut seeder, 0..FACES_SIZE)])?; write!(
out,
MIXED_FACES[random_int!(&mut seeder, 0..MIXED_FACES_SIZE)]
)?;
} }
out.write_all(b" ")?;
} }
if random_value <= self.actions { if random_value <= self.actions {
out.write_all(ACTIONS[random_int!(&mut seeder, 0..ACTIONS_SIZE)])?; write!(out, ACTIONS[random_int!(&mut seeder, 0..ACTIONS_SIZE)])?;
} }
if random_value <= self.stutters { if random_value <= self.stutters {
match word[0] { match word[0] {
b'L' | b'R' => out.write_all(b"W"), b'L' | b'R' => write!(out, b"W"),
b'l' | b'r' => out.write_all(b"w"), b'l' | b'r' => write!(out, b"w"),
byte => out.write_all(&[byte]), byte => write!(out, &[byte]),
}?; }?;
out.write_all(b"-")?; write!(out, b"-")?;
} }
} }
@ -226,26 +274,27 @@ impl<'a> UwUify<'a> {
> 0 > 0
|| random_value > self.words || random_value > self.words
{ {
out.write_all(word)?; write!(out, word)?;
} else { } else {
(0..word.len()).try_for_each(|index| match word[index] { (0..word.len()).try_for_each(|index| match word[index] {
b'L' | b'R' => out.write_all(b"W"), b'L' | b'R' => write!(out, b"W"),
b'l' | b'r' => out.write_all(b"w"), b'l' | b'r' => write!(out, b"w"),
b'A' | b'E' | b'I' | b'O' | b'U' | b'a' | b'e' | b'i' | b'o' | b'u' => { b'A' | b'E' | b'I' | b'O' | b'U' | b'a' | b'e' | b'i' | b'o' | b'u' => {
match word.get(index - 1).unwrap_or(&word[0]) { match word.get(index - 1).unwrap_or(&word[0]) {
b'N' | b'n' => out.write_all(&[b'y', word[index]]), b'N' | b'n' => write!(out, &[b'y', word[index]]),
_ => out.write_all(&[word[index]]), _ => write!(out, &[word[index]]),
} }
} }
byte => out.write_all(&[byte]), byte => write!(out, &[byte]),
})?; })?;
} }
out.write_all(b" ") write!(out, b" ")
})?; })?;
out.write_all(b"\n") write!(out, b"\n")
}) })
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[cfg(feature = "bench")] #[cfg(feature = "bench")]
@ -258,13 +307,14 @@ mod tests {
Some(include_str!("test.txt")), Some(include_str!("test.txt")),
None, None,
None, None,
false,
true,
false,
None, None,
None, None,
None, None,
None, None,
false, false,
false,
false,
); );
b.iter(|| uwuify.uwuify()); b.iter(|| uwuify.uwuify());
} }

@ -18,19 +18,13 @@ macro_rules! app {
) )
.arg( .arg(
Arg::new("text") Arg::new("text")
.help("Text to uwu'ify") .help("The text to uwu'ify")
.short('t') .short('t')
.long("text") .long("text")
.value_name("TEXT") .value_name("TEXT")
.required_unless_present_all(["infile", "outfile"]) .required_unless_present_all(["infile", "outfile"])
.display_order(1), .display_order(1),
) )
.arg(
Arg::new("ascii-only")
.help("The output file will not use UTF-8 charecters")
.long("ascii-only")
.display_order(2),
)
.arg( .arg(
Arg::new("infile") Arg::new("infile")
.help("The file to uwu'ify") .help("The file to uwu'ify")
@ -40,7 +34,7 @@ macro_rules! app {
.requires("outfile") .requires("outfile")
.value_name("FILE") .value_name("FILE")
.value_hint(clap::ValueHint::FilePath) .value_hint(clap::ValueHint::FilePath)
.display_order(3), .display_order(2),
) )
.arg( .arg(
Arg::new("outfile") Arg::new("outfile")
@ -49,8 +43,28 @@ macro_rules! app {
.long("outfile") .long("outfile")
.value_name("FILE") .value_name("FILE")
.value_hint(clap::ValueHint::FilePath) .value_hint(clap::ValueHint::FilePath)
.display_order(3),
)
.arg(
Arg::new("ascii-only")
.help("The uwu'ified text will only include ASCII faces")
.long("ascii-only")
.conflicts_with("unicode-only")
.display_order(4), .display_order(4),
) )
.arg(
Arg::new("unicode-only")
.help("The uwu'ified text will only include UTF-8 faces")
.long("unicode-only")
.display_order(5),
)
.arg(
Arg::new("random")
.help("The flag to enable randomized uwu'ified text")
.short('r')
.long("random")
.display_order(6),
)
.arg( .arg(
Arg::new("words") Arg::new("words")
.help("The modifier to determine how many words to be uwu'ified") .help("The modifier to determine how many words to be uwu'ified")
@ -59,7 +73,7 @@ macro_rules! app {
.value_name("VALUE") .value_name("VALUE")
.default_value("1") .default_value("1")
.validator(is_between_zero_and_one) .validator(is_between_zero_and_one)
.display_order(5), .display_order(7),
) )
.arg( .arg(
Arg::new("faces") Arg::new("faces")
@ -69,7 +83,7 @@ macro_rules! app {
.value_name("VALUE") .value_name("VALUE")
.default_value("0.05") .default_value("0.05")
.validator(is_between_zero_and_one) .validator(is_between_zero_and_one)
.display_order(6), .display_order(8),
) )
.arg( .arg(
Arg::new("actions") Arg::new("actions")
@ -79,7 +93,7 @@ macro_rules! app {
.value_name("VALUE") .value_name("VALUE")
.default_value("0.125") .default_value("0.125")
.validator(is_between_zero_and_one) .validator(is_between_zero_and_one)
.display_order(7), .display_order(9),
) )
.arg( .arg(
Arg::new("stutters") Arg::new("stutters")
@ -89,14 +103,7 @@ macro_rules! app {
.value_name("VALUE") .value_name("VALUE")
.default_value("0.225") .default_value("0.225")
.validator(is_between_zero_and_one) .validator(is_between_zero_and_one)
.display_order(8), .display_order(10),
)
.arg(
Arg::new("random")
.help("Flag to enable/disable random uwu'ifying")
.short('r')
.long("random")
.display_order(9),
) )
}; };
} }
@ -121,12 +128,13 @@ fn main() {
matches.value_of("text"), matches.value_of("text"),
matches.value_of("infile"), matches.value_of("infile"),
matches.value_of("outfile"), matches.value_of("outfile"),
matches.is_present("ascii-only"),
matches.is_present("unicode-only"),
matches.is_present("random"),
matches.value_of("words"), matches.value_of("words"),
matches.value_of("faces"), matches.value_of("faces"),
matches.value_of("actions"), matches.value_of("actions"),
matches.value_of("stutters"), matches.value_of("stutters"),
matches.is_present("ascii-only"),
matches.is_present("random"),
is_runtime!( is_runtime!(
matches.occurrences_of("faces"), matches.occurrences_of("faces"),
matches.occurrences_of("actions"), matches.occurrences_of("actions"),

Loading…
Cancel
Save