MCPcopy Index your code
hub / github.com/AI45Lab/Code / truncate_utf8

Function truncate_utf8

core/src/llm/structured.rs:1095–1104  ·  view source on GitHub ↗

UTF-8-safe truncation to at most `max` bytes (never splits a multibyte char — repair prompts echo arbitrary model output, including CJK).

(s: &str, max: usize)

Source from the content-addressed store, hash-verified

1093/// UTF-8-safe truncation to at most `max` bytes (never splits a multibyte char —
1094/// repair prompts echo arbitrary model output, including CJK).
1095fn truncate_utf8(s: &str, max: usize) -> &str {
1096 if s.len() <= max {
1097 return s;
1098 }
1099 let mut end = max;
1100 while end > 0 && !s.is_char_boundary(end) {
1101 end -= 1;
1102 }
1103 &s[..end]
1104}
1105
1106/// Repair prompt for when nothing parseable was produced at all.
1107fn build_parse_failure_repair(raw_text: &str) -> String {

Callers 6

execute_host_tool_jsonFunction · 0.50
compact_task_outputFunction · 0.50
executeMethod · 0.50
truncate_itemFunction · 0.50

Calls 1

lenMethod · 0.45