@@ -4,29 +4,29 @@ pub(crate) mod printf {
4
4
5
5
/// Represents a single `printf`-style substitution.
6
6
#[ derive( Clone , PartialEq , Debug ) ]
7
- pub enum Substitution < ' a > {
7
+ pub ( crate ) enum Substitution < ' a > {
8
8
/// A formatted output substitution with its internal byte offset.
9
9
Format ( Format < ' a > ) ,
10
10
/// A literal `%%` escape, with its start and end indices.
11
11
Escape ( ( usize , usize ) ) ,
12
12
}
13
13
14
14
impl < ' a > Substitution < ' a > {
15
- pub fn as_str ( & self ) -> & str {
15
+ pub ( crate ) fn as_str ( & self ) -> & str {
16
16
match self {
17
17
Substitution :: Format ( fmt) => fmt. span ,
18
18
Substitution :: Escape ( _) => "%%" ,
19
19
}
20
20
}
21
21
22
- pub fn position ( & self ) -> InnerSpan {
22
+ pub ( crate ) fn position ( & self ) -> InnerSpan {
23
23
match self {
24
24
Substitution :: Format ( fmt) => fmt. position ,
25
25
& Substitution :: Escape ( ( start, end) ) => InnerSpan :: new ( start, end) ,
26
26
}
27
27
}
28
28
29
- pub fn set_position ( & mut self , start : usize , end : usize ) {
29
+ pub ( crate ) fn set_position ( & mut self , start : usize , end : usize ) {
30
30
match self {
31
31
Substitution :: Format ( fmt) => fmt. position = InnerSpan :: new ( start, end) ,
32
32
Substitution :: Escape ( pos) => * pos = ( start, end) ,
@@ -37,7 +37,7 @@ pub(crate) mod printf {
37
37
///
38
38
/// This ignores cases where the substitution does not have an exact equivalent, or where
39
39
/// the substitution would be unnecessary.
40
- pub fn translate ( & self ) -> Result < String , Option < String > > {
40
+ pub ( crate ) fn translate ( & self ) -> Result < String , Option < String > > {
41
41
match self {
42
42
Substitution :: Format ( fmt) => fmt. translate ( ) ,
43
43
Substitution :: Escape ( _) => Err ( None ) ,
@@ -47,31 +47,31 @@ pub(crate) mod printf {
47
47
48
48
#[ derive( Clone , PartialEq , Debug ) ]
49
49
/// A single `printf`-style formatting directive.
50
- pub struct Format < ' a > {
50
+ pub ( crate ) struct Format < ' a > {
51
51
/// The entire original formatting directive.
52
- pub span : & ' a str ,
52
+ span : & ' a str ,
53
53
/// The (1-based) parameter to be converted.
54
- pub parameter : Option < u16 > ,
54
+ parameter : Option < u16 > ,
55
55
/// Formatting flags.
56
- pub flags : & ' a str ,
56
+ flags : & ' a str ,
57
57
/// Minimum width of the output.
58
- pub width : Option < Num > ,
58
+ width : Option < Num > ,
59
59
/// Precision of the conversion.
60
- pub precision : Option < Num > ,
60
+ precision : Option < Num > ,
61
61
/// Length modifier for the conversion.
62
- pub length : Option < & ' a str > ,
62
+ length : Option < & ' a str > ,
63
63
/// Type of parameter being converted.
64
- pub type_ : & ' a str ,
64
+ type_ : & ' a str ,
65
65
/// Byte offset for the start and end of this formatting directive.
66
- pub position : InnerSpan ,
66
+ position : InnerSpan ,
67
67
}
68
68
69
69
impl Format < ' _ > {
70
70
/// Translate this directive into an equivalent Rust formatting directive.
71
71
///
72
72
/// Returns `Err` in cases where the `printf` directive does not have an exact Rust
73
73
/// equivalent, rather than guessing.
74
- pub fn translate ( & self ) -> Result < String , Option < String > > {
74
+ pub ( crate ) fn translate ( & self ) -> Result < String , Option < String > > {
75
75
use std:: fmt:: Write ;
76
76
77
77
let ( c_alt, c_zero, c_left, c_plus) = {
@@ -248,7 +248,7 @@ pub(crate) mod printf {
248
248
249
249
/// A general number used in a `printf` formatting directive.
250
250
#[ derive( Copy , Clone , PartialEq , Debug ) ]
251
- pub enum Num {
251
+ enum Num {
252
252
// The range of these values is technically bounded by `NL_ARGMAX`... but, at least for GNU
253
253
// libc, it apparently has no real fixed limit. A `u16` is used here on the basis that it
254
254
// is *vanishingly* unlikely that *anyone* is going to try formatting something wider, or
@@ -287,12 +287,12 @@ pub(crate) mod printf {
287
287
}
288
288
289
289
/// Returns an iterator over all substitutions in a given string.
290
- pub fn iter_subs ( s : & str , start_pos : usize ) -> Substitutions < ' _ > {
290
+ pub ( crate ) fn iter_subs ( s : & str , start_pos : usize ) -> Substitutions < ' _ > {
291
291
Substitutions { s, pos : start_pos }
292
292
}
293
293
294
294
/// Iterator over substitutions in a string.
295
- pub struct Substitutions < ' a > {
295
+ pub ( crate ) struct Substitutions < ' a > {
296
296
s : & ' a str ,
297
297
pos : usize ,
298
298
}
@@ -326,7 +326,7 @@ pub(crate) mod printf {
326
326
}
327
327
328
328
/// Parse the next substitution from the input string.
329
- pub fn parse_next_substitution ( s : & str ) -> Option < ( Substitution < ' _ > , & str ) > {
329
+ fn parse_next_substitution ( s : & str ) -> Option < ( Substitution < ' _ > , & str ) > {
330
330
use self :: State :: * ;
331
331
332
332
let at = {
@@ -614,37 +614,37 @@ pub(crate) mod printf {
614
614
mod tests;
615
615
}
616
616
617
- pub mod shell {
617
+ pub ( crate ) mod shell {
618
618
use super :: strcursor:: StrCursor as Cur ;
619
619
use rustc_span:: InnerSpan ;
620
620
621
621
#[ derive( Clone , PartialEq , Debug ) ]
622
- pub enum Substitution < ' a > {
622
+ pub ( crate ) enum Substitution < ' a > {
623
623
Ordinal ( u8 , ( usize , usize ) ) ,
624
624
Name ( & ' a str , ( usize , usize ) ) ,
625
625
Escape ( ( usize , usize ) ) ,
626
626
}
627
627
628
628
impl Substitution < ' _ > {
629
- pub fn as_str ( & self ) -> String {
629
+ pub ( crate ) fn as_str ( & self ) -> String {
630
630
match self {
631
631
Substitution :: Ordinal ( n, _) => format ! ( "${n}" ) ,
632
632
Substitution :: Name ( n, _) => format ! ( "${n}" ) ,
633
633
Substitution :: Escape ( _) => "$$" . into ( ) ,
634
634
}
635
635
}
636
636
637
- pub fn position ( & self ) -> InnerSpan {
637
+ pub ( crate ) fn position ( & self ) -> InnerSpan {
638
638
let ( Self :: Ordinal ( _, pos) | Self :: Name ( _, pos) | Self :: Escape ( pos) ) = self ;
639
639
InnerSpan :: new ( pos. 0 , pos. 1 )
640
640
}
641
641
642
- pub fn set_position ( & mut self , start : usize , end : usize ) {
642
+ fn set_position ( & mut self , start : usize , end : usize ) {
643
643
let ( Self :: Ordinal ( _, pos) | Self :: Name ( _, pos) | Self :: Escape ( pos) ) = self ;
644
644
* pos = ( start, end) ;
645
645
}
646
646
647
- pub fn translate ( & self ) -> Result < String , Option < String > > {
647
+ pub ( crate ) fn translate ( & self ) -> Result < String , Option < String > > {
648
648
match self {
649
649
Substitution :: Ordinal ( n, _) => Ok ( format ! ( "{{{}}}" , n) ) ,
650
650
Substitution :: Name ( n, _) => Ok ( format ! ( "{{{}}}" , n) ) ,
@@ -654,12 +654,12 @@ pub mod shell {
654
654
}
655
655
656
656
/// Returns an iterator over all substitutions in a given string.
657
- pub fn iter_subs ( s : & str , start_pos : usize ) -> Substitutions < ' _ > {
657
+ pub ( crate ) fn iter_subs ( s : & str , start_pos : usize ) -> Substitutions < ' _ > {
658
658
Substitutions { s, pos : start_pos }
659
659
}
660
660
661
661
/// Iterator over substitutions in a string.
662
- pub struct Substitutions < ' a > {
662
+ pub ( crate ) struct Substitutions < ' a > {
663
663
s : & ' a str ,
664
664
pos : usize ,
665
665
}
@@ -681,7 +681,7 @@ pub mod shell {
681
681
}
682
682
683
683
/// Parse the next substitution from the input string.
684
- pub fn parse_next_substitution ( s : & str ) -> Option < ( Substitution < ' _ > , & str ) > {
684
+ fn parse_next_substitution ( s : & str ) -> Option < ( Substitution < ' _ > , & str ) > {
685
685
let at = {
686
686
let start = s. find ( '$' ) ?;
687
687
match s[ start + 1 ..] . chars ( ) . next ( ) ? {
@@ -741,24 +741,24 @@ pub mod shell {
741
741
}
742
742
743
743
mod strcursor {
744
- pub struct StrCursor < ' a > {
744
+ pub ( crate ) struct StrCursor < ' a > {
745
745
s : & ' a str ,
746
746
pub at : usize ,
747
747
}
748
748
749
749
impl < ' a > StrCursor < ' a > {
750
- pub fn new_at ( s : & ' a str , at : usize ) -> StrCursor < ' a > {
750
+ pub ( crate ) fn new_at ( s : & ' a str , at : usize ) -> StrCursor < ' a > {
751
751
StrCursor { s, at }
752
752
}
753
753
754
- pub fn at_next_cp ( mut self ) -> Option < StrCursor < ' a > > {
754
+ pub ( crate ) fn at_next_cp ( mut self ) -> Option < StrCursor < ' a > > {
755
755
match self . try_seek_right_cp ( ) {
756
756
true => Some ( self ) ,
757
757
false => None ,
758
758
}
759
759
}
760
760
761
- pub fn next_cp ( mut self ) -> Option < ( char , StrCursor < ' a > ) > {
761
+ pub ( crate ) fn next_cp ( mut self ) -> Option < ( char , StrCursor < ' a > ) > {
762
762
let cp = self . cp_after ( ) ?;
763
763
self . seek_right ( cp. len_utf8 ( ) ) ;
764
764
Some ( ( cp, self ) )
@@ -768,11 +768,11 @@ mod strcursor {
768
768
& self . s [ 0 ..self . at ]
769
769
}
770
770
771
- pub fn slice_after ( & self ) -> & ' a str {
771
+ pub ( crate ) fn slice_after ( & self ) -> & ' a str {
772
772
& self . s [ self . at ..]
773
773
}
774
774
775
- pub fn slice_between ( & self , until : StrCursor < ' a > ) -> Option < & ' a str > {
775
+ pub ( crate ) fn slice_between ( & self , until : StrCursor < ' a > ) -> Option < & ' a str > {
776
776
if !str_eq_literal ( self . s , until. s ) {
777
777
None
778
778
} else {
0 commit comments