#ifndef JES_TEXT_H
#define JES_TEXT_H

#include <stdint.h>
#include "jes/Ref.h"
#include <string>

namespace jes
{
    class Text
    {
    public:
        typedef char Character;
        Text();
        Text(const uint8_t buf[], size_t size);
        size_t get_size() { return m_size - m_gap_size; }

        Character operator[](size_t index)
        {
            return (Character)(m_buffer[index < m_gap_index ? index : index + m_gap_size]);
        }

        std::string to_s();

    protected:
        void compact();

        uint8_t * m_buffer;
        size_t m_size;
        size_t m_gap_index;
        size_t m_gap_size;
    };
    typedef Ref<Text> TextRef;
}

#endif
