decasify/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-FileCopyrightText: © 2023 Caleb Maclennan <caleb@alerque.com>
// SPDX-License-Identifier: LGPL-3.0-only

#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]

mod content;
mod traits;
mod types;

pub use content::Chunk;
#[cfg(feature = "unstable-trait")]
pub use traits::Decasify;
pub use types::{Case, Locale, StyleGuide};

#[cfg(feature = "cli")]
#[doc(hidden)]
pub mod cli;

#[cfg(feature = "luamodule")]
#[doc(hidden)]
pub mod lua;

#[cfg(feature = "pythonmodule")]
#[doc(hidden)]
pub mod python;

#[cfg(feature = "wasm")]
#[doc(hidden)]
pub mod wasm;

mod en;
mod tr;

/// Convert a string to a specific case following typesetting conventions for a target locale
pub fn case(
    chunk: impl Into<Chunk>,
    case: impl Into<Case>,
    locale: impl Into<Locale>,
    style: impl Into<StyleGuide>,
) -> String {
    let chunk: Chunk = chunk.into();
    let case: Case = case.into();
    let locale: Locale = locale.into();
    let style: StyleGuide = style.into();
    match case {
        Case::Lower => lowercase(chunk, locale),
        Case::Upper => uppercase(chunk, locale),
        Case::Sentence => sentencecase(chunk, locale),
        Case::Title => titlecase(chunk, locale, style),
    }
}

/// Convert a string to title case following typesetting conventions for a target locale
pub fn titlecase(
    chunk: impl Into<Chunk>,
    locale: impl Into<Locale>,
    style: impl Into<StyleGuide>,
) -> String {
    let chunk: Chunk = chunk.into();
    let locale: Locale = locale.into();
    let style: StyleGuide = style.into();
    match locale {
        Locale::EN => en::titlecase(chunk, style),
        Locale::TR => tr::titlecase(chunk, style),
    }
}

/// Convert a string to lower case following typesetting conventions for a target locale
pub fn lowercase(chunk: impl Into<Chunk>, locale: impl Into<Locale>) -> String {
    let chunk: Chunk = chunk.into();
    let locale: Locale = locale.into();
    match locale {
        Locale::EN => en::lowercase(chunk),
        Locale::TR => tr::lowercase(chunk),
    }
}

/// Convert a string to upper case following typesetting conventions for a target locale
pub fn uppercase(chunk: impl Into<Chunk>, locale: impl Into<Locale>) -> String {
    let chunk: Chunk = chunk.into();
    let locale: Locale = locale.into();
    match locale {
        Locale::EN => en::uppercase(chunk),
        Locale::TR => tr::uppercase(chunk),
    }
}

/// Convert a string to sentence case following typesetting conventions for a target locale
pub fn sentencecase(chunk: impl Into<Chunk>, locale: impl Into<Locale>) -> String {
    let chunk: Chunk = chunk.into();
    let locale: Locale = locale.into();
    match locale {
        Locale::EN => en::sentencecase(chunk),
        Locale::TR => tr::sentencecase(chunk),
    }
}