(command: &str, windows: bool)
| 213 | } |
| 214 | |
| 215 | fn shell_words_for_platform(command: &str, windows: bool) -> Vec<String> { |
| 216 | let mut words = Vec::new(); |
| 217 | let mut current = String::new(); |
| 218 | let mut quote: Option<char> = None; |
| 219 | let mut escaped = false; |
| 220 | |
| 221 | for c in command.chars() { |
| 222 | if escaped { |
| 223 | current.push(c); |
| 224 | escaped = false; |
| 225 | continue; |
| 226 | } |
| 227 | |
| 228 | match quote { |
| 229 | Some('\'') => { |
| 230 | if c == '\'' { |
| 231 | quote = None; |
| 232 | } else { |
| 233 | current.push(c); |
| 234 | } |
| 235 | } |
| 236 | Some('"') => match c { |
| 237 | '"' => quote = None, |
| 238 | '\\' => escaped = true, |
| 239 | _ => current.push(c), |
| 240 | }, |
| 241 | _ => match c { |
| 242 | '\'' | '"' => quote = Some(c), |
| 243 | '\\' if windows => current.push(c), |
| 244 | '\\' => escaped = true, |
| 245 | c if c.is_whitespace() => { |
| 246 | if !current.is_empty() { |
| 247 | words.push(std::mem::take(&mut current)); |
| 248 | } |
| 249 | } |
| 250 | _ => current.push(c), |
| 251 | }, |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | if escaped { |
| 256 | current.push('\\'); |
| 257 | } |
| 258 | if !current.is_empty() { |
| 259 | words.push(current); |
| 260 | } |
| 261 | words |
| 262 | } |
| 263 | |
| 264 | fn git_subcommand_pos(tokens: &[String]) -> Option<usize> { |
| 265 | if !tokens.first()?.eq_ignore_ascii_case("git") { |
no test coverage detected