#lower-case #upper-case #title-case

changecase

A trait and implementation for changing the case of Strings and &str. It currently supports uppercase, lowercase, alternating case, and inverting case. Title case is in the works.

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 文本处理

MIT许可证

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");

无运行时依赖