hen 0.20.1

Run protocol-aware API request collections from the command line or through MCP.
Documentation
use super::BodyReportOptions;

pub(crate) struct TextDescription {
    pub(crate) value: Option<String>,
    pub(crate) truncated: bool,
    pub(crate) char_count: usize,
    pub(crate) char_limit: Option<usize>,
}

pub(crate) fn describe_text(value: &str, options: BodyReportOptions) -> TextDescription {
    let char_count = value.chars().count();
    let char_limit = options.max_body_chars;

    if !options.include_body {
        return TextDescription {
            value: None,
            truncated: false,
            char_count,
            char_limit,
        };
    }

    match char_limit {
        Some(limit) if char_count > limit => TextDescription {
            value: Some(value.chars().take(limit).collect()),
            truncated: true,
            char_count,
            char_limit,
        },
        _ => TextDescription {
            value: Some(value.to_string()),
            truncated: false,
            char_count,
            char_limit,
        },
    }
}