decasify 0.7.0__tar.gz → 0.7.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {decasify-0.7.0 → decasify-0.7.1}/Cargo.lock +1 -1
- {decasify-0.7.0 → decasify-0.7.1}/Cargo.toml +1 -1
- {decasify-0.7.0 → decasify-0.7.1}/PKG-INFO +1 -1
- {decasify-0.7.0 → decasify-0.7.1}/src/lib.rs +47 -0
- {decasify-0.7.0 → decasify-0.7.1}/src/lua.rs +27 -1
- {decasify-0.7.0 → decasify-0.7.1}/src/python.rs +10 -1
- {decasify-0.7.0 → decasify-0.7.1}/src/types.rs +8 -0
- {decasify-0.7.0 → decasify-0.7.1}/src/wasm.rs +6 -1
- {decasify-0.7.0 → decasify-0.7.1}/README.md +0 -0
- {decasify-0.7.0 → decasify-0.7.1}/build-aux/build.rs +0 -0
- {decasify-0.7.0 → decasify-0.7.1}/pyproject.toml +0 -0
- {decasify-0.7.0 → decasify-0.7.1}/src/bin/decasify.rs +0 -0
- {decasify-0.7.0 → decasify-0.7.1}/src/cli.rs +0 -0
- {decasify-0.7.0 → decasify-0.7.1}/src/content.rs +0 -0
- {decasify-0.7.0 → decasify-0.7.1}/tests/cli.rs +0 -0
|
@@ -26,6 +26,25 @@ pub mod python;
|
|
|
26
26
|
#[cfg(feature = "wasm")]
|
|
27
27
|
pub mod wasm;
|
|
28
28
|
|
|
29
|
+
/// Convert a string to a specific case following typesetting conventions for a target locale
|
|
30
|
+
pub fn to_case(
|
|
31
|
+
chunk: impl Into<Chunk>,
|
|
32
|
+
case: impl Into<Case>,
|
|
33
|
+
locale: impl Into<Locale>,
|
|
34
|
+
style: impl Into<StyleGuide>,
|
|
35
|
+
) -> String {
|
|
36
|
+
let chunk: Chunk = chunk.into();
|
|
37
|
+
let case: Case = case.into();
|
|
38
|
+
let locale: Locale = locale.into();
|
|
39
|
+
let style: StyleGuide = style.into();
|
|
40
|
+
match case {
|
|
41
|
+
Case::Lower => to_lowercase(chunk, locale),
|
|
42
|
+
Case::Upper => to_uppercase(chunk, locale),
|
|
43
|
+
Case::Sentence => to_sentencecase(chunk, locale),
|
|
44
|
+
Case::Title => to_titlecase(chunk, locale, style),
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
29
48
|
/// Convert a string to title case following typesetting conventions for a target locale
|
|
30
49
|
pub fn to_titlecase(
|
|
31
50
|
chunk: impl Into<Chunk>,
|
|
@@ -264,6 +283,34 @@ mod tests {
|
|
|
264
283
|
assert_eq!(res, "Fist");
|
|
265
284
|
}
|
|
266
285
|
|
|
286
|
+
macro_rules! case {
|
|
287
|
+
($name:ident, $case:expr, $locale:expr, $style:expr, $input:expr, $expected:expr) => {
|
|
288
|
+
#[test]
|
|
289
|
+
fn $name() {
|
|
290
|
+
let actual = to_case($input, $case, $locale, $style);
|
|
291
|
+
assert_eq!(actual, $expected);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
case!(
|
|
297
|
+
abc_title_me,
|
|
298
|
+
Case::Title,
|
|
299
|
+
Locale::EN,
|
|
300
|
+
StyleGuide::LanguageDefault,
|
|
301
|
+
"a b c",
|
|
302
|
+
"A B C"
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
case!(
|
|
306
|
+
abc_lower_me,
|
|
307
|
+
Case::Lower,
|
|
308
|
+
Locale::EN,
|
|
309
|
+
StyleGuide::LanguageDefault,
|
|
310
|
+
"A B C",
|
|
311
|
+
"a b c"
|
|
312
|
+
);
|
|
313
|
+
|
|
267
314
|
macro_rules! titlecase {
|
|
268
315
|
($name:ident, $locale:expr, $style:expr, $input:expr, $expected:expr) => {
|
|
269
316
|
#[test]
|
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
use crate::*;
|
|
5
5
|
use mlua::prelude::*;
|
|
6
6
|
|
|
7
|
-
pub use crate::types::{Locale, Result, StyleGuide};
|
|
7
|
+
pub use crate::types::{Case, Locale, Result, StyleGuide};
|
|
8
8
|
|
|
9
9
|
#[mlua::lua_module]
|
|
10
10
|
fn decasify(lua: &Lua) -> LuaResult<LuaTable> {
|
|
11
11
|
let exports = lua.create_table().unwrap();
|
|
12
|
+
let case = lua.create_function(case)?;
|
|
13
|
+
exports.set("case", case).unwrap();
|
|
12
14
|
let titlecase = lua.create_function(titlecase)?;
|
|
13
15
|
exports.set("titlecase", titlecase).unwrap();
|
|
14
16
|
let lowercase = lua.create_function(lowercase)?;
|
|
@@ -23,6 +25,30 @@ fn decasify(lua: &Lua) -> LuaResult<LuaTable> {
|
|
|
23
25
|
Ok(exports)
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
fn case<'a>(
|
|
29
|
+
lua: &'a Lua,
|
|
30
|
+
(input, case, locale, style): (LuaString<'a>, LuaValue<'a>, LuaValue<'a>, LuaValue<'a>),
|
|
31
|
+
) -> LuaResult<LuaString<'a>> {
|
|
32
|
+
let input = input.to_string_lossy();
|
|
33
|
+
let case: Case = match case {
|
|
34
|
+
LuaValue::String(s) => s.to_string_lossy().parse().unwrap_or(Case::Title),
|
|
35
|
+
_ => Case::Title,
|
|
36
|
+
};
|
|
37
|
+
let locale: Locale = match locale {
|
|
38
|
+
LuaValue::String(s) => s.to_string_lossy().parse().unwrap_or(Locale::EN),
|
|
39
|
+
_ => Locale::EN,
|
|
40
|
+
};
|
|
41
|
+
let style: StyleGuide = match style {
|
|
42
|
+
LuaValue::String(s) => s
|
|
43
|
+
.to_string_lossy()
|
|
44
|
+
.parse()
|
|
45
|
+
.unwrap_or(StyleGuide::LanguageDefault),
|
|
46
|
+
_ => StyleGuide::LanguageDefault,
|
|
47
|
+
};
|
|
48
|
+
let output = to_case(&input, case, locale, style);
|
|
49
|
+
lua.create_string(output)
|
|
50
|
+
}
|
|
51
|
+
|
|
26
52
|
fn titlecase<'a>(
|
|
27
53
|
lua: &'a Lua,
|
|
28
54
|
(input, locale, style): (LuaString<'a>, LuaValue<'a>, LuaValue<'a>),
|
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
use crate::*;
|
|
5
5
|
use pyo3::prelude::*;
|
|
6
6
|
|
|
7
|
-
pub use crate::types::{Locale, Result, StyleGuide};
|
|
7
|
+
pub use crate::types::{Case, Locale, Result, StyleGuide};
|
|
8
8
|
|
|
9
9
|
#[pymodule]
|
|
10
10
|
fn decasify(module: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
11
|
+
module.add_class::<Case>()?;
|
|
11
12
|
module.add_class::<Locale>()?;
|
|
12
13
|
module.add_class::<StyleGuide>()?;
|
|
14
|
+
module.add_function(wrap_pyfunction!(py_case, module)?)?;
|
|
13
15
|
module.add_function(wrap_pyfunction!(py_titlecase, module)?)?;
|
|
14
16
|
module.add_function(wrap_pyfunction!(py_lowercase, module)?)?;
|
|
15
17
|
module.add_function(wrap_pyfunction!(py_uppercase, module)?)?;
|
|
@@ -17,6 +19,13 @@ fn decasify(module: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
|
17
19
|
Ok(())
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
#[pyfunction]
|
|
23
|
+
#[pyo3(name = "case")]
|
|
24
|
+
#[pyo3(signature = (input, case, locale, style=StyleGuide::LanguageDefault))]
|
|
25
|
+
fn py_case(input: String, case: Case, locale: Locale, style: StyleGuide) -> PyResult<String> {
|
|
26
|
+
Ok(to_case(&input, case, locale, style))
|
|
27
|
+
}
|
|
28
|
+
|
|
20
29
|
#[pyfunction]
|
|
21
30
|
#[pyo3(name = "titlecase")]
|
|
22
31
|
#[pyo3(signature = (input, locale, style=StyleGuide::LanguageDefault))]
|
|
@@ -37,6 +37,8 @@ pub enum Locale {
|
|
|
37
37
|
|
|
38
38
|
/// Target case selector.
|
|
39
39
|
#[derive(Default, Display, VariantNames, Debug, Clone, Copy, PartialEq)]
|
|
40
|
+
#[cfg_attr(feature = "pythonmodule", pyclass(eq, eq_int))]
|
|
41
|
+
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
|
40
42
|
#[strum(serialize_all = "lowercase")]
|
|
41
43
|
#[non_exhaustive]
|
|
42
44
|
pub enum Case {
|
|
@@ -95,6 +97,12 @@ impl FromStr for Case {
|
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
|
|
100
|
+
impl From<&str> for Case {
|
|
101
|
+
fn from(s: &str) -> Self {
|
|
102
|
+
Self::from_str(s).unwrap()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
impl FromStr for StyleGuide {
|
|
99
107
|
type Err = Box<dyn error::Error>;
|
|
100
108
|
fn from_str(s: &str) -> Result<Self> {
|
|
@@ -5,7 +5,12 @@ use crate::*;
|
|
|
5
5
|
use std::result::Result;
|
|
6
6
|
use wasm_bindgen::prelude::*;
|
|
7
7
|
|
|
8
|
-
pub use crate::types::{Locale, StyleGuide};
|
|
8
|
+
pub use crate::types::{Case, Locale, StyleGuide};
|
|
9
|
+
|
|
10
|
+
#[wasm_bindgen]
|
|
11
|
+
pub fn case(input: &str, case: Case, locale: Locale, style: StyleGuide) -> Result<String, JsError> {
|
|
12
|
+
Ok(to_case(input, case, locale, style))
|
|
13
|
+
}
|
|
9
14
|
|
|
10
15
|
#[wasm_bindgen]
|
|
11
16
|
pub fn titlecase(input: &str, locale: Locale, style: StyleGuide) -> Result<String, JsError> {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|