MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / strip_styling

Function strip_styling

src/text_input.rs:2331–2351  ·  view source on GitHub ↗

Strip all styling markup from a raw string, returning only visible text.

(raw: &str)

Source from the content-addressed store, hash-verified

2329
2330 /// Strip all styling markup from a raw string, returning only visible text.
2331 pub fn strip_styling(raw: &str) -> String {
2332 let mut result = String::new();
2333 let mut escaped = false;
2334 let mut in_style_def = false;
2335 for c in raw.chars() {
2336 if escaped {
2337 result.push(c);
2338 escaped = false;
2339 continue;
2340 }
2341 match c {
2342 '\\' => { escaped = true; }
2343 '{' if !in_style_def => { in_style_def = true; }
2344 '|' if in_style_def => { in_style_def = false; }
2345 '}' if !in_style_def => { /* closing tag, skip */ }
2346 _ if in_style_def => { /* inside style def, skip */ }
2347 _ => { result.push(c); }
2348 }
2349 }
2350 result
2351 }
2352
2353 /// Convert a "structural visual" position (includes } and empty content markers)
2354 /// to a "content position" (just visible chars, matching strip_styling output).

Calls

no outgoing calls

Tested by 4

test_no_styles_backspaceFunction · 0.68
test_no_styles_home_endFunction · 0.68