Skip to content

Commit 0ff7fea

Browse files
committed
Clean up whitespace
1 parent abd4a3a commit 0ff7fea

File tree

2 files changed

+192
-187
lines changed

2 files changed

+192
-187
lines changed

src/UnicodeTrie.coffee

+21-21
Original file line numberDiff line numberDiff line change
@@ -4,94 +4,94 @@ class UnicodeTrie
44

55
# Shift size for getting the index-2 table offset.
66
SHIFT_2 = 5
7-
7+
88
# Difference between the two shift sizes,
99
# for getting an index-1 offset from an index-2 offset. 6=11-5
1010
SHIFT_1_2 = SHIFT_1 - SHIFT_2
11-
11+
1212
# Number of index-1 entries for the BMP. 32=0x20
1313
# This part of the index-1 table is omitted from the serialized form.
1414
OMITTED_BMP_INDEX_1_LENGTH = 0x10000 >> SHIFT_1
15-
15+
1616
# Number of entries in an index-2 block. 64=0x40
1717
INDEX_2_BLOCK_LENGTH = 1 << SHIFT_1_2
18-
18+
1919
# Mask for getting the lower bits for the in-index-2-block offset. */
2020
INDEX_2_MASK = INDEX_2_BLOCK_LENGTH - 1
21-
21+
2222
# Shift size for shifting left the index array values.
2323
# Increases possible data size with 16-bit index values at the cost
2424
# of compactability.
2525
# This requires data blocks to be aligned by DATA_GRANULARITY.
2626
INDEX_SHIFT = 2
27-
27+
2828
# Number of entries in a data block. 32=0x20
2929
DATA_BLOCK_LENGTH = 1 << SHIFT_2
30-
30+
3131
# Mask for getting the lower bits for the in-data-block offset.
3232
DATA_MASK = DATA_BLOCK_LENGTH - 1
33-
33+
3434
# The part of the index-2 table for U+D800..U+DBFF stores values for
3535
# lead surrogate code _units_ not code _points_.
3636
# Values for lead surrogate code _points_ are indexed with this portion of the table.
3737
# Length=32=0x20=0x400>>SHIFT_2. (There are 1024=0x400 lead surrogates.)
3838
LSCP_INDEX_2_OFFSET = 0x10000 >> SHIFT_2
3939
LSCP_INDEX_2_LENGTH = 0x400 >> SHIFT_2
40-
40+
4141
# Count the lengths of both BMP pieces. 2080=0x820
4242
INDEX_2_BMP_LENGTH = LSCP_INDEX_2_OFFSET + LSCP_INDEX_2_LENGTH
43-
43+
4444
# The 2-byte UTF-8 version of the index-2 table follows at offset 2080=0x820.
4545
# Length 32=0x20 for lead bytes C0..DF, regardless of SHIFT_2.
4646
UTF8_2B_INDEX_2_OFFSET = INDEX_2_BMP_LENGTH
4747
UTF8_2B_INDEX_2_LENGTH = 0x800 >> 6 # U+0800 is the first code point after 2-byte UTF-8
48-
48+
4949
# The index-1 table, only used for supplementary code points, at offset 2112=0x840.
5050
# Variable length, for code points up to highStart, where the last single-value range starts.
5151
# Maximum length 512=0x200=0x100000>>SHIFT_1.
5252
# (For 0x100000 supplementary code points U+10000..U+10ffff.)
53-
#
53+
#
5454
# The part of the index-2 table for supplementary code points starts
5555
# after this index-1 table.
56-
#
56+
#
5757
# Both the index-1 table and the following part of the index-2 table
5858
# are omitted completely if there is only BMP data.
5959
INDEX_1_OFFSET = UTF8_2B_INDEX_2_OFFSET + UTF8_2B_INDEX_2_LENGTH
60-
60+
6161
# The alignment size of a data block. Also the granularity for compaction.
6262
DATA_GRANULARITY = 1 << INDEX_SHIFT
63-
63+
6464
constructor: (json = {}) ->
6565
@data = json.data or []
6666
@highStart = json.highStart ? 0
6767
@errorValue = json.errorValue ? -1
68-
68+
6969
get: (codePoint) ->
7070
if codePoint < 0 or codePoint > 0x10ffff
7171
return @errorValue
72-
72+
7373
if (codePoint < 0xd800 or (codePoint > 0xdbff and codePoint <= 0xffff))
7474
# Ordinary BMP code point, excluding leading surrogates.
7575
# BMP uses a single level lookup. BMP index starts at offset 0 in the index.
7676
# data is stored in the index array itself.
7777
index = (@data[codePoint >> SHIFT_2] << INDEX_SHIFT) + (codePoint & DATA_MASK)
7878
return @data[index]
79-
79+
8080
if codePoint <= 0xffff
8181
# Lead Surrogate Code Point. A Separate index section is stored for
8282
# lead surrogate code units and code points.
8383
# The main index has the code unit data.
8484
# For this function, we need the code point data.
8585
index = (@data[LSCP_INDEX_2_OFFSET + ((codePoint - 0xd800) >> SHIFT_2)] << INDEX_SHIFT) + (codePoint & DATA_MASK)
8686
return @data[index]
87-
87+
8888
if codePoint < @highStart
8989
# Supplemental code point, use two-level lookup.
9090
index = @data[(INDEX_1_OFFSET - OMITTED_BMP_INDEX_1_LENGTH) + (codePoint >> SHIFT_1)]
9191
index = @data[index + ((codePoint >> SHIFT_2) & INDEX_2_MASK)]
9292
index = (index << INDEX_SHIFT) + (codePoint & DATA_MASK)
9393
return @data[index]
94-
94+
9595
return @data[@data.length - DATA_GRANULARITY]
96-
96+
9797
module.exports = UnicodeTrie

0 commit comments

Comments
 (0)