MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / source_text

Function source_text

libatomic/src/review/html.rs:375–402  ·  view source on GitHub ↗
(
    result: Result<Option<Vec<u8>>, atomic_repository::RepositoryError>,
    bytes: &mut usize,
)

Source from the content-addressed store, hash-verified

373}
374
375fn source_text(
376 result: Result<Option<Vec<u8>>, atomic_repository::RepositoryError>,
377 bytes: &mut usize,
378) -> SourceText {
379 match result {
380 Ok(Some(content))
381 if content.len() <= atomic_semantic::MAX_SOURCE_BYTES && content.len() <= *bytes =>
382 {
383 if content.contains(&0) {
384 return SourceText::unavailable("Recorded content is binary");
385 }
386 match String::from_utf8(content) {
387 Ok(text) => {
388 *bytes -= text.len();
389 SourceText::Present { text }
390 }
391 Err(_) => SourceText::unavailable("Recorded content is not UTF-8"),
392 }
393 }
394 Ok(Some(_)) => {
395 SourceText::unavailable("Recorded source exceeds the HTML source byte budget")
396 }
397 Ok(None) => SourceText::unavailable(
398 "Recorded source reference could not be materialized; no working-copy fallback",
399 ),
400 Err(error) => SourceText::unavailable(format!("Recorded source unavailable: {error}")),
401 }
402}
403
404fn escape(text: &str) -> String {
405 text.replace('&', "&amp;")

Callers 2

sourcesFunction · 0.85
read_sourceFunction · 0.85

Calls 3

unavailableFunction · 0.50
lenMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected