SHARE
TWEET

Untitled

a guest Aug 17th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use itertools::{Itertools, Position}; // 0.8.0
  2. use std::iter::once;
  3. fn main() {
  4.     let string = "AbcdMg2TOH";
  5.     println!("{:?}", split_uppercase(string));
  6. }
  7.  
  8. pub fn split_uppercase(text: &str) -> Vec<&str> {
  9.   text.match_indices(char::is_uppercase)
  10.   .filter(|(i, _)| *i != 0)
  11.   .map(|(i, _)| i)
  12.   .tuple_windows()
  13.   .with_position()
  14.   .map(|e| {
  15.       match e {
  16.           Position::First((last, i)) => vec![&text[..last], &text[last..i]],
  17.           Position::Middle((last, i)) | Position::Only((last, i)) => vec![&text[last..i]],
  18.           Position::Last((last, i)) => vec![&text[last..i], &text[i..]],
  19.       }
  20.   })
  21.   .flatten()
  22.   .collect()
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top