From e3f156c513a826e7db0b7cc469503cfa4d4f0ad3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 24 Dec 2016 15:35:06 -0500 Subject: [PATCH] add Buffer::insert_code_point() --- src/core/Buffer.cc | 11 +++++++++++ src/core/Buffer.h | 1 + src/core/Encoding.h | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/Buffer.cc b/src/core/Buffer.cc index 82d7d53..04a66e0 100644 --- a/src/core/Buffer.cc +++ b/src/core/Buffer.cc @@ -161,3 +161,14 @@ void Buffer::exit_insert_mode() { m_insert_mode = false; } + +void Buffer::insert_code_point(uint32_t code_point) +{ + if (m_insert_mode) + { + uint8_t encoded[Encoding::MAX_CODE_POINT_SIZE]; + uint8_t bytes = Encoding::encode(code_point, m_encoding, encoded); + m_gap_buffer->insert(m_insert_position, encoded, bytes); + m_insert_position += bytes; + } +} diff --git a/src/core/Buffer.h b/src/core/Buffer.h index d4e4f7b..a1f3720 100644 --- a/src/core/Buffer.h +++ b/src/core/Buffer.h @@ -103,6 +103,7 @@ public: void enter_insert_mode(const Buffer::Iterator & position); void exit_insert_mode(); bool insert_mode() const { return m_insert_mode; } + void insert_code_point(uint32_t code_point); protected: bool m_eol_at_eof; diff --git a/src/core/Encoding.h b/src/core/Encoding.h index 9b2c901..97bf935 100644 --- a/src/core/Encoding.h +++ b/src/core/Encoding.h @@ -13,9 +13,9 @@ public: CP_1252, }; - enum + enum : uint32_t { - MAX_CODE_POINT_SIZE = 8, + MAX_CODE_POINT_SIZE = 8u, }; static Type detect_encoding(const uint8_t * buffer, size_t length);