MCPcopy Create free account
hub / github.com/Canop/codesort / read

Function read

src/analyzers/javascript.rs:13–113  ·  view source on GitHub ↗
(mut reader: R)

Source from the content-addressed store, hash-verified

11}
12
13pub fn read<R: std::io::BufRead>(mut reader: R) -> CsResult<LocList> {
14 let mut locs = Vec::new();
15 let mut braces = BraceStack::default();
16 let mut last_is_antislash = 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 => {
42 state = State::SingleQuotedString;
43 sort_key.push(c);
44 }
45 '"' if !last_is_antislash => {
46 state = State::DoubleQuotedString;
47 sort_key.push(c);
48 }
49 '/' if !last_is_antislash => {
50 if i + 1 < bytes.len() && bytes[i + 1] == b'/' {
51 state = State::LineComment;
52 } else if i + 1 < bytes.len() && bytes[i + 1] == b'*' {
53 state = State::StarComment;
54 } else {
55 sort_key.push(c);
56 }
57 }
58 c if char_is_brace(c) && !last_is_antislash => {
59 braces.push(c)?; // error if unbalanced
60 sort_key.push(c);
61 }
62 ' ' | '\t' | '\n' | '\r' if !last_is_antislash => {
63 // ignore
64 }
65 c => {
66 sort_key.push(c);
67 }
68 }
69 last_is_antislash = c == '\\' && !last_is_antislash;
70 }

Callers

nothing calls this directly

Calls 6

char_is_braceFunction · 0.85
depthMethod · 0.80
lenMethod · 0.80
nextMethod · 0.80
pushMethod · 0.80
starts_withMethod · 0.80

Tested by

no test coverage detected