fix normalize_xml_tags()
This commit is contained in:
parent
8d14c59d56
commit
b55230ce3f
1 changed files with 10 additions and 12 deletions
|
|
@ -447,20 +447,18 @@ fn format_tool_call_xml(name: &str, args_json: &str) -> String {
|
||||||
fn normalize_xml_tags(text: &str) -> String {
|
fn normalize_xml_tags(text: &str) -> String {
|
||||||
let mut result = String::with_capacity(text.len());
|
let mut result = String::with_capacity(text.len());
|
||||||
let mut chars = text.chars().peekable();
|
let mut chars = text.chars().peekable();
|
||||||
|
let mut in_tag = false;
|
||||||
|
|
||||||
while let Some(ch) = chars.next() {
|
while let Some(ch) = chars.next() {
|
||||||
if ch == '<' {
|
if ch == '<' {
|
||||||
let mut tag = String::from('<');
|
in_tag = true;
|
||||||
for inner in chars.by_ref() {
|
result.push(ch);
|
||||||
if inner == '>' {
|
} else if ch == '>' {
|
||||||
tag.push('>');
|
result.push(ch);
|
||||||
break;
|
in_tag = false;
|
||||||
} else if inner.is_whitespace() {
|
} else if in_tag && ch.is_whitespace() {
|
||||||
// Skip whitespace inside tags
|
// Skip whitespace inside tags (between < and >)
|
||||||
} else {
|
continue;
|
||||||
tag.push(inner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.push_str(&tag);
|
|
||||||
} else {
|
} else {
|
||||||
result.push(ch);
|
result.push(ch);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue