Add support for reformatting byte strings (#3176)

This commit is contained in:
Charlie Marsh 2023-02-23 11:50:24 -05:00 committed by GitHub
parent f967f344fc
commit 1e7233a8eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 90 additions and 59 deletions

View file

@ -0,0 +1,10 @@
/// See: <https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals>
pub const TRIPLE_QUOTE_PREFIXES: &[&str] = &[
"br'''", "rb'''", "bR'''", "Rb'''", "Br'''", "rB'''", "RB'''", "BR'''", "b'''", "br\"\"\"",
"rb\"\"\"", "bR\"\"\"", "Rb\"\"\"", "Br\"\"\"", "rB\"\"\"", "RB\"\"\"", "BR\"\"\"", "b\"\"\"",
"B\"\"\"",
];
pub const SINGLE_QUOTE_PREFIXES: &[&str] = &[
"br'", "rb'", "bR'", "Rb'", "Br'", "rB'", "RB'", "BR'", "b'", "br\"", "rb\"", "bR\"", "Rb\"",
"Br\"", "rB\"", "RB\"", "BR\"", "b\"", "B\"",
];

View file

@ -1,7 +1,8 @@
pub mod builtins;
pub mod bytes;
pub mod future;
pub mod identifiers;
pub mod keyword;
pub mod string;
pub mod str;
pub mod sys;
pub mod typing;

View file

@ -6,7 +6,7 @@ pub const TRIPLE_QUOTE_PREFIXES: &[&str] = &[
"u\"\"\"", "u'''", "r\"\"\"", "r'''", "U\"\"\"", "U'''", "R\"\"\"", "R'''", "\"\"\"", "'''",
];
pub const SINGLE_QUOTE_PREFIXES: &[&str] = &[
"u\"", "u'", "r\"", "r'", "u\"", "u'", "r\"", "r'", "U\"", "U'", "R\"", "R'", "\"", "'",
"u\"", "u'", "r\"", "r'", "U\"", "U'", "R\"", "R'", "\"", "'",
];
pub const TRIPLE_QUOTE_SUFFIXES: &[&str] = &["\"\"\"", "'''"];
pub const SINGLE_QUOTE_SUFFIXES: &[&str] = &["\"", "'"];
@ -53,7 +53,7 @@ pub fn strip_quotes_and_prefixes(s: &str) -> &str {
#[cfg(test)]
mod tests {
use crate::string::{is_lower, is_upper, strip_quotes_and_prefixes};
use crate::str::{is_lower, is_upper, strip_quotes_and_prefixes};
#[test]
fn test_is_lower() {