|
1 | 1 | //! Implementation of Printf-Style string formatting
|
2 | 2 | //! as per the [Python Docs](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting).
|
3 |
| -use bitflags::bitflags; |
4 | 3 | use std::{
|
5 | 4 | fmt,
|
6 | 5 | iter::{Enumerate, Peekable},
|
7 | 6 | str::FromStr,
|
8 | 7 | };
|
9 | 8 |
|
| 9 | +use bitflags::bitflags; |
| 10 | + |
10 | 11 | use crate::Case;
|
11 | 12 |
|
12 | 13 | #[derive(Debug, PartialEq)]
|
@@ -96,19 +97,6 @@ bitflags! {
|
96 | 97 | }
|
97 | 98 | }
|
98 | 99 |
|
99 |
| -impl CConversionFlags { |
100 |
| - #[inline] |
101 |
| - pub fn sign_string(&self) -> &'static str { |
102 |
| - if self.contains(CConversionFlags::SIGN_CHAR) { |
103 |
| - "+" |
104 |
| - } else if self.contains(CConversionFlags::BLANK_SIGN) { |
105 |
| - " " |
106 |
| - } else { |
107 |
| - "" |
108 |
| - } |
109 |
| - } |
110 |
| -} |
111 |
| - |
112 | 100 | #[derive(Debug, PartialEq)]
|
113 | 101 | pub enum CFormatQuantity {
|
114 | 102 | Amount(usize),
|
@@ -337,44 +325,12 @@ pub enum CFormatPart<T> {
|
337 | 325 | Spec(CFormatSpec),
|
338 | 326 | }
|
339 | 327 |
|
340 |
| -impl<T> CFormatPart<T> { |
341 |
| - #[inline] |
342 |
| - pub fn is_specifier(&self) -> bool { |
343 |
| - matches!(self, CFormatPart::Spec(_)) |
344 |
| - } |
345 |
| - |
346 |
| - #[inline] |
347 |
| - pub fn has_key(&self) -> bool { |
348 |
| - match self { |
349 |
| - CFormatPart::Spec(s) => s.mapping_key.is_some(), |
350 |
| - CFormatPart::Literal(_) => false, |
351 |
| - } |
352 |
| - } |
353 |
| -} |
354 |
| - |
355 | 328 | #[derive(Debug, PartialEq)]
|
356 | 329 | pub struct CFormatStrOrBytes<S> {
|
357 | 330 | parts: Vec<(usize, CFormatPart<S>)>,
|
358 | 331 | }
|
359 | 332 |
|
360 | 333 | impl<S> CFormatStrOrBytes<S> {
|
361 |
| - pub fn check_specifiers(&self) -> Option<(usize, bool)> { |
362 |
| - let mut count = 0; |
363 |
| - let mut mapping_required = false; |
364 |
| - for (_, part) in &self.parts { |
365 |
| - if part.is_specifier() { |
366 |
| - let has_key = part.has_key(); |
367 |
| - if count == 0 { |
368 |
| - mapping_required = has_key; |
369 |
| - } else if mapping_required != has_key { |
370 |
| - return None; |
371 |
| - } |
372 |
| - count += 1; |
373 |
| - } |
374 |
| - } |
375 |
| - Some((count, mapping_required)) |
376 |
| - } |
377 |
| - |
378 | 334 | #[inline]
|
379 | 335 | pub fn iter(&self) -> impl Iterator<Item = &(usize, CFormatPart<S>)> {
|
380 | 336 | self.parts.iter()
|
@@ -430,11 +386,6 @@ impl CFormatBytes {
|
430 | 386 | }
|
431 | 387 | Ok(Self { parts })
|
432 | 388 | }
|
433 |
| - |
434 |
| - pub fn parse_from_bytes(bytes: &[u8]) -> Result<Self, CFormatError> { |
435 |
| - let mut iter = bytes.iter().copied().enumerate().peekable(); |
436 |
| - Self::parse(&mut iter) |
437 |
| - } |
438 | 389 | }
|
439 | 390 |
|
440 | 391 | pub type CFormatString = CFormatStrOrBytes<String>;
|
|
0 commit comments