From 65c1c56edcbe1d8b0ff0a81482868d327143a4ff Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 27 Sep 2013 22:02:30 +0200 Subject: [PATCH] [DEV] add capabilities at the unichar element --- etk/Buffer.h | 18 ++++++++++++++---- etk/UniChar.cpp | 24 ++++++++++++++++++++++++ etk/UniChar.h | 13 +++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/etk/Buffer.h b/etk/Buffer.h index 336c10e..1b311d6 100644 --- a/etk/Buffer.h +++ b/etk/Buffer.h @@ -282,14 +282,24 @@ namespace etk * @param[in] _items Data that might be inserted. */ void Insert(int32_t _pos, etk::Vector& _items) + { + Insert(_pos, _items.DataPointer(), _items.Size()); + } + /** + * @brief Insert data in the buffer + * @param[in] _pos Position where data might be inserted + * @param[in] _items Data that might be inserted. (no need of '\0') + * @param[in] _nbElement number of element to insert + */ + void Insert(int32_t _pos, int8_t* _items, int32_t _nbElement) { if( _pos > Size() || _pos < 0 ) { TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize="< GapSize() ) { - if (false == GapResize(_pos, GAP_SIZE_MIN + _items.Size()) ) { + if(_nbElement > GapSize()) { + if (false == GapResize(_pos, GAP_SIZE_MIN + _nbElement) ) { return; } } else { @@ -297,10 +307,10 @@ namespace etk return; } } - for(esize_t iii=0; iii<_items.Size(); iii++) { + for(esize_t iii=0; iii<_nbElement; iii++) { m_data[m_gapStart+iii] = _items[iii]; } - m_gapStart += _items.Size(); + m_gapStart += _nbElement; } /** * @brief Replace one element in the buffer diff --git a/etk/UniChar.cpp b/etk/UniChar.cpp index 910f123..af8ab9b 100644 --- a/etk/UniChar.cpp +++ b/etk/UniChar.cpp @@ -269,3 +269,27 @@ int8_t etk::UniChar::SetUtf8(const char* _input) } } +int8_t etk::UniChar::TheoricUTF8Len(const char _input) +{ + if((_input&0x80) == 0x00 ) { + return 1; + } + if((_input&0xE0) == 0xC0) { + return 2; + } + if((_input&0xF0) == 0xE0) { + return 3; + } + if((_input&0xF8) == 0xF0) { + return 4; + } + return 1; +} + +bool etk::UniChar::TheoricUTF8First(const char _input) +{ + if((_input&0x80) == 0x80 ) { + return false; + } + return true; +} diff --git a/etk/UniChar.h b/etk/UniChar.h index a5f5306..1ade65d 100644 --- a/etk/UniChar.h +++ b/etk/UniChar.h @@ -178,6 +178,19 @@ namespace etk int8_t GetUtf8(char _output[5]) const; //etk::Vector GetUtf8(void) const; int8_t SetUtf8(const char* _input); + public: + /** + * @brief Get the size of an utf8 char with his first char. + * @param[in] _input Char to parse + * @return number of char needed + */ + static int8_t TheoricUTF8Len(const char _input); + /** + * @brief When parsing a string in a reverse mode, we need to know if we get the first char + * @param[in] _input Char to parse. + * @return true if it was the first char. + */ + static bool TheoricUTF8First(const char _input); }; };