strip the code wrapper that ChatGPT generated with code.
(input: &str)
| 308 | |
| 309 | /// strip the code wrapper that ChatGPT generated with code. |
| 310 | fn strip_code_wrapper(input: &str) -> String { |
| 311 | let mut input = input.trim(); |
| 312 | let mut event = ""; |
| 313 | if let Some(idx) = input.find("```") { |
| 314 | event = &input[..idx]; |
| 315 | input = &input[idx..]; |
| 316 | } |
| 317 | let input = strip_code_prefix(input, "cpp"); |
| 318 | let input = strip_code_prefix(input, "CPP"); |
| 319 | let input = strip_code_prefix(input, "C++"); |
| 320 | let input = strip_code_prefix(input, "c++"); |
| 321 | let input = strip_code_prefix(input, "c"); |
| 322 | let input = strip_code_prefix(input, "C"); |
| 323 | let input = strip_code_prefix(input, "\n"); |
| 324 | if let Some(idx) = input.rfind("```") { |
| 325 | let input = &input[..idx]; |
| 326 | let input = ["/*", event, "*/\n", input].concat(); |
| 327 | return input; |
| 328 | } |
| 329 | ["/*", event, "*/\n", input].concat() |
| 330 | } |
| 331 | |
| 332 | #[cfg(test)] |
| 333 | mod tests { |
no test coverage detected