qubit_json/json_decode_options.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9//! Defines the option type used to configure the lenient JSON decoder.
10//!
11//! Author: Haixing Hu
12
13/// Configuration switches for [`crate::LenientJsonDecoder`].
14///
15/// Each flag controls one normalization rule applied before parsing JSON.
16/// Defaults are intentionally conservative and cover the most common
17/// non-fully-trusted text inputs without attempting aggressive repair.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub struct JsonDecodeOptions {
20 /// Controls whether leading and trailing whitespace is removed before any
21 /// other normalization step is applied.
22 pub trim_whitespace: bool,
23 /// Controls whether a leading UTF-8 byte order mark (`U+FEFF`) is removed
24 /// before parsing.
25 pub strip_utf8_bom: bool,
26 /// Controls whether one outer Markdown code fence is removed.
27 ///
28 /// Typical examples include `````json ... ````` and bare fenced blocks
29 /// starting with ````` followed by a newline.
30 pub strip_markdown_code_fence: bool,
31 /// Controls whether raw ASCII control characters inside JSON string
32 /// literals are converted into valid JSON escape sequences.
33 pub escape_control_chars_in_strings: bool,
34}
35
36impl Default for JsonDecodeOptions {
37 fn default() -> Self {
38 Self {
39 trim_whitespace: true,
40 strip_utf8_bom: true,
41 strip_markdown_code_fence: true,
42 escape_control_chars_in_strings: true,
43 }
44 }
45}