Is there a simple way to use str::matches case-insensitively?
You can always convert both strings to the same casing. This will work for some cases:
let needle = "μτς";
let haystack = "ΜΤΣ";
let needle = needle.to_lowercase();
let haystack = haystack.to_lowercase();
for i in haystack.matches(&needle) {
println!("{:?}", i);
}
In other cases, the regex crate might do enough case-folding for you:
extern crate regex;
use regex::RegexBuilder;
fn main() {
let needle = "μτς";
let haystack = "ΜΤΣ";
let needle = RegexBuilder::new(needle)
.case_insensitive(true)
.build()
.expect("Invalid Regex");
for i in needle.find_iter(haystack) {
println!("{:?}", i);
}
}
However, remember that ultimately Rust's strings are UTF-8. Yes, you need to deal with all of UTF-8. This means that picking upper- or lower-case might change your results. Likewise, the only correct way to change text casing requires that you know the language of the text; it's not an inherent property of the bytes. Yes, you can have strings which contain emoji and other exciting things beyond the Basic Multilingual Plane.
See also:
If you're using the regex crate, you can make the pattern case insensitive:
let re = Regex::new(r"(?i)μτς").unwrap();
let mat = re.find("ΜΤΣ").unwrap();