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 OxideEngine PreProcessors 3 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  98461823_e26d_bba9_a56a_e76d8b308f61["json.rs"]
  6035db9d_2f6b_6f62_e990_3204fb9702cf["super::Json"]
  98461823_e26d_bba9_a56a_e76d8b308f61 --> 6035db9d_2f6b_6f62_e990_3204fb9702cf
  e4e20bdf_ad1e_e4a0_5cba_d0f5a5db787e["crate::cursor"]
  98461823_e26d_bba9_a56a_e76d8b308f61 --> e4e20bdf_ad1e_e4a0_5cba_d0f5a5db787e
  a55fec3d_3fee_4b46_48f2_43f3844c61e4["crate::extractor::pre_processors::pre_processor::PreProcessor"]
  98461823_e26d_bba9_a56a_e76d8b308f61 --> a55fec3d_3fee_4b46_48f2_43f3844c61e4
  style 98461823_e26d_bba9_a56a_e76d8b308f61 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 OxideEngine 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: OxideEngine, 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