Returns the outer quotes to use and the number of quotes that need to be escaped.
(
single_count: usize,
double_count: usize,
preferred_quote: Quote,
)
| 71 | /// Returns the outer quotes to use and the number of quotes that need to be |
| 72 | /// escaped. |
| 73 | pub(crate) const fn choose_quote( |
| 74 | single_count: usize, |
| 75 | double_count: usize, |
| 76 | preferred_quote: Quote, |
| 77 | ) -> (Quote, usize) { |
| 78 | let (primary_count, secondary_count) = match preferred_quote { |
| 79 | Quote::Single => (single_count, double_count), |
| 80 | Quote::Double => (double_count, single_count), |
| 81 | }; |
| 82 | |
| 83 | // always use primary unless we have primary but no secondary |
| 84 | let use_secondary = primary_count > 0 && secondary_count == 0; |
| 85 | if use_secondary { |
| 86 | (preferred_quote.swap(), secondary_count) |
| 87 | } else { |
| 88 | (preferred_quote, primary_count) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | pub struct UnicodeEscape<'a> { |
| 93 | source: &'a Wtf8, |
no test coverage detected