stuff
This commit is contained in:
@@ -146,6 +146,7 @@ in
|
||||
)
|
||||
# pkgs included everywhere
|
||||
''
|
||||
altcaps
|
||||
ddrescue
|
||||
dig
|
||||
dnsutils
|
||||
|
@@ -8,13 +8,17 @@ fn main() {
|
||||
args.next().expect("There should always be an argv[0] (program name)");
|
||||
let the_str_os:OsString = itertools::Itertools::intersperse(args, " ".into()).collect();
|
||||
let the_string = the_str_os.into_string().expect("Passed arg is not valid utf-8");
|
||||
let the_str = the_string.as_str();
|
||||
print!("{}", alternate_caps(the_string.as_str()));
|
||||
}
|
||||
|
||||
fn alternate_caps(old_s: &str) -> String {
|
||||
let segmenter = icu_segmenter::GraphemeClusterSegmenter::new();
|
||||
let li = icu_locale::langid!("en-US");
|
||||
let casemapper = icu_casemap::CaseMapper::new();
|
||||
let mut new_s = String::with_capacity(the_str.len());
|
||||
let mut new_s = String::with_capacity(old_s.len());
|
||||
let mut caps = false;
|
||||
for cluster in segmenter.segment_str(the_str).tuple_windows().map(|(i, j)| &the_str[i..j]) {
|
||||
for cluster in segmenter.segment_str(old_s).tuple_windows().map(|(i, j)| &old_s[i..j]) {
|
||||
// dbg!(cluster, caps);
|
||||
// for readability, always lowercase i and capitalize L
|
||||
let new_cluster:Cow<str>;
|
||||
if cluster == "I" {
|
||||
@@ -24,16 +28,31 @@ fn main() {
|
||||
new_cluster = "L".into();
|
||||
caps = false;
|
||||
} else {
|
||||
let uppercase_version = casemapper.uppercase_to_string(cluster, &li);
|
||||
let lowercase_version = casemapper.lowercase_to_string(cluster, &li);
|
||||
let case_equiv = uppercase_version == lowercase_version;
|
||||
// dbg!(&uppercase_version, &lowercase_version, case_equiv);
|
||||
new_cluster = if caps {
|
||||
casemapper.uppercase_to_string(cluster, &li)
|
||||
uppercase_version
|
||||
} else {
|
||||
casemapper.lowercase_to_string(cluster, &li)
|
||||
lowercase_version
|
||||
};
|
||||
if new_cluster != cluster {
|
||||
// dbg!(&new_cluster);
|
||||
if !case_equiv {
|
||||
caps = !caps;
|
||||
}
|
||||
}
|
||||
new_s.push_str(&new_cluster);
|
||||
}
|
||||
println!("{}", new_s);
|
||||
return new_s;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn test1() {
|
||||
assert_eq!(alternate_caps("hello"), "hELLo");
|
||||
assert_eq!(alternate_caps("this is a message"), "tHiS iS a MeSsAgE");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user