#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct JsonDecodeOptions {
pub trim_whitespace: bool,
pub strip_utf8_bom: bool,
pub strip_markdown_code_fence: bool,
pub strip_markdown_code_fence_requires_closing: bool,
pub strip_markdown_code_fence_json_only: bool,
pub escape_control_chars_in_strings: bool,
pub max_input_bytes: Option<usize>,
}
impl JsonDecodeOptions {
#[must_use]
pub const fn lenient() -> Self {
Self {
trim_whitespace: true,
strip_utf8_bom: true,
strip_markdown_code_fence: true,
strip_markdown_code_fence_requires_closing: false,
strip_markdown_code_fence_json_only: false,
escape_control_chars_in_strings: true,
max_input_bytes: None,
}
}
#[must_use]
pub const fn strict() -> Self {
Self {
trim_whitespace: false,
strip_utf8_bom: false,
strip_markdown_code_fence: false,
strip_markdown_code_fence_requires_closing: false,
strip_markdown_code_fence_json_only: false,
escape_control_chars_in_strings: false,
max_input_bytes: None,
}
}
#[must_use]
pub const fn json_code_fences_only() -> Self {
let mut options = Self::lenient();
options.strip_markdown_code_fence_json_only = true;
options
}
#[must_use]
pub const fn with_max_input_bytes(mut self, max_input_bytes: usize) -> Self {
self.max_input_bytes = Some(max_input_bytes);
self
}
}
impl Default for JsonDecodeOptions {
fn default() -> Self {
Self::lenient()
}
}