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

Function dedent_docstring

codegraph-kernel/src/python.rs:79–101  ·  view source on GitHub ↗
(raw: &str)

Source from the content-addressed store, hash-verified

77}
78
79fn dedent_docstring(raw: &str) -> String {
80 let normalized = raw.replace("\r\n", "\n").replace('\r', "\n");
81 let lines: Vec<String> = normalized.split('\n').map(|line| {
82 let mut column = 0;
83 let mut expanded = String::new();
84 for c in line.chars() {
85 let width = if c == '\t' { 8 - column % 8 } else { 1 };
86 column += width;
87 if c == '\t' { expanded.push_str(&" ".repeat(width)); } else { expanded.push(c); }
88 }
89 expanded
90 }).collect();
91 let indent = lines.iter().skip(1).filter(|l| !l.trim_matches(docstring_space).is_empty())
92 .map(|l| l.chars().take_while(|c| docstring_space(*c)).count()).min().unwrap_or(0);
93 let out: Vec<String> = lines.iter().enumerate().map(|(i, l)| {
94 if i == 0 { l.trim_matches(docstring_space).to_string() } else {
95 l.chars().skip(indent).collect::<String>().trim_end_matches(docstring_space).to_string()
96 }
97 }).collect();
98 let start = out.iter().position(|l| !l.trim_matches(docstring_space).is_empty()).unwrap_or(out.len());
99 let end = out.iter().rposition(|l| !l.trim_matches(docstring_space).is_empty()).map_or(start, |i| i + 1);
100 out[start..end].join("\n")
101}
102
103fn docstring_for(node: Node, src: &str) -> Option<String> {
104 let preceding = preceding_docstring(node, src);

Callers 1

body_docstringFunction · 0.85

Calls 7

docstring_spaceFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
positionMethod · 0.80
lenMethod · 0.80
collectMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected