File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919
2020module MoonScript
2121 module VLQ
22- VLQ_BASE_SHIFT = 5
23- VLQ_BASE = 1 << VLQ_BASE_SHIFT
24- VLQ_BASE_MASK = VLQ_BASE - 1
22+ VLQ_BASE_SHIFT = 5
23+
24+ VLQ_BASE = 1 << VLQ_BASE_SHIFT
25+
26+ VLQ_BASE_MASK = VLQ_BASE - 1
27+
2528 VLQ_CONTINUATION_BIT = VLQ_BASE
2629
30+ BASE64_DIGITS =
31+ " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" .chars
32+
2733 def self.encode (int )
2834 vlq = to_vlq_signed(int)
2935 encoded = " "
30- cond = True
36+ cond = true
3137
3238 while cond
3339 digit = vlq & VLQ_BASE_MASK
3440 vlq >> = VLQ_BASE_SHIFT
3541 digit |= VLQ_CONTINUATION_BIT if vlq > 0
42+ encoded += base64 _encode(digit)
3643 cond = vlq > 0
3744 end
45+
46+ encoded
3847 end
3948
4049 private def self.base64_encode (int )
41- BASE64_DIGITS [int]? || raise ArgumentError .new " #{ int } is not valid base64 digit"
50+ BASE64_DIGITS [int]? || raise ArgumentError .new " #{ int } is not a valid base64 digit"
4251 end
4352
4453 private def self.to_vlq_signed (int )
45- if int < 0
46- ((- int) << 1 ) + 1
47- else
48- int << 1
54+ if int < 0
55+ ((- int) << 1 ) + 1
56+ else
57+ int << 1
58+ end
4959 end
5060 end
5161end
You can’t perform that action at this time.
0 commit comments