#white-space #proc-macro #graphql #string-literal

macro merge-whitespace

Procedural macros for merging whitespace in const contexts

2 releases (1 stable)

new 1.0.0 Jun 3, 2024
0.1.0 May 14, 2024

#675 in Text processing

Download history 121/week @ 2024-05-13 16/week @ 2024-05-20

137 downloads per month

EUPL-1.2

20KB
375 lines

merge_whitespace

Crates.io Crates.io GitHub Workflow Status docs.rs codecov

This crate contains procedural macros for removing multiple consecutive whitespaces from a given string literal, replacing them with a single space.

Example

The example below uses an optional quotation characters to keep quoted text ranges un-merged, as well as an optional escape character to ensure that quotation character literals are kept as-is.

use merge_whitespace::merge_whitespace;

const QUERY: &str = merge_whitespace!(r#"
     query {
       users (limit: 1, filter: "bought a 12\" vinyl
                                 named \"spaces  in  space \"") {
         id
         name
         todos(order_by: {created_at: desc}, limit: 5) {
           id
           title
         }
       }
     }
     "#,
     quote_char = '"',
     escape_char = '\\');

#[test]
fn test() {
    assert_eq!(QUERY, r#"query { users (limit: 1, filter: "bought a 12\" vinyl
                                 named \"spaces  in  space \"") { id name todos(order_by: {created_at: desc}, limit: 5) { id title } } }"#);
}

Dependencies

~0.3–0.8MB
~19K SLoC