@@ -81,91 +81,6 @@ use std::path::Path;
8181use std:: str;
8282use std:: task:: { ready, Poll } ;
8383
84- /// Crates.io treats hyphen and underscores as interchangeable, but the index and old Cargo do not.
85- /// Therefore, the index must store uncanonicalized version of the name so old Cargo's can find it.
86- /// This loop tries all possible combinations of switching hyphen and underscores to find the
87- /// uncanonicalized one. As all stored inputs have the correct spelling, we start with the spelling
88- /// as-provided.
89- pub struct UncanonicalizedIter < ' s > {
90- input : & ' s str ,
91- num_hyphen_underscore : u32 ,
92- hyphen_combination_num : u16 ,
93- }
94-
95- impl < ' s > UncanonicalizedIter < ' s > {
96- pub fn new ( input : & ' s str ) -> Self {
97- let num_hyphen_underscore = input. chars ( ) . filter ( |& c| c == '_' || c == '-' ) . count ( ) as u32 ;
98- UncanonicalizedIter {
99- input,
100- num_hyphen_underscore,
101- hyphen_combination_num : 0 ,
102- }
103- }
104- }
105-
106- impl < ' s > Iterator for UncanonicalizedIter < ' s > {
107- type Item = String ;
108-
109- fn next ( & mut self ) -> Option < Self :: Item > {
110- if self . hyphen_combination_num > 0
111- && self . hyphen_combination_num . trailing_zeros ( ) >= self . num_hyphen_underscore
112- {
113- return None ;
114- }
115-
116- let ret = Some (
117- self . input
118- . chars ( )
119- . scan ( 0u16 , |s, c| {
120- // the check against 15 here's to prevent
121- // shift overflow on inputs with more than 15 hyphens
122- if ( c == '_' || c == '-' ) && * s <= 15 {
123- let switch = ( self . hyphen_combination_num & ( 1u16 << * s) ) > 0 ;
124- let out = if ( c == '_' ) ^ switch { '_' } else { '-' } ;
125- * s += 1 ;
126- Some ( out)
127- } else {
128- Some ( c)
129- }
130- } )
131- . collect ( ) ,
132- ) ;
133- self . hyphen_combination_num += 1 ;
134- ret
135- }
136- }
137-
138- #[ test]
139- fn no_hyphen ( ) {
140- assert_eq ! (
141- UncanonicalizedIter :: new( "test" ) . collect:: <Vec <_>>( ) ,
142- vec![ "test" . to_string( ) ]
143- )
144- }
145-
146- #[ test]
147- fn two_hyphen ( ) {
148- assert_eq ! (
149- UncanonicalizedIter :: new( "te-_st" ) . collect:: <Vec <_>>( ) ,
150- vec![
151- "te-_st" . to_string( ) ,
152- "te__st" . to_string( ) ,
153- "te--st" . to_string( ) ,
154- "te_-st" . to_string( )
155- ]
156- )
157- }
158-
159- #[ test]
160- fn overflow_hyphen ( ) {
161- assert_eq ! (
162- UncanonicalizedIter :: new( "te-_-_-_-_-_-_-_-_-st" )
163- . take( 100 )
164- . count( ) ,
165- 100
166- )
167- }
168-
16984/// Manager for handling the on-disk index.
17085///
17186/// Note that local and remote registries store the index differently. Local
0 commit comments