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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (C) 2024-2026 Takayuki Sato. All Rights Reserved.
// This program is free software under MIT License.
// See the file LICENSE in this distribution for more details.
//! This library provides some functions that convert string cases between Ada_Case, camelCase,
//! COBOL-CASE, kebab-case, MACRO_CASE, PascalCase, snake_case, Title Case, and Train-Case.
//! In addition, generic functions `capitalize`, `lowerize`, and `upperize` are provided to convert
//! string cases with a custom joiner character.
//! And this library also provides a trait `Caser` which enables strings to convert themselves
//! to their cases by their own methods.
//!
//! Basically, these functions only target ASCII uppercase and lowercase letters for
//! capitalization. All characters other than ASCII uppercase and lowercase letters and ASCII
//! numbers are removed as word separators.
//!
//! If you want to use some symbols as separators, specify those symbols in the `separators` field
//! of `Options` struct and use the `〜case_with_options` function for the desired case.
//! If you want to retain certain symbols and use everything else as separators, specify those
//! symbols in `keep` field of `Options` struct and use the `〜case_with_options` function for the
//! desired case.
//!
//! Additionally, you can specify whether to place word boundaries before and/or after
//! non-alphabetic characters with conversion options.
//! This can be set using the `separate_before_non_alphabets` and `separate_after_non_alphabets`
//! fields in the `Options` struct.
//!
//! The `〜_case` functions that do not take `Options` as an argument only place word boundaries
//! after non-alphabetic characters.
//! In other words, they behave as if `separate_before_non_alphabets = false` and
//! `separate_after_non_alphabets = true`.
//!
//! ## Install
//!
//! In `Cargo.toml`, write this crate as a dependency.
//!
//! ```toml
//! [dependencies]
//! stringcase = "1.0.0"
//! ```
//!
//! ## Usage
//!
//! The functions in this crate can be used as follows:
//!
//! ```rust
//! use stringcase::snake_case;
//!
//! fn main() {
//! let input = "fooBar123Baz";
//! let snake = snake_case(input);
//! assert_eq!(snake, "foo_bar123_baz");
//! }
//! ```
//!
//! If you want the conversion to behave differently, use `〜_case_with_options`.
//!
//! ```rust
//! use stringcase::{snake_case_with_options, Options};
//!
//! fn main() {
//! let opts = Options{separate_before_non_alphabets: true, ..Default::default()};
//! let input = "fooBar123Baz";
//! let snake = snake_case_with_options(input, &opts);
//! assert_eq!(snake, "foo_bar_123_baz");
//! }
//! ```
//!
//! You can also use the generic functions `capitalize`, `lowerize`, and `upperize` to convert
//! strings into capitalized, lowercased, or uppercased words joined by a custom joiner
//! character:
//!
//! ```rust
//! use stringcase::{capitalize, lowerize, upperize, Options};
//!
//! fn main() {
//! let opts = Options {
//! separate_before_non_alphabets: true,
//! separate_after_non_alphabets: true,
//! ..Default::default()
//! };
//! let input = "fooBar123Baz";
//! assert_eq!(capitalize::<'.'>(input, &opts), "Foo.Bar.123.Baz");
//! assert_eq!(lowerize::<'.'>(input, &opts), "foo.bar.123.baz");
//! assert_eq!(upperize::<'.'>(input, &opts), "FOO.BAR.123.BAZ");
//! }
//! ```
//!
//! And by bringing `Caser` with `use` declaration, it will be able to execute
//! methods of strings, `String` or `&str`, to convert to their cases.
//!
//! ```rust
//! use stringcase::{Caser, Options};
//!
//! fn main() {
//! let input = "fooBar123Baz";
//! let snake = input.to_snake_case();
//! assert_eq!(snake, "foo_bar123_baz");
//!
//! let opts = Options{separate_before_non_alphabets: true, ..Default::default()};
//! let snake = input.to_snake_case_with_options(&opts);
//! assert_eq!(snake, "foo_bar_123_baz");
//! }
//! ```
pub use Options;
pub use upperize;
pub use *;
pub use *;
pub use lowerize;
pub use *;
pub use *;
pub use capitalize;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;