mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
@@ -26,6 +26,7 @@
|
||||
require('../platform/CCSys');
|
||||
|
||||
var EXTNAME_RE = /(\.[^\.\/\?\\]*)(\?.*)?$/;
|
||||
var DIRNAME_RE = /((.*)(\/|\\|\\\\))?(.*?\..*$)?/;
|
||||
var NORMALIZE_RE = /[^\.\/]+\/\.\.\//;
|
||||
|
||||
/**
|
||||
@@ -104,7 +105,8 @@ cc.path = /** @lends cc.path# */{
|
||||
* @returns {*}
|
||||
*/
|
||||
dirname: function (pathStr) {
|
||||
return pathStr.replace(/((.*)(\/|\\|\\\\))?(.*?\..*$)?/, '$2');
|
||||
var temp = DIRNAME_RE.exec(pathStr);
|
||||
return temp ? temp[2] : '';
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
module('cc.path', SetupEngine);
|
||||
|
||||
test('dirname', function () {
|
||||
|
||||
ok(cc.path.dirname('aa/bb/cc') === 'aa/bb', 'get success');
|
||||
ok(cc.path.dirname('aa/bb/cc.png') === 'aa/bb', 'get success');
|
||||
ok(cc.path.dirname('aa/bb/cc/') === 'aa/bb/cc', 'get success');
|
||||
ok(cc.path.dirname('aa/bb/cc.png/ee.png') === 'aa/bb/cc.png', 'get success');
|
||||
ok(cc.path.dirname('D:\\aa\\bb') === 'D:\\aa', 'get success');
|
||||
ok(cc.path.dirname('aa/bb/.github/.gitignore') === 'aa/bb/.github', 'get success');
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user