File tree 2 files changed +14
-11
lines changed
2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -218,8 +218,8 @@ mod test {
218
218
#[ test]
219
219
fn test_prefix_rpath ( ) {
220
220
let res = get_install_prefix_rpath ( "/usr/lib" , "triple" ) ;
221
- assert str :: ends_with ( res , #env ( "CFG_PREFIX" )
222
- + "/lib/rustc/triple/lib" ) ;
221
+ let d = fs :: connect ( #env ( "CFG_PREFIX" ) , "/lib/rustc/triple/lib" ) ;
222
+ assert str :: ends_with ( res , d ) ;
223
223
}
224
224
225
225
#[ test]
Original file line number Diff line number Diff line change @@ -81,17 +81,20 @@ Function: connect
81
81
82
82
Connects to path segments
83
83
84
- Given paths `pre` and `post` this function will return a path
85
- that is equal to `post` appended to `pre`, inserting a path separator
86
- between the two as needed .
84
+ Given paths `pre` and `post, removes any trailing path separator on `pre` and
85
+ any leading path separator on `post`, and returns the concatenation of the two
86
+ with a single path separator between them .
87
87
*/
88
- fn connect ( pre : path , post : path ) -> path {
89
- let len = str:: byte_len ( pre) ;
90
- ret if pre[ len - 1 u] == os_fs:: path_sep as u8 {
91
88
92
- // Trailing '/'?
93
- pre + post
94
- } else { pre + path_sep ( ) + post } ;
89
+ fn connect ( pre : path , post : path ) -> path {
90
+ let pre_ = pre;
91
+ let post_ = post;
92
+ let sep = os_fs:: path_sep as u8 ;
93
+ let pre_len = str:: byte_len ( pre) ;
94
+ let post_len = str:: byte_len ( post) ;
95
+ if pre_len > 1 u && pre[ pre_len-1 u] == sep { str:: pop_byte ( pre_) ; }
96
+ if post_len > 1 u && post[ 0 ] == sep { str:: shift_byte ( post_) ; }
97
+ ret pre_ + path_sep ( ) + post_;
95
98
}
96
99
97
100
/*
You can’t perform that action at this time.
0 commit comments