Unify enums used for internal representation of quoting style (#10383)

This commit is contained in:
Alex Waygood 2024-03-13 17:19:17 +00:00 committed by GitHub
parent d59433b12e
commit c2e15f38ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 148 additions and 228 deletions

View file

@ -2,7 +2,7 @@ use std::fmt;
use bitflags::bitflags;
use ruff_python_ast::{str::QuoteStyle, StringLiteralPrefix};
use ruff_python_ast::{str::Quote, StringLiteralPrefix};
use ruff_text_size::{TextLen, TextSize};
bitflags! {
@ -171,11 +171,11 @@ impl StringKind {
}
/// Does the string use single or double quotes in its opener and closer?
pub const fn quote_style(self) -> QuoteStyle {
pub const fn quote_style(self) -> Quote {
if self.0.contains(StringFlags::DOUBLE) {
QuoteStyle::Double
Quote::Double
} else {
QuoteStyle::Single
Quote::Single
}
}
@ -190,13 +190,13 @@ impl StringKind {
pub const fn quote_str(self) -> &'static str {
if self.is_triple_quoted() {
match self.quote_style() {
QuoteStyle::Single => "'''",
QuoteStyle::Double => r#"""""#,
Quote::Single => "'''",
Quote::Double => r#"""""#,
}
} else {
match self.quote_style() {
QuoteStyle::Single => "'",
QuoteStyle::Double => "\"",
Quote::Single => "'",
Quote::Double => "\"",
}
}
}