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

Function js_multiline_strip

codegraph-kernel/src/docstring.rs:80–104  ·  view source on GitHub ↗

JS-semantics `str.replace(/^ /gm, "")`: try the \A-anchored `pat` at position 0 and after every JS line terminator, left to right, resuming after each match's end — a faithful /g replace. (Remaining known divergence: JS `\s` includes U+FEFF, Rust's does not; an embedded BOM inside a comment is accepted as unreachable.)

(s: &str, pat: &Regex)

Source from the content-addressed store, hash-verified

78/// divergence: JS `\s` includes U+FEFF, Rust's does not; an embedded BOM
79/// inside a comment is accepted as unreachable.)
80fn js_multiline_strip(s: &str, pat: &Regex) -> String {
81 let mut out = String::with_capacity(s.len());
82 let mut last = 0usize;
83 let mut pos = 0usize;
84 while pos <= s.len() {
85 let at_line_start = pos == 0
86 || s[..pos].chars().next_back().is_some_and(is_js_line_terminator);
87 if at_line_start {
88 if let Some(m) = pat.find(&s[pos..]) {
89 if !m.is_empty() {
90 out.push_str(&s[last..pos]);
91 last = pos + m.end();
92 pos = last;
93 continue;
94 }
95 }
96 }
97 match s[pos..].chars().next() {
98 Some(c) => pos += c.len_utf8(),
99 None => break,
100 }
101 }
102 out.push_str(&s[last..]);
103 out
104}
105
106/// cleanCommentMarkers — strip comment syntax, keep the prose.
107pub fn clean_comment_markers(comment: &str) -> String {

Callers 1

clean_comment_markersFunction · 0.85

Calls 2

lenMethod · 0.80
nextMethod · 0.80

Tested by

no test coverage detected