Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
41b5c4cc
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
41b5c4cc
编写于
5月 30, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve paths#getRootLength and add tests
上级
72ebf298
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
25 deletion
+83
-25
src/vs/base/common/paths.ts
src/vs/base/common/paths.ts
+67
-25
src/vs/base/test/common/paths.test.ts
src/vs/base/test/common/paths.test.ts
+16
-0
未找到文件。
src/vs/base/common/paths.ts
浏览文件 @
41b5c4cc
...
...
@@ -112,43 +112,79 @@ export function extname(path: string): string {
return
idx
?
path
.
substring
(
~
idx
)
:
''
;
}
function
getRootLength
(
path
:
string
):
number
{
/**
* Return the length of the denoting part of this path, like `c:\files === 3 (c:\)`,
* `files:///files/path === 8 (files:///)`, or `\\server\shares\path === 16 (\\server\shares\)`
*/
export
function
getRootLength
(
path
:
string
):
number
{
if
(
!
path
)
{
return
0
;
}
path
=
path
.
replace
(
/
\/
|
\\
/g
,
'
/
'
);
if
(
path
[
0
]
===
'
/
'
)
{
if
(
path
[
1
]
!==
'
/
'
)
{
// /far/boo
return
1
;
}
else
{
// //server/far/boo
return
2
;
let
len
=
path
.
length
;
let
code
=
path
.
charCodeAt
(
0
);
if
(
code
===
_slash
||
code
===
_backslash
)
{
code
=
path
.
charCodeAt
(
1
);
if
(
code
===
_slash
||
code
===
_backslash
)
{
// UNC candidate \\localhost\shares\ddd
// ^^^^^^^^^^^^^^^^^^^
let
pos
=
2
;
let
start
=
pos
;
for
(;
pos
<
len
;
pos
++
)
{
code
=
path
.
charCodeAt
(
pos
);
if
(
code
===
_slash
||
code
===
_backslash
)
{
break
;
}
}
if
(
start
!==
pos
)
{
pos
+=
1
;
for
(;
pos
<
len
;
pos
++
)
{
code
=
path
.
charCodeAt
(
pos
);
if
(
code
===
_slash
||
code
===
_backslash
)
{
return
pos
+
1
;
// consume this separator
}
}
}
}
}
if
(
path
[
1
]
===
'
:
'
)
{
if
(
path
[
2
]
===
'
/
'
)
{
// c:/boo/far.txt
return
3
;
}
else
{
// c:
return
2
;
// /user/far
// ^
return
1
;
}
else
if
((
code
>=
_A
&&
code
<=
_Z
)
||
(
code
>=
_a
&&
code
<=
_z
))
{
// check for windows drive letter c:\ or c:
if
(
path
.
charCodeAt
(
1
)
===
_colon
)
{
code
=
path
.
charCodeAt
(
2
);
if
(
code
===
_slash
||
code
===
_backslash
)
{
// C:\fff
// ^^^
return
3
;
}
else
{
// C:
// ^^
return
2
;
}
}
}
if
(
path
.
indexOf
(
'
file:///
'
)
===
0
)
{
return
8
;
// 8 -> 'file:///'.length
// check for URI
// scheme://authority/path
// ^^^^^^^^^^^^^^^^^^^
let
pos
=
path
.
indexOf
(
'
://
'
);
if
(
pos
!==
-
1
)
{
pos
+=
3
;
// 3 -> "://".length
for
(;
pos
<
len
;
pos
++
)
{
code
=
path
.
charCodeAt
(
pos
);
if
(
code
===
_slash
||
code
===
_backslash
)
{
return
pos
+
1
;
// consume this separator
}
}
}
var
idx
=
path
.
indexOf
(
'
://
'
);
if
(
idx
!==
-
1
)
{
return
idx
+
3
;
// 3 -> "://".length
}
return
0
;
}
...
...
@@ -214,6 +250,12 @@ export function isRelative(path: string): boolean {
}
const
_slash
=
'
/
'
.
charCodeAt
(
0
);
const
_backslash
=
'
\\
'
.
charCodeAt
(
0
);
const
_colon
=
'
:
'
.
charCodeAt
(
0
);
const
_a
=
'
a
'
.
charCodeAt
(
0
);
const
_A
=
'
A
'
.
charCodeAt
(
0
);
const
_z
=
'
z
'
.
charCodeAt
(
0
);
const
_Z
=
'
Z
'
.
charCodeAt
(
0
);
export
function
isEqualOrParent
(
path
:
string
,
candidate
:
string
):
boolean
{
...
...
src/vs/base/test/common/paths.test.ts
浏览文件 @
41b5c4cc
...
...
@@ -53,6 +53,22 @@ suite('Paths', () => {
assert
.
equal
(
paths
.
normalize
(
'
/foo/bar.test
'
),
'
/foo/bar.test
'
);
});
test
(
'
getRootLength
'
,
()
=>
{
assert
.
equal
(
paths
.
getRootLength
(
'
/user/far
'
),
1
);
assert
.
equal
(
paths
.
getRootLength
(
'
\\\\
server
\\
share
\\
some
\\
path
'
),
15
);
assert
.
equal
(
paths
.
getRootLength
(
'
//server/share/some/path
'
),
15
);
assert
.
equal
(
paths
.
getRootLength
(
'
//server/share
'
),
1
);
assert
.
equal
(
paths
.
getRootLength
(
'
//server
'
),
1
);
assert
.
equal
(
paths
.
getRootLength
(
'
c:/user/far
'
),
3
);
assert
.
equal
(
paths
.
getRootLength
(
'
c:user/far
'
),
2
);
assert
.
equal
(
paths
.
getRootLength
(
'
http://wwww
'
),
0
);
assert
.
equal
(
paths
.
getRootLength
(
'
http://wwww/
'
),
12
);
assert
.
equal
(
paths
.
getRootLength
(
'
file:///foo
'
),
8
);
assert
.
equal
(
paths
.
getRootLength
(
'
file://foo
'
),
0
);
});
test
(
'
makeAbsolute
'
,
()
=>
{
assert
.
equal
(
paths
.
makeAbsolute
(
'
foo
'
),
'
/foo
'
);
assert
.
equal
(
paths
.
makeAbsolute
(
'
foo/bar
'
),
'
/foo/bar
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录