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

Function extract_unquoted_json_like_literal

core/src/tools/builtin/bash.rs:730–784  ·  view source on GitHub ↗
(command: &str, start: usize)

Source from the content-addressed store, hash-verified

728
729#[cfg(windows)]
730fn extract_unquoted_json_like_literal(command: &str, start: usize) -> Option<(String, usize)> {
731 let bytes = command.as_bytes();
732 if start >= bytes.len() {
733 return None;
734 }
735
736 let first = bytes[start];
737 if first == b'\'' || first == b'"' || first != b'{' {
738 return None;
739 }
740
741 let mut brace_depth = 0i32;
742 let mut bracket_depth = 0i32;
743 let mut in_single = false;
744 let mut in_double = false;
745 let mut i = start;
746
747 while i < bytes.len() {
748 let ch = bytes[i] as char;
749 if ch == '\'' && !in_double {
750 in_single = !in_single;
751 i += 1;
752 continue;
753 }
754 if ch == '"' && !in_single {
755 let escaped = i > start && bytes[i - 1] == b'\\';
756 if !escaped {
757 in_double = !in_double;
758 }
759 i += 1;
760 continue;
761 }
762
763 if !in_single && !in_double {
764 match ch {
765 '{' => brace_depth += 1,
766 '}' => {
767 brace_depth -= 1;
768 if brace_depth == 0 && bracket_depth == 0 {
769 let end = i + 1;
770 let literal = command[start..end].to_string();
771 return Some((literal, end));
772 }
773 }
774 '[' => bracket_depth += 1,
775 ']' => bracket_depth -= 1,
776 _ => {}
777 }
778 }
779
780 i += 1;
781 }
782
783 None
784}
785
786#[cfg(windows)]
787fn normalize_json_like_literal(input: &str) -> Option<String> {

Callers 1

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected