pass encoding to GapBuffer

This commit is contained in:
Josh Holtrop 2016-11-02 20:36:35 -04:00
parent 2598b10e36
commit a865ff0163
3 changed files with 10 additions and 6 deletions

View File

@ -22,7 +22,7 @@ Buffer::Buffer(const char * filename)
void Buffer::load_empty_buffer()
{
m_gap_buffer = std::make_shared<GapBuffer>();
m_gap_buffer = std::make_shared<GapBuffer>(Encoding::UTF_8);
m_eol_at_eof = true;
}
@ -57,7 +57,7 @@ bool Buffer::load_from_file(const char * filename)
size_t loaded_size;
text_loader.load_buffer(buffer, file_size, &loaded_size);
m_gap_buffer = std::make_shared<GapBuffer>(buffer, buffer_size, loaded_size);
m_gap_buffer = std::make_shared<GapBuffer>(buffer, buffer_size, loaded_size, text_loader.get_encoding());
m_eol_at_eof = text_loader.get_eol_at_eof();
return true;

View File

@ -1,20 +1,22 @@
#include "GapBuffer.h"
#include "System.h"
GapBuffer::GapBuffer()
GapBuffer::GapBuffer(Encoding::Type encoding)
{
m_buffer = (uint8_t *)System::alloc_pages(1u);
m_buffer_size = System::page_size;
m_size = 0u;
m_gap_position = 0u;
m_encoding = encoding;
}
GapBuffer::GapBuffer(uint8_t * buffer, size_t buffer_size, size_t size)
GapBuffer::GapBuffer(uint8_t * buffer, size_t buffer_size, size_t size, Encoding::Type encoding)
{
m_buffer = buffer;
m_buffer_size = buffer_size;
m_size = size;
m_gap_position = size;
m_encoding = encoding;
}
GapBuffer::~GapBuffer()

View File

@ -3,12 +3,13 @@
#include <stdint.h>
#include <stdlib.h>
#include "Encoding.h"
class GapBuffer
{
public:
GapBuffer();
GapBuffer(uint8_t * buffer, size_t buffer_size, size_t size);
GapBuffer(Encoding::Type encoding);
GapBuffer(uint8_t * buffer, size_t buffer_size, size_t size, Encoding::Type encoding);
~GapBuffer();
protected:
@ -16,6 +17,7 @@ protected:
size_t m_buffer_size;
size_t m_size;
size_t m_gap_position;
Encoding::Type m_encoding;
};
#endif