(mut reader: R)
| 10 | } |
| 11 | |
| 12 | pub fn read<R: std::io::BufRead>(mut reader: R) -> CsResult<LocList> { |
| 13 | let mut locs = Vec::new(); |
| 14 | let mut braces = BraceStack::default(); |
| 15 | let mut last_is_antislash = false; |
| 16 | let mut last_is_quote = false; |
| 17 | let mut state = State::Normal; |
| 18 | loop { |
| 19 | if state == State::LineComment { |
| 20 | state = State::Normal; |
| 21 | } |
| 22 | let starts_normal = state == State::Normal; |
| 23 | let mut content = String::new(); |
| 24 | let n = reader.read_line(&mut content)?; |
| 25 | if n == 0 { |
| 26 | break; |
| 27 | } |
| 28 | let start_depth = braces.depth(); |
| 29 | let indented = content.trim_start(); |
| 30 | let bytes = indented.as_bytes(); |
| 31 | let indent = content.len() - indented.len(); |
| 32 | let mut chars = indented.char_indices(); |
| 33 | let mut sort_key = String::new(); |
| 34 | let wishes = Vec::new(); // not used in java |
| 35 | let gifts = Vec::new(); // not used in java |
| 36 | loop { |
| 37 | let Some((i, c)) = chars.next() else { break }; |
| 38 | match state { |
| 39 | State::Normal => { |
| 40 | match c { |
| 41 | '"' if !last_is_antislash && !last_is_quote => { |
| 42 | state = State::DoubleQuotedString; |
| 43 | sort_key.push(c); |
| 44 | } |
| 45 | '/' if !last_is_antislash && !last_is_quote => { |
| 46 | if i + 1 < bytes.len() && bytes[i + 1] == b'/' { |
| 47 | state = State::LineComment; |
| 48 | } else if i + 1 < bytes.len() && bytes[i + 1] == b'*' { |
| 49 | state = State::StarComment; |
| 50 | } else { |
| 51 | sort_key.push(c); |
| 52 | } |
| 53 | } |
| 54 | c if char_is_brace(c) && !last_is_antislash && !last_is_quote => { |
| 55 | braces.push(c)?; // error if unbalanced |
| 56 | sort_key.push(c); |
| 57 | } |
| 58 | ' ' | '\t' | '\n' | '\r' |
| 59 | if !last_is_antislash && !last_is_quote => |
| 60 | { |
| 61 | // ignore |
| 62 | } |
| 63 | c => { |
| 64 | sort_key.push(c); |
| 65 | } |
| 66 | } |
| 67 | last_is_antislash = c == '\\' && !last_is_antislash; |
| 68 | last_is_quote = c == '\''; |
| 69 | } |
nothing calls this directly
no test coverage detected