<commit_before>#include "oniguruma.h"
#include "onig-scanner.h"
#include "onig-reg-exp.h"
#include "onig-result.h"
#include "unicode-utils.h"

using ::v8::Function;
using ::v8::FunctionTemplate;
using ::v8::HandleScope;
using ::v8::Local;
using ::v8::Null;
using ::v8::Persistent;

void OnigScanner::Init(Handle<Object> target) {
  Local<FunctionTemplate> tpl = FunctionTemplate::New(OnigScanner::New);
  tpl->SetClassName(String::NewSymbol("OnigScanner"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  tpl->PrototypeTemplate()->Set(String::NewSymbol("findNextMatch"), FunctionTemplate::New(OnigScanner::FindNextMatch)->GetFunction());

  Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
  target->Set(String::NewSymbol("OnigScanner"), constructor);
}

NODE_MODULE(onig_scanner, OnigScanner::Init)

Handle<Value> OnigScanner::New(const Arguments& args) {
  HandleScope scope;
  OnigScanner* scanner = new OnigScanner(Local<Array>::Cast(args[0]));
  scanner->Wrap(args.This());
  return args.This();
}

Handle<Value> OnigScanner::FindNextMatch(const Arguments& args) {
  HandleScope scope;
  OnigScanner* scanner = node::ObjectWrap::Unwrap<OnigScanner>(args.This());
  return scope.Close(scanner->FindNextMatch(Local<String>::Cast(args[0]), Local<Number>::Cast(args[1]), args.This()));
}

OnigScanner::OnigScanner(Handle<Array> sources) {
  int length = sources->Length();
  regExps.resize(length);
  cachedResults.resize(length);

  for (int i = 0; i < length; i++) {
    String::Utf8Value utf8Value(sources->Get(i));
    regExps[i] = unique_ptr<OnigRegExp>(new OnigRegExp(string(*utf8Value)));
  }
};

OnigScanner::~OnigScanner() {};

Handle<Value> OnigScanner::FindNextMatch(Handle<String> v8String, Handle<Number> v8StartLocation, Handle<Value> v8Scanner) {
  String::Utf8Value utf8Value(v8String);
  string string(*utf8Value);
  int startLocation = UnicodeUtils::bytes_in_characters(string.data(), v8StartLocation->Value());
  int bestIndex = -1;
  int bestLocation = NULL;
  OnigResult* bestResult = NULL;

  bool useCachedResults = (string == lastMatchedString && startLocation >= lastStartLocation);
  lastStartLocation = startLocation;

  if (!useCachedResults) {
    ClearCachedResults();
    lastMatchedString = string;
  }

  vector< unique_ptr<OnigRegExp> >::iterator iter = regExps.begin();
  int index = 0;
  while (iter < regExps.end()) {
    OnigRegExp *regExp = (*iter).get();

    bool useCachedResult = false;<commit_msg>:lipstick: Fix compiler warnings.<commit_after>#include "oniguruma.h"
#include "onig-scanner.h"
#include "onig-reg-exp.h"
#include "onig-result.h"
#include "unicode-utils.h"

using ::v8::Function;
using ::v8::FunctionTemplate;
using ::v8::HandleScope;
using ::v8::Local;
using ::v8::Null;
using ::v8::Persistent;

void OnigScanner::Init(Handle<Object> target) {
  Local<FunctionTemplate> tpl = FunctionTemplate::New(OnigScanner::New);
  tpl->SetClassName(String::NewSymbol("OnigScanner"));
  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  tpl->PrototypeTemplate()->Set(String::NewSymbol("findNextMatch"), FunctionTemplate::New(OnigScanner::FindNextMatch)->GetFunction());

  Persistent<Function> constructor = Persistent<Function>::New(tpl->GetFunction());
  target->Set(String::NewSymbol("OnigScanner"), constructor);
}

NODE_MODULE(onig_scanner, OnigScanner::Init)

Handle<Value> OnigScanner::New(const Arguments& args) {
  HandleScope scope;
  OnigScanner* scanner = new OnigScanner(Local<Array>::Cast(args[0]));
  scanner->Wrap(args.This());
  return args.This();
}

Handle<Value> OnigScanner::FindNextMatch(const Arguments& args) {
  HandleScope scope;
  OnigScanner* scanner = node::ObjectWrap::Unwrap<OnigScanner>(args.This());
  return scope.Close(scanner->FindNextMatch(Local<String>::Cast(args[0]), Local<Number>::Cast(args[1]), args.This()));
}

OnigScanner::OnigScanner(Handle<Array> sources) {
  int length = sources->Length();
  regExps.resize(length);
  cachedResults.resize(length);

  for (int i = 0; i < length; i++) {
    String::Utf8Value utf8Value(sources->Get(i));
    regExps[i] = unique_ptr<OnigRegExp>(new OnigRegExp(string(*utf8Value)));
  }
}

OnigScanner::~OnigScanner() {}

Handle<Value> OnigScanner::FindNextMatch(Handle<String> v8String, Handle<Number> v8StartLocation, Handle<Value> v8Scanner) {
  String::Utf8Value utf8Value(v8String);
  string string(*utf8Value);
  int startLocation = UnicodeUtils::bytes_in_characters(string.data(), v8StartLocation->Value());
  int bestIndex = -1;
  int bestLocation = 0;
  OnigResult* bestResult = NULL;

  bool useCachedResults = (string == lastMatchedString && startLocation >= lastStartLocation);
  lastStartLocation = startLocation;

  if (!useCachedResults) {
    ClearCachedResults();
    lastMatchedString = string;
  }

  vector< unique_ptr<OnigRegExp> >::iterator iter = regExps.begin();
  int index = 0;
  while (iter < regExps.end()) {
    OnigRegExp *regExp = (*iter).get();

    bool useCachedResult = false;
{'fraction_non_alphanumeric': 0.16201565950612326, 'fraction_numerical': 0.009837382051796828, 'mean_word_length': 6.945773524720893, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 67, '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': '6469398', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1668, 'n_words': 280}