<commit_before>/*
 * Copyright (c) 2010, The Infrastructure Developers Group
 * All rights reserved.
 *
 * This file is subject to the New BSD License (see the LICENSE file).
 */

#include "utils.h"

#include <limits.h>
#include <pthread.h>
#include <stdlib.h>

namespace tyrion {

std::string CreateError(std::string code, std::string message) {
  Escape(message);
  return "Error: org.tyrion.error." + code + (!message.empty() ? ": " +
      message : message) + "\n";
}

void Escape(std::string& text) {
  StringReplace(text, "\n", "\\n");
  StringReplace(text, "\r", "\\r");
}

std::string RealPath(const std::string& path) {
  char buffer[PATH_MAX + 1];
  char *rc = realpath(path.c_str(), buffer);

  return rc ? std::string(buffer) : "";
}

void StringReplace(std::string& text, const std::string& search,
                   const std::string& replace) {
  std::string::size_type pos = text.find(search);

  while (pos != std::string::npos) {
    text.replace(pos, search.length(), replace);
    pos = text.find(search, pos+search.length());
  }
}

}  // namespace tyrion<commit_msg>Capitalize ERROR: in error line<commit_after>/*
 * Copyright (c) 2010, The Infrastructure Developers Group
 * All rights reserved.
 *
 * This file is subject to the New BSD License (see the LICENSE file).
 */

#include "utils.h"

#include <limits.h>
#include <pthread.h>
#include <stdlib.h>

namespace tyrion {

std::string CreateError(std::string code, std::string message) {
  Escape(message);
  return "ERROR: org.tyrion.error." + code + (!message.empty() ? ": " +
      message : message) + "\n";
}

void Escape(std::string& text) {
  StringReplace(text, "\n", "\\n");
  StringReplace(text, "\r", "\\r");
}

std::string RealPath(const std::string& path) {
  char buffer[PATH_MAX + 1];
  char *rc = realpath(path.c_str(), buffer);

  return rc ? std::string(buffer) : "";
}

void StringReplace(std::string& text, const std::string& search,
                   const std::string& replace) {
  std::string::size_type pos = text.find(search);

  while (pos != std::string::npos) {
    text.replace(pos, search.length(), replace);
    pos = text.find(search, pos+search.length());
  }
}

}  // namespace tyrion
{'fraction_non_alphanumeric': 0.1751592356687898, 'fraction_numerical': 0.004549590536851683, 'mean_word_length': 3.8758314855875833, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5952008', 'n_tokens_mistral': 750, 'n_tokens_neox': 721, 'n_words': 191}