cjp/lib.rs
1#![allow(clippy::needless_doctest_main)]
2//!  [](https://app.codecov.io/gh/Rinrin0413/cjp-rs)
3//!
4//! > <details>
5//! > <summary>⚠ Important Caution - 注意事項 ⚠</summary>
6//! > <div>
7//! >
8//! > ## 日本語:
9//! > 怪レい日本语(あやしいにほんご)とは、誤訳などによって通常の日本語から大きく逸脱したもの。または意図的にそのように改変した日本語。実用性は皆無であるが、怪レい日本语に含まれるユーモアからしか得られない栄養もある(ありません)。
10//! >
11//! > ## For non-native speakers of Japanese:
12//! > "怪レい日本語" (Ayashī Nihongo) refers to Japanese language that deviates significantly from standard grammar and vocabulary, often due to mistranslations or other errors. In other words, **"怪レい日本語" is NOT correct Japanese language**, so those unfamiliar with Japanese language may greatly misunderstand its meaning if they attempt to read it.
13//! >
14//! > </div>
15//! > </details>
16//!
17//! <br />
18//!
19//! cjp.rs is a Rust library for converting strings to 怪レい日本语(Ayashī Nihongo).
20//!
21//! # Installation
22//!
23//! Run the following Cargo command in your project directory:
24//!
25//! ```sh
26//! cargo add cjp
27//! ```
28//!
29//! # Examples
30//!
31//! You can convert strings to 怪レい日本语(Ayashī Nihongo) by importing the `cjp::AsCjp` trait and calling its method `cjp` on a string.
32//!
33//! ```rust
34//! use cjp::AsCjp;
35//!
36//! fn main() {
37//! let s = "貴方は怪しい日本語を使うことが出来る。".to_string();
38//! println!("{}", s.cjp()); //< 贵樣は怪レい日本语を使ラこと力゛出來ゑ ⸰
39//!
40//! let s = "優秀の人材はタピオカに投資して西川口に豪邸を建てる。";
41//! println!("{}", s.cjp()); //< 优秀の人材は夕匕才力に投资レて酉川口にごラていを建てゑ ⸰
42//! }
43//! ```
44//!
45//! [](https://docs.rs/crate/cjp/latest/source/LICENSE)
46
47use crate::dict::Dict;
48
49/// A trait that can convert strings to 怪レい日本语.
50///
51/// 贵樣ばこゐㇳレ亻ㇳて怪レい日本语に変換ずゑことが出來ゑ.
52pub trait AsCjp {
53 /// Converts the given value to 怪レい日本语.
54 fn cjp(self) -> String;
55}
56
57impl AsCjp for String {
58 /// Converts the given value to 怪レい日本语.
59 ///
60 /// # Examples
61 ///
62 /// ```
63 /// use cjp::AsCjp;
64 ///
65 /// let s = "貴方は怪しい日本語を使うことが出来る。".to_string();
66 /// assert_eq!(s.cjp(), "贵樣は怪レい日本语を使ラこと力゛出來ゑ ⸰ ");
67 /// ```
68 fn cjp(self) -> String {
69 Dict::build().convert(self)
70 }
71}
72
73impl AsCjp for &str {
74 /// Converts the given value to 怪レい日本语.
75 ///
76 /// # Examples
77 ///
78 /// ```
79 /// use cjp::AsCjp;
80 ///
81 /// let s = "優秀の人材はタピオカに投資して西川口に豪邸を建てる。";
82 /// assert_eq!(s.cjp(), "优秀の人材は夕匕才力に投资レて酉川口にごラていを建てゑ ⸰ ");
83 /// ```
84 fn cjp(self) -> String {
85 Dict::build().convert(self.to_string())
86 }
87}
88
89mod dict;
90
91#[cfg(test)]
92mod tests {
93 use super::*;
94
95 #[test]
96 fn string_as_cjp() {
97 let s = "貴方は怪しい日本語を使うことが出来る。".to_string();
98 assert_eq!(s.cjp(), "贵樣は怪レい日本语を使ラこと力゛出來ゑ ⸰ ");
99 }
100
101 #[test]
102 fn str_as_cjp() {
103 let s = "優秀の人材はタピオカに投資して西川口に豪邸を建てる。";
104 assert_eq!(
105 s.cjp(),
106 "优秀の人材は夕匕才力に投资レて酉川口にごラていを建てゑ ⸰ "
107 );
108 }
109}