/src/libsass/src/base64vlq.cpp
Line | Count | Source |
1 | | // sass.hpp must go before all system headers to get the |
2 | | // __EXTENSIONS__ fix on Solaris. |
3 | | #include "sass.hpp" |
4 | | |
5 | | #include "base64vlq.hpp" |
6 | | |
7 | | namespace Sass { |
8 | | |
9 | | sass::string Base64VLQ::encode(const int number) const |
10 | 0 | { |
11 | 0 | sass::string encoded = ""; |
12 | |
|
13 | 0 | int vlq = to_vlq_signed(number); |
14 | |
|
15 | 0 | do { |
16 | 0 | int digit = vlq & VLQ_BASE_MASK; |
17 | 0 | vlq >>= VLQ_BASE_SHIFT; |
18 | 0 | if (vlq > 0) { |
19 | 0 | digit |= VLQ_CONTINUATION_BIT; |
20 | 0 | } |
21 | 0 | encoded += base64_encode(digit); |
22 | 0 | } while (vlq > 0); |
23 | |
|
24 | 0 | return encoded; |
25 | 0 | } |
26 | | |
27 | | char Base64VLQ::base64_encode(const int number) const |
28 | 0 | { |
29 | 0 | int index = number; |
30 | 0 | if (index < 0) index = 0; |
31 | 0 | if (index > 63) index = 63; |
32 | 0 | return CHARACTERS[index]; |
33 | 0 | } |
34 | | |
35 | | int Base64VLQ::to_vlq_signed(const int number) const |
36 | 0 | { |
37 | 0 | return (number < 0) ? ((-number) << 1) + 1 : (number << 1) + 0; |
38 | 0 | } |
39 | | |
40 | | const char* Base64VLQ::CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
41 | | |
42 | | const int Base64VLQ::VLQ_BASE_SHIFT = 5; |
43 | | const int Base64VLQ::VLQ_BASE = 1 << VLQ_BASE_SHIFT; |
44 | | const int Base64VLQ::VLQ_BASE_MASK = VLQ_BASE - 1; |
45 | | const int Base64VLQ::VLQ_CONTINUATION_BIT = VLQ_BASE; |
46 | | |
47 | | } |