MCPcopy Create free account
hub / github.com/AI45Lab/Code / rewrite_curl_json_literals

Function rewrite_curl_json_literals

core/src/tools/builtin/bash.rs:664–727  ·  view source on GitHub ↗
(command: &str, verbatim_mode: bool)

Source from the content-addressed store, hash-verified

662
663#[cfg(windows)]
664fn rewrite_curl_json_literals(command: &str, verbatim_mode: bool) -> String {
665 const FLAGS: [&str; 5] = ["--data-raw", "--data-binary", "--data", "-d", "--json"];
666
667 let bytes = command.as_bytes();
668 let mut out = String::with_capacity(command.len() + 16);
669 let mut i = 0usize;
670
671 while i < bytes.len() {
672 let mut matched_flag = None;
673 for flag in FLAGS {
674 if command[i..].starts_with(flag) {
675 let before_ok = i == 0 || command[..i].chars().last().unwrap().is_whitespace();
676 let after = i + flag.len();
677 let after_ok = after >= bytes.len()
678 || bytes[after].is_ascii_whitespace()
679 || bytes[after] == b'=';
680 if before_ok && after_ok {
681 matched_flag = Some(flag);
682 break;
683 }
684 }
685 }
686
687 let Some(flag) = matched_flag else {
688 out.push(bytes[i] as char);
689 i += 1;
690 continue;
691 };
692
693 out.push_str(flag);
694 i += flag.len();
695
696 let mut j = i;
697 while j < bytes.len() && bytes[j].is_ascii_whitespace() {
698 out.push(bytes[j] as char);
699 j += 1;
700 }
701
702 if j < bytes.len() && bytes[j] == b'=' {
703 out.push('=');
704 j += 1;
705 while j < bytes.len() && bytes[j].is_ascii_whitespace() {
706 out.push(bytes[j] as char);
707 j += 1;
708 }
709 }
710
711 if let Some((literal, end)) = extract_unquoted_json_like_literal(command, j) {
712 let normalized = normalize_json_like_literal(&literal).unwrap_or(literal);
713 if verbatim_mode {
714 out.push_str(&normalized);
715 } else {
716 out.push('\'');
717 out.push_str(&normalized.replace('\'', "''"));
718 out.push('\'');
719 }
720 i = end;
721 } else {

Callers 1

Calls 3

lenMethod · 0.45

Tested by

no test coverage detected