<commit_before>// For conditions of distribution and use, see copyright notice in license.txt

#ifndef __incl_Core_Exception_h__
#define __incl_Core_Exception_h__

namespace Core
{
    class Exception : public std::exception
    {
    public:
        Exception() : std::exception() {}

        explicit Exception(const char *exception) : std::exception(), exception_(exception) {}

        Exception(const Exception &other)
        {
            exception_ = other.exception_;
        }

        virtual ~Exception() {}

        virtual const char *what () const throw ()
        {
            return exception_;
        }
    private:
        const char *exception_;
    };
}
#endif

<commit_msg>Fixed exception class. should be safer now to use.<commit_after>// For conditions of distribution and use, see copyright notice in license.txt

#ifndef __incl_Core_Exception_h__
#define __incl_Core_Exception_h__

namespace Core
{
    //! Generic exception class.
    /*! 
        \note Uses non-safe string manipulation, so do not supply exception parameters from outside source!
    */
    class Exception : public std::exception
    {
    public:
        Exception() : std::exception(), what_(0), do_free_(0) {}

        explicit Exception(const char * const& what) : std::exception()
        {
            do_free_ = 1;

            int len = strlen(what);
            what_ = static_cast< char* >(malloc(len + 1));
            strcpy(const_cast< char* >(what_), what);
        }

        Exception(const Exception &other)
        {
            do_free_ = other.do_free_;

            if (do_free_)
            {
                int len = strlen(other.what_);
                what_ = static_cast< char* >(malloc(len + 1));
                strcpy(const_cast< char* >(what_), other.what_);
            } else
            {
                what_ = other.what_;
            }
        }

        Exception& operator =(const Exception &other)
        {
            if (this != &other)
            {
                do_free_ = other.do_free_;

                if (do_free_)
                {
                    int len = strlen(other.what_);
                    what_ = static_cast< char* >(malloc(len + 1));
                    strcpy(const_cast< char* >(what_), other.what_);
                } else
                {
                    what_ = other.what_;
                }
            }

            return *this;
        }

        virtual ~Exception()
        {
            if (do_free_)
            {
                free(const_cast< char* >(what_));
            }
        }

        virtual const char *what () const throw ()
        {
            if (what_ != 0)
                return what_;
            else
                return "Unknown exception";
        }
    private:
        const char *what_;
        int do_free_;
    };
}
#endif


{'fraction_non_alphanumeric': 0.09870038637161925, 'fraction_numerical': 0.0024587284861257463, 'mean_word_length': 1.4960560911481158, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3785246', 'n_tokens_mistral': 774, 'n_tokens_neox': 741, 'n_words': 203}