Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
ef537b0a
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ef537b0a
编写于
6月 03, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
path#normalize - reduce slice-calls
上级
86d32cbe
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
21 deletion
+24
-21
src/vs/base/common/paths.ts
src/vs/base/common/paths.ts
+24
-21
未找到文件。
src/vs/base/common/paths.ts
浏览文件 @
ef537b0a
...
...
@@ -92,57 +92,60 @@ export function normalize(path: string, toOSPath?: boolean): string {
return
path
;
}
le
t
len
=
path
.
length
;
cons
t
len
=
path
.
length
;
if
(
len
===
0
)
{
return
'
.
'
;
}
if
(
_isNormal
(
path
,
isWindows
&&
toOSPath
))
{
const
wantsBackslash
=
isWindows
&&
toOSPath
;
if
(
_isNormal
(
path
,
wantsBackslash
))
{
return
path
;
}
// operate on the 'path-portion' only
const
sep
=
isWindows
&&
toOSPath
?
'
\\
'
:
'
/
'
;
const
sep
=
wantsBackslash
?
'
\\
'
:
'
/
'
;
const
root
=
getRoot
(
path
,
sep
);
path
=
path
.
slice
(
root
.
length
);
len
-=
root
.
length
;
// skip the root-portion of the path
let
start
=
root
.
length
;
let
skip
=
false
;
let
res
=
''
;
let
start
=
0
;
for
(
let
end
=
0
;
end
<=
len
;
end
++
)
{
for
(
let
end
=
root
.
length
;
end
<=
len
;
end
++
)
{
// either at the end or at a path-separator character
if
(
end
===
len
||
path
.
charCodeAt
(
end
)
===
_slash
||
path
.
charCodeAt
(
end
)
===
_backslash
)
{
let
part
=
path
.
slice
(
start
,
end
);
start
=
end
+
1
;
if
(
part
===
'
.
'
&&
(
root
||
res
||
end
<
len
-
1
))
{
// skip current (if there is already something or if there is more to come)
continue
;
}
if
(
part
===
'
..
'
)
{
if
(
streql
(
path
,
start
,
end
,
'
..
'
))
{
// skip current and remove parent (if there is already something)
let
prev_start
=
res
.
lastIndexOf
(
sep
);
let
prev_part
=
res
.
slice
(
prev_start
+
1
);
if
((
root
||
prev_part
.
length
>
0
)
&&
prev_part
!==
'
..
'
)
{
res
=
prev_start
===
-
1
?
''
:
res
.
slice
(
0
,
prev_start
);
contin
ue
;
skip
=
tr
ue
;
}
}
else
if
(
streql
(
path
,
start
,
end
,
'
.
'
)
&&
(
root
||
res
||
end
<
len
-
1
))
{
// skip current (if there is already something or if there is more to come)
skip
=
true
;
}
if
(
res
!==
''
&&
res
[
res
.
length
-
1
]
!==
sep
)
{
res
+=
sep
;
if
(
!
skip
)
{
let
part
=
path
.
slice
(
start
,
end
);
if
(
res
!==
''
&&
res
[
res
.
length
-
1
]
!==
sep
)
{
res
+=
sep
;
}
res
+=
part
;
}
res
+=
part
;
start
=
end
+
1
;
}
}
return
root
+
res
;
}
function
streql
(
value
:
string
,
start
:
number
,
end
:
number
,
other
:
string
):
boolean
{
return
start
+
other
.
length
===
end
&&
value
.
indexOf
(
other
,
start
)
===
start
;
}
/**
* Computes the _root_ this path, like `getRoot('c:\files') === c:\`,
* `getRoot('files:///files/path') === files:///`,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录