#string #reserved #string-conversion #case #formatting #keyword

convert_string

A trait to convert Strings to safe non-keywords and/or convert a Strings case (snake_case, PascalCase, ...)

5 releases

0.2.0 Aug 30, 2024
0.1.3 Nov 25, 2023
0.1.2 Aug 30, 2023
0.1.1 Aug 29, 2023
0.1.0 Aug 29, 2023

#699 in Text processing

Download history 25/week @ 2024-09-07 26/week @ 2024-09-14 43/week @ 2024-09-21 22/week @ 2024-09-28 104/week @ 2024-10-05 209/week @ 2024-10-12 180/week @ 2024-10-19 170/week @ 2024-10-26 215/week @ 2024-11-02 282/week @ 2024-11-09 263/week @ 2024-11-16 324/week @ 2024-11-23 357/week @ 2024-11-30 266/week @ 2024-12-07 184/week @ 2024-12-14 88/week @ 2024-12-21

930 downloads per month
Used in xml_schema_generator

Apache-2.0

13KB
144 lines

convert_string

github crates.io docs.rs build status

A trait for String-like types to check if a string is a reserved keyword, and convert it to a safe non-keyword if so. Offers some type conversions as well

Only strict and reserved keywords are checked against; weak keywords are not include

You can add this dependency with:

[dependencies]
convert_string = "0.2.0"

Example

use convert_string::ConvertString;;

assert_eq!("r_type", String::from("type").to_valid_key(&String::from("r")));
assert_eq!("foo", String::from("ns:foo").remove_namespace());
assert_eq!("YdTax", String::from("yd_tax").to_pascal_case());
assert_eq!("yd_tax", String::from("YdTax").to_snake_case());

Rust Editions

[dependencies]
convert_string = { version = "0.2.0" }

Future Rust editions may add new keywords, and this crate will be updated to reflect (Or you can create an issue on github if I don't.)

Credit

Huge parts of this library are taken from https://github.com/JoelCourtney/check_keyword

Source

License: Apache-2.0

https://github.com/Thomblin/convert_string

No runtime deps