File tree Expand file tree Collapse file tree 3 files changed +23
-17
lines changed Expand file tree Collapse file tree 3 files changed +23
-17
lines changed Original file line number Diff line number Diff line change 55
66function d = drop_slash(p )
77arguments
8- p ( 1 , 1 ) string
8+ p { mustBeTextScalar }
99end
1010
1111s = stdlib .posix(p );
1212
13- uncslash = ispc && startsWith(s , " // " );
13+ uncslash = ispc && startsWith(s , ' // ' );
1414
1515% drop repeated slashes inside string
16- d = regexprep(s , " /+ " , " / " );
16+ d = regexprep(s , ' /+ ' , ' / ' );
1717
1818L = strlength(d );
1919
2020if L < 2
2121 if uncslash
22- d = " // " ;
22+ d = ' // ' ;
2323 end
24- return ;
24+ elseif ~ispc || (L ~= 3 || ~strcmp(d , stdlib .root(s )))
25+ d = regexprep(d , ' /$' , ' ' );
2526end
2627
27- if ~ispc || (L ~= 3 || ~strcmp(d , stdlib .root(s )))
28- if ischar(s )
29- if d(end ) == ' /'
30- d = d(1 : end - 1 );
31- end
32- else
33- d = strip(d , " right" , " /" );
34- end
28+ if uncslash
29+ d = strcat(' /' , d );
3530end
3631
37- if uncslash
38- d = strcat( " / " , d );
32+ if isstring( p )
33+ d = string( d );
3934end
4035
4136end
Original file line number Diff line number Diff line change 88methods (Test )
99
1010function test_posix(tc )
11- import matlab .unittest .constraints .ContainsSubstring
1211
12+ tc .verifyEqual(stdlib .posix(' ' ), ' ' )
1313tc .verifyEqual(stdlib .posix(" " ), " " )
1414
1515if ispc
16- tc .verifyThat (stdlib .posix(" c:\foo " ), ~ContainsSubstring( " \ " ) )
16+ tc .verifyEqual (stdlib .posix(" c:\abc " ), " c:/abc " )
1717end
1818end
1919
20+
21+ function test_drop_slash(tc )
22+ tc .verifyEqual(stdlib .drop_slash(' ' ), ' ' )
23+ tc .verifyEqual(stdlib .drop_slash(' /' ), ' /' )
24+ tc .verifyEqual(stdlib .drop_slash(' a//b' ), ' a/b' )
25+ tc .verifyEqual(stdlib .drop_slash(' a//b/' ), ' a/b' )
26+ tc .verifyEqual(stdlib .drop_slash(" a//b/c" ), " a/b/c" )
27+
28+ end
29+
2030function test_root_name(tc , p )
2131tc .verifyEqual(stdlib .root_name(p{1 }), p{2 })
2232end
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ function test_parent(tc, p)
2424{" a/" , " \." }, ...
2525{" a/b" , " a" }, ...
2626{' a/b/' , ' a' }, ...
27+ {' a//b' , ' a' }, ...
2728{" ab/.parent" , " ab" }, ...
2829{" ab/.parent.txt" , " ab" }, ...
2930{" a/b/../.parent.txt" , " a/b/\.\." }, ...
You can’t perform that action at this time.
0 commit comments