File tree Expand file tree Collapse file tree 3 files changed +11
-15
lines changed Expand file tree Collapse file tree 3 files changed +11
-15
lines changed Original file line number Diff line number Diff line change 11%% DROP_SLASH drop repeated and trailing slash
2- %
32
43function d = drop_slash(filepath )
5- arguments
6- filepath string
7- end
84
95s = stdlib .posix(filepath );
106
117% drop repeated slashes inside string
128d = regexprep(s , ' /+' , ' /' );
139
1410% drop all trailing slashes
15- i = ~strcmp(d , ' /' ) & ~strcmp(d , stdlib .root(s ));
16-
17- d( i ) = regexprep(d( i ), ' /$ ' , ' ' );
11+ if ~strcmp(d , ' /' ) & & ~strcmp(d , stdlib .root(s ));
12+ d = regexprep( d , ' /$ ' , ' ' );
13+ end
1814
1915end
Original file line number Diff line number Diff line change 99% stdlib.parent("a/b/c/") == "a/b"
1010
1111function p = parent(file )
12- arguments
13- file (1 ,1 ) string
14- end
1512
1613p = fileparts(stdlib .drop_slash(file ));
1714
1815if stdlib .strempty(p )
19- p = " ." ;
16+ p = ' .' ;
17+ if isstring(file )
18+ p = string(p );
19+ end
2020elseif ispc() && p == stdlib .root_name(file )
21- p = p + " / " ;
21+ p = append( p , ' / ' ) ;
2222end
2323
2424end
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ function test_parent(tc, p)
2626{" ." , " ." }, ...
2727{" .." , " ." }, ...
2828{" ../.." , " .." }, ...
29- {" a/ " , " . " }, ...
29+ {' a/ ' , ' . ' }, ...
3030{" a/b" , " a" }, ...
3131{" ab/.parent" , " ab" }, ...
3232{" ab/.parent.txt" , " ab" }, ...
@@ -41,7 +41,7 @@ function test_parent(tc, p)
4141p{end + 1 } = {" c:" , " c:/" };
4242end
4343
44- p{end + 1 } = {' a/b/' , " a " };
45- p{end + 1 } = {' a//b' , " a " };
44+ p{end + 1 } = {' a/b/' , ' a ' };
45+ p{end + 1 } = {' a//b' , ' a ' };
4646
4747end
You can’t perform that action at this time.
0 commit comments