<commit_before>#include "pawlib/onestring.hpp"

namespace pawlib
{
    /*******************************************
    * Constructors + Destructor
    *******************************************/
    onestring::onestring()
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        //assign('\0');
    }

    onestring::onestring(char ch)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        assign(ch);
    }

    onestring::onestring(const onechar& ochr)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        assign(ochr);
    }

    onestring::onestring(const char* cstr)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        assign(cstr);
    }

    onestring::onestring(const std::string& str)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        append(str);
    }

    onestring::onestring(const onestring& ostr)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        assign(ostr);
    }

    onestring::~onestring()
    {
        if (_c_str != nullptr)
        {
            delete[] _c_str;
        }

        if (internal != nullptr)
        {
            delete[] internal;
        }
    }

    /*******************************************
    * Memory Management
    *******************************************/

    void onestring::allocate(size_t capacity)
    {
        this->_capacity = capacity;

        // If we're allocating down, throw away the excess elements.
        if (this->_elements > this->_capacity)
        {
            this->_elements = this->_capacity;
        }

        // TODO: Would it be better to use realloc? (If so, be sure to throw bad_alloc as needed)

        // Allocate a new array with the new size.
        onechar* newArr = new onechar[this->_capacity];

        // If an old array exists...
        if(this->internal != nullptr)
        {
            // Move the contents over<commit_msg>Dismissed idea of realloc for onestring<commit_after>#include "pawlib/onestring.hpp"

namespace pawlib
{
    /*******************************************
    * Constructors + Destructor
    *******************************************/
    onestring::onestring()
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        //assign('\0');
    }

    onestring::onestring(char ch)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        assign(ch);
    }

    onestring::onestring(const onechar& ochr)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        assign(ochr);
    }

    onestring::onestring(const char* cstr)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        assign(cstr);
    }

    onestring::onestring(const std::string& str)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        append(str);
    }

    onestring::onestring(const onestring& ostr)
    :_capacity(BASE_SIZE), _elements(0), internal(nullptr), _c_str(0)
    {
        allocate(this->_capacity);
        assign(ostr);
    }

    onestring::~onestring()
    {
        if (_c_str != nullptr)
        {
            delete[] _c_str;
        }

        if (internal != nullptr)
        {
            delete[] internal;
        }
    }

    /*******************************************
    * Memory Management
    *******************************************/

    void onestring::allocate(size_t capacity)
    {
        this->_capacity = capacity;

        // If we're allocating down, throw away the excess elements.
        if (this->_elements > this->_capacity)
        {
            this->_elements = this->_capacity;
        }

        // Allocate a new array with the new size.
        onechar* newArr = new onechar[this->_capacity];

        // If an old array exists...
        if(this->internal != nullptr)
        {
            // Move the contents over
{'fraction_non_alphanumeric': 0.19936058460835807, 'fraction_numerical': 0.00593742863667504, 'mean_word_length': 2.4789515488482925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '2623539', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1292, 'n_words': 245}