[DEV] add capabilities at the unichar element

This commit is contained in:
Edouard DUPIN 2013-09-27 22:02:30 +02:00
parent 7a8b994ca9
commit 65c1c56edc
3 changed files with 51 additions and 4 deletions

View File

@ -282,14 +282,24 @@ namespace etk
* @param[in] _items Data that might be inserted.
*/
void Insert(int32_t _pos, etk::Vector<int8_t>& _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="<<Size());
return;
}
if( _items.Size() > 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

View File

@ -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;
}

View File

@ -178,6 +178,19 @@ namespace etk
int8_t GetUtf8(char _output[5]) const;
//etk::Vector<int8_t> 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);
};
};