Blame src/base64vlq.cpp

Packit Service 7770af
#include "sass.hpp"
Packit Service 7770af
#include "base64vlq.hpp"
Packit Service 7770af
Packit Service 7770af
namespace Sass {
Packit Service 7770af
Packit Service 7770af
  std::string Base64VLQ::encode(const int number) const
Packit Service 7770af
  {
Packit Service 7770af
    std::string encoded = "";
Packit Service 7770af
Packit Service 7770af
    int vlq = to_vlq_signed(number);
Packit Service 7770af
Packit Service 7770af
    do {
Packit Service 7770af
      int digit = vlq & VLQ_BASE_MASK;
Packit Service 7770af
      vlq >>= VLQ_BASE_SHIFT;
Packit Service 7770af
      if (vlq > 0) {
Packit Service 7770af
        digit |= VLQ_CONTINUATION_BIT;
Packit Service 7770af
      }
Packit Service 7770af
      encoded += base64_encode(digit);
Packit Service 7770af
    } while (vlq > 0);
Packit Service 7770af
Packit Service 7770af
    return encoded;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  char Base64VLQ::base64_encode(const int number) const
Packit Service 7770af
  {
Packit Service 7770af
    int index = number;
Packit Service 7770af
    if (index < 0) index = 0;
Packit Service 7770af
    if (index > 63) index = 63;
Packit Service 7770af
    return CHARACTERS[index];
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  int Base64VLQ::to_vlq_signed(const int number) const
Packit Service 7770af
  {
Packit Service 7770af
    return (number < 0) ? ((-number) << 1) + 1 : (number << 1) + 0;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  const char* Base64VLQ::CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
Packit Service 7770af
Packit Service 7770af
  const int Base64VLQ::VLQ_BASE_SHIFT = 5;
Packit Service 7770af
  const int Base64VLQ::VLQ_BASE = 1 << VLQ_BASE_SHIFT;
Packit Service 7770af
  const int Base64VLQ::VLQ_BASE_MASK = VLQ_BASE - 1;
Packit Service 7770af
  const int Base64VLQ::VLQ_CONTINUATION_BIT = VLQ_BASE;
Packit Service 7770af
Packit Service 7770af
}