diff --git a/src/core/Buffer.cc b/src/core/Buffer.cc index ea67af5..46053a7 100644 --- a/src/core/Buffer.cc +++ b/src/core/Buffer.cc @@ -12,6 +12,7 @@ Buffer::Buffer() m_file_buffer_size = 0u; m_eol_at_eof = true; m_line_endings = LineEndings::LF; + m_encoding = Encoding::UTF_8; } Buffer::~Buffer() @@ -63,6 +64,7 @@ bool Buffer::load_from_file(const char * filename) m_eol_at_eof = text_loader.get_eol_at_eof(); m_line_endings = text_loader.get_line_endings(); + m_encoding = text_loader.get_encoding(); return true; } diff --git a/src/core/Buffer.h b/src/core/Buffer.h index 80b1490..ead7c47 100644 --- a/src/core/Buffer.h +++ b/src/core/Buffer.h @@ -5,6 +5,7 @@ #include #include "PieceTable.h" #include "LineEndings.h" +#include "Encoding.h" class Buffer { @@ -21,6 +22,7 @@ protected: unsigned long m_file_buffer_size; bool m_eol_at_eof; LineEndings::Type m_line_endings; + Encoding::Type m_encoding; void free_file_buffer(); }; diff --git a/src/core/TextLoader.cc b/src/core/TextLoader.cc index c638f2a..73a982c 100644 --- a/src/core/TextLoader.cc +++ b/src/core/TextLoader.cc @@ -5,6 +5,7 @@ TextLoader::TextLoader() { m_line_endings = LineEndings::LF; + m_encoding = Encoding::UTF_8; m_lines = NULL; m_eol_at_eof = true; } @@ -79,4 +80,6 @@ void TextLoader::load_buffer(uint8_t * buffer, size_t size) m_lines->push_back(Span(&buffer[line_start[m_line_endings]], size - line_start[m_line_endings])); m_eol_at_eof = false; } + + m_encoding = Encoding::detect_encoding(buffer, size); } diff --git a/src/core/TextLoader.h b/src/core/TextLoader.h index 899ff53..18ad8bd 100644 --- a/src/core/TextLoader.h +++ b/src/core/TextLoader.h @@ -6,6 +6,7 @@ #include #include "Span.h" #include "LineEndings.h" +#include "Encoding.h" class TextLoader { @@ -24,12 +25,14 @@ public: } } LineEndings::Type get_line_endings() { return m_line_endings; } + Encoding::Type get_encoding() { return m_encoding; } auto begin() { return m_lines->begin(); } auto end() { return m_lines->end(); } bool get_eol_at_eof() { return m_eol_at_eof; } protected: LineEndings::Type m_line_endings; + Encoding::Type m_encoding; bool m_eol_at_eof; std::shared_ptr> m_lines; };