MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / collapse_js_whitespace

Function collapse_js_whitespace

codegraph-kernel/src/python.rs:1153–1176  ·  view source on GitHub ↗

`s.replace(/\s+/g, ' ').trim()` with JavaScript's `\s` class, so a receiver qualifier is byte-identical to the one TreeSitterExtractor emits. Rust's `char::is_whitespace` is NOT the same set: it counts U+0085 (NEL), which JS `\s` does not, and omits U+FEFF (ZWNBSP), which JS `\s` includes.

(s: &str)

Source from the content-addressed store, hash-verified

1151/// `char::is_whitespace` is NOT the same set: it counts U+0085 (NEL), which JS
1152/// `\s` does not, and omits U+FEFF (ZWNBSP), which JS `\s` includes.
1153fn collapse_js_whitespace(s: &str) -> String {
1154 fn is_js_space(c: char) -> bool {
1155 matches!(
1156 c,
1157 '\t' | '\n' | '\u{b}' | '\u{c}' | '\r' | ' ' | '\u{a0}' | '\u{feff}'
1158 | '\u{2028}' | '\u{2029}'
1159 | '\u{1680}' | '\u{2000}'..='\u{200a}' | '\u{202f}' | '\u{205f}' | '\u{3000}'
1160 )
1161 }
1162 let mut out = String::with_capacity(s.len());
1163 let mut in_space = false;
1164 for c in s.chars() {
1165 if is_js_space(c) {
1166 in_space = true;
1167 } else {
1168 if in_space && !out.is_empty() {
1169 out.push(' ');
1170 }
1171 in_space = false;
1172 out.push(c);
1173 }
1174 }
1175 out
1176}
1177
1178/// LITERAL_RECEIVER_TYPES membership (shared table; python names among them).
1179fn is_literal_receiver(kind: &str) -> bool {

Callers 1

extract_callMethod · 0.85

Calls 3

lenMethod · 0.80
pushMethod · 0.80
is_js_spaceFunction · 0.70

Tested by

no test coverage detected