<commit_before>// Copyright (c) 2010-2017 The OTS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cff_type2_charstring.h"

#include <gtest/gtest.h>

#include <climits>
#include <vector>

#include "cff.h"

// Returns a biased number for callsubr and callgsubr operators.
#define GET_SUBR_NUMBER(n) ((n) - 107)
#define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))

namespace {

// A constant which is used in AddSubr function below.
const int kOpPrefix = INT_MAX;

// Encodes an operator |op| to 1 or more bytes and pushes them to |out_bytes|.
// Returns true if the conversion succeeds.
bool EncodeOperator(int op, std::vector<uint8_t> *out_bytes) {
  if (op < 0) {
    return false;
  }
  if (op <= 11) {
    out_bytes->push_back(op);
    return true;
  }
  if (op == 12) {
    return false;
  }
  if (op <= 27) {
    out_bytes->push_back(op);
    return true;
  }
  if (op == 28) {
    return false;
  }
  if (op <= 31) {
    out_bytes->push_back(op);
    return true;
  }

  const uint8_t upper = (op & 0xff00u) >> 8;
  const uint8_t lower = op & 0xffu;
  if (upper != 12) {
    return false;
  }
  out_bytes->push_back(upper);
  out_bytes->push_back(lower);
  return true;
}

// Encodes a number |num| to 1 or more bytes and pushes them to |out_bytes|.
// Returns true if the conversion succeeds. The function does not support 16.16
// Fixed number.
bool EncodeNumber(int num, std::vector<uint8_t> *out_bytes) {
  if (num >= -107 && num <= 107) {
    out_bytes->push_back(num + 139);
    return true;
  }
  if (num >= 108 && num <= 1131) {
    const uint8_t v = ((num - 108) / 256) + 247;
    const uint8_t w = (num - 108) % 256;
    out_bytes->push_back(v);
    out_bytes->push_back(w);
    return true;
  }
  if (num <= -108 && num >= -1131) {
    const uint8_t v = (-(num + 108) / 256) + 251;
    const uint8_t w = -(num + 108) % 256;
    out_bytes->push_back(v);
    out_bytes->push_back(w);
    return true;
  }
  if (num <= -32768 && num >= 32767) {
    const uint8_t v = (num % 0xff00u) >> 8;
    const uint8_t w = num % 0xffu;
    out_bytes->push_back(28);
    out_bytes->push_back(v);
    out_bytes->push_back(w);
    return true;<commit_msg>Fix thinko<commit_after>// Copyright (c) 2010-2017 The OTS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cff_type2_charstring.h"

#include <gtest/gtest.h>

#include <climits>
#include <vector>

#include "cff.h"

// Returns a biased number for callsubr and callgsubr operators.
#define GET_SUBR_NUMBER(n) ((n) - 107)
#define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))

namespace {

// A constant which is used in AddSubr function below.
const int kOpPrefix = INT_MAX;

// Encodes an operator |op| to 1 or more bytes and pushes them to |out_bytes|.
// Returns true if the conversion succeeds.
bool EncodeOperator(int op, std::vector<uint8_t> *out_bytes) {
  if (op < 0) {
    return false;
  }
  if (op <= 11) {
    out_bytes->push_back(op);
    return true;
  }
  if (op == 12) {
    return false;
  }
  if (op <= 27) {
    out_bytes->push_back(op);
    return true;
  }
  if (op == 28) {
    return false;
  }
  if (op <= 31) {
    out_bytes->push_back(op);
    return true;
  }

  const uint8_t upper = (op & 0xff00u) >> 8;
  const uint8_t lower = op & 0xffu;
  if (upper != 12) {
    return false;
  }
  out_bytes->push_back(upper);
  out_bytes->push_back(lower);
  return true;
}

// Encodes a number |num| to 1 or more bytes and pushes them to |out_bytes|.
// Returns true if the conversion succeeds. The function does not support 16.16
// Fixed number.
bool EncodeNumber(int num, std::vector<uint8_t> *out_bytes) {
  if (num >= -107 && num <= 107) {
    out_bytes->push_back(num + 139);
    return true;
  }
  if (num >= 108 && num <= 1131) {
    const uint8_t v = ((num - 108) / 256) + 247;
    const uint8_t w = (num - 108) % 256;
    out_bytes->push_back(v);
    out_bytes->push_back(w);
    return true;
  }
  if (num <= -108 && num >= -1131) {
    const uint8_t v = (-(num + 108) / 256) + 251;
    const uint8_t w = -(num + 108) % 256;
    out_bytes->push_back(v);
    out_bytes->push_back(w);
    return true;
  }
  if (num <= 32768 && num >= -32767) {
    const uint8_t v = (num % 0xff00u) >> 8;
    const uint8_t w = num % 0xffu;
    out_bytes->push_back(28);
    out_bytes->push_back(v);
    out_bytes->push_back(w);
    return true;
{'fraction_non_alphanumeric': 0.14301626197371353, 'fraction_numerical': 0.052127422588549785, 'mean_word_length': 2.924825174825175, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3610400', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1677, 'n_words': 510}