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 5
5
6
6
function d = drop_slash(p )
7
7
arguments
8
- p ( 1 , 1 ) string
8
+ p { mustBeTextScalar }
9
9
end
10
10
11
11
s = stdlib .posix(p );
12
12
13
- uncslash = ispc && startsWith(s , " // " );
13
+ uncslash = ispc && startsWith(s , ' // ' );
14
14
15
15
% drop repeated slashes inside string
16
- d = regexprep(s , " /+ " , " / " );
16
+ d = regexprep(s , ' /+ ' , ' / ' );
17
17
18
18
L = strlength(d );
19
19
20
20
if L < 2
21
21
if uncslash
22
- d = " // " ;
22
+ d = ' // ' ;
23
23
end
24
- return ;
24
+ elseif ~ispc || (L ~= 3 || ~strcmp(d , stdlib .root(s )))
25
+ d = regexprep(d , ' /$' , ' ' );
25
26
end
26
27
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 );
35
30
end
36
31
37
- if uncslash
38
- d = strcat( " / " , d );
32
+ if isstring( p )
33
+ d = string( d );
39
34
end
40
35
41
36
end
Original file line number Diff line number Diff line change 8
8
methods (Test )
9
9
10
10
function test_posix(tc )
11
- import matlab .unittest .constraints .ContainsSubstring
12
11
12
+ tc .verifyEqual(stdlib .posix(' ' ), ' ' )
13
13
tc .verifyEqual(stdlib .posix(" " ), " " )
14
14
15
15
if ispc
16
- tc .verifyThat (stdlib .posix(" c:\foo " ), ~ContainsSubstring( " \ " ) )
16
+ tc .verifyEqual (stdlib .posix(" c:\abc " ), " c:/abc " )
17
17
end
18
18
end
19
19
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
+
20
30
function test_root_name(tc , p )
21
31
tc .verifyEqual(stdlib .root_name(p{1 }), p{2 })
22
32
end
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ function test_parent(tc, p)
24
24
{" a/" , " \." }, ...
25
25
{" a/b" , " a" }, ...
26
26
{' a/b/' , ' a' }, ...
27
+ {' a//b' , ' a' }, ...
27
28
{" ab/.parent" , " ab" }, ...
28
29
{" ab/.parent.txt" , " ab" }, ...
29
30
{" a/b/../.parent.txt" , " a/b/\.\." }, ...
You can’t perform that action at this time.
0 commit comments