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