Frozen experimental predictor: boundaries and IDs are never inferred. Every classification that differs from the author's value is stored explicitly.
(bytes: &[u8])
| 97 | // Frozen experimental predictor: boundaries and IDs are never inferred. Every |
| 98 | // classification that differs from the author's value is stored explicitly. |
| 99 | fn predict(bytes: &[u8]) -> u64 { |
| 100 | if matches!(bytes, b"\n" | b"\r\n" | b"\r") { |
| 101 | 7 |
| 102 | } else if !bytes.is_empty() && bytes.iter().all(u8::is_ascii_whitespace) { |
| 103 | 1 |
| 104 | } else if bytes.starts_with(b"//") { |
| 105 | 6 |
| 106 | } else if bytes.len() >= 2 && matches!(bytes[0], b'\'' | b'"') && bytes.last() == bytes.first() |
| 107 | { |
| 108 | 4 |
| 109 | } else if bytes.first().is_some_and(u8::is_ascii_digit) { |
| 110 | 5 |
| 111 | } else if bytes.len() == 1 && b"(){}[];,.".contains(&bytes[0]) { |
| 112 | 3 |
| 113 | } else if !bytes.is_empty() && bytes.iter().all(|b| b"+-*/%=!<>|&^~?:@".contains(b)) { |
| 114 | 2 |
| 115 | } else if std::str::from_utf8(bytes).is_ok_and(|s| { |
| 116 | s.chars() |
| 117 | .next() |
| 118 | .is_some_and(|c| c.is_alphabetic() || c == '_') |
| 119 | && s.chars().all(|c| c.is_alphanumeric() || c == '_') |
| 120 | }) { |
| 121 | 0 |
| 122 | } else { |
| 123 | 8 |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | pub fn predict_kinds(view: &View<'_>, content: &[u8]) -> Result<Vec<u8>> { |
| 128 | let mut actual = view.kinds; |