forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunicode.ts
More file actions
62 lines (59 loc) · 1.77 KB
/
unicode.ts
File metadata and controls
62 lines (59 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
export enum UnicodeCategory {
Unknown,
UppercaseLetter,
LowercaseLetter,
TitlecaseLetter,
ModifierLetter,
OtherLetter,
LetterNumber,
NonSpacingMark,
SpacingCombiningMark,
DecimalDigitNumber,
ConnectorPunctuation,
}
export function getUnicodeCategory(ch: number): UnicodeCategory {
const unicodeLu = require('unicode/category/Lu');
const unicodeLl = require('unicode/category/Ll');
const unicodeLt = require('unicode/category/Lt');
const unicodeLo = require('unicode/category/Lo');
const unicodeLm = require('unicode/category/Lm');
const unicodeNl = require('unicode/category/Nl');
const unicodeMn = require('unicode/category/Mn');
const unicodeMc = require('unicode/category/Mc');
const unicodeNd = require('unicode/category/Nd');
const unicodePc = require('unicode/category/Pc');
if (unicodeLu[ch]) {
return UnicodeCategory.UppercaseLetter;
}
if (unicodeLl[ch]) {
return UnicodeCategory.LowercaseLetter;
}
if (unicodeLt[ch]) {
return UnicodeCategory.TitlecaseLetter;
}
if (unicodeLo[ch]) {
return UnicodeCategory.OtherLetter;
}
if (unicodeLm[ch]) {
return UnicodeCategory.ModifierLetter;
}
if (unicodeNl[ch]) {
return UnicodeCategory.LetterNumber;
}
if (unicodeMn[ch]) {
return UnicodeCategory.NonSpacingMark;
}
if (unicodeMc[ch]) {
return UnicodeCategory.SpacingCombiningMark;
}
if (unicodeNd[ch]) {
return UnicodeCategory.DecimalDigitNumber;
}
if (unicodePc[ch]) {
return UnicodeCategory.ConnectorPunctuation;
}
return UnicodeCategory.Unknown;
}