copied from rustpython_common::str, so we don't have to depend on it just for this function
(input: &str, tab_size: usize)
| 10459 | |
| 10460 | // copied from rustpython_common::str, so we don't have to depend on it just for this function |
| 10461 | fn expandtabs(input: &str, tab_size: usize) -> String { |
| 10462 | let tab_stop = tab_size; |
| 10463 | let mut expanded_str = String::with_capacity(input.len()); |
| 10464 | let mut tab_size = tab_stop; |
| 10465 | let mut col_count = 0usize; |
| 10466 | for ch in input.chars() { |
| 10467 | match ch { |
| 10468 | '\t' => { |
| 10469 | let num_spaces = tab_size - col_count; |
| 10470 | col_count += num_spaces; |
| 10471 | let expand = " ".repeat(num_spaces); |
| 10472 | expanded_str.push_str(&expand); |
| 10473 | } |
| 10474 | '\r' | '\n' => { |
| 10475 | expanded_str.push(ch); |
| 10476 | col_count = 0; |
| 10477 | tab_size = 0; |
| 10478 | } |
| 10479 | _ => { |
| 10480 | expanded_str.push(ch); |
| 10481 | col_count += 1; |
| 10482 | } |
| 10483 | } |
| 10484 | if col_count >= tab_size { |
| 10485 | tab_size += tab_stop; |
| 10486 | } |
| 10487 | } |
| 10488 | expanded_str |
| 10489 | } |
| 10490 | |
| 10491 | fn split_doc<'a>(body: &'a [ast::Stmt], opts: &CompileOpts) -> (Option<String>, &'a [ast::Stmt]) { |
| 10492 | if let Some((ast::Stmt::Expr(expr), body_rest)) = body.split_first() { |