Home / File/ json.rs — tailwindcss Source File

json.rs — tailwindcss Source File

Architecture documentation for json.rs, a rust file in the tailwindcss codebase. 3 imports, 0 dependents.

File rust Oxide PreProcessors 3 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  c06d3dd4_a7b7_9924_07c7_c486c5e5c84a["json.rs"]
  ca9df7e1_f49d_01ec_8027_9a3178f169c7["super::Json"]
  c06d3dd4_a7b7_9924_07c7_c486c5e5c84a --> ca9df7e1_f49d_01ec_8027_9a3178f169c7
  96a36755_a007_15e1_ec6c_526c02d24b9b["crate::cursor"]
  c06d3dd4_a7b7_9924_07c7_c486c5e5c84a --> 96a36755_a007_15e1_ec6c_526c02d24b9b
  ed5b6564_5e78_f7bf_cdc6_b0150d9116c1["crate::extractor::pre_processors::pre_processor::PreProcessor"]
  c06d3dd4_a7b7_9924_07c7_c486c5e5c84a --> ed5b6564_5e78_f7bf_cdc6_b0150d9116c1
  style c06d3dd4_a7b7_9924_07c7_c486c5e5c84a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

use crate::cursor;
use crate::extractor::pre_processors::pre_processor::PreProcessor;

#[derive(Debug, Default)]
pub struct Json;

impl PreProcessor for Json {
    fn process(&self, content: &[u8]) -> Vec<u8> {
        let len = content.len();
        let mut result = content.to_vec();
        let mut cursor = cursor::Cursor::new(content);

        while cursor.pos < len {
            match cursor.curr {
                // Consume strings as-is
                b'"' => {
                    cursor.advance();

                    while cursor.pos < len {
                        match cursor.curr {
                            // Escaped character, skip ahead to the next character
                            b'\\' => cursor.advance_twice(),

                            // End of the string
                            b'"' => break,

                            // Everything else is valid
                            _ => cursor.advance(),
                        };
                    }
                }

                // Replace brackets and curlies with spaces
                b'[' | b'{' | b']' | b'}' => {
                    result[cursor.pos] = b' ';
                }

                // Consume everything else
                _ => {}
            };

            cursor.advance();
        }

        result
    }
}

#[cfg(test)]
mod tests {
    use super::Json;
    use crate::extractor::pre_processors::pre_processor::PreProcessor;

    #[test]
    fn test_json_pre_processor() {
        let (input, expected) = (
            r#"[1,[2,[3,4,["flex flex-1 content-['hello_world']"]]], {"flex": true}]"#,
            r#" 1, 2, 3,4, "flex flex-1 content-['hello_world']"   ,  "flex": true  "#,
        );

        Json::test(input, expected);
    }
}

Domain

Subdomains

Dependencies

  • crate::cursor
  • crate::extractor::pre_processors::pre_processor::PreProcessor
  • super::Json

Frequently Asked Questions

What does json.rs do?
json.rs is a source file in the tailwindcss codebase, written in rust. It belongs to the Oxide domain, PreProcessors subdomain.
What functions are defined in json.rs?
json.rs defines 2 function(s): process, test_json_pre_processor.
What does json.rs depend on?
json.rs imports 3 module(s): crate::cursor, crate::extractor::pre_processors::pre_processor::PreProcessor, super::Json.
Where is json.rs in the architecture?
json.rs is located at crates/oxide/src/extractor/pre_processors/json.rs (domain: Oxide, subdomain: PreProcessors, directory: crates/oxide/src/extractor/pre_processors).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free