<commit_before>//===- seec/Util/Error.hpp ------------------------------------------ C++ -===//
//
//                                    SeeC
//
// This file is distributed under The MIT License (MIT). See LICENSE.TXT for
// details.
//
//===----------------------------------------------------------------------===//
///
/// \file
///
//===----------------------------------------------------------------------===//

#ifndef SEEC_UTIL_ERROR_HPP
#define SEEC_UTIL_ERROR_HPP

#include "seec/ICU/LazyMessage.hpp"

#include <memory>


namespace seec {


class Error {
private:
  std::unique_ptr<seec::LazyMessage> Message;
  
public:
  Error(std::unique_ptr<seec::LazyMessage> WithMessage)
  : Message(std::move(WithMessage))
  {}
  
  Error(Error const &) = delete;
  
  Error(Error &&) = default;
  
  Error &operator=(Error const &) = delete;
  
  Error &operator=(Error &&) = default;
  
  UnicodeString getMessage(UErrorCode &Status, Locale const &GetLocale) const {
    if (U_FAILURE(Status))
      return UnicodeString();
    
    if (!Message)
      return UnicodeString();
    
    UnicodeString Msg = Message->get(Status, GetLocale);
    if (U_FAILURE(Status)) {
      return UnicodeString::fromUTF8("Couldn't load error message: ")
             + Message->describe();
    }
    
    return Msg;
  }
};


} // namespace seec
<commit_msg>Add Error::describe(), which gives a description of the message that would be produced (potentially informative even if the message itself cannot be formatted).<commit_after>//===- seec/Util/Error.hpp ------------------------------------------ C++ -===//
//
//                                    SeeC
//
// This file is distributed under The MIT License (MIT). See LICENSE.TXT for
// details.
//
//===----------------------------------------------------------------------===//
///
/// \file
///
//===----------------------------------------------------------------------===//

#ifndef SEEC_UTIL_ERROR_HPP
#define SEEC_UTIL_ERROR_HPP

#include "seec/ICU/LazyMessage.hpp"

#include <memory>


namespace seec {


class Error {
private:
  std::unique_ptr<seec::LazyMessage> Message;
  
public:
  Error(std::unique_ptr<seec::LazyMessage> WithMessage)
  : Message(std::move(WithMessage))
  {}
  
  Error(Error const &) = delete;
  
  Error(Error &&) = default;
  
  Error &operator=(Error const &) = delete;
  
  Error &operator=(Error &&) = default;
  
  UnicodeString getMessage(UErrorCode &Status, Locale const &GetLocale) const {
    if (U_FAILURE(Status))
      return UnicodeString();
    
    if (!Message)
      return UnicodeString();
    
    UnicodeString Msg = Message->get(Status, GetLocale);
    if (U_FAILURE(Status)) {
      return UnicodeString::fromUTF8("Couldn't load error message: ")
             + Message->describe();
    }
    
    return Msg;
  }
  
  UnicodeString describeMessage() const {
    return Message->describe();
  }
};


} // namespace seec

{'fraction_non_alphanumeric': 0.2575445816186557, 'fraction_numerical': 0.0006858710562414266, 'mean_word_length': 1.807507218479307, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '5080189', 'n_tokens_mistral': 851, 'n_tokens_neox': 828, 'n_words': 188}