File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 55% %% Outputs
66% filename (including suffix) without directory
77
8- function f = filename(p )
8+ function f = filename(p , method )
9+ arguments
10+ p
11+ method = ' pattern'
12+ end
913
10- f = extractAfter(p , asManyOfPattern(wildcardPattern + (" /" | filesep )));
14+ % the pattern method is a few percent faster than regexp
15+ switch method
16+ case ' pattern' , f = extractAfter(p , asManyOfPattern(wildcardPattern + (" /" | filesep )));
17+ case ' regexp'
18+ f = regexp(p , [' [^/\' filesep ' ]*$' ], ' match' , ' once' );
19+ try % #ok<TRYNC>
20+ f(ismissing(f )) = " " ;
21+ end
22+ otherwise , error(' unknown method %s ' , method )
23+ end
1124
1225end
Original file line number Diff line number Diff line change 33properties (TestParameter )
44p = init_p()
55e = {' /a/b/c/' , " a/b/c/" }
6+ method = {' pattern' , ' regexp' }
67end
78
89methods (TestClassSetup )
@@ -13,12 +14,15 @@ function pkg_path(tc)
1314end
1415
1516methods (Test , TestTags = " pure" )
16- function test_filename(tc , p )
17- tc .verifyEqual(stdlib .filename(p{1 }), p{2 })
17+
18+ function test_filename(tc , p , method )
19+ fn = stdlib .filename(p{1 }, method );
20+ tc .verifyEqual(fn , p{2 })
1821end
1922
20- function test_filename_empty(tc , e )
21- tc .verifyEqual(strlength(stdlib .filename(e )), 0 )
23+ function test_filename_empty(tc , e , method )
24+ fn = stdlib .filename(e , method );
25+ tc .verifyEqual(strlength(fn ), 0 )
2226end
2327
2428end
You can’t perform that action at this time.
0 commit comments