Use shared leading_quote implementation in ruff_python_formatter (#3396)

This commit is contained in:
Charlie Marsh 2023-03-08 13:21:59 -05:00 committed by GitHub
parent dfe1cad928
commit ff2c0dd491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 114 additions and 123 deletions

View file

@ -1,10 +0,0 @@
/// 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,5 +1,4 @@
pub mod builtins;
pub mod bytes;
pub mod future;
pub mod identifiers;
pub mod keyword;

View file

@ -1,6 +1,3 @@
use once_cell::sync::Lazy;
use regex::Regex;
/// See: <https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals>
pub const TRIPLE_QUOTE_PREFIXES: &[&str] = &[
"u\"\"\"", "u'''", "r\"\"\"", "r'''", "U\"\"\"", "U'''", "R\"\"\"", "R'''", "\"\"\"", "'''",
@ -11,9 +8,6 @@ pub const SINGLE_QUOTE_PREFIXES: &[&str] = &[
pub const TRIPLE_QUOTE_SUFFIXES: &[&str] = &["\"\"\"", "'''"];
pub const SINGLE_QUOTE_SUFFIXES: &[&str] = &["\"", "'"];
pub static STRING_QUOTE_PREFIX_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"^(?i)[urb]*['"](?P<raw>.*)['"]$"#).unwrap());
pub fn is_lower(s: &str) -> bool {
let mut cased = false;
for c in s.chars() {