File tree Expand file tree Collapse file tree 5 files changed +25
-27
lines changed Expand file tree Collapse file tree 5 files changed +25
-27
lines changed Original file line number Diff line number Diff line change 22% ROOT(P) returns the root path of P.
33
44function r = root(p )
5- arguments
6- p {mustBeTextScalar }
7- end
85
96r = strcat(stdlib .root_name(p ), stdlib .root_dir(p ));
107
Original file line number Diff line number Diff line change 11%% ROOT_DIR get root directory
22% Examples:
3-
3+ %
44%% Windows
55% * root_dir('C:\path\to\file') returns '\'
66% * root_dir('C:path\to\file') returns ''
1313 p {mustBeTextScalar }
1414end
1515
16- matches = regexp(p , ' ^([/\\ ])|^[A-Za-z]:([/\\ ])' , ' tokens' );
17-
18- if isempty(matches )
16+ sep = characterListPattern(" /" + filesep());
17+ pat = (textBoundary + sep );
18+ if ispc()
19+ pat = pat | (lookBehindBoundary(lettersPattern(1 ) + " :" ) + sep );
20+ end
1921
22+ r = extract(p , pat );
23+ if isempty(r )
2024 r = ' ' ;
2125 if isstring(p )
2226 r = " " ;
2327 end
24-
25- else
26-
27- r = matches{1 };
28- if iscell(r )
29- r = r{1 };
30- end
31-
28+ elseif iscell(r )
29+ r = r{1 };
3230end
3331
3432end
Original file line number Diff line number Diff line change 1010 p {mustBeTextScalar }
1111end
1212
13- r = ' ' ;
14-
15- if ~ispc() || strlength(p ) < 2
16- % noop
13+ if ispc()
14+ r = extract(p , textBoundary + lettersPattern(1 ) + " :" );
15+ if ~isempty(r ) && iscell(r )
16+ r = r{1 };
17+ end
1718else
18- c = char(p );
19+ r = ' ' ;
20+ end
1921
20- if c(2 ) == ' :' && isletter(c(1 ))
21- r = c(1 : 2 );
22+ if isempty(r )
23+ r = ' ' ;
24+ if isstring(p )
25+ r = " " ;
2226 end
2327end
2428
25- if isstring(p )
26- r = string(r );
27- end
2829
2930end
3031
Original file line number Diff line number Diff line change 1717cnomex = ~HasTag(" exe" ) & ~HasTag(" mex" ) & ~HasTag(" java" );
1818if ispc()
1919 cnomex = cnomex & ~HasTag(" unix" );
20+ else
21+ cnomex = cnomex & ~HasTag(" windows" );
2022end
2123
2224cmex = HasTag(" mex" );
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ function test_root(tc, p)
1313end
1414
1515function test_root_dir(tc , rd )
16- tc .verifyEqual(stdlib .root_dir(rd{1 }), rd{2 })
16+ tc .verifyEqual(stdlib .root_dir(rd{1 }), rd{2 }, " root_dir( " + rd{ 1 } + " ) " )
1717end
1818
1919function test_root_name(tc , rn )
@@ -36,7 +36,7 @@ function test_root_name(tc, rn)
3636{" c:/etc" , " " }, ...
3737{' c:\etc' , ' ' }};
3838
39- if ispc
39+ if ispc()
4040p{6 }{2 } = " c:" ;
4141p{7 }{2 } = " c:/" ;
4242p{8 }{2 } = ' c:\' ;
You can’t perform that action at this time.
0 commit comments