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

Function safe_utf8_truncate

core/src/workspace/remote_git.rs:723–732  ·  view source on GitHub ↗

Truncate `s` to at most `max_bytes`, rounding down to the nearest UTF-8 character boundary to keep the result a valid `&str`.

(s: &str, max_bytes: usize)

Source from the content-addressed store, hash-verified

721/// Truncate `s` to at most `max_bytes`, rounding down to the nearest UTF-8
722/// character boundary to keep the result a valid `&str`.
723fn safe_utf8_truncate(s: &str, max_bytes: usize) -> usize {
724 if s.len() <= max_bytes {
725 return s.len();
726 }
727 let mut idx = max_bytes;
728 while idx > 0 && !s.is_char_boundary(idx) {
729 idx -= 1;
730 }
731 idx
732}
733
734/// Map a non-2xx response to an `anyhow::Error`, attaching a typed
735/// [`RemoteGitConflict`] when the server returned a recoverable code under

Callers 1

diffMethod · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected