Initial commit
[yaffs-website] / node_modules / node-sass / src / libsass / src / base64vlq.cpp
1 #include "sass.hpp"
2 #include "base64vlq.hpp"
3
4 namespace Sass {
5
6   std::string Base64VLQ::encode(const int number) const
7   {
8     std::string encoded = "";
9
10     int vlq = to_vlq_signed(number);
11
12     do {
13       int digit = vlq & VLQ_BASE_MASK;
14       vlq >>= VLQ_BASE_SHIFT;
15       if (vlq > 0) {
16         digit |= VLQ_CONTINUATION_BIT;
17       }
18       encoded += base64_encode(digit);
19     } while (vlq > 0);
20
21     return encoded;
22   }
23
24   char Base64VLQ::base64_encode(const int number) const
25   {
26     int index = number;
27     if (index < 0) index = 0;
28     if (index > 63) index = 63;
29     return CHARACTERS[index];
30   }
31
32   int Base64VLQ::to_vlq_signed(const int number) const
33   {
34     return (number < 0) ? ((-number) << 1) + 1 : (number << 1) + 0;
35   }
36
37   const char* Base64VLQ::CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
38
39   const int Base64VLQ::VLQ_BASE_SHIFT = 5;
40   const int Base64VLQ::VLQ_BASE = 1 << VLQ_BASE_SHIFT;
41   const int Base64VLQ::VLQ_BASE_MASK = VLQ_BASE - 1;
42   const int Base64VLQ::VLQ_CONTINUATION_BIT = VLQ_BASE;
43
44 }