7个版本
使用旧的Rust 2015
0.0.7 | 2018年12月11日 |
---|---|
0.0.6 | 2015年4月9日 |
0.0.5 | 2015年3月12日 |
0.0.3 | 2015年2月28日 |
#1162 in 文本处理
10KB
179 行
rust-changecase 
在Rust中更改String的字符大小写。它也实现了对&str
的支持。在后一种情况下,它返回一个String。
可用函数
- 大写
- 小写
- 反转大小写(反转每个字符的大小写)
- 交替大小写
我在做什么
- 标题大小写
注意:对&str
的实现返回String。我确实希望它返回&str
,但我注意到std::ascii:AsciiExt
也为&str
返回String,所以我选择了那个。我也不是很清楚如何让函数返回&str
😕
示例
extern crate changecase;
use changecase::ChangeCase;
use changecase::Case;
assert_eq!(String::from_str("Some").to_uppercase(), "SOME");
assert_eq!(String::from_str("Some").to_lowercase(), "some");
assert_eq!(String::from_str("Some").to_invertedcase(), "sOME");
assert_eq!(String::from_str("some thing").to_capitalized(), "Some thing");
assert_eq!(String::from_str("Some").to_altcase(Case::Lower), "sOmE");
assert_eq!(String::from_str("Some").to_altcase(Case::Upper), "SoMe");
assert_eq!("Some".to_uppercase(), "SOME");
assert_eq!("Some".to_lowercase(), "some");
assert_eq!("Some".to_invertedcase(), "sOME");
assert_eq!("some thing".to_capitalized(), "Some thing");
assert_eq!("Some".to_altcase(Case::Lower), "sOmE");
assert_eq!("Some".to_altcase(Case::Upper), "SoMe");