krasa / StringManipulation

IntelliJ plugin - https://plugins.jetbrains.com/plugin/2162
Apache License 2.0
698 stars 81 forks source link

Convert to/from Rust raw strings #179

Open nyurik opened 2 years ago

nyurik commented 2 years ago

Rust has a concept of a raw string to avoid any kind of escaping. This is similar to #166 (but not the same). It would be great if a standard non-raw representation of a string could be easily converted to/from the raw form. A raw string starts as r#", and only terminates when it sees "#. If original string literal contains "#, it should be wrapped with one more #: r##" ... "# ... "##

Describe alternatives you've considered Lots of manual regex

Additional context From the second example:

fn main() {
    let raw_str = r"Escapes don't work here: \x3F \u{211D}";
    println!("{}", raw_str);

    // If you need quotes in a raw string, add a pair of #s
    let quotes = r#"And then I said: "There is no escape!""#;
    println!("{}", quotes);

    // If you need "# in your string, just use more #s in the delimiter.
    // You can use up to 65535 #s.
    let longer_delimiter = r###"A string with "# in it. And even "##!"###;
    println!("{}", longer_delimiter);
}