Skip to content

Commit 5fa4ad1

Browse files
committed
fix(code_signature): trying to fix rust string creation
1 parent ea12b66 commit 5fa4ad1

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/code_signature.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,31 @@ impl CodeSignature {
126126
fn resolve_rust_declaration(test_data: &str) -> String {
127127
let trimmed = test_data.trim();
128128

129-
// Handle string literals
130-
if trimmed.starts_with('"') && trimmed.ends_with('"') {
131-
return format!("{}.to_string()", trimmed);
132-
}
129+
if trimmed.starts_with('"') {
130+
let mut end_quote = 1;
131+
let chars: Vec<char> = trimmed.chars().collect();
132+
133+
while end_quote < chars.len() {
134+
if chars[end_quote] == '"'
135+
&& (end_quote == 1 || chars[end_quote - 1] != '\\')
136+
{
137+
break;
138+
}
139+
end_quote += 1;
140+
}
141+
142+
if end_quote >= chars.len() {
143+
end_quote = chars.len();
144+
} else {
145+
end_quote += 1;
146+
}
133147

134-
// Handle arrays/vectors
148+
let string_content = &trimmed[1..end_quote - 1];
149+
return format!(
150+
"\"{}\".to_string()",
151+
string_content.replace('\\', "\\\\")
152+
);
153+
}
135154
if trimmed.starts_with('[') && trimmed.ends_with(']') {
136155
let inner = &trimmed[1..trimmed.len() - 1];
137156
let elements = Self::parse_array_elements(inner);
@@ -141,17 +160,12 @@ impl CodeSignature {
141160
.collect();
142161
return format!("vec![{}]", converted_elements.join(", "));
143162
}
144-
145-
// Handle primitives (numbers, booleans)
146163
if trimmed.parse::<i64>().is_ok()
147-
|| trimmed.parse::<f64>().is_ok()
148164
|| trimmed == "true"
149165
|| trimmed == "false"
150166
{
151167
return trimmed.to_string();
152168
}
153-
154-
// Default case
155169
trimmed.to_string()
156170
}
157171

0 commit comments

Comments
 (0)