Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a304998c
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,发现更多精彩内容 >>
提交
a304998c
编写于
3月 03, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - modernize uuid and remove unused stuff
上级
076c919a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
53 addition
and
103 deletion
+53
-103
src/vs/base/common/uuid.ts
src/vs/base/common/uuid.ts
+45
-92
src/vs/base/test/common/uuid.test.ts
src/vs/base/test/common/uuid.test.ts
+7
-6
src/vs/workbench/contrib/tasks/test/common/configuration.test.ts
...workbench/contrib/tasks/test/common/configuration.test.ts
+1
-5
未找到文件。
src/vs/base/common/uuid.ts
浏览文件 @
a304998c
...
...
@@ -3,87 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* Represents a UUID as defined by rfc4122.
*/
export
interface
UUID
{
/**
* @returns the canonical representation in sets of hexadecimal numbers separated by dashes.
*/
asHex
():
string
;
}
class
ValueUUID
implements
UUID
{
constructor
(
public
_value
:
string
)
{
// empty
}
public
asHex
():
string
{
return
this
.
_value
;
}
}
class
V4UUID
extends
ValueUUID
{
private
static
readonly
_chars
=
[
'
0
'
,
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
,
'
5
'
,
'
6
'
,
'
7
'
,
'
8
'
,
'
9
'
,
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
,
'
e
'
,
'
f
'
];
private
static
readonly
_timeHighBits
=
[
'
8
'
,
'
9
'
,
'
a
'
,
'
b
'
];
private
static
_oneOf
(
array
:
string
[]):
string
{
return
array
[
Math
.
floor
(
array
.
length
*
Math
.
random
())];
}
private
static
_randomHex
():
string
{
return
V4UUID
.
_oneOf
(
V4UUID
.
_chars
);
}
constructor
()
{
super
([
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
'
-
'
,
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
'
-
'
,
'
4
'
,
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
'
-
'
,
V4UUID
.
_oneOf
(
V4UUID
.
_timeHighBits
),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
'
-
'
,
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
V4UUID
.
_randomHex
(),
].
join
(
''
));
}
}
export
function
v4
():
UUID
{
return
new
V4UUID
();
}
const
_UUIDPattern
=
/^
[
0-9a-f
]{8}
-
[
0-9a-f
]{4}
-
[
0-9a-f
]{4}
-
[
0-9a-f
]{4}
-
[
0-9a-f
]{12}
$/i
;
...
...
@@ -91,18 +10,52 @@ export function isUUID(value: string): boolean {
return
_UUIDPattern
.
test
(
value
);
}
/**
* Parses a UUID that is of the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
* @param value A uuid string.
*/
export
function
parse
(
value
:
string
):
UUID
{
if
(
!
isUUID
(
value
))
{
throw
new
Error
(
'
invalid uuid
'
);
}
return
new
ValueUUID
(
value
);
// prep-work
const
_data
=
new
Uint8Array
(
16
);
const
_hex
:
string
[]
=
[];
for
(
let
i
=
0
;
i
<
256
;
i
++
)
{
_hex
.
push
(
i
.
toString
(
16
).
padStart
(
2
,
'
0
'
));
}
const
_fillRandomValues
=
typeof
crypto
===
'
object
'
?
crypto
.
getRandomValues
.
bind
(
crypto
)
:
function
(
bucket
:
Uint8Array
):
Uint8Array
{
// todo@jrieken node nodejs use `crypto#randomBytes`, see: https://nodejs.org/docs/latest/api/crypto.html#crypto_crypto_randombytes_size_callback
for
(
let
i
=
0
;
i
<
bucket
.
length
;
i
++
)
{
bucket
[
i
]
=
Math
.
floor
(
Math
.
random
()
*
256
);
}
return
bucket
;
};
export
function
generateUuid
():
string
{
return
v4
().
asHex
();
// get data
_fillRandomValues
(
_data
);
// set version bits
_data
[
6
]
=
(
_data
[
6
]
&
0x0f
)
|
0x40
;
_data
[
8
]
=
(
_data
[
8
]
&
0x3f
)
|
0x80
;
// print as string
let
i
=
0
;
let
result
=
''
;
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
'
-
'
;
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
'
-
'
;
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
'
-
'
;
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
'
-
'
;
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
result
+=
_hex
[
_data
[
i
++
]];
return
result
;
}
src/vs/base/test/common/uuid.test.ts
浏览文件 @
a304998c
...
...
@@ -7,16 +7,17 @@ import * as uuid from 'vs/base/common/uuid';
suite
(
'
UUID
'
,
()
=>
{
test
(
'
generation
'
,
()
=>
{
const
asHex
=
uuid
.
v4
().
asHex
();
const
asHex
=
uuid
.
generateUuid
();
assert
.
equal
(
asHex
.
length
,
36
);
assert
.
equal
(
asHex
[
14
],
'
4
'
);
assert
.
ok
(
asHex
[
19
]
===
'
8
'
||
asHex
[
19
]
===
'
9
'
||
asHex
[
19
]
===
'
a
'
||
asHex
[
19
]
===
'
b
'
);
});
test
(
'
parse
'
,
()
=>
{
const
id
=
uuid
.
v4
();
const
asHext
=
id
.
asHex
();
const
id2
=
uuid
.
parse
(
asHext
);
assert
.
equal
(
id
.
asHex
(),
id2
.
asHex
());
test
(
'
self-check
'
,
function
()
{
const
t1
=
Date
.
now
();
while
(
Date
.
now
()
-
t1
<
50
)
{
const
value
=
uuid
.
generateUuid
();
assert
.
ok
(
uuid
.
isUUID
(
value
));
}
});
});
src/vs/workbench/contrib/tasks/test/common/configuration.test.ts
浏览文件 @
a304998c
...
...
@@ -514,11 +514,7 @@ function assertProblemMatcher(actual: string | ProblemMatcher, expected: string
}
if
(
typeof
actual
!==
'
string
'
&&
typeof
expected
!==
'
string
'
)
{
if
(
expected
.
owner
===
ProblemMatcherBuilder
.
DEFAULT_UUID
)
{
try
{
UUID
.
parse
(
actual
.
owner
);
}
catch
(
err
)
{
assert
.
fail
(
actual
.
owner
,
'
Owner must be a UUID
'
);
}
assert
.
ok
(
UUID
.
isUUID
(
actual
.
owner
),
'
Owner must be a UUID
'
);
}
else
{
assert
.
strictEqual
(
actual
.
owner
,
expected
.
owner
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录