diff --git a/etk/Buffer.h b/etk/Buffer.h index 523d080..151cbcb 100644 --- a/etk/Buffer.h +++ b/etk/Buffer.h @@ -211,18 +211,18 @@ namespace etk * @param[in] _nbElement Number of element needed. * @return The data requested */ - etk::Vector get(int32_t _pos, int32_t _nbElement) { - etk::Vector tmpBuffer; + std::vector get(int32_t _pos, int32_t _nbElement) { + std::vector tmpBuffer; tmpBuffer.clear(); if (_pos < m_gapStart) { if (_pos + _nbElement < m_gapStart) { - tmpBuffer.pushBack(&m_data[_pos], _nbElement); + tmpBuffer.push_back(&m_data[_pos], _nbElement); } else { - tmpBuffer.pushBack(&m_data[_pos], m_gapStart - _pos); - tmpBuffer.pushBack(&m_data[m_gapEnd], _nbElement - (m_gapStart - _pos) ); + tmpBuffer.push_back(&m_data[_pos], m_gapStart - _pos); + tmpBuffer.push_back(&m_data[m_gapEnd], _nbElement - (m_gapStart - _pos) ); } } else { - tmpBuffer.pushBack(&m_data[_pos+(m_gapEnd-m_gapStart)], _nbElement); + tmpBuffer.push_back(&m_data[_pos+(m_gapEnd-m_gapStart)], _nbElement); } return tmpBuffer; } @@ -230,7 +230,7 @@ namespace etk * @brief Add at the Last position of the Vector * @param[in] _item Element to add at the end of vector */ - void pushBack(const int8_t& _item) { + void push_back(const int8_t& _item) { insert(size(), _item); } /** @@ -270,7 +270,7 @@ namespace etk * @param[in] _pos Position where data might be inserted * @param[in] _items Data that might be inserted. */ - void insert(int32_t _pos, etk::Vector& _items) { + void insert(int32_t _pos, std::vector& _items) { insert(_pos, _items.dataPointer(), _items.size()); } /** @@ -323,7 +323,7 @@ namespace etk * @param[in] _nbRemoveElement number of element to remove. * @param[in] _items Data that might be inserted. */ - void replace(int32_t _pos, int32_t _nbRemoveElement, etk::Vector& _items) { + void replace(int32_t _pos, int32_t _nbRemoveElement, std::vector& _items) { replace(_pos, _nbRemoveElement, _items.dataPointer(), _items.size()); } /** diff --git a/etk/Char.cpp b/etk/Char.cpp index ad93ca0..21114fe 100644 --- a/etk/Char.cpp +++ b/etk/Char.cpp @@ -6,45 +6,4 @@ * @license BSD v3 (see license file) */ -#include -#include -#include - -etk::Char::Char(void) { - m_data.pushBack('\0'); -} - -etk::Char::~Char(void) -{ - -} - -etk::Char::operator const char *() -{ - return &m_data[0]; -}; - -etk::Char::operator void *() -{ - return &m_data[0]; -}; - - -void etk::Char::setValue(const etk::Vector& _data) -{ - m_data = _data; - // check presence of '\0' (note : start by the end might be faster ... - for (int32_t iii=m_data.size()-1; iii>=0; iii--) { - if (m_data[iii] == '\0') { - return; - } - } - m_data.pushBack('\0'); -} - - -int64_t etk::Char::size(void) -{ - return m_data.size()-1; -} diff --git a/etk/Char.h b/etk/Char.h index 1216029..a1af0f1 100644 --- a/etk/Char.h +++ b/etk/Char.h @@ -9,24 +9,6 @@ #ifndef __ETK_CHAR_H__ #define __ETK_CHAR_H__ -#include - -namespace etk -{ - class Char - { - private: - etk::Vector m_data; - public: - Char(void); - ~Char(void); - operator const char *(); - operator void *(); - void setValue(const etk::Vector& _data); - int64_t size(void); - }; -}; - #endif diff --git a/etk/Color.cpp b/etk/Color.cpp index 37cdf3f..b64f53f 100644 --- a/etk/Color.cpp +++ b/etk/Color.cpp @@ -10,9 +10,10 @@ #include #include #include +#include +#include -static bool strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen) -{ +static bool strnCmpNoCase(const char * input1, const char * input2, int32_t maxLen) { int32_t iii=0; while ('\0' != *input1 && '\0' != *input2 && iii < maxLen) { char in1 = *input1; @@ -43,110 +44,103 @@ typedef struct { static esize_t getColorSize(void); static const colorList_ts* getColorList(void); -namespace etk -{ - template<> void Color::set(float _r, float _g, float _b, float _a) - { +namespace etk { + template<> void Color::set(float _r, float _g, float _b, float _a) { m_r = (uint8_t)(_r*255.0f); m_g = (uint8_t)(_g*255.0f); m_b = (uint8_t)(_b*255.0f); m_a = (uint8_t)(_a*255.0f); } - template<> void Color::set(float _r, float _g, float _b, float _a) - { + template<> void Color::set(float _r, float _g, float _b, float _a) { m_r = _r; m_g = _g; m_b = _b; m_a = _a; } - template<> void Color::set(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a) - { + template<> void Color::set(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a) { m_r = _r; m_g = _g; m_b = _b; m_a = _a; } - template<> void Color::set(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a) - { + template<> void Color::set(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a) { m_r = ((float)_r)/255.0f; m_g = ((float)_g)/255.0f; m_b = ((float)_b)/255.0f; m_a = ((float)_a)/255.0f; } - template<> uint32_t Color::get(void) const - { + template<> uint32_t Color::get(void) const { return (((uint32_t)m_r)<<24) + (((uint32_t)m_g)<<16) + (((uint32_t)m_b)<<8) + (uint32_t)m_a; } - template<> uint32_t Color::get(void) const - { + template<> uint32_t Color::get(void) const { return Color(*this).get(); } - template<> Color::Color(const etk::UString& _input) : - m_r(255), - m_g(255), - m_b(255), - m_a(255) - { - etk::Char input = _input.c_str(); - const char* inputData = input; - size_t len = strlen(input); - if( len >=1 - && inputData[0] == '#') { - if(len == 4) { - int32_t red=0, green=0, blue=0; - if (sscanf(inputData + 1, "%1x%1x%1x", &red, &green, &blue) == 3) { - m_r = (red | red << 4); - m_g = (green | green << 4); - m_b = (blue | blue << 4); - } else { - TK_ERROR(" pb in parsing the color : \"" << inputData << "\""); - } - } else if (len==5) { - int32_t red=0, green=0, blue=0, alpha=0; - if (sscanf(inputData + 1, "%1x%1x%1x%1x", &red, &green, &blue, &alpha) == 4) { - m_r = (red | red << 4); - m_g = (green | green << 4); - m_b = (blue | blue << 4); - m_a = (alpha | alpha << 4); - } else { - TK_ERROR(" pb in parsing the color : \"" << inputData << "\""); - } - } else if (len == 7) { - int32_t red=0, green=0, blue=0; - if (sscanf(inputData + 1, "%2x%2x%2x", &red, &green, &blue) == 3) { - m_r = red; - m_g = green; - m_b = blue; - } else { - TK_ERROR(" pb in parsing the color : \"" << inputData << "\""); - } - } else if (len == 9) { - int32_t red=0, green=0, blue=0, alpha=0; - if (sscanf(inputData + 1, "%2x%2x%2x%2x", &red, &green, &blue, &alpha) == 4) { - m_r = red; - m_g = green; - m_b = blue; - m_a = alpha; - } else { - TK_ERROR(" pb in parsing the color : \"" << inputData << "\""); - } + template<> Color::Color(std::u32string _input) : + m_r(255), + m_g(255), + m_b(255), + m_a(255) { + if ( _input.size() >=1 + && _input[0] == '#') { + // remove '#' + _input.erase(0, 1); + uint32_t val = 0; + //std::ostringstream oss; + //oss << to_u8string(_input); + //oss >> std::hex >> val; + std::string plop = to_u8string(_input); + val = stoul(plop); + if(_input.size() == 3) { + m_r = (val & 0x00000F00) >> 8; + m_r = (m_r | m_r << 4); + m_g = (val & 0x000000F0) >> 4; + m_g = (m_g | m_g << 4); + m_b = (val & 0x0000000F) >> 0; + m_b = (m_b | m_b << 4); + } else if (_input.size() == 4) { + m_r = (val & 0x0000F000) >> 12; + m_r = (m_r | m_r << 4); + m_g = (val & 0x00000F00) >> 8; + m_g = (m_g | m_g << 4); + m_b = (val & 0x000000F0) >> 4; + m_b = (m_b | m_b << 4); + m_a = (val & 0x0000000F) >> 0; + m_a = (m_a | m_a << 4); + } else if (_input.size() == 6) { + m_r = (val & 0x00FF0000) >> 16; + m_r = (m_r | m_r << 4); + m_g = (val & 0x0000FF00) >> 8; + m_g = (m_g | m_g << 4); + m_b = (val & 0x000000FF) >> 0; + m_b = (m_b | m_b << 4); + } else if (_input.size() == 8) { + m_r = (val & 0xFF000000) >> 24; + m_r = (m_r | m_r << 4); + m_g = (val & 0x00FF0000) >> 16; + m_g = (m_g | m_g << 4); + m_b = (val & 0x0000FF00) >> 8; + m_b = (m_b | m_b << 4); + m_a = (val & 0x000000FF) >> 0; + m_a = (m_a | m_a << 4); } else { - TK_ERROR(" pb in parsing the color : \"" << inputData << "\" ==> unknown methode ..."); + TK_ERROR(" pb in parsing the color : \"" << _input << "\" ==> unknown methode ..."); } - } else if( 4 <= len - && inputData[0] == 'r' - && inputData[1] == 'g' - && inputData[2] == 'b' - && inputData[3] == '(' ) { + } else if( _input.size() >= 4 + && _input[0] == 'r' + && _input[1] == 'g' + && _input[2] == 'b' + && _input[3] == '(' ) { + /* + int32_t _red=0, _green=0, _blue=0, _alpha=0; float fred=0, fgreen=0, fblue=0, falpha=0; if (sscanf(inputData + 4, "%u,%u,%u,%u", &_red, &_green, &_blue, &_alpha) == 4) { @@ -177,11 +171,13 @@ namespace etk } else { TK_ERROR(" pb in parsing the color : \"" << inputData << "\" ==> unknown methode ..."); } + */ } else { bool findIt = false; + std::string tmputf8string = to_u8string(_input); // direct named color ... for (esize_t iii=0; iii " << *this); + TK_VERBOSE("Parse color : \"" << _input << "\" ==> " << *this); } - template<> Color::Color(const etk::UString& _input) + template<> Color::Color(std::u32string _input) { etk::Color tmpColor(_input); *this = tmpColor; diff --git a/etk/Color.h b/etk/Color.h index 39a0bc4..e5b961c 100644 --- a/etk/Color.h +++ b/etk/Color.h @@ -34,7 +34,7 @@ namespace etk { }; Color(const etk::Color& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); }; Color(const etk::Color& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); }; - Color(const etk::UString& _input); + Color(std::u32string _input); ~Color(void) { }; Color& operator=(const etk::Color& _input) { @@ -73,20 +73,36 @@ namespace etk { (uint8_t)(etk_avg(0,_b,255)), (uint8_t)(etk_avg(0,_a,255)) ); } - etk::UString getHexString(void) const { - return etk::UString(get(), etk::UString::printModeHexadecimal, true); + std::u32string getHexString(void) const { + return U"0x" + to_u32string(get(), std::hex); }; - etk::UString getString(void) const { - return etk::UString("#") + etk::UString(get(), etk::UString::printModeHexadecimal); + std::u32string getString(void) const { + return U"#" + to_u32string(get(), std::hex); + }; + MY_TYPE r(void) const { + return m_r; + }; + MY_TYPE g(void) const { + return m_g; + }; + MY_TYPE b(void) const { + return m_b; + }; + MY_TYPE a(void) const { + return m_a; + }; + void setR(MY_TYPE _r) { + m_r=_r; + }; + void setG(MY_TYPE _g) { + m_g=_g; + }; + void setB(MY_TYPE _b) { + m_b=_b; + }; + void setA(MY_TYPE _a) { + m_a=_a; }; - MY_TYPE r(void) const { return m_r; }; - MY_TYPE g(void) const { return m_g; }; - MY_TYPE b(void) const { return m_b; }; - MY_TYPE a(void) const { return m_a; }; - void setR(MY_TYPE _r) { m_r=_r; }; - void setG(MY_TYPE _g) { m_g=_g; }; - void setB(MY_TYPE _b) { m_b=_b; }; - void setA(MY_TYPE _a) { m_a=_a; }; }; etk::CCout& operator <<(etk::CCout &_os, const Color& _obj); etk::CCout& operator <<(etk::CCout &_os, const Color& _obj); diff --git a/etk/Hash.h b/etk/Hash.h index 3259ee8..a4ae4f1 100644 --- a/etk/Hash.h +++ b/etk/Hash.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include #undef __class__ @@ -21,9 +21,9 @@ namespace etk { template class HashData { public: - etk::UString m_key; //!< name of the current hash + std::u32string m_key; //!< name of the current hash MY_TYPE m_value; //!< data of the current Hash - HashData(const etk::UString& _key, const MY_TYPE& _val) : + HashData(const std::u32string& _key, const MY_TYPE& _val) : m_key(_key), m_value(_val) { // nothing to do ... @@ -32,7 +32,7 @@ namespace etk { template class Hash { private: - etk::Vector* > m_data; //!< Data of the hash ==> the Hash table is composed of pointer, this permit to have high speed when resize the vestor ... + std::vector* > m_data; //!< Data of the hash ==> the Hash table is composed of pointer, this permit to have high speed when resize the vestor ... public: Hash(int32_t _count=0) : m_data(_count) { @@ -58,7 +58,7 @@ namespace etk { * @param[in] _key Name of the hash requested * @return Id of the element in the table or -1 of it does not existed */ - int64_t getId(const etk::UString& _key) const { + int64_t getId(const std::u32string& _key) const { for (int32_t iii=0; iiim_key << "' with '" << _key << "'" ); @@ -75,7 +75,7 @@ namespace etk { * @param[in] _key Name of the hash requested * @return true if the element exist */ - bool exist(const etk::UString& _name) const { + bool exist(const std::u32string& _name) const { int64_t elementId = getId(_name); //TK_INFO(" Exist ? '" << _name << "' id=" << elementId ); if (elementId<0) { @@ -90,7 +90,7 @@ namespace etk { * @param[in] _key Name of the hash requested * @return Reference on the Element */ - MY_TYPE& get(const etk::UString& _key) const { + MY_TYPE& get(const std::u32string& _key) const { static MY_TYPE g_error; int64_t elementId = getId(_key); if (elementId<0) { @@ -104,14 +104,14 @@ namespace etk { * @param[in] _key Name of the hash requested * @return An reference on the copy of selected element */ - MY_TYPE& operator[] (const etk::UString& _key) { + MY_TYPE& operator[] (const std::u32string& _key) { return get(_key); } - const MY_TYPE& operator[] (const etk::UString& _key) const { + const MY_TYPE& operator[] (const std::u32string& _key) const { return get(_key); } - void add(const etk::UString& _key, const MY_TYPE& _value) { + void add(const std::u32string& _key, const MY_TYPE& _value) { int64_t elementId = getId(_key); if (elementId <0) { HashData* tmp = new HashData(_key, _value); @@ -119,15 +119,15 @@ namespace etk { TK_ERROR("allocation error in Hash table : '" << _key << "'"); return; } - m_data.pushBack(tmp); + m_data.push_back(tmp); return; } m_data[elementId]->m_value = _value; } - void set(const etk::UString& _key, const MY_TYPE& _value) { + void set(const std::u32string& _key, const MY_TYPE& _value) { add(_key, _value); } - void remove(const etk::UString& _key) { + void remove(const std::u32string& _key) { int64_t elementId = getId(_key); if (elementId <0) { //nothing to do ==> not existed @@ -150,7 +150,7 @@ namespace etk { const MY_TYPE& operator[] (esize_t _pos) const { return getValue(_pos); } - const etk::UString& getKey(esize_t _pos) const { + const std::u32string& getKey(esize_t _pos) const { // NOTE :Do not change log level, this generate error only in debug mode #if DEBUG_LEVEL > 2 if(_pos>m_data.size()){ diff --git a/etk/MessageFifo.h b/etk/MessageFifo.h index 8f7911b..e299dfa 100644 --- a/etk/MessageFifo.h +++ b/etk/MessageFifo.h @@ -11,7 +11,7 @@ #include #include -#include +#include namespace etk { @@ -20,7 +20,7 @@ namespace etk private : etk::Mutex m_mutex; etk::Semaphore m_semaphore; - etk::Vector m_data; + std::vector m_data; public : MessageFifo(void) { @@ -85,7 +85,7 @@ namespace etk void post(MY_TYPE &_data) { m_mutex.lock(); - m_data.pushBack(_data); + m_data.push_back(_data); m_semaphore.post(); m_mutex.unLock(); }; diff --git a/etk/Noise.cpp b/etk/Noise.cpp index 9b84bbe..b8589ee 100644 --- a/etk/Noise.cpp +++ b/etk/Noise.cpp @@ -21,7 +21,7 @@ etk::BaseNoise::BaseNoise(ivec2 _size, float _min, float _max) : m_data(_size.x()*_size.y()), m_size(_size) { - m_data.reSize(_size.x()*_size.y(), 0); + m_data.resize(_size.x()*_size.y(), 0); for(int32_t iii=0; iii m_data; + std::vector m_data; ivec2 m_size; public: BaseNoise(ivec2 _size, float _min, float _max); @@ -37,7 +37,7 @@ namespace etk { NOISE_WOOD }; private: - etk::Vector m_data; + std::vector m_data; ivec2 m_size; enum noise m_type; float smoothNoise(float _x, float _y, const etk::BaseNoise& _noise); diff --git a/etk/RegExp.cpp b/etk/RegExp.cpp index 4fa5242..7fc3482 100644 --- a/etk/RegExp.cpp +++ b/etk/RegExp.cpp @@ -64,11 +64,10 @@ const etk::convertionTable_ts etk::constConvertionTable[] = { }; const esize_t etk::constConvertionTableSize = sizeof(etk::constConvertionTable) / sizeof(etk::convertionTable_ts) ; -void etk::displayElem(const etk::Vector& _data, esize_t _start, esize_t _stop) -{ +void etk::displayElem(const std::vector& _data, esize_t _start, esize_t _stop) { etk::cout<< ETK_BASH_COLOR_NORMAL; for (esize_t iii=_start; iii<_data.size() && iii<_stop ; iii++) { - switch(_data[iii].get()) + switch(_data[iii]) { case REGEXP_OPCODE_PTHESE_IN: etk::cout<& _data, esize_t _start, esiz } } } -char * etk::levelSpace(uint32_t _level) -{ + +char * etk::levelSpace(uint32_t _level) { switch(_level) { case 0: return (char*)""; @@ -125,8 +124,7 @@ char * etk::levelSpace(uint32_t _level) } -esize_t etk::getLenOfPTheseElem(const etk::Vector& _data, esize_t _startPos) -{ +esize_t etk::getLenOfPTheseElem(const std::vector& _data, esize_t _startPos) { if (_startPos>=_data.size()){ return 0; } @@ -166,8 +164,7 @@ esize_t etk::getLenOfPTheseElem(const etk::Vector& _data, esize_t _s return pos - _startPos; } -esize_t etk::getLenOfPThese(const etk::Vector& _data, esize_t _startPos) -{ +esize_t etk::getLenOfPThese(const std::vector& _data, esize_t _startPos) { esize_t pos = _startPos; int32_t nbOpen = 0; // special case of the (...) or | ==> we search '|' or ')' @@ -208,8 +205,7 @@ esize_t etk::getLenOfPThese(const etk::Vector& _data, esize_t _start } -esize_t etk::getLenOfBracket(const etk::Vector& _data, esize_t _startPos) -{ +esize_t etk::getLenOfBracket(const std::vector& _data, esize_t _startPos) { esize_t pos = _startPos; // special case of the (...) or | ==> we search '|' or ')' if(_data[pos]==REGEXP_OPCODE_BRACKET_OUT) { @@ -233,7 +229,7 @@ esize_t etk::getLenOfBracket(const etk::Vector& _data, esize_t _star return sizeInside; } else if( _data[pos] != REGEXP_OPCODE_TO && _data[pos] > 0xFF ) { - TK_ERROR("Error in the [...] not permited element at "<< pos << " '" << (char)_data[pos].get() << "'"); + TK_ERROR("Error in the [...] not permited element at "<< pos << " '" << (char)_data[pos] << "'"); return 0; } pos++; @@ -242,8 +238,7 @@ esize_t etk::getLenOfBracket(const etk::Vector& _data, esize_t _star } -esize_t etk::getLenOfBrace(const etk::Vector& _data, esize_t _startPos) -{ +esize_t etk::getLenOfBrace(const std::vector& _data, esize_t _startPos) { int32_t pos = _startPos; // special case of the (...) or | ==> we search '|' or ')' if(_data[pos]==REGEXP_OPCODE_BRACE_OUT) { @@ -268,7 +263,7 @@ esize_t etk::getLenOfBrace(const etk::Vector& _data, esize_t _startP } else if( _data[pos] != ',' && ( _data[pos] < '0' || _data[pos] > '9') ) { - TK_ERROR("Error in the {...} not permited element at "<< pos << " '" << _data[pos].get() << "'"); + TK_ERROR("Error in the {...} not permited element at "<< pos << " '" << _data[pos] << "'"); return 0; } pos++; @@ -277,14 +272,11 @@ esize_t etk::getLenOfBrace(const etk::Vector& _data, esize_t _startP } -esize_t etk::getLenOfNormal(const etk::Vector& _data, esize_t _startPos) -{ +esize_t etk::getLenOfNormal(const std::vector& _data, esize_t _startPos) { esize_t pos = _startPos; - // find size ... while (pos < _data.size() ) { - switch(_data[pos].get()) - { + switch(_data[pos]) { case REGEXP_OPCODE_PTHESE_IN: case REGEXP_OPCODE_PTHESE_OUT: case REGEXP_OPCODE_BRACKET_IN: @@ -329,7 +321,7 @@ esize_t etk::getLenOfNormal(const etk::Vector& _data, esize_t _start } -bool etk::parseBrace(const etk::Vector& _data, uint32_t& _min, uint32_t& _max) +bool etk::parseBrace(const std::vector& _data, uint32_t& _min, uint32_t& _max) { //TK_INFO("parse {...} in "; DisplayElem(data); ); esize_t k=0; @@ -337,34 +329,34 @@ bool etk::parseBrace(const etk::Vector& _data, uint32_t& _min, uint3 int32_t firstElement = 0; int32_t SecondElement = 0; - while(k<_data.size()) { - if (_data[k]==',') { + while(k < _data.size()) { + if (_data[k] == ',') { k++; break; - } if (_data[k]=='}') { + } if (_data[k] == '}' ) { SecondElement = firstElement; goto allIsSet; - } else if(true==_data[k].isInteger()) { - firstElement *=10; - firstElement += _data[k].toInt32(); + } else if(etk::isInteger(_data[k]) == true) { + firstElement *= 10; + firstElement += etk::toInt32(_data[k]); } else { - TK_ERROR("Can not parse this element " << (char)_data[k].get() << " at pos " << k); + TK_ERROR("Can not parse this element " << (char)_data[k] << " at pos " << k); return false; } k++; } - if (k==_data.size()) { + if (k == _data.size()) { SecondElement = firstElement; } - while(k<_data.size()) { - if (_data[k]==',') { + while(k < _data.size()) { + if (_data[k] == ',') { TK_ERROR("Can not find a second , in {} at pos " << k); return false; - } if (_data[k]=='}') { + } if (_data[k] == '}') { goto allIsSet; - } else if (true==_data[k].isInteger()) { - SecondElement *=10; - SecondElement += _data[k].toInt32(); + } else if (true == etk::isInteger(_data[k])) { + SecondElement *= 10; + SecondElement += etk::toInt32(_data[k]); } else { TK_ERROR("Can not parse this element " << _data[k] << " at pos " << k); return false; diff --git a/etk/RegExp.h b/etk/RegExp.h index 7d5c7db..f639b7f 100644 --- a/etk/RegExp.h +++ b/etk/RegExp.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #define TK_REG_EXP_DBG_MODE TK_VERBOSE @@ -56,14 +56,14 @@ typedef struct { extern const convertionTable_ts constConvertionTable[]; extern const esize_t constConvertionTableSize; -void displayElem(const etk::Vector& _data, esize_t _start=0, esize_t _stop=0x7FFFFFFF); +void displayElem(const std::vector& _data, esize_t _start=0, esize_t _stop=0x7FFFFFFF); char * levelSpace(uint32_t _level); -esize_t getLenOfPTheseElem(const etk::Vector& _data, esize_t _startPos); -esize_t getLenOfPThese(const etk::Vector& _data, esize_t _startPos); -esize_t getLenOfBracket(const etk::Vector& _data, esize_t _startPos); -esize_t getLenOfBrace(const etk::Vector& _data, esize_t _startPos); -esize_t getLenOfNormal(const etk::Vector& _data, esize_t _startPos); -bool parseBrace(const etk::Vector& _data, uint32_t& _min, uint32_t& _max); +esize_t getLenOfPTheseElem(const std::vector& _data, esize_t _startPos); +esize_t getLenOfPThese(const std::vector& _data, esize_t _startPos); +esize_t getLenOfBracket(const std::vector& _data, esize_t _startPos); +esize_t getLenOfBrace(const std::vector& _data, esize_t _startPos); +esize_t getLenOfNormal(const std::vector& _data, esize_t _startPos); +bool parseBrace(const std::vector& _data, uint32_t& _min, uint32_t& _max); #undef __class__ @@ -78,7 +78,7 @@ template class RegExpNode uint32_t m_multipleMin; //!< minimum repetition (included) uint32_t m_multipleMax; //!< maximum repetition (included) // Data Section ... (can have no data...) - etk::Vector m_RegExpData; //!< data to parse and compare in some case ... + std::vector m_RegExpData; //!< data to parse and compare in some case ... public : /** * @brief Constructor @@ -98,7 +98,7 @@ template class RegExpNode * @param[in] _data Property of the regexp * @return the number of element used */ - virtual int32_t generate(const etk::Vector& _data) + virtual int32_t generate(const std::vector& _data) { return 0; }; @@ -151,7 +151,7 @@ template class RegExpNodeValue : public RegExpNode { protected : // SubNodes : - etk::Vector m_data; + std::vector m_data; public : /** @@ -164,13 +164,13 @@ template class RegExpNodeValue : public RegExpNode */ ~RegExpNodeValue(void) { }; - int32_t generate(const etk::Vector& _data) + int32_t generate(const std::vector& _data) { RegExpNode::m_RegExpData = _data; TK_REG_EXP_DBG_MODE("Request Parse \"Value\" data="; displayElem(RegExpNode::m_RegExpData);); m_data.clear(); for (int32_t i=0; i::m_RegExpData.size(); i++) { - m_data.pushBack(RegExpNode::m_RegExpData[i]); + m_data.push_back(RegExpNode::m_RegExpData[i]); } return _data.size(); }; @@ -234,7 +234,7 @@ template class RegExpNodeBracket : public RegExpNode m_data; + std::vector m_data; public : /** @@ -247,13 +247,13 @@ template class RegExpNodeBracket : public RegExpNode& _data) + int32_t generate(const std::vector& _data) { RegExpNode::m_RegExpData = _data; TK_REG_EXP_DBG_MODE("Request Parse [...] data="; displayElem(_data);); m_data.clear(); - etk::UChar lastElement = 'a'; + char32_t lastElement = 'a'; bool multipleElement = false; // for (int32_t kkk=0; kkk::m_RegExpData.size(); kkk++) { @@ -261,16 +261,16 @@ template class RegExpNodeBracket : public RegExpNode::m_RegExpData[kkk]; jjj+=1) { - m_data.pushBack(jjj); + m_data.push_back(jjj); } multipleElement = false; } else if(RegExpNode::m_RegExpData[kkk] == REGEXP_OPCODE_TO) { multipleElement = true; } else { lastElement = RegExpNode::m_RegExpData[kkk]; - m_data.pushBack(lastElement); + m_data.push_back(lastElement); } } // check size ... @@ -347,7 +347,7 @@ template class RegExpNodeDigit : public RegExpNode bool tmpFind = true; uint32_t jjj; for (jjj=0; jjj::m_multipleMax && tmpFind ==true && jjj < _lenMax; jjj++) { - etk::UChar tmpVal = _data[_currentPos+jjj]; + char32_t tmpVal = _data[_currentPos+jjj]; TK_REG_EXP_DBG_MODE("compare : " << tmpVal); if( tmpVal >= '0' && tmpVal <= '9') @@ -402,7 +402,7 @@ template class RegExpNodeDigitNot : public RegExpNode::m_multipleMax && tmpFind ==true && jjj < _lenMax; jjj++) { - etk::UChar tmpVal = _data[_currentPos+jjj]; + char32_t tmpVal = _data[_currentPos+jjj]; if( tmpVal < '0' || tmpVal > '9') { _findLen += 1; @@ -451,7 +451,7 @@ template class RegExpNodeLetter : public RegExpNode::m_multipleMax && tmpFind ==true && jjj < _lenMax; jjj++) { - etk::UChar tmpVal = _data[_currentPos+jjj]; + char32_t tmpVal = _data[_currentPos+jjj]; if( ( tmpVal >= 'a' && tmpVal <= 'z') || ( tmpVal >= 'A' @@ -505,7 +505,7 @@ template class RegExpNodeLetterNot : public RegExpNode::m_multipleMax && tmpFind ==true && jjj < _lenMax; jjj++) { - etk::UChar tmpVal = _data[_currentPos+jjj]; + char32_t tmpVal = _data[_currentPos+jjj]; if( ( tmpVal < 'a' && tmpVal > 'Z') || tmpVal < 'A' @@ -559,7 +559,7 @@ template class RegExpNodeWhiteSpace : public RegExpNode::m_multipleMax && tmpFind ==true && jjj < _lenMax; jjj++) { - etk::UChar tmpVal = _data[_currentPos+jjj]; + char32_t tmpVal = _data[_currentPos+jjj]; if( tmpVal == ' ' || tmpVal == '\t' || tmpVal == '\n' @@ -615,7 +615,7 @@ template class RegExpNodeWhiteSpaceNot : public RegExpNode::m_multipleMax && tmpFind ==true && jjj < _lenMax; jjj++) { - etk::UChar tmpVal = _data[_currentPos+jjj]; + char32_t tmpVal = _data[_currentPos+jjj]; if( tmpVal != ' ' && tmpVal != '\t' && tmpVal != '\n' @@ -670,7 +670,7 @@ template class RegExpNodeWordChar : public RegExpNode::m_multipleMax && tmpFind ==true && jjj < _lenMax; jjj++) { - etk::UChar tmpVal = _data[_currentPos+jjj]; + char32_t tmpVal = _data[_currentPos+jjj]; if( ( tmpVal >= 'a' && tmpVal <= 'z' ) || ( tmpVal >= 'A' @@ -725,7 +725,7 @@ template class RegExpNodeWordCharNot : public RegExpNode::m_multipleMax && tmpFind ==true && jjj < _lenMax; jjj++) { - etk::UChar tmpVal = _data[_currentPos+jjj]; + char32_t tmpVal = _data[_currentPos+jjj]; if( ( tmpVal < 'A' && tmpVal > '9' ) || ( tmpVal < 'a' @@ -782,7 +782,7 @@ template class RegExpNodeDot : public RegExpNode bool tmpFind = true; uint32_t jjj; for (jjj=0; jjj::m_multipleMax && tmpFind ==true && jjj < _lenMax; jjj++) { - etk::UChar tmpVal = _data[_currentPos+jjj]; + char32_t tmpVal = _data[_currentPos+jjj]; if( ( tmpVal > 0x08 && tmpVal < 0x0A ) || ( tmpVal > 0x1F @@ -896,7 +896,7 @@ template class RegExpNodePTheseElem : public RegExpNode*> m_subNode; + std::vector*> m_subNode; public : /** * @brief Constructor @@ -908,13 +908,13 @@ template class RegExpNodePTheseElem : public RegExpNode& _data) + int32_t generate(const std::vector& _data) { RegExpNode::m_RegExpData = _data; TK_REG_EXP_DBG_MODE("Request Parse (elem) data="; displayElem(RegExpNode::m_RegExpData);); esize_t pos = 0; esize_t elementSize = 0; - etk::Vector tmpData; + std::vector tmpData; while (pos < RegExpNode::m_RegExpData.size()) { tmpData.clear(); switch (RegExpNode::m_RegExpData[pos].get()) { @@ -922,12 +922,12 @@ template class RegExpNodePTheseElem : public RegExpNode::m_RegExpData, pos); for (esize_t kkk=pos+1; kkk::m_RegExpData[kkk]); + tmpData.push_back(RegExpNode::m_RegExpData[kkk]); } RegExpNodePThese * myElem = new RegExpNodePThese(); (void)myElem->generate(tmpData); // add to the subnode list : - m_subNode.pushBack(myElem); + m_subNode.push_back(myElem); // move current position ... pos += elementSize+1; } @@ -939,12 +939,12 @@ template class RegExpNodePTheseElem : public RegExpNode::m_RegExpData, pos); for (esize_t kkk=pos+1; kkk::m_RegExpData[kkk]); + tmpData.push_back(RegExpNode::m_RegExpData[kkk]); } RegExpNodeBracket * myElem = new RegExpNodeBracket(); (void)myElem->generate(tmpData); // add to the subnode list : - m_subNode.pushBack(myElem); + m_subNode.push_back(myElem); // move current position ... pos += elementSize+1; } @@ -956,7 +956,7 @@ template class RegExpNodePTheseElem : public RegExpNode::m_RegExpData, pos); for (esize_t kkk=pos+1; kkk::m_RegExpData[kkk]); + tmpData.push_back(RegExpNode::m_RegExpData[kkk]); } uint32_t min = 0; uint32_t max = 0; @@ -986,49 +986,49 @@ template class RegExpNodePTheseElem : public RegExpNode()); + m_subNode.push_back(new RegExpNodeDot()); break; case REGEXP_OPCODE_START_OF_LINE: - m_subNode.pushBack(new RegExpNodeSOL()); + m_subNode.push_back(new RegExpNodeSOL()); break; case REGEXP_OPCODE_END_OF_LINE: - m_subNode.pushBack(new RegExpNodeEOL()); + m_subNode.push_back(new RegExpNodeEOL()); break; case REGEXP_OPCODE_DIGIT: - m_subNode.pushBack(new RegExpNodeDigit()); + m_subNode.push_back(new RegExpNodeDigit()); break; case REGEXP_OPCODE_DIGIT_NOT: - m_subNode.pushBack(new RegExpNodeDigitNot()); + m_subNode.push_back(new RegExpNodeDigitNot()); break; case REGEXP_OPCODE_LETTER: - m_subNode.pushBack(new RegExpNodeLetter()); + m_subNode.push_back(new RegExpNodeLetter()); break; case REGEXP_OPCODE_LETTER_NOT: - m_subNode.pushBack(new RegExpNodeLetterNot()); + m_subNode.push_back(new RegExpNodeLetterNot()); break; case REGEXP_OPCODE_SPACE: - m_subNode.pushBack(new RegExpNodeWhiteSpace()); + m_subNode.push_back(new RegExpNodeWhiteSpace()); break; case REGEXP_OPCODE_SPACE_NOT: - m_subNode.pushBack(new RegExpNodeWhiteSpaceNot()); + m_subNode.push_back(new RegExpNodeWhiteSpaceNot()); break; case REGEXP_OPCODE_WORD: - m_subNode.pushBack(new RegExpNodeWordChar()); + m_subNode.push_back(new RegExpNodeWordChar()); break; case REGEXP_OPCODE_WORD_NOT: - m_subNode.pushBack(new RegExpNodeWordCharNot()); + m_subNode.push_back(new RegExpNodeWordCharNot()); break; default: { elementSize = getLenOfNormal(RegExpNode::m_RegExpData, pos); for (esize_t kkk=pos; kkk::m_RegExpData[kkk]); + tmpData.push_back(RegExpNode::m_RegExpData[kkk]); } RegExpNodeValue * myElem = new RegExpNodeValue(); (void)myElem->generate(tmpData); // add to the subnode list : - m_subNode.pushBack(myElem); + m_subNode.push_back(myElem); // move current position ... pos += elementSize-1; } @@ -1105,7 +1105,7 @@ template class RegExpNodePTheseElem : public RegExpNode class RegExpNodePThese : public RegExpNode { protected : - etk::Vector*> m_subNode; //!< Subnode list + std::vector*> m_subNode; //!< Subnode list public : /** * @brief Constructor @@ -1123,7 +1123,7 @@ template class RegExpNodePThese : public RegExpNode& _data) + int32_t generate(const std::vector& _data) { RegExpNode::m_RegExpData = _data; TK_REG_EXP_DBG_MODE("Request Parse (...) data="; displayElem(RegExpNode::m_RegExpData);); @@ -1133,14 +1133,14 @@ template class RegExpNodePThese : public RegExpNode0) { // geerate output deta ... - etk::Vector tmpData; + std::vector tmpData; for (esize_t kkk=pos; kkk::m_RegExpData[kkk]); + tmpData.push_back(RegExpNode::m_RegExpData[kkk]); } RegExpNodePTheseElem * myElem = new RegExpNodePTheseElem(); (void)myElem->generate(tmpData); // add to the subnode list : - m_subNode.pushBack(myElem); + m_subNode.push_back(myElem); pos += elementSize+1; TK_REG_EXP_DBG_MODE("plop="; displayElem(_data, pos, pos+1);); elementSize = getLenOfPTheseElem(RegExpNode::m_RegExpData, pos); @@ -1207,7 +1207,7 @@ template class RegExpNodePThese : public RegExpNode class RegExp { private: - etk::UString m_expressionRequested; //!< Regular expression parsed ... + std::u32string m_expressionRequested; //!< Regular expression parsed ... elementPos_ts m_areaFind; //!< position around selection RegExpNodePThese m_exprRootNode; //!< The tree where data is set bool m_isOk; //!< Known if we can process with this regExp @@ -1220,8 +1220,8 @@ template class RegExp * @brief Constructor * @param[in,out] _exp Regular expression to parse */ - RegExp(const etk::UString &_exp="") : - m_expressionRequested(""), + RegExp(const std::u32string &_exp=U"") : + m_expressionRequested(U""), m_isOk(false), m_notBeginWithChar(false), m_notEndWithChar(false) @@ -1245,10 +1245,10 @@ template class RegExp * @brief Set a new regular expression matching * @param[in] _regexp the new expression to search */ - void setRegExp(const etk::UString &_regexp) + void setRegExp(const std::u32string &_regexp) { m_expressionRequested = _regexp; - etk::Vector tmpExp; + std::vector tmpExp; TK_REG_EXP_DBG_MODE("---------------------------------------------------------------------"); TK_REG_EXP_DBG_MODE("Parse RegExp : (" << _regexp << ")" ); @@ -1279,9 +1279,9 @@ template class RegExp && _regexp[iii+1] == constConvertionTable[jjj].inputValue) { if (constConvertionTable[jjj].newValue==0) { - tmpExp.pushBack(constConvertionTable[jjj].specialChar); + tmpExp.push_back(constConvertionTable[jjj].specialChar); } else { - tmpExp.pushBack(constConvertionTable[jjj].newValue); + tmpExp.push_back(constConvertionTable[jjj].newValue); } break; } @@ -1315,9 +1315,9 @@ template class RegExp && _regexp[iii] == constConvertionTable[jjj].inputValue) { if (constConvertionTable[jjj].newValue==0) { - tmpExp.pushBack(constConvertionTable[jjj].specialChar); + tmpExp.push_back(constConvertionTable[jjj].specialChar); } else { - tmpExp.pushBack(constConvertionTable[jjj].newValue); + tmpExp.push_back(constConvertionTable[jjj].newValue); } break; } @@ -1325,7 +1325,7 @@ template class RegExp // not find : normal element if (jjj==constConvertionTableSize) { //TK_REG_EXP_DBG_MODE("parse : '" << _regexp[iii] << "'" ); - tmpExp.pushBack(_regexp[iii]); + tmpExp.push_back(_regexp[iii]); } } } @@ -1357,7 +1357,7 @@ template class RegExp //TK_DEBUG("=> must not begin with char"); m_notBeginWithChar = true; // remove element - tmpExp.erase(0); + tmpExp.erase(tmpExp.begin()); } if ( tmpExp.size()>0 && tmpExp[tmpExp.size()-1] == REGEXP_OPCODE_NO_CHAR) @@ -1365,7 +1365,7 @@ template class RegExp //TK_DEBUG("=> must not end with char"); m_notEndWithChar = true; // remove element - tmpExp.erase(tmpExp.size()-1); + tmpExp.erase(tmpExp.end()); } if (tmpExp.size() != m_exprRootNode.generate(tmpExp) ) { @@ -1382,7 +1382,7 @@ template class RegExp * @brief Get the regular expression string * @return the string representing the RegExp */ - const etk::UString& getRegExp(void) const + const std::u32string& getRegExp(void) const { return m_expressionRequested; }; @@ -1409,7 +1409,7 @@ template class RegExp bool process(const CLASS_TYPE& _SearchIn, esize_t _startPos, esize_t _endPos, - etk::UChar _escapeChar=0) + char32_t _escapeChar=0) { if (false == m_isOk) { return false; @@ -1426,7 +1426,7 @@ template class RegExp esize_t maxlen = _endPos-iii; if (true == m_notBeginWithChar) { if (iii>0) { - etk::UChar tmpVal = _SearchIn[iii-1]; + char32_t tmpVal = _SearchIn[iii-1]; if( ( tmpVal >= 'a' && tmpVal <= 'z' ) || ( tmpVal >= 'A' @@ -1451,7 +1451,7 @@ template class RegExp // Check end : if (true == m_notEndWithChar) { if (iii+findLen < _SearchIn.size() ) { - etk::UChar tmpVal = _SearchIn[iii+findLen]; + char32_t tmpVal = _SearchIn[iii+findLen]; if( ( tmpVal >= 'a' && tmpVal <= 'z' ) || ( tmpVal >= 'A' @@ -1487,7 +1487,7 @@ template class RegExp bool processOneElement( const CLASS_TYPE& _SearchIn, esize_t _startPos, esize_t _endPos, - etk::UChar _escapeChar=0) + char32_t _escapeChar=0) { if (false == m_isOk) { return false; @@ -1503,7 +1503,7 @@ template class RegExp esize_t maxlen = _endPos-_startPos; if (true == m_notBeginWithChar) { if (_startPos>0) { - etk::UChar tmpVal = _SearchIn[_startPos-1]; + char32_t tmpVal = _SearchIn[_startPos-1]; if( ( tmpVal >= 'a' && tmpVal <= 'z' ) || ( tmpVal >= 'A' @@ -1528,7 +1528,7 @@ template class RegExp // Check end : if (true == m_notEndWithChar) { if (_startPos+findLen < _SearchIn.size() ) { - etk::UChar tmpVal = _SearchIn[_startPos+findLen]; + char32_t tmpVal = _SearchIn[_startPos+findLen]; if( ( tmpVal >= 'a' && tmpVal <= 'z' ) || ( tmpVal >= 'A' @@ -1574,10 +1574,10 @@ template class RegExp * @param[in,out] * @return */ - bool checkGoodPosition(const etk::Vector& _tmpExp, esize_t& _pos) + bool checkGoodPosition(const std::vector& _tmpExp, esize_t& _pos) { - etk::UChar curentCode = _tmpExp[_pos]; - etk::UChar endCode = REGEXP_OPCODE_PTHESE_OUT; + char32_t curentCode = _tmpExp[_pos]; + char32_t endCode = REGEXP_OPCODE_PTHESE_OUT; const char *input = "(...)"; if (curentCode == REGEXP_OPCODE_BRACKET_IN) { endCode = REGEXP_OPCODE_BRACKET_OUT; @@ -1603,7 +1603,7 @@ template class RegExp } else { // otherwise, we check the error in the element ... char *find = NULL; - switch (_tmpExp[_pos].get()) + switch (_tmpExp[_pos]) { case REGEXP_OPCODE_PTHESE_IN: find = (char*)"("; break; case REGEXP_OPCODE_BRACKET_IN: find = (char*)"["; break; @@ -1679,7 +1679,7 @@ template class RegExp * @param[in,out] * @return */ - bool checkGoodPosition(const etk::Vector& _tmpExp) + bool checkGoodPosition(const std::vector& _tmpExp) { esize_t pos = 0; while (pos < _tmpExp.size()) { diff --git a/etk/Stream.cpp b/etk/Stream.cpp index fba252e..22f0065 100644 --- a/etk/Stream.cpp +++ b/etk/Stream.cpp @@ -149,10 +149,10 @@ etk::CCout::~CCout() }; -etk::CCout& etk::CCout::operator << (const etk::UChar& _t) +etk::CCout& etk::CCout::operator << (char32_t _t) { char output[5]; - _t.getUtf8(output); + getUtf8(_t, output); snprintf(tmp, MAX_LOG_SIZE_TMP, "%s", output); strncat(m_tmpChar, tmp, MAX_LOG_SIZE); return *this; diff --git a/etk/Stream.h b/etk/Stream.h index 66603e7..73f82f4 100644 --- a/etk/Stream.h +++ b/etk/Stream.h @@ -31,7 +31,7 @@ namespace etk { public: CCout(void); ~CCout(void); - CCout& operator << (const etk::UChar& _t);; + CCout& operator << (char32_t _t);; CCout& operator << (int8_t _t); CCout& operator << (int16_t _t); CCout& operator << (int32_t _t); diff --git a/etk/UChar.cpp b/etk/UChar.cpp index 1c7c3b7..41f2f32 100644 --- a/etk/UChar.cpp +++ b/etk/UChar.cpp @@ -12,150 +12,104 @@ #include #include -#include +#include #include -const etk::UChar etk::UChar::Null('\0'); -const etk::UChar etk::UChar::Return('\n'); -const etk::UChar etk::UChar::CarrierReturn('\r'); -const etk::UChar etk::UChar::Tabulation('\t'); -const etk::UChar etk::UChar::Suppress((const char)127); -const etk::UChar etk::UChar::Delete((const char)8); -const etk::UChar etk::UChar::Space(' '); -const etk::UChar etk::UChar::Escape((const char)27); -void etk::UChar::lower(void) -{ - if( m_value>=(uint32_t)'A' - && m_value<=(uint32_t)'Z') { - m_value += (uint32_t)'a' - (uint32_t)'A'; - } -} - -etk::UChar etk::UChar::toLower(void) const -{ - if( m_value>=(uint32_t)'A' - && m_value<=(uint32_t)'Z') { - return m_value + (uint32_t)'a' - (uint32_t)'A'; - } - return m_value; -} - -void etk::UChar::upper(void) -{ - if( m_value>=(uint32_t)'a' - && m_value<=(uint32_t)'z') { - m_value += (uint32_t)'A' - (uint32_t)'a'; - } -} - -etk::UChar etk::UChar::toUpper(void) const -{ - if( m_value>=(uint32_t)'a' - && m_value<=(uint32_t)'z') { - return m_value + (uint32_t)'A' - (uint32_t)'a'; - } - return m_value; -} - - - -bool etk::UChar::compareNoCase(const etk::UChar& _obj) const -{ - return toUpper() == _obj.toUpper(); -} - - -etk::UChar etk::UChar::changeOrder(void) const -{ - if (m_value >= 'A' && m_value <= 'Z') { - return (m_value - (uint32_t)'A')*2 + 'A'; - } - if (m_value >= 'a' && m_value <= 'z') { - return (m_value - (uint32_t)'a')*2 + 'A' + 1; - } - if (m_value >= ':' && m_value <= '@') { - return m_value + 52; - } - if (m_value >= '[' && m_value <= '`') { - return m_value +26; - } - return m_value; -} - - -bool etk::UChar::isWhiteChar(void) const -{ - if( m_value == ' ' - || m_value == '\t' - || m_value == '\n' - || m_value == '\r') { +bool etk::isWhiteChar(char32_t _val) { + if( _val == ' ' + || _val == '\t' + || _val == '\n' + || _val == '\r') { return true; } return false; } -bool etk::UChar::isSpecialChar(void) const -{ - if( m_value < '0' - || (m_value > '9' && m_value < 'A') - || (m_value > 'Z' && m_value < 'a') - || (m_value > 'z' && m_value < 0xFF) ) { +bool etk::isSpecialChar(char32_t _val) { + if( _val < '0' + || (_val > '9' && _val < 'A') + || (_val > 'Z' && _val < 'a') + || (_val > 'z' && _val < 0xFF) ) { return true; } return false; } -bool etk::UChar::isInteger(void) const -{ - if( m_value>=(uint32_t)'0' - && m_value<=(uint32_t)'9') { +bool etk::isInteger(char32_t _val) { + if( _val >= (uint32_t)'0' + && _val <= (uint32_t)'9') { return true; } return false; } -int32_t etk::UChar::toInt32(void) const -{ - return m_value - (uint32_t)'0'; +int32_t etk::toInt32(char32_t _val) { + return _val - (uint32_t)'0'; } -/* -etk::CCout& etk::operator <<(etk::CCout& _os, const etk::UChar& _obj) -{ - char output_UTF8[8]; - unicode::convertUnicodeToUtf8(_obj, output_UTF8); - _os << &output_UTF8[0]; - return _os; + +char32_t etk::toLower(char32_t _val) { + if( _val>=(uint32_t)'A' + && _val<=(uint32_t)'Z') { + return _val + (uint32_t)'a' - (uint32_t)'A'; + } + return _val; +} + +char32_t etk::toUpper(char32_t _val) { + if( _val>=(uint32_t)'a' + && _val<=(uint32_t)'z') { + return _val + (uint32_t)'A' - (uint32_t)'a'; + } + return _val; +} + +bool etk::compareNoCase(char32_t _val1, char32_t _val2) { + return toUpper(_val1) == toUpper(_val2); } -*/ -uint32_t etk::UChar::getUtf8(void) const -{ +char32_t etk::changeOrder(char32_t _val) { + if (_val >= 'A' && _val <= 'Z') { + return (_val - (uint32_t)'A')*2 + 'A'; + } + if (_val >= 'a' && _val <= 'z') { + return (_val - (uint32_t)'a')*2 + 'A' + 1; + } + if (_val >= ':' && _val <= '@') { + return _val + 52; + } + if (_val >= '[' && _val <= '`') { + return _val +26; + } + return _val; +} + +static uint32_t getUtf8Val(char32_t _val) { uint32_t output = 0; - if (m_value <= 127) { - output = m_value; - } else if (m_value <= 2047) { + if (_val <= 127) { + output = _val; + } else if (_val <= 2047) { // output ==> 00000000 00000000 110xxxxx 10xxxxxx // input ==> -------- -------- -----222 22111111 output = 0x0000C080; - output+= (m_value & 0x000007C0)<<2; - output+= m_value & 0x0000003F; - } else if (m_value <= 65535) { + output+= (_val & 0x000007C0)<<2; + output+= _val & 0x0000003F; + } else if (_val <= 65535) { // output ==> 00000000 1110xxxx 10xxxxxx 10xxxxxx // input ==> -------- -------- 33332222 22111111 output = 0x00E08080; - output+= (m_value & 0x0000F000)<<4; - output+= (m_value & 0x00000FC0)<<2; - output+= m_value & 0x0000003F; - } else if (m_value <= 1114111) { + output+= (_val & 0x0000F000)<<4; + output+= (_val & 0x00000FC0)<<2; + output+= _val & 0x0000003F; + } else if (_val <= 1114111) { // output ==> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx // input ==> -------- ---44433 33332222 22111111 output = 0xF0808080; - output+= (m_value & 0x001C0000)<<6; - output+= (m_value & 0x0003F000)<<4; - output+= (m_value & 0x00000FC0)<<2; - output+= m_value & 0x0000003F; + output+= (_val & 0x001C0000)<<6; + output+= (_val & 0x0003F000)<<4; + output+= (_val & 0x00000FC0)<<2; + output+= _val & 0x0000003F; } else { TK_ERROR("NON UTF8 caracter input..."); return 0; @@ -164,9 +118,8 @@ uint32_t etk::UChar::getUtf8(void) const return output; } -int8_t etk::UChar::getUtf8(char _output[5]) const -{ - uint32_t value = getUtf8(); +int8_t etk::getUtf8(char32_t _val, char _output[5]) { + uint32_t value = getUtf8Val(_val); if (0xFF >= value) { _output[0] = (char)value; _output[1] = '\0'; @@ -191,10 +144,134 @@ int8_t etk::UChar::getUtf8(char _output[5]) const return 4; } } -/* -etk::Vector etk::UChar::GetUtf8(void) const + +uint8_t sizeElement(const char* _data, int32_t _lenMax) { - etk::Vector ret; + uint8_t size = 0; + TK_ASSERT(0 <= _lenMax, "size can not be < 0 ..."); + if (0 > _lenMax) { + return 0; + } + //4 case + if( _lenMax >= 1 + && (_data[0] & 0x80) == 0x00 ) { + // One Char Element + size = 1; + } else if( _lenMax >= 2 + && (_data[0] & 0xE0) == 0xC0 + && (_data[1] & 0xC0) == 0x80) { + size = 2; + } else if( _lenMax >= 3 + && (_data[0] & 0xF0) == 0xE0 + && (_data[1] & 0xC0) == 0x80 + && (_data[2] & 0xC0) == 0x80) { + size = 3; + } else if( _lenMax >= 4 + && (_data[0] & 0xF8) == 0xF0 + && (_data[1] & 0xC0) == 0x80 + && (_data[2] & 0xC0) == 0x80 + && (_data[3] & 0xC0) == 0x80) { + size = 4; + } + return size; +} + +char32_t etk::setUtf8(const char* _input) { + char32_t value = 0; + if (NULL == _input) { + return value; + } + int32_t len = strlen(_input); + len = sizeElement(_input, len); + switch (len) { + default: + // case 0 : An error occured... + value = _input[0]; + return value; + case 1: + value = (uint8_t)(_input[0]) & 0x7F; + return value; + case 2: + value = (((uint8_t)_input[0]) & 0x1F)<< 6; + value += ((uint8_t)_input[1]) & 0x3F; + return value; + case 3: + value = (((uint8_t)_input[0]) & 0x0F)<< 12; + value += (((uint8_t)_input[1]) & 0x3F)<< 6; + value += ((uint8_t)_input[2]) & 0x3F; + return value; + case 4: + value = (((uint8_t)_input[0]) & 0x07)<< 18; + value += (((uint8_t)_input[1]) & 0x3F)<< 12; + value += (((uint8_t)_input[2]) & 0x3F)<< 6; + value += ((uint8_t)_input[3]) & 0x3F; + return value; + } +} + +#if 0 +const char32_t char32_t::Null('\0'); +const char32_t char32_t::Return('\n'); +const char32_t char32_t::CarrierReturn('\r'); +const char32_t char32_t::Tabulation('\t'); +const char32_t char32_t::Suppress((const char)127); +const char32_t char32_t::Delete((const char)8); +const char32_t char32_t::Space(' '); +const char32_t char32_t::Escape((const char)27); + + + +bool char32_t::isWhiteChar(void) const +{ + if( m_value == ' ' + || m_value == '\t' + || m_value == '\n' + || m_value == '\r') { + return true; + } + return false; +} + +bool char32_t::isSpecialChar(void) const +{ + if( m_value < '0' + || (m_value > '9' && m_value < 'A') + || (m_value > 'Z' && m_value < 'a') + || (m_value > 'z' && m_value < 0xFF) ) { + return true; + } + return false; +} + +bool char32_t::isInteger(void) const +{ + if( m_value>=(uint32_t)'0' + && m_value<=(uint32_t)'9') { + return true; + } + return false; +} + +int32_t char32_t::toInt32(void) const +{ + return m_value - (uint32_t)'0'; +} +/* +etk::CCout& etk::operator <<(etk::CCout& _os, char32_t _obj) +{ + char output_UTF8[8]; + unicode::convertUnicodeToUtf8(_obj, output_UTF8); + _os << &output_UTF8[0]; + return _os; +} +*/ + + + +/* +std::vector char32_t::GetUtf8(void) const +{ + std::vector ret; uint32_t value = GetUtf8(); if (0xFF >= value) { ret.PushBack((char)value); @@ -246,7 +323,7 @@ uint8_t sizeElement(const char* _data, int32_t _lenMax) } -int8_t etk::UChar::setUtf8(const char* _input) +int8_t char32_t::setUtf8(const char* _input) { m_value = 0; if (NULL == _input) { @@ -280,7 +357,7 @@ int8_t etk::UChar::setUtf8(const char* _input) } } -int8_t etk::UChar::theoricUTF8Len(const char _input) +int8_t char32_t::theoricUTF8Len(const char _input) { if((_input&0x80) == 0x00 ) { return 1; @@ -297,7 +374,7 @@ int8_t etk::UChar::theoricUTF8Len(const char _input) return 1; } -bool etk::UChar::theoricUTF8First(const char _input) +bool char32_t::theoricUTF8First(const char _input) { // When started with the bit 0 then the size is signle element. if((_input&0x80) == 0x00 ) { @@ -309,3 +386,5 @@ bool etk::UChar::theoricUTF8First(const char _input) } return false; } + +#endif diff --git a/etk/UChar.h b/etk/UChar.h index 418f78c..28143e3 100644 --- a/etk/UChar.h +++ b/etk/UChar.h @@ -39,7 +39,8 @@ namespace etk { REGEXP_OPCODE_ERROR, // not used }; - class UChar { + #if 0 + class UChar : public char32_t{ public: // classic unicar code : static const UChar Null; //!< '\0' static const UChar Return; //!< '\n' @@ -49,126 +50,14 @@ namespace etk { static const UChar Delete; //!< DEL static const UChar Space; //!< ' ' SPACE static const UChar Escape; //!< ESC Escape - private: - uint32_t m_value; - public: - // note : No preset at this element to prevent unneded set - UChar(void) { - - }; - UChar(const etk::UChar& _obj) : - m_value(_obj.m_value) { - - }; - UChar(const char _obj) : - m_value((uint32_t)_obj){ - - }; - UChar(const enum regExpPrivateSection _obj) : - m_value((uint32_t)_obj) { - - }; - ~UChar(void) {} - - /***************************************************** - * = assigment - *****************************************************/ - const etk::UChar& operator= (const etk::UChar& _obj ) { - m_value = _obj.m_value; - return *this; - }; - /***************************************************** - * == operator - *****************************************************/ - bool operator== (const etk::UChar& _obj) const { - return m_value == _obj.m_value; - }; - bool compareNoCase(const etk::UChar& _obj) const; - /***************************************************** - * != operator - *****************************************************/ - bool operator!= (const etk::UChar& _obj) const { - return m_value != _obj.m_value; - }; - /***************************************************** - * > < >= <= operator - *****************************************************/ - bool operator> (const etk::UChar& _obj) const { - return m_value > _obj.m_value; - }; - bool operator>= (const etk::UChar& _obj) const { - return m_value >= _obj.m_value; - }; - bool operator< (const etk::UChar& _obj) const { - return m_value < _obj.m_value; - }; - bool operator<= (const etk::UChar& _obj) const { - return m_value <= _obj.m_value; - }; - /***************************************************** - * += operator - *****************************************************/ - const etk::UChar& operator+= (const etk::UChar& _obj) { - m_value += _obj.m_value; - return *this; - }; - /***************************************************** - * + operator - *****************************************************/ - etk::UChar operator+ (const etk::UChar& _obj) const { - etk::UChar tmp = *this; - tmp += _obj; - return tmp; - }; - /***************************************************** - * -= operator - *****************************************************/ - const etk::UChar& operator-= (const etk::UChar& _obj) { - if (_obj.m_value >= m_value) { - m_value = 0; - } else { - m_value -= _obj.m_value; - } - return *this; - }; - /***************************************************** - * - operator - *****************************************************/ - etk::UChar operator- (const etk::UChar& _obj) const { - etk::UChar tmp = *this; - tmp -= _obj; - return tmp; - }; - /***************************************************** - * () operator - *****************************************************/ - //operator uint32_t() const { return m_value; }; - /** - * @brief check if the curent element is white or not : '\t' '\n' '\r' ' ' - * @return tue if it is white char - */ - bool isWhiteChar(void) const; - bool isSpecialChar(void) const; - /** - * @brief check if the curent element is number or not - * @return tue if it is a number char - */ - bool isInteger(void) const; - int32_t toInt32(void) const; - - void lower(void); - UChar toLower(void) const; - void upper(void); - UChar toUpper(void) const; - - UChar changeOrder(void) const; + }; uint32_t get(void) const { return m_value; }; void set(uint32_t _val) { m_value = _val; }; uint32_t getUtf8(void) const; int8_t getUtf8(char _output[5]) const; - //etk::Vector GetUtf8(void) const; + //std::vector GetUtf8(void) const; int8_t setUtf8(const char* _input); public: /** @@ -184,6 +73,30 @@ namespace etk { */ static bool theoricUTF8First(const char _input); }; + #endif + /** + * @brief check if the curent element is white or not : '\t' '\n' '\r' ' ' + * @return tue if it is white char + */ + bool isWhiteChar(char32_t _val); + bool isSpecialChar(char32_t _val); + /** + * @brief check if the curent element is number or not + * @return tue if it is a number char + */ + bool isInteger(char32_t _val); + int32_t toInt32(char32_t _val); + + char32_t toLower(char32_t _val); + char32_t toUpper(char32_t _val); + bool compareNoCase(char32_t _val1, char32_t _val2); + char32_t changeOrder(char32_t _val); + + int8_t getUtf8(char32_t _val, char _output[5]); + char32_t setUtf8(const char* _input); + // TODO : Not needed : tolower(int ...) + char32_t toLower(char32_t _val); + char32_t toUpper(char32_t _val); }; #endif diff --git a/etk/UString.cpp b/etk/UString.cpp index c7f6dfa..f34f03a 100644 --- a/etk/UString.cpp +++ b/etk/UString.cpp @@ -10,7 +10,328 @@ #include #include -int32_t strlen(const etk::UChar * _data) { +#undef __class__ +#define __class__ "std::u32string" + +etk::CCout& etk::operator <<(etk::CCout& _os, const std::u32string& _obj) { + _os << to_u8string(_obj).c_str(); + return _os; +} + +etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector& _obj) { + _os << "{"; + for (int32_t iii=0; iii< _obj.size(); iii++) { + if (iii>0) { + _os << " ~ "; + } + _os << _obj[iii]; + } + _os << "}"; + return _os; +} + +std::string to_u8string(const std::u32string& _obj) { + std::vector tmpp; + for (size_t iii=0; iii<_obj.size(); ++iii) { + tmpp.push_back(_obj[iii]); + } + std::vector output_UTF8; + unicode::convertUnicodeToUtf8(tmpp, output_UTF8); + output_UTF8.push_back('\0'); + std::string out = &output_UTF8[0]; + return out; +} + +std::u32string to_u32string(const std::string& _obj) { + // TODO : Change this ... + std::vector transformData; + for ( size_t iii=0; iii< _obj.size(); ++iii) { + transformData.push_back(_obj[iii]); + } + std::vector output_Unicode; + unicode::convertUtf8ToUnicode(transformData, output_Unicode); + if( 0 == output_Unicode.size() + || output_Unicode[output_Unicode.size()-1] != 0) { + return U""; + } + std::u32string out; + for ( size_t iii=0; iii< output_Unicode.size(); ++iii) { + transformData.push_back((char32_t)output_Unicode[iii]); + } + return out; +} +std::u32string to_u32string(const char* _obj) { + if (_obj == NULL) { + return U""; + } + int64_t len = strlen(_obj); + // TODO : Change this ... + std::vector transformData; + for ( size_t iii=0; iii < len; ++iii) { + transformData.push_back(_obj[iii]); + } + std::vector output_Unicode; + unicode::convertUtf8ToUnicode(transformData, output_Unicode); + if( 0 == output_Unicode.size() + || output_Unicode[output_Unicode.size()-1] != 0) { + return U""; + } + std::u32string out; + for ( size_t iii=0; iii< output_Unicode.size(); ++iii) { + transformData.push_back((char32_t)output_Unicode[iii]); + } + return out; +} + +// TODO : Might remove this when it will be port on STL ... +std::u32string to_u32string(int _val) { + return to_u32string(std::to_string(_val)); +} + +std::u32string to_u32string(long _val) { + return to_u32string(std::to_string(_val)); +} + +std::u32string to_u32string(long long _val) { + return to_u32string(std::to_string(_val)); +} + +std::u32string to_u32string(unsigned _val) { + return to_u32string(std::to_string(_val)); +} + +std::u32string to_u32string(unsigned long _val) { + return to_u32string(std::to_string(_val)); +} + +std::u32string to_u32string(unsigned long long _val) { + return to_u32string(std::to_string(_val)); +} + +std::u32string to_u32string(float _val) { + return to_u32string(std::to_string(_val)); +} + +std::u32string to_u32string(double _val) { + return to_u32string(std::to_string(_val)); +} + +std::u32string to_u32string(long double _val) { + return to_u32string(std::to_string(_val)); +} + +double stod(const std::u32string& _str, size_t* _idx) { + std::string tmp = to_u8string(_str); + return std::stod(tmp, _idx); +} + +float stof(const std::u32string& _str, size_t* _idx) { + std::string tmp = to_u8string(_str); + return std::stof(tmp, _idx); +} + +int stoi(const std::u32string& _str, size_t* _idx, int _base) { + std::string tmp = to_u8string(_str); + return std::stoi(tmp, _idx, _base); +} + +long stol(const std::u32string& _str, size_t* _idx, int _base) { + std::string tmp = to_u8string(_str); + return std::stol(tmp, _idx, _base); +} + +long double stold(const std::u32string& _str, size_t* _idx) { + std::string tmp = to_u8string(_str); + return std::stold(tmp, _idx); +} + +long long stoll(const std::u32string& _str, size_t* _idx, int _base) { + std::string tmp = to_u8string(_str); + return std::stoll(tmp, _idx, _base); +} + +unsigned long stoul(const std::u32string& _str, size_t* _idx, int _base) { + std::string tmp = to_u8string(_str); + return std::stoul(tmp, _idx, _base); +} + +unsigned long long stoull(const std::u32string& _str, size_t* _idx, int _base) { + std::string tmp = to_u8string(_str); + return std::stoull(tmp, _idx, _base); +} + +bool stobool(const std::u32string& _str) { + if( true == compare_no_case(_str, U"true") + || true == compare_no_case(_str, U"enable") + || true == compare_no_case(_str, U"yes") + || _str == U"1") { + return true; + } + return false; +} + +bool stobool(const std::string& _str) { + if( true == compare_no_case(_str, "true") + || true == compare_no_case(_str, "enable") + || true == compare_no_case(_str, "yes") + || _str == u8"1") { + return true; + } + return false; +} + +bool compare_no_case(const std::u32string& _obj, const std::u32string& _val) { + if (_val.size() != _obj.size()) { + return false; + } + for(size_t iii=0; iii<_val.size(); ++iii) { + if (tolower(_val[iii]) != tolower(_obj[iii])) { + return false; + } + } + return true; +} + +bool compare_no_case(const std::string& _obj, const std::string& _val) { + if (_val.size() != _obj.size()) { + return false; + } + for(size_t iii=0; iii<_val.size(); ++iii) { + if (tolower(_val[iii]) != tolower(_obj[iii])) { + return false; + } + } + return true; +} + +std::u32string to_lower(const std::u32string& _obj) { + std::u32string out; + for(size_t iii=0 ; iii<_obj.size() ; iii++) { + out.push_back(tolower(_obj[iii])); + } + return out; +} + +std::u32string to_upper(const std::u32string& _obj) { + std::u32string out; + for(size_t iii=0 ; iii<_obj.size() ; iii++) { + out.push_back(toupper(_obj[iii])); + } + return out; +} + +bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { + if (_val.size() == 0) { + return false; + } + if (_val.size() > _obj.size()) { + return false; + } + if (true == _caseSensitive) { + for( int64_t iii=_val.size()-1, jjj=_obj.size()-1; + iii>=0 && jjj>=0; + iii--, jjj--) { + if (_obj[jjj] != _val[iii]) { + return false; + } + } + return true; + } + for( int64_t iii=_val.size()-1, jjj=_obj.size()-1; + iii>=0 && jjj>=0; + iii--, jjj--) { + if (tolower(_val[iii]) != tolower(_obj[jjj])) { + return false; + } + } + return true; +} + +bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { + if (_val.size() == 0) { + return false; + } + if (_val.size() > _obj.size()) { + return false; + } + if (true == _caseSensitive) { + for( size_t iii = 0; + iii < _obj.size(); + iii++) { + if (_obj[iii] != _val[iii]) { + return false; + } + } + return true; + } + for( size_t iii = 0; + iii < _obj.size(); + iii++) { + if (tolower(_val[iii]) != tolower(_obj[iii])) { + return false; + } + } + return true; +} + +std::u32string replace(const std::u32string& _obj, char32_t _val, char32_t _replace) { + std::u32string copy(_obj); + for( size_t iii = 0; + iii < copy.size(); + iii++) { + if (copy[iii] == _val) { + copy[iii] = _replace; + } + } + return copy; +} + +std::string replace(const std::string& _obj, char _val, char _replace) { + std::string copy(_obj); + for( size_t iii = 0; + iii < copy.size(); + iii++) { + if (copy[iii] == _val) { + copy[iii] = _replace; + } + } + return copy; +} + +std::u32string extract_line(const std::u32string& _obj, int32_t _pos) { + // search back : '\n' + esize_t startPos = _obj.rfind('\n', _pos); + if (startPos == _pos) { + startPos = 0; + } else { + startPos++; + } + // search forward : '\n' + size_t stopPos = _pos; + if (_obj[_pos] != '\n') { + stopPos = _obj.find('\n', _pos); + if (stopPos == _pos) { + stopPos = _obj.size(); + } + } + if (startPos < 0) { + startPos = 0; + } else if (startPos >= _obj.size() ) { + return U""; + } + if (stopPos < 0) { + return U""; + } else if (stopPos >= _obj.size() ) { + stopPos = _obj.size(); + } + return std::u32string(_obj, startPos, stopPos); +} + + +#if 0 + + +int32_t strlen(const char32_t * _data) { if (NULL == _data) { return 0; } @@ -26,17 +347,17 @@ int32_t strlen(const etk::UChar * _data) { } #undef __class__ -#define __class__ "etk::UString" +#define __class__ "std::string" -etk::CCout& etk::operator <<(etk::CCout& _os, const etk::UString& _obj) { - etk::Vector output_UTF8; +etk::CCout& etk::operator <<(etk::CCout& _os, const std::string& _obj) { + std::vector output_UTF8; unicode::convertUnicodeToUtf8(_obj.m_data, output_UTF8); - output_UTF8.pushBack('\0'); + output_UTF8.push_back('\0'); _os << &output_UTF8[0]; return _os; } -etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector& _obj) { +etk::CCout& etk::operator <<(etk::CCout& _os, const std::vector& _obj) { _os << "{"; for (int32_t iii=0; iii< _obj.size(); iii++) { if (iii>0) { @@ -48,18 +369,18 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector& _ return _os; } -etk::UString::UString(void) +std::string::UString(void) { - //TK_INFO("new etk::UString()"); - m_data.pushBack(etk::UChar::Null); + //TK_INFO("new std::string()"); + m_data.push_back(char32_t::Null); } -etk::UString::UString(const char* _data, enum unicode::charset _inputCharset) { +std::string::UString(const char* _data, enum unicode::charset _inputCharset) { // TODO : Change this ... - etk::Vector transformData; + std::vector transformData; while (*_data != '\0') { - transformData.pushBack(*_data); + transformData.push_back(*_data); _data++; } m_data.clear(); @@ -69,79 +390,79 @@ etk::UString::UString(const char* _data, enum unicode::charset _inputCharset) { unicode::convertIsoToUnicode(_inputCharset, transformData, m_data); } if( 0 == m_data.size() - || m_data[m_data.size()-1]!=etk::UChar::Null) { - m_data.pushBack(etk::UChar::Null); + || m_data[m_data.size()-1]!=char32_t::Null) { + m_data.push_back(char32_t::Null); } } // single element adding -etk::UString::UString(const bool _inputData, enum etk::UString::printMode _mode, bool _preset) { +std::string::UString(const bool _inputData, enum std::string::printMode _mode, bool _preset) { m_data.clear(); if (_preset==true) { switch(_mode) { - case etk::UString::printModeBinary : - m_data.pushBack('0'); - m_data.pushBack('b'); + case std::string::printModeBinary : + m_data.push_back('0'); + m_data.push_back('b'); break; - case etk::UString::printModeOctal : - m_data.pushBack('0'); - m_data.pushBack('o'); + case std::string::printModeOctal : + m_data.push_back('0'); + m_data.push_back('o'); break; - case etk::UString::printModeDecimal : + case std::string::printModeDecimal : break; - case etk::UString::printModeHexadecimal : - m_data.pushBack('0'); - m_data.pushBack('x'); + case std::string::printModeHexadecimal : + m_data.push_back('0'); + m_data.push_back('x'); break; default: - case etk::UString::printModeString : + case std::string::printModeString : break; } } switch(_mode) { - case etk::UString::printModeBinary : - case etk::UString::printModeOctal : - case etk::UString::printModeDecimal : - case etk::UString::printModeHexadecimal : + case std::string::printModeBinary : + case std::string::printModeOctal : + case std::string::printModeDecimal : + case std::string::printModeHexadecimal : if (true == _inputData) { - m_data.pushBack('1'); + m_data.push_back('1'); } else { - m_data.pushBack('0'); + m_data.push_back('0'); } break; default: - case etk::UString::printModeString : + case std::string::printModeString : if (true == _inputData) { - m_data.pushBack('t'); - m_data.pushBack('r'); - m_data.pushBack('u'); - m_data.pushBack('e'); + m_data.push_back('t'); + m_data.push_back('r'); + m_data.push_back('u'); + m_data.push_back('e'); } else { - m_data.pushBack('f'); - m_data.pushBack('a'); - m_data.pushBack('l'); - m_data.pushBack('s'); - m_data.pushBack('e'); + m_data.push_back('f'); + m_data.push_back('a'); + m_data.push_back('l'); + m_data.push_back('s'); + m_data.push_back('e'); } break; } - m_data.pushBack(etk::UChar::Null); + m_data.push_back(char32_t::Null); } -etk::UString::UString(const etk::UString& _obj) +std::string::UString(const std::string& _obj) { //etk_INFO("Constructeur de recopie"); m_data = _obj.m_data; } -etk::UString::UString(const etk::UChar& _inputData) +std::string::UString(char32_t _inputData) { - m_data.pushBack(_inputData); - m_data.pushBack(etk::UChar::Null); + m_data.push_back(_inputData); + m_data.push_back(char32_t::Null); } -etk::UString::UString(const float _inputData) +std::string::UString(const float _inputData) { // TODO : Rework this ... char tmpVal[256]; @@ -151,7 +472,7 @@ etk::UString::UString(const float _inputData) set(tmpVal); } -etk::UString::UString(const double _inputData) +std::string::UString(const double _inputData) { // TODO : Rework this ... char tmpVal[256]; @@ -178,9 +499,9 @@ etk::UString::UString(const double _inputData) // TODO : Does not work at all ... /* -etk::UString etk::UString::WrapHidenChar(void) const +std::string std::string::WrapHidenChar(void) const { - etk::UString out; + std::string out; for (int32_t iii=0; iii0) { uint64_t quotient = tmpVal / base; uint64_t rest = tmpVal - quotient*base; @@ -284,16 +605,16 @@ void etk::UString::setNumber(bool _negative, const uint64_t& _inputData, enum et //TK_ERROR (" " << ploppp); } if (m_data.size()==0) { - m_data.pushBack(etk::UChar::Null); - } else if (m_data[m_data.size()-1]!=etk::UChar::Null) { - m_data.pushBack(etk::UChar::Null); + m_data.push_back(char32_t::Null); + } else if (m_data[m_data.size()-1]!=char32_t::Null) { + m_data.push_back(char32_t::Null); } //TK_ERROR(" convert : " << _inputData << " in : " << *this << " len=" << m_data.Size()); } -void etk::UString::set(const int64_t& _inputData, enum etk::UString::printMode _mode, bool _preset, int32_t _leadingZero) +void std::string::set(const int64_t& _inputData, enum std::string::printMode _mode, bool _preset, int32_t _leadingZero) { - if (_preset==true && _mode != etk::UString::printModeString) { + if (_preset==true && _mode != std::string::printModeString) { setNumber(false, (uint64_t)_inputData, _mode, _preset, _leadingZero); return; } @@ -305,80 +626,80 @@ void etk::UString::set(const int64_t& _inputData, enum etk::UString::printMode _ } } -void etk::UString::set(const uint64_t& _inputData, enum etk::UString::printMode _mode, bool _preset, int32_t _leadingZero) +void std::string::set(const uint64_t& _inputData, enum std::string::printMode _mode, bool _preset, int32_t _leadingZero) { setNumber(false, (uint64_t)_inputData, _mode, _preset, _leadingZero); } // multiple element add -etk::UString::UString(const etk::UChar* _inputData, int32_t _len) +std::string::UString(const char32_t* _inputData, int32_t _len) { set(_inputData, _len); } -etk::UString::UString(const char* _inputData, int32_t _len) +std::string::UString(const char* _inputData, int32_t _len) { set(_inputData, _len); } -etk::UString::UString(const etk::Vector& _inputData) +std::string::UString(const std::vector& _inputData) { set(_inputData); } -etk::UString::UString(const etk::Vector& _inputData) +std::string::UString(const std::vector& _inputData) { set(_inputData); } -etk::UString::UString(const etk::Vector& _inputData) +std::string::UString(const std::vector& _inputData) { set(_inputData); } -void etk::UString::set(const etk::Vector& _inputData) +void std::string::set(const std::vector& _inputData) { if (_inputData.size()==0) { clear(); return; } - etk::Vector output_Unicode; + std::vector output_Unicode; unicode::convertUtf8ToUnicode(_inputData, output_Unicode); set(output_Unicode); } -void etk::UString::set(const etk::Vector& _inputData) +void std::string::set(const std::vector& _inputData) { if (_inputData.size()==0) { clear(); return; } - etk::Vector output_Unicode; + std::vector output_Unicode; unicode::convertUtf8ToUnicode(_inputData, output_Unicode); set(output_Unicode); } -void etk::UString::set(const etk::Vector& _inputData) +void std::string::set(const std::vector& _inputData) { m_data = _inputData; if (m_data.size()>0) { - if (m_data[m_data.size()-1] != etk::UChar::Null) { - m_data.pushBack(etk::UChar::Null); + if (m_data[m_data.size()-1] != char32_t::Null) { + m_data.push_back(char32_t::Null); } } else { - m_data.pushBack(etk::UChar::Null); + m_data.push_back(char32_t::Null); } //TK_DEBUG("m_dataLen="< (const etk::UString& _obj) const +bool std::string::operator> (const std::string& _obj) const { if( this != &_obj ) { for (int32_t iii=0; iii < m_data.size() && iii < _obj.m_data.size(); iii++) { //TK_DEBUG(" compare : '" << (char)m_data[iii] << "'>'" << (char)_obj.m_data[iii] << "' ==> " << changeOrder(m_data[iii]) << ">" << changeOrder(_obj.m_data[iii]) << ""); - etk::UChar elemA = m_data[iii].changeOrder(); - etk::UChar elemB = _obj.m_data[iii].changeOrder(); + char32_t elemA = m_data[iii].changeOrder(); + char32_t elemB = _obj.m_data[iii].changeOrder(); if (elemA != elemB) { if (elemA > elemB) { return true; @@ -463,12 +784,12 @@ bool etk::UString::operator> (const etk::UString& _obj) const return false; } -bool etk::UString::operator>= (const etk::UString& _obj) const +bool std::string::operator>= (const std::string& _obj) const { if( this != &_obj ) { for (int32_t iii=0; iii < m_data.size() && iii < _obj.m_data.size(); iii++) { - etk::UChar elemA = m_data[iii].changeOrder(); - etk::UChar elemB = _obj.m_data[iii].changeOrder(); + char32_t elemA = m_data[iii].changeOrder(); + char32_t elemB = _obj.m_data[iii].changeOrder(); if (elemA != elemB) { if (elemA > elemB) { return true; @@ -483,12 +804,12 @@ bool etk::UString::operator>= (const etk::UString& _obj) const return false; } -bool etk::UString::operator< (const etk::UString& _obj) const +bool std::string::operator< (const std::string& _obj) const { if( this != &_obj ) { for (int32_t iii=0; iii < m_data.size() && iii < _obj.m_data.size(); iii++) { - etk::UChar elemA = m_data[iii].changeOrder(); - etk::UChar elemB = _obj.m_data[iii].changeOrder(); + char32_t elemA = m_data[iii].changeOrder(); + char32_t elemB = _obj.m_data[iii].changeOrder(); if (elemA != elemB) { if (elemA < elemB) { return true; @@ -503,12 +824,12 @@ bool etk::UString::operator< (const etk::UString& _obj) const return false; } -bool etk::UString::operator<= (const etk::UString& _obj) const +bool std::string::operator<= (const std::string& _obj) const { if( this != &_obj ) { for (int32_t iii=0; iii < m_data.size() && iii < _obj.m_data.size(); iii++) { - etk::UChar elemA = m_data[iii].changeOrder(); - etk::UChar elemB = _obj.m_data[iii].changeOrder(); + char32_t elemA = m_data[iii].changeOrder(); + char32_t elemB = _obj.m_data[iii].changeOrder(); if (elemA != elemB) { if (elemA < elemB) { return true; @@ -524,7 +845,7 @@ bool etk::UString::operator<= (const etk::UString& _obj) const } -bool etk::UString::operator== (const etk::UString& _obj) const +bool std::string::operator== (const std::string& _obj) const { if( this != &_obj ) { if (_obj.m_data.size() != m_data.size()) { @@ -540,7 +861,7 @@ bool etk::UString::operator== (const etk::UString& _obj) const return true; } -bool etk::UString::compareNoCase(const etk::UString& _obj) const +bool std::string::compareNoCase(const std::string& _obj) const { if( this != &_obj ) { if (_obj.m_data.size() != m_data.size()) { @@ -557,12 +878,12 @@ bool etk::UString::compareNoCase(const etk::UString& _obj) const } -bool etk::UString::operator!= (const etk::UString& _obj) const +bool std::string::operator!= (const std::string& _obj) const { return !(*this == _obj); } -const etk::UString& etk::UString::operator+= (const etk::UString &_obj) +const std::string& std::string::operator+= (const std::string &_obj) { if (0 < _obj.size()) { // remove the last '\0' @@ -572,22 +893,22 @@ const etk::UString& etk::UString::operator+= (const etk::UString &_obj) // This previous include the \0 in case of the 2 UString are different... if( this == &_obj ) { // add the removed end UString - m_data.pushBack(etk::UChar::Null); + m_data.push_back(char32_t::Null); } } return *this; } -etk::UString etk::UString::operator+ (const etk::UString &_obj) const +std::string std::string::operator+ (const std::string &_obj) const { - etk::UString temp; + std::string temp; temp += *this; temp += _obj; return temp; } -bool etk::UString::isEmpty(void) const +bool std::string::isEmpty(void) const { if(1 >= m_data.size() ) { return true; @@ -597,7 +918,7 @@ bool etk::UString::isEmpty(void) const } -int32_t etk::UString::size(void) const +int32_t std::string::size(void) const { if (m_data.size() == 0) { return 0; @@ -607,14 +928,14 @@ int32_t etk::UString::size(void) const } -void etk::UString::add(int32_t _currentID, const char* _inputData) +void std::string::add(int32_t _currentID, const char* _inputData) { - etk::UString tmpString(_inputData); + std::string tmpString(_inputData); add(_currentID, tmpString.pointer() ); } -void etk::UString::add(int32_t _currentID, const etk::UChar* _inputData) +void std::string::add(int32_t _currentID, const char32_t* _inputData) { // get the input lenght int32_t len = strlen(_inputData); @@ -626,30 +947,30 @@ void etk::UString::add(int32_t _currentID, const etk::UChar* _inputData) _currentID = 0; } else if (_currentID > size() ) { TK_ERROR("Curent ID(" << _currentID << ") > maxSize ... (" << size() << ") ==> add at the end ..."); - m_data.pushBack(_inputData, len); + m_data.push_back(_inputData, len); return; } m_data.insert(_currentID, _inputData, len); } -void etk::UString::add(int32_t _currentID, const etk::UChar _inputData) +void std::string::add(int32_t _currentID, const char32_t _inputData) { - etk::UChar data[2]; + char32_t data[2]; data[0] = _inputData; - data[1] = etk::UChar::Null; + data[1] = char32_t::Null; add(_currentID, data); } -void etk::UString::append(const etk::UChar& _inputData) +void std::string::append(char32_t _inputData) { m_data.popBack(); - m_data.pushBack(_inputData); - m_data.pushBack(etk::UChar::Null); + m_data.push_back(_inputData); + m_data.push_back(char32_t::Null); } -void etk::UString::remove(int32_t _currentID, int32_t _len) +void std::string::remove(int32_t _currentID, int32_t _len) { if (0 >= _len) { TK_ERROR("no data to remove on the current UString"); @@ -660,13 +981,13 @@ void etk::UString::remove(int32_t _currentID, int32_t _len) } -void etk::UString::clear(void) +void std::string::clear(void) { m_data.clear(); - m_data.pushBack(etk::UChar::Null); + m_data.push_back(char32_t::Null); } -int32_t etk::UString::findForward(const etk::UChar _element, int32_t _startPos) const +int32_t std::string::findForward(const char32_t _element, int32_t _startPos) const { if (_startPos < 0) { _startPos = 0; @@ -681,7 +1002,7 @@ int32_t etk::UString::findForward(const etk::UChar _element, int32_t _startPos) return -1; } -int32_t etk::UString::findBack(const etk::UChar _element, int32_t _startPos) const +int32_t std::string::findBack(const char32_t _element, int32_t _startPos) const { if (_startPos < 0) { return -1; @@ -697,9 +1018,9 @@ int32_t etk::UString::findBack(const etk::UChar _element, int32_t _startPos) con } -etk::UString etk::UString::extract(int32_t _posStart, int32_t _posEnd) const +std::string std::string::extract(int32_t _posStart, int32_t _posEnd) const { - etk::UString out; + std::string out; if (_posStart < 0) { _posStart = 0; } else if (_posStart >= size() ) { @@ -711,11 +1032,11 @@ etk::UString etk::UString::extract(int32_t _posStart, int32_t _posEnd) const _posEnd = size(); } out.m_data = m_data.extract(_posStart, _posEnd); - out.m_data.pushBack(etk::UChar::Null); + out.m_data.push_back(char32_t::Null); return out; } -etk::UString etk::UString::extractLine(int32_t _pos) const +std::string std::string::extractLine(int32_t _pos) const { // search back : '\n' int32_t startPos = findBack('\n', _pos); @@ -732,7 +1053,7 @@ etk::UString etk::UString::extractLine(int32_t _pos) const stopPos = size(); } } - etk::UString out; + std::string out; if (startPos < 0) { startPos = 0; } else if (startPos >= size() ) { @@ -744,19 +1065,19 @@ etk::UString etk::UString::extractLine(int32_t _pos) const stopPos = size(); } out.m_data = m_data.extract(startPos, stopPos); - out.m_data.pushBack(etk::UChar::Null); + out.m_data.push_back(char32_t::Null); return out; } -etk::Vector etk::UString::getVector(void) +std::vector std::string::getVector(void) { - etk::Vector out = m_data; + std::vector out = m_data; out.popBack(); return out; } -bool etk::UString::startWith(const etk::UString& _data, bool _caseSensitive) const +bool std::string::startWith(const std::string& _data, bool _caseSensitive) const { if (_data.size() == 0) { return false; @@ -781,7 +1102,7 @@ bool etk::UString::startWith(const etk::UString& _data, bool _caseSensitive) con } -bool etk::UString::endWith(const etk::UString& _data, bool _caseSensitive) const +bool std::string::endWith(const std::string& _data, bool _caseSensitive) const { if (_data.size() == 0) { return false; @@ -810,10 +1131,10 @@ bool etk::UString::endWith(const etk::UString& _data, bool _caseSensitive) const } -etk::Char etk::UString::c_str(void) const +etk::Char std::string::c_str(void) const { etk::Char tmpVar; - etk::Vector tmpData; + std::vector tmpData; // UTF8 generation : tmpData.clear(); unicode::convertUnicodeToUtf8(m_data, tmpData); @@ -821,24 +1142,24 @@ etk::Char etk::UString::c_str(void) const return tmpVar; } -etk::Vector etk::UString::split(const etk::UChar& _val) +std::vector std::string::split(char32_t _val) { - etk::Vector list; + std::vector list; int32_t lastStartPos=0; for(int32_t iii=0; iii -#include -#include -#include +#include +#include +#include namespace etk { + /* + std::u32string to_string(int _val); + std::u32string to_string(long _val); + std::u32string to_string(long long _val); + std::u32string to_string(unsigned _val); + std::u32string to_string(unsigned long _val); + std::u32string to_string(unsigned long long _val); + std::u32string to_string(float _val); + std::u32string to_string(double _val); + std::u32string to_string(long double _val); + */ + //typedef std::u32string UString; + #if 0 class UString { public: enum printMode { @@ -25,18 +38,18 @@ namespace etk { printModeString, }; private : - etk::Vector m_data; //!< internal data is stored in the Unicode properties ... + std::vector m_data; //!< internal data is stored in the Unicode properties ... public: // Constructeurs UString(void); // destructor : ~UString(void) { }; // recopy operator : - UString(const etk::UString& _obj); + UString(const std::string& _obj); // single element adding UString(const bool _inputData, enum printMode _mode=printModeString, bool _preset=false); - UString(const etk::UChar& _inputData); + UString(char32_t _inputData); UString(const char* _data, enum unicode::charset _inputCharset); UString(const float _inputData); UString(const double _inputData); @@ -65,17 +78,17 @@ namespace etk { set(_inputData, _mode, _preset, _leadingZero); }; // multiple element add - UString(const etk::UChar* _inputData, int32_t _len = -1); + UString(const char32_t* _inputData, int32_t _len = -1); UString(const char* _inputData, int32_t _len = -1); - UString(const etk::Vector& _inputData); - UString(const etk::Vector& _inputData); - UString(const etk::Vector& _inputData); + UString(const std::vector& _inputData); + UString(const std::vector& _inputData); + UString(const std::vector& _inputData); // generic setter - void set(const etk::UChar* _inputData, int32_t _len=-1); + void set(const char32_t* _inputData, int32_t _len=-1); void set(const char* _inputData, int32_t _len=-1); - void set(const etk::Vector& _inputData); - void set(const etk::Vector& _inputData); - void set(const etk::Vector& _inputData); + void set(const std::vector& _inputData); + void set(const std::vector& _inputData); + void set(const std::vector& _inputData); private: void setNumber(bool _negative, const uint64_t& _inputData, enum printMode _mode, bool _preset, int32_t _leadingZero); public: @@ -85,39 +98,39 @@ namespace etk { /***************************************************** * = assigment *****************************************************/ - const etk::UString& operator= (const etk::UString& _obj ); + const std::string& operator= (const std::string& _obj ); /***************************************************** * == operator *****************************************************/ - bool operator== (const etk::UString& _obj) const; - bool compareNoCase(const etk::UString& _obj) const; + bool operator== (const std::string& _obj) const; + bool compareNoCase(const std::string& _obj) const; /***************************************************** * != operator *****************************************************/ - bool operator!= (const etk::UString& _obj) const; + bool operator!= (const std::string& _obj) const; /***************************************************** * > < >= <= operator *****************************************************/ - bool operator> (const etk::UString& _obj) const; - bool operator>= (const etk::UString& _obj) const; - bool operator< (const etk::UString& _obj) const; - bool operator<= (const etk::UString& _obj) const; + bool operator> (const std::string& _obj) const; + bool operator>= (const std::string& _obj) const; + bool operator< (const std::string& _obj) const; + bool operator<= (const std::string& _obj) const; /***************************************************** * += operator *****************************************************/ - const etk::UString& operator+= (const etk::UString& _obj); - //const etk::UString& operator+= (const etk::UChar& _obj); + const std::string& operator+= (const std::string& _obj); + //const std::string& operator+= (char32_t _obj); /***************************************************** * + operator *****************************************************/ - etk::UString operator+ (const etk::UString &_obj) const; + std::string operator+ (const std::string &_obj) const; /***************************************************** * << operator *****************************************************/ /* - const etk::UString& operator <<= (const char input); - const etk::UString& operator <<= (const int input); - const etk::UString& operator <<= (const unsigned int input); + const std::string& operator <<= (const char input); + const std::string& operator <<= (const int input); + const std::string& operator <<= (const unsigned int input); */ /***************************************************** * >> operator @@ -126,14 +139,14 @@ namespace etk { /***************************************************** * Cout << operator *****************************************************/ - friend etk::CCout& operator <<( etk::CCout& _os,const etk::UString& _obj); + friend etk::CCout& operator <<( etk::CCout& _os,const std::string& _obj); /***************************************************** * [] operator *****************************************************/ - const etk::UChar& operator[] (esize_t _pos) const { + char32_t operator[] (esize_t _pos) const { return m_data[_pos]; } - etk::UChar& operator[] (esize_t _pos) { + char32_t operator[] (esize_t _pos) { return m_data[_pos]; } @@ -141,12 +154,12 @@ namespace etk { * toolbox *****************************************************/ // Start With ... - bool startWith(const etk::UString& _data, bool _caseSensitive=true) const ; + bool startWith(const std::string& _data, bool _caseSensitive=true) const ; // End With ... - bool endWith(const etk::UString& _data, bool _caseSensitive=true) const ; + bool endWith(const std::string& _data, bool _caseSensitive=true) const ; // Find element - int32_t findForward(const etk::UChar _data, int32_t _startPos=0) const; - int32_t findBack(const etk::UChar _data, int32_t _startPos=0x7FFFFFFF) const; + int32_t findForward(const char32_t _data, int32_t _startPos=0) const; + int32_t findBack(const char32_t _data, int32_t _startPos=0x7FFFFFFF) const; bool isEmpty(void) const; int32_t size(void) const; @@ -155,44 +168,44 @@ namespace etk { * Generic modification function *****************************************************/ void add(int32_t _currentID, const char* _inputData); - void add(int32_t _currentID, const etk::UChar* _inputData); - void add(int32_t _currentID, const etk::UChar _inputData); + void add(int32_t _currentID, const char32_t* _inputData); + void add(int32_t _currentID, const char32_t _inputData); void remove(int32_t _currentID, int32_t _len = 1); void clear(void); - void append(const etk::UChar& _inputData); + void append(char32_t _inputData); /** * @brief Split a string in multiple separate by a specific char * @param[in] _val Separate value of the string * @return The list of all sthe string splited. */ - etk::Vector split(const etk::UChar& _val); + std::vector split(char32_t _val); /** * @brief Replace a char with an other * @param[in] _out element to replace. * @param[in] _in Element to set. */ - void replace(const etk::UChar& _out, const etk::UChar& _in); + void replace(char32_t _out, char32_t _in); - etk::Vector getVector(void); - etk::UChar* pointer(void) { return &m_data[0]; }; + std::vector getVector(void); + char32_t* pointer(void) { return &m_data[0]; }; etk::Char c_str(void) const; void lower(void); - etk::UString toLower(void) const; + std::string toLower(void) const; void upper(void); - etk::UString toUpper(void) const; + std::string toUpper(void) const; /** * @brief transform tab in \t and '\r' in \r * @return the new string */ - //etk::UString WrapHidenChar(void) const; + //std::string WrapHidenChar(void) const; // Sting operation : - etk::UString extract(int32_t _posStart=0, int32_t _posEnd=0x7FFFFFFF) const; - etk::UString extractLine(int32_t _pos=0) const; + std::string extract(int32_t _posStart=0, int32_t _posEnd=0x7FFFFFFF) const; + std::string extractLine(int32_t _pos=0) const; /** * @brief Transform the current string in an int64_t * @return the requested int @@ -249,14 +262,66 @@ namespace etk { */ bool toBool(void) const; }; + #endif - etk::CCout& operator <<(etk::CCout& _os, const etk::UString& _obj); - etk::CCout& operator <<(etk::CCout& _os, const etk::Vector& _obj); + etk::CCout& operator <<(etk::CCout& _os, const std::u32string& _obj); + etk::CCout& operator <<(etk::CCout& _os, const std::vector& _obj); +}; +std::string to_u8string(const std::u32string& _obj); +std::u32string to_u32string(const std::string& _obj); +std::u32string to_u32string(const char* _obj); + + +template std::string to_string(T t, std::ios_base & (*f)(std::ios_base&)) { + std::ostringstream oss; + oss << f << t; + return oss.str(); } -int32_t strlen(const etk::UChar * _data); +template std::u32string to_u32string(T t, std::ios_base & (*f)(std::ios_base&)) { + std::ostringstream oss; + oss << f << t; + return to_u32string(oss.str()); +} +std::u32string to_u32string(int _val); +std::u32string to_u32string(long _val); +std::u32string to_u32string(long long _val); +std::u32string to_u32string(unsigned _val); +std::u32string to_u32string(unsigned long _val); +std::u32string to_u32string(unsigned long long _val); +std::u32string to_u32string(float _val); +std::u32string to_u32string(double _val); +std::u32string to_u32string(long double _val); + +double stod(const std::u32string& _str, size_t* _idx = 0); +float stof(const std::u32string& _str, size_t* _idx = 0); +int stoi(const std::u32string& _str, size_t* _idx = 0, int _base = 10); +long stol(const std::u32string& _str, size_t* _idx = 0, int _base = 10); +long double stold(const std::u32string& _str, size_t* _idx = 0); +long long stoll(const std::u32string& _str, size_t* _idx = 0, int _base = 10); +unsigned long stoul(const std::u32string& _str, size_t* _idx = 0, int _base = 10); +unsigned long long stoull(const std::u32string& _str, size_t* _idx = 0, int _base = 10); +bool stobool(const std::u32string& _str); +bool stobool(const std::string& _str); + + +std::u32string to_lower(const std::u32string& _obj); +std::u32string to_upper(const std::u32string& _obj); + +bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false); +bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = false); + +bool compare_no_case(const std::u32string& _obj, const std::u32string& _val); +bool compare_no_case(const std::string& _obj, const std::string& _val); + +std::u32string replace(const std::u32string& _obj, char32_t _val, char32_t _replace); +std::string replace(const std::string& _obj, char _val, char _replace); + +int32_t strlen(const char32_t * _data); + +std::u32string extract_line(const std::u32string& _obj, int32_t _pos); #endif diff --git a/etk/Vector.h b/etk/Vector.h index 588f0f2..e69de29 100644 --- a/etk/Vector.h +++ b/etk/Vector.h @@ -1,729 +0,0 @@ -/** - * @author Edouard DUPIN - * - * @copyright 2011, Edouard DUPIN, all right reserved - * - * @license BSD v3 (see license file) - */ - -#ifndef __ETK_VECTOR_H__ -#define __ETK_VECTOR_H__ - -#include -#include - -#undef __class__ -#define __class__ "etk::Vector" - - -namespace etk -{ - /** - * @brief Vector classes ... - * - * @tparam[in] MY_TYPE class type of the current element. - * - * m_data - * <------------ m_dataSize ------------> - * ---------------------------------------- - * | 0 | - * |--------------------------------------| - * | 1 | - * |--------------------------------------| - * | 2 | - * |--------------------------------------| - * m_size | 3 | - * |--------------------------------------| - * | x | - * |--------------------------------------| - * | x | - * |--------------------------------------| - * | x | - * |--------------------------------------| - * | x | - * |--------------------------------------| - * | x | - * |--------------------------------------| - * | x | - * |--------------------------------------| - * m_allocated | x | - * ---------------------------------------- - * - */ - template class Vector - { - public: - class Iterator { - // Private data : - private: - esize_t m_current; //!< curent Id on the vector - Vector* m_vector; //!< Pointer on the curent element of the vectorBin - public: - /** - * @brief Basic itarator constructor with no link with an etkVector - */ - Iterator(void): - m_current(0), - m_vector(NULL) { - // nothing to do ... - } - /** - * @brief Recopy constructor on a specific etkVector. - * @param[in] _obj The Iterator that might be copy - */ - Iterator(const Iterator & _obj): - m_current(_obj.m_current), - m_vector(_obj.m_vector) { - // nothing to do ... - } - /** - * @brief Asignation operator. - * @param[in] _otherIterator The Iterator that might be copy - * @return reference on the curent Iterator - */ - Iterator& operator=(const Iterator & _otherIterator) { - m_current = _otherIterator.m_current; - m_vector = _otherIterator.m_vector; - return *this; - } - /** - * @brief Basic destructor - */ - ~Iterator(void) { - m_current = 0; - m_vector = NULL; - } - /** - * @brief basic boolean cast - * @return true if the element is present in the etkVector size - */ - operator bool (void) { - return (m_current < m_vector->size()); - } - /** - * @brief Incremental operator - * @return Reference on the current iterator incremented - */ - Iterator& operator++ (void) { - if ( m_vector != NULL - && m_current < m_vector->size() ) - { - m_current++; - } - return *this; - } - /** - * @brief Decremental operator - * @return Reference on the current iterator decremented - */ - Iterator& operator-- (void) { - if ( m_vector != NULL - && m_current > 0) { - m_current--; - } - return *this; - } - /** - * @brief Incremental operator - * @return Reference on a new iterator and increment the other one - */ - Iterator operator++ (int32_t) { - Iterator it(*this); - ++(*this); - return it; - } - /** - * @brief Decremental operator - * @return Reference on a new iterator and decrement the other one - */ - Iterator operator-- (int32_t) { - Iterator it(*this); - --(*this); - return it; - } - /** - * @brief Get reference on the current Element - * @return the reference on the current Element - */ - MY_TYPE & operator-> (void) const { - TK_CHECK_INOUT(m_current < m_vector->size()); - return &m_vector->get(m_current); - } - /** - * @brief Get reference on the current Element - * @return the reference on the current Element - */ - MY_TYPE & operator* (void) const { - TK_CHECK_INOUT(m_current < m_vector->size()); - return m_vector->get(m_current); - } - private: - Iterator(Vector * _obj, int32_t _pos): - m_current(_pos), - m_vector(_obj) { - // nothing to do ... - } - friend class Vector; - }; - - private: - MY_TYPE* m_data; //!< pointer on the curetn table of Data - esize_t m_size; //!< nb Element in the buffer - esize_t m_allocated; //!< Current allocated size - public: - /** - * @brief Create an empty vector - * @param[in] _count Minimum request size of the Buffer - */ - Vector(int32_t _count = 0): - m_data(NULL), - m_size(0), - m_allocated(0) { - changeAllocation(_count); - } - /** - * @brief Re-copy constructor (copy all needed data) - * @param[in] _obj Vector that might be copy - */ - Vector(const etk::Vector& _obj) { - m_allocated = _obj.m_allocated; - m_size = _obj.m_size; - m_data = NULL; - //TK_DEBUG("USE Specific vector allocator ... Evb.m_size=" << Evb.m_size << " Evb.m_increment=" << Evb.m_increment); - // allocate all same data - m_data = new MY_TYPE[m_allocated]; - if (NULL==m_data) { - TK_CRITICAL("Vector : Error in data allocation ... might nor work corectly anymore"); - return; - } - // Copy all data ... - for(esize_t iii=0; iii& _obj) { - // avoid Swap of itself - if(this != &_obj) { - MY_TYPE* tmpData = m_data; - esize_t tmpAllocated = m_allocated; - esize_t tmpSize = m_size; - m_data = _obj.m_data; - m_allocated = _obj.m_allocated; - m_size = _obj.m_size; - _obj.m_data = tmpData; - _obj.m_allocated = tmpAllocated; - _obj.m_size = tmpSize; - } - } - /** - * @brief Re-copy operator - * @param[in] _obj Vector that might be copy - * @return reference on the curent re-copy vector - */ - Vector& operator=(const etk::Vector & _obj) { - //TK_DEBUG("USE RECOPY vector ... Evb.m_size=" << Evb.m_size << " Evb.m_increment=" << Evb.m_increment); - if( this != &_obj ) { - if (NULL!=m_data) { - delete[] m_data; - m_data = NULL; - } - // Set the new value - m_allocated = _obj.m_allocated; - m_size = _obj.m_size; - // allocate all same data - m_data = new MY_TYPE[m_allocated]; - if (NULL==m_data) { - TK_CRITICAL("Vector : Error in data allocation ... might nor work corectly anymore"); - return *this; - } - for(esize_t iii=0; iii & _obj) { - esize_t nbElememt = _obj.size(); - esize_t idx = m_size; - resize(m_size+nbElememt); - if (m_size<=idx) { - TK_CRITICAL("allocation error"); - return *this; - } - for(esize_t iii=0; iii idx) { - // initialize data ... - for(esize_t iii=idx; iii<_newSize; iii++) { - m_data[iii] = _basicElement; - } - } - } - /** - * @brief Get the Allocated size in the vector - * @return The size of allocation - */ - esize_t allocatedSize(void) const { - return m_allocated; - } - /** - * @brief Get a current element in the vector - * @param[in] _pos Desired position read - * @return Reference on the Element - */ - MY_TYPE& get(esize_t _pos) { - // NOTE :Do not change log level, this generate error only in debug mode - #if DEBUG_LEVEL > 2 - if(_pos>m_size){ - TK_CRITICAL("[CRITICAL] Access to an unexistant data in vector : " << _pos << "/ " << m_size); - } - #endif - return m_data[_pos]; - } - /** - * @brief Get an copy Element an a special position - * @param[in] _pos Position in the vector that might be get [0..Size()] - * @return An reference on the copy of selected element - */ - MY_TYPE& operator[] (esize_t _pos) { - return get(_pos); - } - /** - * @brief Get an Element an a special position - * @param[in] _pos Position in the vector that might be get [0..Size()] - * @return An reference on the selected element - */ - const MY_TYPE& operator[] (esize_t _pos) const { - // NOTE :Do not change log level, this generate error only in debug mode - #if DEBUG_LEVEL > 2 - if(_pos>m_size){ - TK_CRITICAL("[CRITICAL] Access to an unexistant data in vector : " << _pos << "/ " << m_size); - } - #endif - return m_data[_pos]; - } - /** - * @brief Add at the First position of the Vector - * @param[in] _item Element to add at the end of vector - */ - void pushFront(const MY_TYPE& _item) { - insert(0, &_item, 1); - } - /** - * @brief Add at the Last position of the Vector - * @param[in] _item Pointer on a list of Element to add at the start of vector - * @param[in] _nbElement Number of element to add. - */ - void pushFront(const MY_TYPE * _item, esize_t _nbElement) { - insert(0, _item, _nbElement); - } - /** - * @brief Add at the Last position of the Vector - * @param[in] _item Element to add at the end of vector - */ - void pushBack(const MY_TYPE& _item) { - esize_t idx = m_size; - resize(m_size+1); - if (idx < m_size) { - m_data[idx] = _item; - } else { - TK_ERROR("Resize does not work corectly ... not added item"); - } - } - /** - * @brief Add at the Last position of the Vector - * @param[in] _item Pointer on a list of Element to add at the end of vector - * @param[in] _nbElement Number of element to add. - */ - void pushBack(const MY_TYPE * _item, esize_t _nbElement) { - if (NULL == _item) { - return; - } - esize_t idx = m_size; - resize(m_size+_nbElement); - if (idx > m_size) { - TK_ERROR("Resize does not work corectly ... not added item"); - return; - } - for (esize_t iii=0; iii<_nbElement; iii++) { - m_data[idx+iii] = _item[iii]; - } - } - /** - * @brief Remove the last element of the vector - */ - void popBack(void) { - if(m_size>0) { - resize(m_size-1); - } - } - /** - * @brief Remove all alement in the current vector - */ - void clear(void) { - if(m_size>0) { - resize(0); - } - } - /** - * @brief Insert N element in the Vector. - * @param[in] _pos Position to add the elements. - * @param[in] _item Pointer on a table of the elements to add. - * @param[in] _nbElement Number of element to add in the Vector - */ - void insert(esize_t _pos, const MY_TYPE * _item, esize_t _nbElement) { - if (_pos>m_size) { - TK_WARNING(" can not insert Element at this position : " << _pos << " > " << m_size << " add it at the end ... "); - pushBack(_item, _nbElement); - return; - } - esize_t idx = m_size; - // Request resize of the current buffer - resize(m_size+_nbElement); - if (idx>=m_size) { - TK_ERROR("Resize does not work corectly ... not added item"); - return; - } - // move curent data (after the position) - esize_t sizeToMove = (idx - _pos); - if ( 0 < sizeToMove) { - for (esize_t iii=1; iii<=sizeToMove; iii++) { - m_data[m_size-iii] = m_data[idx-iii]; - } - } - // affectation of all input element - for (esize_t iii=0; iii<_nbElement; iii++) { - m_data[_pos+iii] = _item[iii]; - } - } - /** - * @brief Insert one element in the Vector at a specific position - * @param[in] _pos Position to add the elements. - * @param[in] _item Element to add. - */ - void insert(esize_t _pos, const MY_TYPE& _item) { - insert(_pos, &_item, 1); - } - /** - * @brief Remove N element - * @param[in] _pos Position to remove the data - * @param[in] _nbElement number of element to remove - */ - void eraseLen(esize_t _pos, esize_t _nbElement) { - if (_pos>m_size) { - TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << m_size); - return; - } - if (_pos+_nbElement>m_size) { - _nbElement = m_size - _pos; - } - esize_t idx = m_size; - // move curent data - esize_t sizeToMove = (idx - (_pos+_nbElement)); - if ( 0 < sizeToMove) { - for (esize_t iii=0; iiim_size) { - TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << m_size); - return; - } - if (_posEnd>m_size) { - _posEnd = m_size; - } - esize_t nbElement = m_size - _pos; - esize_t tmpSize = m_size; - // move curent data - esize_t sizeToMove = (tmpSize - (_pos+nbElement)); - if ( 0 < sizeToMove) { - for (esize_t iii=0; iii extract(esize_t _posStart = 0, esize_t _posEnd=0x7FFFFFFF) const { - Vector out; - if (_posStart >= size() ) { - return out; - } - if (_posEnd >= size() ) { - _posEnd = size(); - } - out.pushBack(&m_data[_posStart], _posEnd-_posStart); - return out; - } - /** - * @brief Get the pointer on the sata - * @return the type pointer on data - */ - MY_TYPE* dataPointer(void) { - return &m_data[0]; - } - /** - * @brief Get an iterator an an specific position - * @param[in] _pos Requested position of the iterator in the vector - * @return The Iterator - */ - Iterator position(esize_t _pos) { - return iterator(this, _pos); - } - /** - * @brief Get an Iterator on the start position of the Vector - * @return The Iterator - */ - Iterator begin(void) { - return position(0); - } - /** - * @brief Get an Iterator on the end position of the Vector - * @return The Iterator - */ - Iterator end(void) { - return position( size()-1 ); - } - private: - /** - * @brief Change the current size of the vector - * @param[in] _newSize New requested size of element in the vector - */ - void resize(esize_t _newSize) { - // Reallocate memory - if (_newSize > m_allocated) { - changeAllocation(_newSize); - } - m_size = _newSize; - } - /** - * @brief Change the current allocation to the corect one (depend on the current size) - * @param[in] _newSize Minimum number of element needed - */ - void changeAllocation(esize_t _newSize) { - // set the minimal size to 1 - if(_newSize == 0) { - _newSize = 1; - } - esize_t requestSize = m_allocated; - // set the size with the corect chose type : - if (_newSize == requestSize) { - return; - } else if (_newSize < requestSize) { - // we did not remove data ??? - } else { - while(_newSize > requestSize) { - if (0 == requestSize) { - requestSize = 1; - } else { - requestSize = requestSize * 2; - } - } - } - // No reallocation needed : - if (requestSize <= m_allocated) { - return; - } - //TK_INFO("Change vector allocation : " << m_allocated << "==>" << requestSize); - // check if something is allocated : - if (NULL == m_data) { - // no data allocated ==> request an allocation (might be the first) - m_data = new MY_TYPE[requestSize]; - if (NULL==m_data) { - TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(MY_TYPE)) << "bytes" ); - m_allocated = 0; - return; - } - // no data to copy - } else { - // allocate a new pool of data: - MY_TYPE* m_dataTmp = new MY_TYPE[requestSize]; - if (NULL==m_dataTmp) { - TK_CRITICAL("Vector : Error in data allocation request allocation:" << requestSize << "*" << (int32_t)(sizeof(MY_TYPE)) << "bytes" ); - m_allocated = 0; - return; - } - // copy data in the new pool - esize_t nbElements = etk_min(requestSize, m_allocated); - for(esize_t iii=0; iii& _obj) const { - // check if it was the same pointer - if( this == &_obj ) { - return true; - } - // fiist step : check the size ... - if (m_size!=_obj.m_size) { - return false; - } - if( NULL==m_data - || NULL==_obj.m_data) { - return false; - } - for (esize_t iii=0; iii& _obj) const { - // check if it was the same pointer - if( this == &_obj ) { - return false; - } - // fiist step : check the size ... - if (m_size!=_obj.m_size) { - return true; - } - if( NULL==m_data - || NULL==_obj.m_data) { - return false; - } - for (esize_t iii=0; iii| Class Data | - * |--------| |-----------------------| - * | 1 |----| - * |--------| | - * | 2 |====|==============| |-----------------------| - * |--------| | --->| Class Data | - * m_count | 3 |-| | |-----------------------| - * |--------| | | - * | x | | | |-----------------------| - * |--------| | -------->| Class Data | - * | x | | |-----------------------| - * |--------| | - * | x | | - * |--------| | |-----------------------| - * | x | --------------------->| Class Data | - * |--------| |-----------------------| - * | x | - * |--------| - * | x | - * |--------| - * m_size | x | - * ---------- - * - */ - /* - template class List - { - - }; - */ -} - -#undef __class__ -#define __class__ NULL - -#endif - diff --git a/etk/archive/Archive.cpp b/etk/archive/Archive.cpp index 259ff3e..d9204b8 100644 --- a/etk/archive/Archive.cpp +++ b/etk/archive/Archive.cpp @@ -10,8 +10,7 @@ #include #include -const etk::Archive::Content& etk::Archive::getContent(const etk::UString& _key) const -{ +const etk::Archive::Content& etk::Archive::getContent(const std::u32string& _key) const { static const etk::Archive::Content g_error; if (m_content.exist(_key)==false) { TK_ERROR("File does not exist : " << _key); @@ -29,13 +28,12 @@ void etk::Archive::display(void) } } -etk::Archive* etk::Archive::load(const etk::UString& _fileName) -{ +etk::Archive* etk::Archive::load(const std::u32string& _fileName) { etk::Archive* output=NULL; - etk::UString tmpName = _fileName.toLower(); + std::u32string tmpName = to_lower(_fileName); // select the corect Loader : - if( true == tmpName.endWith(".zip") - || true == tmpName.endWith(".apk") ) { + if( true == end_with(tmpName, U".zip") + || true == end_with(tmpName, U".apk") ) { output = new etk::archive::Zip(_fileName); if (NULL==output) { TK_ERROR("An error occured when load archive : " << _fileName); @@ -47,8 +45,7 @@ etk::Archive* etk::Archive::load(const etk::UString& _fileName) } -void etk::Archive::open(const etk::UString& _key) -{ +void etk::Archive::open(const std::u32string& _key) { if (m_content.exist(_key)==false) { TK_ERROR("Try open an unexistant file : '" << _key << "'"); return; @@ -60,8 +57,7 @@ void etk::Archive::open(const etk::UString& _key) m_content[_key].increaseRef(); } -void etk::Archive::close(const etk::UString& _key) -{ +void etk::Archive::close(const std::u32string& _key) { if (m_content.exist(_key)==false) { TK_ERROR("Try close an unexistant file : '" << _key << "'"); return; diff --git a/etk/archive/Archive.h b/etk/archive/Archive.h index ec3807a..52824c3 100644 --- a/etk/archive/Archive.h +++ b/etk/archive/Archive.h @@ -10,7 +10,7 @@ #define __ETK_ARCHIVE_H__ #include -#include +#include #include namespace etk @@ -31,24 +31,24 @@ namespace etk public: esize_t getTheoricSize(void) const { return m_theoricSize; }; private: - etk::Vector m_data; + std::vector m_data; public: Content(esize_t _basicSize=0) : m_link(-1), m_theoricSize(_basicSize) { }; esize_t size(void) const { return m_data.size(); }; void* data(void) const { return (void*)&m_data[0]; }; - etk::Vector& getDataVector(void) { return m_data; }; + std::vector& getDataVector(void) { return m_data; }; }; public: - Archive(const etk::UString& _fileName) : m_fileName(_fileName) { }; + Archive(const std::u32string& _fileName) : m_fileName(_fileName) { }; virtual ~Archive(void) { }; protected: - etk::UString m_fileName; //!< File name when it came from an file + std::u32string m_fileName; //!< File name when it came from an file public: /** * @brief Get the current file name. * @return the requested file name. */ - const etk::UString& getFileName(void) { return m_fileName; }; + const std::u32string& getFileName(void) { return m_fileName; }; protected: etk::Hash m_content; public: @@ -62,7 +62,7 @@ namespace etk * @param[in] _id id of the element (must be < Size()) * @return FileName of the requested id */ - const etk::UString& getName(esize_t _id) const { return m_content.getKey(_id); }; + const std::u32string& getName(esize_t _id) const { return m_content.getKey(_id); }; /** * @brief Get the File name of the ID * @param[in] _id id of the element (must be < Size()) @@ -74,23 +74,23 @@ namespace etk * @param[in] _key name of the file * @return FileName of the requested id */ - const Content& getContent(const etk::UString& _key) const; + const Content& getContent(const std::u32string& _key) const; /** * @brief Check if a file exist * @param[in] _key Name of the file * @return true if the file is present */ - bool exist(const etk::UString& _key) const { return m_content.exist(_key); }; + bool exist(const std::u32string& _key) const { return m_content.exist(_key); }; /** * @brief Load the specific file in the memory * @param[in] _key Name of the file */ - void open(const etk::UString& _key); + void open(const std::u32string& _key); /** * @brief Un-Load the specific file from the memory * @param[in] _key Name of the file */ - void close(const etk::UString& _key); + void close(const std::u32string& _key); /** * @brief Display all Element in the archive */ @@ -107,14 +107,14 @@ namespace etk * @param[in] _fileName File name of the specific archive. * @return A pointer an the specified archive, the user might delete it. */ - static Archive* load(const etk::UString& _fileName); + static Archive* load(const std::u32string& _fileName); /** * @brief Create an Achive with a specific name. * @param[in] _fileName File name of the specific archive. * @return A pointer an the specified archive. it is empty due to the fact of create a new archive file. */ - //Archive* create(const etk::UString& _fileName); + //Archive* create(const std::u32string& _fileName); }; }; #endif diff --git a/etk/archive/Zip.cpp b/etk/archive/Zip.cpp index 9299018..663d9b9 100644 --- a/etk/archive/Zip.cpp +++ b/etk/archive/Zip.cpp @@ -8,13 +8,14 @@ #include #include +#include -etk::archive::Zip::Zip(const etk::UString& _fileName) : +etk::archive::Zip::Zip(const std::u32string& _fileName) : etk::Archive(_fileName), m_ctx(NULL) { /* Open the zip file */ - m_ctx = unzOpen(m_fileName.c_str()); + m_ctx = unzOpen(to_u8string(m_fileName).c_str()); if(!m_ctx) { TK_ERROR("Unable to open the zip file '" << m_fileName << "'"); return; @@ -37,7 +38,7 @@ etk::archive::Zip::Zip(const etk::UString& _fileName) : if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) { // find directory ... } else { - m_content.add(tmpFileName, etk::Archive::Content(tmpFileInfo.uncompressed_size)); + m_content.add(to_u32string(tmpFileName), etk::Archive::Content(tmpFileInfo.uncompressed_size)); } /* Go the the next entry listed in the zip file. */ if((iii+1) < m_info.number_entry) { @@ -59,7 +60,7 @@ etk::archive::Zip::~Zip(void) void etk::archive::Zip::loadFile(int32_t _id) { - etk::UString fileNameRequested = m_content.getKey(_id); + std::u32string fileNameRequested = m_content.getKey(_id); TK_VERBOSE("Real load file : " << _id << " = '" << fileNameRequested << "'"); unzGoToFirstFile(m_ctx); @@ -73,7 +74,7 @@ void etk::archive::Zip::loadFile(int32_t _id) TK_ERROR("Could not read file info from the zip file '" << m_fileName << "'"); return; } - if (fileNameRequested == tmpFileName ) { + if (fileNameRequested == to_u32string(tmpFileName) ) { // Entry is a file, so extract it. if(unzOpenCurrentFile(m_ctx) != UNZ_OK) { TK_ERROR("Could not open file '" << fileNameRequested << "' into the zip file '" << m_fileName << "'"); @@ -81,7 +82,7 @@ void etk::archive::Zip::loadFile(int32_t _id) } int error = UNZ_OK; // request the resize of the data : - m_content.getValue(_id).getDataVector().reSize(m_content.getValue(_id).getTheoricSize(), 0); + m_content.getValue(_id).getDataVector().resize(m_content.getValue(_id).getTheoricSize(), 0); void* data = m_content.getValue(_id).data(); if(NULL == data) { TK_ERROR("Allocation error..."); diff --git a/etk/archive/Zip.h b/etk/archive/Zip.h index ff42ea4..00c3d1d 100644 --- a/etk/archive/Zip.h +++ b/etk/archive/Zip.h @@ -14,17 +14,14 @@ extern "C" { #include } -namespace etk -{ - namespace archive - { - class Zip : public etk::Archive - { +namespace etk { + namespace archive { + class Zip : public etk::Archive { private: unzFile m_ctx; //!< mini zip context unz_global_info m_info; //!< global information of the Zip public: - Zip(const etk::UString& _fileName); + Zip(const std::u32string& _fileName); virtual ~Zip(void); protected: // herited functions : virtual void loadFile(int32_t _id); diff --git a/etk/math/Matrix.h b/etk/math/Matrix.h index ff143d4..cdb33a9 100644 --- a/etk/math/Matrix.h +++ b/etk/math/Matrix.h @@ -11,7 +11,7 @@ #include #include -#include +#include namespace etk { @@ -19,7 +19,7 @@ namespace etk { private: etk::Vector2D m_size; - etk::Vector m_data; + std::vector m_data; public: /***************************************************** * Constructor diff --git a/etk/math/Plane.h b/etk/math/Plane.h index 991d3af..3e2df9b 100644 --- a/etk/math/Plane.h +++ b/etk/math/Plane.h @@ -10,7 +10,7 @@ #define __ETK_TYPES_PLANE_H__ #include -#include +#include namespace etk { template class Plane { diff --git a/etk/math/Vector2D.cpp b/etk/math/Vector2D.cpp index cf1392a..52042d1 100644 --- a/etk/math/Vector2D.cpp +++ b/etk/math/Vector2D.cpp @@ -49,153 +49,145 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D& _obj) } -namespace etk -{ - template<> Vector2D::operator etk::UString(void) const - { - etk::UString str; - str = "("; +namespace etk { + template<> Vector2D::operator std::u32string(void) const { + std::u32string str; + str = U"("; str += x(); - str += ","; + str += U","; str += y(); - str += ")"; + str += U")"; return str; } - template<> Vector2D::Vector2D(const etk::UString& _str) - { + template<> Vector2D::Vector2D(const std::u32string& _str) { m_floats[0] = false; m_floats[1] = false; // copy to permit to modify it : - etk::UString tmpStr = _str; - if (_str.startWith("(")) { - tmpStr.remove(0,1); + std::u32string tmpStr = _str; + if (_str[0] == '(') { + tmpStr.erase(tmpStr.begin()); } - if (tmpStr.endWith(")")) { - tmpStr.remove(tmpStr.size()-1,1); + if (*tmpStr.end() == ')') { + tmpStr.erase(tmpStr.end()); } - int32_t posComa = tmpStr.findForward(','); - if (posComa <= 0) { + size_t posComa = tmpStr.find(','); + if (posComa == 0) { // no coma ... // in every case, we parse the first element : - m_floats[0] = tmpStr.toBool(); + m_floats[0] = stobool(tmpStr); m_floats[1] = m_floats[0]; } else { - m_floats[0] = tmpStr.extract(0,posComa).toBool(); - tmpStr.remove(0,posComa+1); - m_floats[1] = tmpStr.toBool(); + m_floats[0] = stobool(std::u32string(tmpStr, 0, posComa)); + tmpStr.erase(0, posComa+1); + m_floats[1] = stobool(tmpStr); } TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } - template<> Vector2D::operator etk::UString(void) const - { - etk::UString str; - str = "("; + template<> Vector2D::operator std::u32string(void) const { + std::u32string str; + str = U"("; str += x(); - str += ","; + str += U","; str += y(); - str += ")"; + str += U")"; return str; } - template<> Vector2D::Vector2D(const etk::UString& _str) - { + template<> Vector2D::Vector2D(const std::u32string& _str) { m_floats[0] = 0; m_floats[1] = 0; // copy to permit to modify it : - etk::UString tmpStr = _str; - if (_str.startWith("(")) { - tmpStr.remove(0,1); + std::u32string tmpStr = _str; + if (_str[0] == '(') { + tmpStr.erase(tmpStr.begin()); } - if (tmpStr.endWith(")")) { - tmpStr.remove(tmpStr.size()-1,1); + if (*tmpStr.end() == ')') { + tmpStr.erase(tmpStr.end()); } - int32_t posComa = tmpStr.findForward(','); - if (posComa <= 0) { + size_t posComa = tmpStr.find(','); + if (posComa == 0) { // no coma ... // in every case, we parse the first element : - m_floats[0] = tmpStr.toInt32(); + m_floats[0] = stoi(tmpStr); m_floats[1] = m_floats[0]; } else { - m_floats[0] = tmpStr.extract(0,posComa).toInt32(); - tmpStr.remove(0,posComa+1); - m_floats[1] = tmpStr.toInt32(); + m_floats[0] = stoi(std::u32string(tmpStr, 0, posComa)); + tmpStr.erase(0,posComa+1); + m_floats[1] = stoi(tmpStr); } TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } - template<> Vector2D::operator etk::UString(void) const - { - etk::UString str; - str = "("; + template<> Vector2D::operator std::u32string(void) const { + std::u32string str; + str = U"("; str += x(); - str += ","; + str += U","; str += y(); - str += ")"; + str += U")"; return str; } - template<> Vector2D::Vector2D(const etk::UString& _str) + template<> Vector2D::Vector2D(const std::u32string& _str) { m_floats[0] = 0; m_floats[1] = 0; // copy to permit to modify it : - etk::UString tmpStr = _str; - if (_str.startWith("(")) { - tmpStr.remove(0,1); + std::u32string tmpStr = _str; + if (_str[0] == '(') { + tmpStr.erase(tmpStr.begin()); } - if (tmpStr.endWith(")")) { - tmpStr.remove(tmpStr.size()-1,1); + if (*tmpStr.end() == ')') { + tmpStr.erase(tmpStr.end()); } - int32_t posComa = tmpStr.findForward(','); - if (posComa <= 0) { + size_t posComa = tmpStr.find(','); + if (posComa == 0) { // no coma ... // in every case, we parse the first element : - m_floats[0] = tmpStr.toUInt32(); + m_floats[0] = stoi(tmpStr); m_floats[1] = m_floats[0]; } else { - m_floats[0] = tmpStr.extract(0,posComa).toUInt32(); - tmpStr.remove(0,posComa+1); - m_floats[1] = tmpStr.toUInt32(); + m_floats[0] = stoi(std::u32string(tmpStr, 0, posComa)); + tmpStr.erase(0,posComa+1); + m_floats[1] = stoi(tmpStr); } TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } - template<> Vector2D::operator etk::UString(void) const - { - etk::UString str; - str = "("; + template<> Vector2D::operator std::u32string(void) const { + std::u32string str; + str = U"("; str += x(); - str += ","; + str += U","; str += y(); - str += ")"; + str += U")"; return str; } - template<> Vector2D::Vector2D(const etk::UString& _str) - { + template<> Vector2D::Vector2D(const std::u32string& _str) { m_floats[0] = 0; m_floats[1] = 0; // copy to permit to modify it : - etk::UString tmpStr = _str; - if (_str.startWith("(")) { - tmpStr.remove(0,1); + std::u32string tmpStr = _str; + if (_str[0] == '(') { + tmpStr.erase(tmpStr.begin()); } - if (tmpStr.endWith(")")) { - tmpStr.remove(tmpStr.size()-1,1); + if (*tmpStr.end() == ')') { + tmpStr.erase(tmpStr.end()); } - int32_t posComa = tmpStr.findForward(','); - if (posComa <= 0) { + size_t posComa = tmpStr.find(','); + if (posComa == 0) { // no coma ... // in every case, we parse the first element : - m_floats[0] = tmpStr.toFloat(); + m_floats[0] = stof(tmpStr); m_floats[1] = m_floats[0]; } else { - m_floats[0] = tmpStr.extract(0,posComa).toFloat(); - tmpStr.remove(0,posComa+1); - m_floats[1] = tmpStr.toFloat(); + m_floats[0] = stof(std::u32string(tmpStr, 0, posComa)); + tmpStr.erase(0,posComa+1); + m_floats[1] = stof(tmpStr); } TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); } diff --git a/etk/math/Vector2D.h b/etk/math/Vector2D.h index 460c57e..ba5c1c0 100644 --- a/etk/math/Vector2D.h +++ b/etk/math/Vector2D.h @@ -42,7 +42,7 @@ namespace etk Vector2D(const Vector2D& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; Vector2D(const Vector2D& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; Vector2D(const Vector2D& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); }; - Vector2D(const etk::UString& str); + Vector2D(const std::u32string& str); ~Vector2D(void) { }; /***************************************************** * = assigment @@ -364,8 +364,8 @@ namespace etk return m_floats[0] == 0 && m_floats[1] == 0; } //!< string cast : - operator etk::UString(void) const; - //etk::UString UString(void) const { return *this; }; + operator std::u32string(void) const; + //std::u32string UString(void) const { return *this; }; }; /** * @brief Debug operator To display the curent element in a Human redeable information diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 7f9be5d..3d362e5 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #ifdef __TARGET_OS__Windows #include "windows.h" #endif @@ -36,10 +36,10 @@ extern "C" { -static etk::UString simplifyPathAbstractPath(etk::UString _input) +static std::u32string simplifyPathAbstractPath(std::u32string _input) { - int32_t findStartPos = _input.findForward('/') + 1; - int32_t findPos = _input.findForward('/', findStartPos); + int32_t findStartPos = _input.find('/') + 1; + int32_t findPos = _input.find('/', findStartPos); //TK_DEBUG("Siplify : \"" << input << "\""); int32_t preventBadCode = 0; while (findPos!=-1) @@ -54,7 +54,7 @@ static etk::UString simplifyPathAbstractPath(etk::UString _input) || ( _input[findPos+1] == '.' && _input.size()==findPos+2 )) { // cleane the element path - _input.remove(findPos+1, 1); + _input.erase(findPos+1, 1); //TK_DEBUG(" Remove // string=\"" << input << "\""); } else { if (_input.size()5000) { TK_CRITICAL("ERROR when getting the small path ... this is loop prevention..."); @@ -90,7 +90,7 @@ static etk::UString simplifyPathAbstractPath(etk::UString _input) char * ok = realpath(input.c_str(), buf); if (!ok) { TK_ERROR("Error to get the real path"); - input = "/"; + input = U"/"; } else { input = buf; } @@ -103,30 +103,30 @@ static etk::UString simplifyPathAbstractPath(etk::UString _input) // zip file of the apk file for Android ==> set to zip file apk access -static etk::UString s_fileAPK = ""; -static etk::UString baseApplName = "ewolNoName"; -static etk::UString baseRunPath = "/"; +static std::u32string s_fileAPK = U""; +static std::u32string baseApplName = U"ewolNoName"; +static std::u32string baseRunPath = U"/"; #if defined(__TARGET_OS__Android) - static etk::UString baseFolderHome = "/sdcard/"; // home folder - static etk::UString baseFolderData = "assets/"; // program Data - static etk::UString baseFolderDataUser = "/sdcard/.tmp/userData/"; // Data specific user (local modification) - static etk::UString baseFolderCache = "/sdcard/.tmp/cache/"; // Temporary data (can be removed the next time) + static std::u32string baseFolderHome = U"/sdcard/"; // home folder + static std::u32string baseFolderData = U"assets/"; // program Data + static std::u32string baseFolderDataUser = U"/sdcard/.tmp/userData/"; // Data specific user (local modification) + static std::u32string baseFolderCache = U"/sdcard/.tmp/cache/"; // Temporary data (can be removed the next time) #elif defined(__TARGET_OS__Windows) - static etk::UString baseFolderHome = "c:/test"; // home folder - static etk::UString baseFolderData = "c:/test/share/"; // program Data - static etk::UString baseFolderDataUser = "c:/test/userData/"; // Data specific user (local modification) - static etk::UString baseFolderCache = "c:/Windows/Temp/ewol/"; // Temporary data (can be removed the next time) + static std::u32string baseFolderHome = U"c:/test"; // home folder + static std::u32string baseFolderData = U"c:/test/share/"; // program Data + static std::u32string baseFolderDataUser = U"c:/test/userData/"; // Data specific user (local modification) + static std::u32string baseFolderCache = U"c:/Windows/Temp/ewol/"; // Temporary data (can be removed the next time) #else - static etk::UString baseFolderHome = "~"; // home folder - static etk::UString baseFolderData = "share/"; // program Data - static etk::UString baseFolderDataUser = "~/.tmp/userData/"; // Data specific user (local modification) - static etk::UString baseFolderCache = "~/.tmp/cache/"; // Temporary data (can be removed the next time) + static std::u32string baseFolderHome = U"~"; // home folder + static std::u32string baseFolderData = U"share/"; // program Data + static std::u32string baseFolderDataUser = U"~/.tmp/userData/"; // Data specific user (local modification) + static std::u32string baseFolderCache = U"~/.tmp/cache/"; // Temporary data (can be removed the next time) #endif #ifdef __TARGET_OS__Android static etk::Archive* s_APKArchive = NULL; - static void loadAPK(etk::UString& _apkPath) + static void loadAPK(std::u32string& _apkPath) { TK_DEBUG("Loading APK \"" << _apkPath << "\""); s_APKArchive = etk::Archive::load(_apkPath); @@ -140,7 +140,7 @@ static etk::UString baseRunPath = "/"; void etk::setBaseFolderData(const char* _folder) { #ifdef __TARGET_OS__Android - baseFolderData = "assets/"; + baseFolderData = U"assets/"; s_fileAPK = _folder; loadAPK(s_fileAPK); #else @@ -166,8 +166,8 @@ void etk::setBaseFolderCache(const char* _folder) #endif } -etk::UString l_argZero=""; -void etk::setArgZero(const etk::UString& _val) +std::u32string l_argZero = U""; +void etk::setArgZero(const std::u32string& _val) { l_argZero = _val; } @@ -185,9 +185,9 @@ void etk::setArgZero(const etk::UString& _val) Note that it is up to the calling process to set argv[0] correctly. It is right most of the times however there are occasions when the calling process cannot be trusted (ex. setuid executable). On Windows: use GetModuleFileName(NULL, buf, bufsize) */ -etk::UString getApplicationPath(void) +std::u32string getApplicationPath(void) { - etk::UString binaryName = "no-name"; + std::u32string binaryName = U"no-name"; char binaryCompleatePath[FILENAME_MAX]; memset(binaryCompleatePath, 0, FILENAME_MAX); #ifdef __TARGET_OS__Windows @@ -201,22 +201,22 @@ etk::UString getApplicationPath(void) // check it to prevent test mode in local folder ... // Generic Linux system readlink("/proc/self/exe", binaryCompleatePath, FILENAME_MAX); - if(0!=strlen(binaryCompleatePath)) { - binaryName = binaryCompleatePath; + if(strlen(binaryCompleatePath) != 0) { + binaryName = to_u32string(binaryCompleatePath); return binaryName; } // generic FreeBSD system memset(binaryCompleatePath, 0, FILENAME_MAX); readlink("/proc/curproc/file", binaryCompleatePath, FILENAME_MAX); - if(0!=strlen(binaryCompleatePath)) { - binaryName = binaryCompleatePath; + if(strlen(binaryCompleatePath) != 0) { + binaryName = to_u32string(binaryCompleatePath); return binaryName; } // generic Solaris system memset(binaryCompleatePath, 0, FILENAME_MAX); readlink("/proc/self/path/a.out", binaryCompleatePath, FILENAME_MAX); - if(0!=strlen(binaryCompleatePath)) { - binaryName = binaryCompleatePath; + if(strlen(binaryCompleatePath) != 0) { + binaryName = to_u32string(binaryCompleatePath); return binaryName; } // now we are in a really bad case ... @@ -225,21 +225,21 @@ etk::UString getApplicationPath(void) return binaryName; } TK_VERBOSE("Parse arg0 = '" << l_argZero << "' start with '/' ???"); - if (l_argZero.startWith("/")==true) { + if (l_argZero[0] == '/') { binaryName = l_argZero; return simplifyPathAbstractPath(binaryName); } TK_VERBOSE("Parse arg0 = '" << l_argZero << "' try add PWD"); char * basicPathPWD = getenv("PWD"); if (NULL != basicPathPWD) { - etk::UString testCompleatePath = basicPathPWD; - testCompleatePath += "/"; + std::u32string testCompleatePath = to_u32string(basicPathPWD); + testCompleatePath += U"/"; testCompleatePath += l_argZero; // check if the element existed : TK_VERBOSE("test path: '" << testCompleatePath << "'"); memset(binaryCompleatePath, 0, FILENAME_MAX); struct stat statProperty; - if (-1 != stat(testCompleatePath.c_str(), &statProperty)) { + if (-1 != stat(to_u8string(testCompleatePath).c_str(), &statProperty)) { //Normal case when the file does not exist ... ==> the it was in unknow mode ... binaryName = testCompleatePath; TK_VERBOSE("find real name = '" << binaryName << "'"); @@ -258,57 +258,57 @@ etk::UString getApplicationPath(void) void etk::initDefaultFolder(const char* _applName) { - baseApplName = _applName; + baseApplName = to_u32string(_applName); char cCurrentPath[FILENAME_MAX]; char * basicPath = getenv("HOME"); if (NULL == basicPath) { TK_ERROR("ERROR while trying to get the path of the home folder"); #if defined(__TARGET_OS__Windows) - baseFolderHome = "c:/"; + baseFolderHome = U"c:/"; #elif defined(__TARGET_OS__Android) - baseFolderHome = "/sdcard"; + baseFolderHome = U"/sdcard"; #else - baseFolderHome = "~"; + baseFolderHome = U"~"; #endif } else { - baseFolderHome = basicPath; + baseFolderHome = to_u32string(basicPath); } if (!getcwd(cCurrentPath, FILENAME_MAX)) { - baseRunPath = "."; + baseRunPath = U"."; } else { cCurrentPath[FILENAME_MAX - 1] = '\0'; if (cCurrentPath[0] == '/') { - baseRunPath = cCurrentPath+1; + baseRunPath = to_u32string(cCurrentPath+1); } else { - baseRunPath = cCurrentPath; + baseRunPath = to_u32string(cCurrentPath); } } TK_DBG_MODE("Find Basic running PATH : \"" << baseRunPath << "\""); #ifndef __TARGET_OS__Android - etk::UString binaryPath = getApplicationPath(); - binaryPath.replace('\\', '/'); - int32_t pos = binaryPath.findBack('/'); - etk::UString binaryName = binaryPath.extract(pos); - binaryPath.remove(pos, binaryName.size()); + std::u32string binaryPath = getApplicationPath(); + binaryPath = replace(binaryPath, '\\', '/'); + int32_t pos = binaryPath.rfind('/'); + std::u32string binaryName(binaryPath, pos); + binaryPath.erase(binaryName.begin() + pos, binaryName.end()); TK_INFO("Bianry name : '" << binaryPath << "' && '" << binaryName << "'" ); #ifdef __TARGET_OS__Windows baseFolderData = binaryPath; - baseFolderData += "/data/"; + baseFolderData += U"/data/"; baseFolderDataUser = binaryPath; - baseFolderDataUser += "/user/"; + baseFolderDataUser += U"/user/"; baseFolderCache = binaryPath; - baseFolderCache += "/tmp/"; + baseFolderCache += U"/tmp/"; #else // if element is installed : - baseFolderData = "/usr/share"; + baseFolderData = U"/usr/share"; baseFolderData += binaryName; - baseFolderData += "/"; + baseFolderData += U"/"; - etk::UString theoricInstalledName = "/usr/bin"; + std::u32string theoricInstalledName = U"/usr/bin"; theoricInstalledName += binaryName; TK_VERBOSE(" position : '" << binaryPath << "' installed position : '" << theoricInstalledName << "'"); if (binaryPath != theoricInstalledName) { @@ -316,22 +316,22 @@ void etk::initDefaultFolder(const char* _applName) // remove bin/applName baseFolderData = binaryPath; #ifdef __TARGET_OS__MacOs - baseFolderData += "/../../Resources/"; + baseFolderData += U"/../../Resources/"; #else - baseFolderData += "/../../share"; + baseFolderData += U"/../../share"; baseFolderData += binaryName; - baseFolderData += "/"; + baseFolderData += U"/"; #endif baseFolderData = simplifyPathAbstractPath(baseFolderData); } baseFolderDataUser = baseFolderHome; - baseFolderDataUser += "/.local/share/"; + baseFolderDataUser += U"/.local/share/"; baseFolderDataUser += binaryName; - baseFolderDataUser += "/"; + baseFolderDataUser += U"/"; - baseFolderCache = "/tmp/"; + baseFolderCache = U"/tmp/"; baseFolderCache += binaryName; - baseFolderCache += "/"; + baseFolderCache += U"/"; #endif #endif TK_INFO("baseFolderHome : '" << baseFolderHome << "'"); @@ -340,12 +340,12 @@ void etk::initDefaultFolder(const char* _applName) TK_INFO("baseFolderCache : '" << baseFolderCache << "'"); } -etk::UString etk::getUserHomeFolder(void) +std::u32string etk::getUserHomeFolder(void) { return baseFolderHome; } -etk::UString etk::getUserRunFolder(void) +std::u32string etk::getUserRunFolder(void) { return baseRunPath; } @@ -429,8 +429,8 @@ static int32_t FSNODE_LOCAL_mkPath(const char* _path, mode_t _mode) #undef __class__ #define __class__ "FSNode" -etk::FSNode::FSNode(const etk::UString& _nodeName) : - m_userFileName(""), +etk::FSNode::FSNode(const std::u32string& _nodeName) : + m_userFileName(U""), m_type(etk::FSN_TYPE_UNKNOW), m_typeNode(etk::FSN_UNKNOW), m_PointerFile(NULL), @@ -458,8 +458,8 @@ etk::FSNode::~FSNode(void) { } -void etk::FSNode::sortElementList(etk::Vector& _list) { - etk::Vector tmpList = _list; +void etk::FSNode::sortElementList(std::vector& _list) { + std::vector tmpList = _list; _list.clear(); for(int32_t iii=0; iii& _list) { } } //EWOL_DEBUG("position="< go to the root Folder - destFilename = "ROOT:"; + destFilename = U"ROOT:"; } else { destFilename = _newName; } @@ -523,69 +523,69 @@ void etk::FSNode::privateSetName(const etk::UString& _newName) } } #else - isRootFolder = destFilename.startWith("/"); + isRootFolder = destFilename[0] == '/'; #endif - if (true == destFilename.startWith(baseFolderHome) ) { + if (true == start_with(destFilename, baseFolderHome) ) { TK_DBG_MODE(" ==> detect home"); - destFilename.remove(0, baseFolderHome.size()); + destFilename.erase(0, baseFolderHome.size()); m_type = etk::FSN_TYPE_HOME; } else if(true == isRootFolder) { TK_DBG_MODE(" ==> detect root"); #ifdef __TARGET_OS__Windows - destFilename.remove(0, 3); + destFilename.erase(0, 3); #else - destFilename.remove(0, 1); + destFilename.erase(0, 1); #endif m_type = etk::FSN_TYPE_DIRECT; - } else if( true == destFilename.startWith("ROOT:") - || true == destFilename.startWith("root:") ) { + } else if( true == start_with(destFilename, U"ROOT:") + || true == start_with(destFilename, U"root:") ) { TK_DBG_MODE(" ==> detect root 2 "); - destFilename.remove(0, 5); + destFilename.erase(0, 5); m_type = etk::FSN_TYPE_DIRECT; - if(true == destFilename.startWith("~")) { - destFilename.remove(0, 1); + if(true == start_with(destFilename, U"~")) { + destFilename.erase(0, 1); m_type = etk::FSN_TYPE_HOME; } - } else if( true == destFilename.startWith("DIRECT:") - || true == destFilename.startWith("direct:") ) { + } else if( true == start_with(destFilename, U"DIRECT:") + || true == start_with(destFilename, U"direct:") ) { TK_DBG_MODE(" ==> detect direct"); - destFilename.remove(0, 7); + destFilename.erase(0, 7); m_type = etk::FSN_TYPE_DIRECT; - if(true == destFilename.startWith("~")) { - destFilename.remove(0, 1); + if(true == start_with(destFilename, U"~")) { + destFilename.erase(0, 1); m_type = etk::FSN_TYPE_HOME; } - } else if( true == destFilename.startWith("DATA:") - || true == destFilename.startWith("data:") ) { + } else if( true == start_with(destFilename, U"DATA:") + || true == start_with(destFilename, U"data:") ) { TK_DBG_MODE(" ==> detect data"); - destFilename.remove(0, 5); + destFilename.erase(0, 5); m_type = etk::FSN_TYPE_DATA; - } else if( true == destFilename.startWith("USERDATA:") - || true == destFilename.startWith("userdata:") ) { + } else if( true == start_with(destFilename, U"USERDATA:") + || true == start_with(destFilename, U"userdata:") ) { TK_DBG_MODE(" ==> detect User-data"); - destFilename.remove(0, 9); + destFilename.erase(0, 9); m_type = etk::FSN_TYPE_USER_DATA; - } else if( true == destFilename.startWith("CACHE:") - || true == destFilename.startWith("cache:") ) { + } else if( true == start_with(destFilename, U"CACHE:") + || true == start_with(destFilename, U"cache:") ) { TK_DBG_MODE(" ==> detect Cach"); - destFilename.remove(0, 6); + destFilename.erase(0, 6); m_type = etk::FSN_TYPE_CACHE; - } else if( true == destFilename.startWith("THEME:") - || true == destFilename.startWith("theme:") ) { + } else if( true == start_with(destFilename, U"THEME:") + || true == start_with(destFilename, U"theme:") ) { TK_DBG_MODE(" ==> detect theme"); - destFilename.remove(0, 6); + destFilename.erase(0, 6); m_type = etk::FSN_TYPE_THEME; - } else if(true == destFilename.startWith("~")) { + } else if(true == start_with(destFilename, U"~")) { TK_DBG_MODE(" ==> detect home 2"); - destFilename.remove(0, 1); + destFilename.erase(0, 1); m_type = etk::FSN_TYPE_HOME; - } else if( true == destFilename.startWith("HOME:") - || true == destFilename.startWith("home:") ) { + } else if( true == start_with(destFilename, U"HOME:") + || true == start_with(destFilename, U"home:") ) { TK_DBG_MODE(" ==> detect home 3"); - destFilename.remove(0, 5); + destFilename.erase(0, 5); m_type = etk::FSN_TYPE_HOME; - if(true == destFilename.startWith("~")) { - destFilename.remove(0, 1); + if(true == start_with(destFilename, U"~")) { + destFilename.erase(0, 1); } } /*else if(true == destFilename.StartWith(baseRunPath)) { destFilename.Remove(0, baseRunPath.Size()); @@ -597,7 +597,7 @@ void etk::FSNode::privateSetName(const etk::UString& _newName) m_type = etk::FSN_TYPE_RELATIF; // we force to have the correct name : (can generate many problem otherwise ... - etk::UString tmpName = etk::getUserRunFolder() + "/" + destFilename; + std::u32string tmpName = etk::getUserRunFolder() + U"/" + destFilename; destFilename = tmpName; m_type = etk::FSN_TYPE_DIRECT; @@ -620,8 +620,7 @@ void etk::FSNode::privateSetName(const etk::UString& _newName) } -bool directCheckFile(etk::UString _tmpFileNameDirect, bool _checkInAPKIfNeeded=false) -{ +bool directCheckFile(std::u32string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) { #ifdef __TARGET_OS__Android if (true == _checkInAPKIfNeeded) { if( NULL != s_APKArchive @@ -633,23 +632,21 @@ bool directCheckFile(etk::UString _tmpFileNameDirect, bool _checkInAPKIfNeeded=f #endif // tmpStat Buffer : struct stat statProperty; - if (-1 == stat(_tmpFileNameDirect.c_str(), &statProperty)) { + if (-1 == stat(to_u8string(_tmpFileNameDirect).c_str(), &statProperty)) { return false; } return true; } // Now we generate the real FS path: -void etk::FSNode::generateFileSystemPath(void) -{ - switch (m_type) - { +void etk::FSNode::generateFileSystemPath(void) { + switch (m_type) { default: case etk::FSN_TYPE_UNKNOW: m_systemFileName = baseFolderHome; break; case etk::FSN_TYPE_DIRECT: - m_systemFileName = "/"; + m_systemFileName = U"/"; break; case etk::FSN_TYPE_RELATIF: { @@ -661,8 +658,8 @@ void etk::FSNode::generateFileSystemPath(void) cCurrentPath[1] = '\0'; } cCurrentPath[FILENAME_MAX - 1] = '\0'; - m_systemFileName = cCurrentPath; - m_systemFileName += "/"; + m_systemFileName = to_u32string(cCurrentPath); + m_systemFileName += U"/"; } break; case etk::FSN_TYPE_HOME: @@ -680,44 +677,44 @@ void etk::FSNode::generateFileSystemPath(void) case etk::FSN_TYPE_THEME: case etk::FSN_TYPE_THEME_DATA: { - //etk::UString myCompleateName=baseFolderData + "/theme/"; - etk::UString themeName(""); - etk::UString basicName(m_userFileName); - int32_t firstPos = m_userFileName.findForward(':'); - if (-1 != firstPos) { + //std::u32string myCompleateName=baseFolderData + "/theme/"; + std::u32string themeName(U""); + std::u32string basicName(m_userFileName); + size_t firstPos = m_userFileName.find(':'); + if (0 != firstPos) { // we find a theme name : We extracted it : - themeName = m_userFileName.extract(0, firstPos); - basicName = m_userFileName.extract(firstPos+1); + themeName = std::u32string(m_userFileName, 0, firstPos); + basicName = std::u32string(m_userFileName, firstPos+1); } TK_DBG_MODE(" THEME party : \"" << themeName << "\" => \"" << basicName << "\""); themeName = etk::theme::getName(themeName); TK_DBG_MODE(" ==> theme Folder \"" << themeName << "\""); // search the corect folder : - if (themeName == "") { + if (themeName == U"") { TK_WARNING("no theme name detected : set it to \"default\""); - } else if (themeName != "default") { + } else if (themeName != U"default") { // Selected theme : // check in the user data : - m_systemFileName = baseFolderDataUser + "theme/" + themeName + "/" + basicName; - if (true==directCheckFile(m_systemFileName)) { + m_systemFileName = baseFolderDataUser + U"theme/" + themeName + U"/" + basicName; + if (directCheckFile(m_systemFileName) == true) { return; } // check in the Appl data : - m_systemFileName = baseFolderData + "theme/" + themeName + "/" + basicName; - if (true==directCheckFile(m_systemFileName, true)) { + m_systemFileName = baseFolderData + U"theme/" + themeName + U"/" + basicName; + if (directCheckFile(m_systemFileName, true) == true) { m_type = etk::FSN_TYPE_THEME_DATA; return; } } - themeName = "default"; + themeName = U"default"; // default theme : // check in the user data : - m_systemFileName = baseFolderDataUser + "theme/" + themeName + "/" + basicName; + m_systemFileName = baseFolderDataUser + U"theme/" + themeName + U"/" + basicName; if (true==directCheckFile(m_systemFileName)) { return; } // check in the Appl data : In every case we return this one ... - m_systemFileName = baseFolderData + "theme/" + themeName + "/" + basicName; + m_systemFileName = baseFolderData + U"theme/" + themeName + U"/" + basicName; if (true==directCheckFile(m_systemFileName, true)) { m_type = etk::FSN_TYPE_THEME_DATA; return; @@ -750,8 +747,8 @@ void etk::FSNode::updateFileSystemProperty(void) // ---------------------------------------- // = Check if it was a folder : = // ---------------------------------------- - etk::UString folderName="/"; - if (true==m_systemFileName.endWith(folderName)) { + std::u32string folderName = U"/"; + if (true == m_systemFileName.endWith(folderName)) { folderName = m_systemFileName; } else { folderName = m_systemFileName + "/"; @@ -771,7 +768,7 @@ void etk::FSNode::updateFileSystemProperty(void) #endif // tmpStat Buffer : struct stat statProperty; - if (-1 == stat(m_systemFileName.c_str(), &statProperty)) { + if (-1 == stat(to_u8string(m_systemFileName).c_str(), &statProperty)) { //Normal case when the file does not exist ... ==> the it was in unknow mode ... return; } @@ -808,54 +805,52 @@ bool etk::FSNode::setRight(etk::FSNodeRight _newRight) return false; } -void etk::FSNode::setName(const etk::UString& _newName) +void etk::FSNode::setName(const std::u32string& _newName) { privateSetName(_newName); } -etk::UString etk::FSNode::getNameFolder(void) const -{ - int32_t lastPos = m_systemFileName.findBack('/'); - if (-1 != lastPos) { - return m_systemFileName.extract(0, lastPos); +std::u32string etk::FSNode::getNameFolder(void) const { + size_t lastPos = m_systemFileName.rfind('/'); + if (0 != lastPos) { + return std::u32string(m_systemFileName, 0, lastPos); } - return ""; + return U""; } -etk::UString etk::FSNode::getFileSystemName(void) const -{ + +std::u32string etk::FSNode::getFileSystemName(void) const { return m_systemFileName; } -etk::UString etk::FSNode::getName(void) const -{ - etk::UString output; +std::u32string etk::FSNode::getName(void) const { + std::u32string output; switch (m_type) { default: case etk::FSN_TYPE_UNKNOW: - output = "HOME:"; + output = U"HOME:"; break; case etk::FSN_TYPE_DIRECT: - output = "/"; + output = U"/"; break; case etk::FSN_TYPE_RELATIF: - output = ""; + output = U""; break; case etk::FSN_TYPE_HOME: - output = "~"; + output = U"~"; break; case etk::FSN_TYPE_DATA: - output = "DATA:"; + output = U"DATA:"; break; case etk::FSN_TYPE_USER_DATA: - output = "USERDATA:"; + output = U"USERDATA:"; break; case etk::FSN_TYPE_CACHE: - output = "CACHE:"; + output = U"CACHE:"; break; case etk::FSN_TYPE_THEME: case etk::FSN_TYPE_THEME_DATA: - output = "THEME:"; + output = U"THEME:"; break; } output += m_userFileName; @@ -863,30 +858,28 @@ etk::UString etk::FSNode::getName(void) const } -etk::UString etk::FSNode::getNameFile(void) const -{ - int32_t lastPos = m_systemFileName.findBack('/'); - if (-1 != lastPos) { - return m_systemFileName.extract(lastPos+1); +std::u32string etk::FSNode::getNameFile(void) const { + size_t lastPos = m_systemFileName.rfind('/'); + if (0 != lastPos) { + return std::u32string(m_systemFileName, lastPos+1); } - return ""; + return U""; } -etk::UString etk::FSNode::getRelativeFolder(void) const -{ - etk::UString tmppp = getName(); +std::u32string etk::FSNode::getRelativeFolder(void) const { + std::u32string tmppp = getName(); TK_DBG_MODE("get REF folder : " << tmppp ); switch (m_typeNode) { case etk::FSN_UNKNOW: case etk::FSN_FOLDER: case etk::FSN_LINK: - if (tmppp.endWith("/") == true) { + if (*tmppp.end() == '/') { TK_DBG_MODE(" ==> : " << tmppp ); return tmppp; } else { - etk::UString tmpVal = tmppp; - tmpVal += "/"; + std::u32string tmpVal = tmppp; + tmpVal += U"/"; TK_DBG_MODE(" ==> : " << tmppp ); return tmpVal; } @@ -899,26 +892,25 @@ etk::UString etk::FSNode::getRelativeFolder(void) const default: break; } - int32_t lastPos = tmppp.findBack('/'); - if (-1 != lastPos) { + size_t lastPos = tmppp.rfind('/'); + if (0 != lastPos) { TK_DBG_MODE(" ==> : " << tmppp.extract(0, lastPos+1) ); - return tmppp.extract(0, lastPos+1); + return std::u32string(tmppp, 0, lastPos+1); } - lastPos = tmppp.findBack(':'); - if (-1 != lastPos) { + lastPos = tmppp.rfind(':'); + if (0 != lastPos) { TK_DBG_MODE(" ==> : " << tmppp.extract(0, lastPos+1) ); - return tmppp.extract(0, lastPos+1); + return std::u32string(tmppp, 0, lastPos+1); } TK_DBG_MODE(" ==> : \"\"" ); - return ""; + return U""; } -bool etk::FSNode::touch(void) -{ +bool etk::FSNode::touch(void) { TK_DEBUG("Touch FILE : " << getName()); //just open in write an close ==> this will update the time - if (false==fileOpenAppend()) { + if (fileOpenAppend() == false) { return false; } bool ret = fileClose(); @@ -927,14 +919,13 @@ bool etk::FSNode::touch(void) return ret; } -bool etk::FSNode::move(const etk::UString& _path) -{ +bool etk::FSNode::move(const std::u32string& _path) { etk::FSNode tmpDst(_path); if (tmpDst.exist()==true) { tmpDst.remove(); } TK_DEBUG("Move : \"" << getFileSystemName() << "\" ==> \"" << tmpDst.getFileSystemName() << "\""); - int32_t res = rename(getFileSystemName().c_str(), tmpDst.getFileSystemName().c_str()); + int32_t res = rename(to_u8string(getFileSystemName()).c_str(), to_u8string(tmpDst.getFileSystemName()).c_str()); if (res!=0) { return false; } else { @@ -942,18 +933,17 @@ bool etk::FSNode::move(const etk::UString& _path) } } -bool etk::FSNode::remove(void) -{ +bool etk::FSNode::remove(void) { if (getNodeType()==etk::FSN_FOLDER) { // remove the folder - if( 0!=rmdir(m_systemFileName.c_str()) ) { + if( 0!=rmdir(to_u8string(m_systemFileName).c_str()) ) { if (ENOTEMPTY == errno) { TK_ERROR("The Directory is not empty..."); } return false; } } else { - if( 0!=unlink(m_systemFileName.c_str()) ) { + if( 0!=unlink(to_u8string(m_systemFileName).c_str()) ) { return false; } } @@ -967,12 +957,12 @@ uint64_t etk::FSNode::timeCreated(void) const return m_timeCreate; } -etk::UString etk::FSNode::timeCreatedString(void) const +std::u32string etk::FSNode::timeCreatedString(void) const { time_t tmpVal = (int32_t)m_timeCreate; - etk::UString tmpTime = ctime(&tmpVal); + std::u32string tmpTime = to_u32string(ctime(&tmpVal)); if (tmpTime[tmpTime.size()-1] == '\n') { - tmpTime.remove(tmpTime.size()-1, 1); + tmpTime.erase(tmpTime.end()); } return tmpTime; } @@ -982,12 +972,12 @@ uint64_t etk::FSNode::timeModified(void) const return m_timeModify; } -etk::UString etk::FSNode::timeModifiedString(void) const +std::u32string etk::FSNode::timeModifiedString(void) const { time_t tmpVal = (int32_t)m_timeModify; - etk::UString tmpTime = ctime(&tmpVal); + std::u32string tmpTime = to_u32string(ctime(&tmpVal)); if (tmpTime[tmpTime.size()-1] == '\n') { - tmpTime.remove(tmpTime.size()-1, 1); + tmpTime.erase(tmpTime.end()); } return tmpTime; } @@ -997,12 +987,12 @@ uint64_t etk::FSNode::timeAccessed(void) const return m_timeAccess; } -etk::UString etk::FSNode::timeAccessedString(void) const +std::u32string etk::FSNode::timeAccessedString(void) const { time_t tmpVal = (int32_t)m_timeAccess; - etk::UString tmpTime = ctime(&tmpVal); + std::u32string tmpTime = to_u32string(ctime(&tmpVal)); if (tmpTime[tmpTime.size()-1] == '\n') { - tmpTime.remove(tmpTime.size()-1, 1); + tmpTime.erase(tmpTime.end()); } return tmpTime; } @@ -1027,7 +1017,7 @@ const etk::FSNode& etk::FSNode::operator= (const etk::FSNode &_obj ) m_zipContent = NULL; m_zipReadingOffset = 0; #endif - etk::UString tmppp = _obj.getName(); + std::u32string tmppp = _obj.getName(); privateSetName(tmppp); } return *this; @@ -1139,13 +1129,13 @@ int64_t etk::FSNode::folderCount(void) int64_t counter=0; DIR *dir = NULL; struct dirent *ent = NULL; - dir = opendir(m_systemFileName.c_str()); + dir = opendir(to_u8string(m_systemFileName).c_str()); if (dir != NULL) { // for each element in the drectory... while ((ent = readdir(dir)) != NULL) { - etk::UString tmpName(ent->d_name); - if( tmpName=="." - || tmpName==".." ) { + std::u32string tmpName(to_u32string(ent->d_name)); + if( tmpName == U"." + || tmpName == U".." ) { // do nothing ... continue; } @@ -1158,9 +1148,9 @@ int64_t etk::FSNode::folderCount(void) } return counter; } -etk::Vector etk::FSNode::folderGetSubList(bool _showHidenFile, bool _getFolderAndOther, bool _getFile, bool _temporaryFile) +std::vector etk::FSNode::folderGetSubList(bool _showHidenFile, bool _getFolderAndOther, bool _getFile, bool _temporaryFile) { - etk::Vector tmpp; + std::vector tmpp; if (m_typeNode != etk::FSN_FOLDER ) { return tmpp; } @@ -1169,18 +1159,18 @@ etk::Vector etk::FSNode::folderGetSubList(bool _showHidenFile, bo etk::FSNode * tmpEmement; DIR *dir = NULL; struct dirent *ent = NULL; - dir = opendir(m_systemFileName.c_str()); + dir = opendir(to_u8string(m_systemFileName).c_str()); if (dir != NULL) { // for each element in the drectory... while ((ent = readdir(dir)) != NULL) { - etk::UString tmpName(ent->d_name); + std::u32string tmpName(to_u32string(ent->d_name)); TK_VERBOSE(" search in folder\"" << tmpName << "\""); - if( tmpName=="." - || tmpName==".." ) { + if( tmpName == U"." + || tmpName == U".." ) { // do nothing ... continue; } - if( false == tmpName.startWith(".") + if( false == start_with(tmpName, U".") || true == _showHidenFile) { tmpEmement = new etk::FSNode(getRelativeFolder()+tmpName); if (NULL == tmpEmement) { @@ -1189,13 +1179,13 @@ etk::Vector etk::FSNode::folderGetSubList(bool _showHidenFile, bo } if(tmpEmement->getNodeType() == etk::FSN_FILE) { if (true == _getFile) { - tmpp.pushBack(tmpEmement); + tmpp.push_back(tmpEmement); } else { delete(tmpEmement); tmpEmement = NULL; } } else if (_getFolderAndOther) { - tmpp.pushBack(tmpEmement); + tmpp.push_back(tmpEmement); } else { delete(tmpEmement); tmpEmement = NULL; @@ -1218,30 +1208,30 @@ etk::FSNode etk::FSNode::folderGetParent(void) return tmpp; } -void etk::FSNode::folderGetRecursiveFiles(etk::Vector& _output, bool _recursiveEnable) +void etk::FSNode::folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable) { #ifdef __TARGET_OS__Android if( m_type == etk::FSN_TYPE_DATA || m_type == etk::FSN_TYPE_THEME_DATA) { - etk::UString assetsName = "assets/"; - etk::UString FolderName = getNameFolder(); + std::u32string assetsName = U"assets/"; + std::u32string FolderName = getNameFolder(); if (s_APKArchive==NULL) { return; } for (int iii=0; iiisize(); iii++) { - etk::UString filename = s_APKArchive->getName(iii); + std::u32string filename = s_APKArchive->getName(iii); if (filename.startWith(FolderName) == true) { - etk::UString tmpString; + std::u32string tmpString; if(m_type == etk::FSN_TYPE_DATA) { - tmpString = "DATA:"; + tmpString = U"DATA:"; } else { - tmpString = "THEME:"; + tmpString = U"THEME:"; } if (true == filename.startWith(assetsName)) { filename.remove(0,assetsName.size()); } tmpString += filename; - _output.pushBack(tmpString); + _output.push_back(tmpString); } } return; @@ -1251,14 +1241,14 @@ void etk::FSNode::folderGetRecursiveFiles(etk::Vector& _output, bo etk::FSNode * tmpEmement; DIR *dir = NULL; struct dirent *ent = NULL; - dir = opendir(m_systemFileName.c_str()); + dir = opendir(to_u8string(m_systemFileName).c_str()); //TK_DEBUG(" ** open Folder : " << m_systemFileName ); if (dir != NULL) { // for each element in the drectory... while ((ent = readdir(dir)) != NULL) { - etk::UString tmpName(ent->d_name); - if( tmpName=="." - || tmpName==".." ) { + std::u32string tmpName(to_u32string(ent->d_name)); + if( tmpName == U"." + || tmpName == U".." ) { // do nothing ... continue; } @@ -1266,8 +1256,8 @@ void etk::FSNode::folderGetRecursiveFiles(etk::Vector& _output, bo tmpEmement = new etk::FSNode(getRelativeFolder()+tmpName); if (NULL != tmpEmement) { if(tmpEmement->getNodeType() == etk::FSN_FILE) { - etk::UString tmpVal = tmpEmement->getName(); - _output.pushBack(tmpVal); + std::u32string tmpVal = tmpEmement->getName(); + _output.push_back(tmpVal); } if(tmpEmement->getNodeType() == etk::FSN_FOLDER) { if (true==_recursiveEnable) { @@ -1293,9 +1283,8 @@ void etk::FSNode::folderGetRecursiveFiles(etk::Vector& _output, bo */ bool etk::FSNode::fileHasExtention(void) { - int32_t lastPos = m_userFileName.findBack('.'); - if( -1 != lastPos // not find the . - && 0 != lastPos // Find a . at the fist position .jdlskjdfklj ==> hiden file + size_t lastPos = m_userFileName.rfind('.'); + if( 0 != lastPos // Find a . at the fist position .jdlskjdfklj ==> hiden file && m_userFileName.size() != lastPos ) // Remove file ended with . { return true; @@ -1304,18 +1293,16 @@ bool etk::FSNode::fileHasExtention(void) } } -etk::UString etk::FSNode::fileGetExtention(void) +std::u32string etk::FSNode::fileGetExtention(void) { - etk::UString tmpExt = ""; - int32_t lastPos = m_userFileName.findBack('.'); - if( -1 != lastPos // not find the . - && 0 != lastPos // Find a . at the fist position .jdlskjdfklj ==> hiden file + size_t lastPos = m_userFileName.rfind('.'); + if( 0 != lastPos // Find a . at the fist position .jdlskjdfklj ==> hiden file && m_userFileName.size() != lastPos ) // Remove file ended with . { // Get the FileName - tmpExt = m_userFileName.extract(lastPos+1); + return std::u32string(m_userFileName, lastPos+1); } - return tmpExt; + return U""; } uint64_t etk::FSNode::fileSize(void) @@ -1336,7 +1323,7 @@ uint64_t etk::FSNode::fileSize(void) // Note : this is a proper methode to get the file size for Big files ... otherwithe the size is limited at 2^31 bytes // tmpStat Buffer : struct stat statProperty; - if (-1 == stat(m_systemFileName.c_str(), &statProperty)) { + if (-1 == stat(to_u8string(m_systemFileName).c_str(), &statProperty)) { //Normal case when the file does not exist ... ==> the it was in unknow mode ... TK_ERROR("mlkmlkmlkmlkmlkmlk"); return 0; @@ -1366,7 +1353,7 @@ bool etk::FSNode::fileOpenRead(void) return true; } TK_VERBOSE(" Read file : " << m_systemFileName); - m_PointerFile=fopen(m_systemFileName.c_str(),"rb"); + m_PointerFile=fopen(to_u8string(m_systemFileName).c_str(),"rb"); if(NULL == m_PointerFile) { TK_ERROR("Can not find the file " << *this ); return false; @@ -1385,9 +1372,9 @@ bool etk::FSNode::fileOpenWrite(void) TK_CRITICAL("File Already open : " << *this); return true; } - FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777); + FSNODE_LOCAL_mkPath(to_u8string(getNameFolder()).c_str() , 0777); TK_VERBOSE(" write file : " << m_systemFileName); - m_PointerFile=fopen(m_systemFileName.c_str(),"wb"); + m_PointerFile=fopen(to_u8string(m_systemFileName).c_str(),"wb"); if(NULL == m_PointerFile) { TK_ERROR("Can not find the file " << *this); return false; @@ -1406,11 +1393,11 @@ bool etk::FSNode::fileOpenAppend(void) TK_CRITICAL("File Already open : " << *this); return true; } - FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777); + FSNODE_LOCAL_mkPath(to_u8string(getNameFolder()).c_str() , 0777); TK_VERBOSE(" append file : " << m_systemFileName); - m_PointerFile=fopen(m_systemFileName.c_str(),"ab"); + m_PointerFile=fopen(to_u8string(m_systemFileName).c_str(),"ab"); if(NULL == m_PointerFile) { TK_ERROR("Can not find the file " << *this); return false; @@ -1606,14 +1593,14 @@ void etk::FSNode::fileFlush(void) class tmpThemeElement { public: - etk::UString refName; - etk::UString folderName; + std::u32string refName; + std::u32string folderName; }; -static etk::Vector g_listTheme; +static std::vector g_listTheme; // set the Folder of a subset of a theme ... -void etk::theme::setName(etk::UString _refName, etk::UString _folderName) +void etk::theme::setName(std::u32string _refName, std::u32string _folderName) { for(int32_t iii=0; iiirefName = _refName; tmpp->folderName = _folderName; - g_listTheme.pushBack(tmpp); + g_listTheme.push_back(tmpp); } // get the folder from a Reference theme -etk::UString etk::theme::getName(etk::UString _refName) -{ +std::u32string etk::theme::getName(std::u32string _refName) { for(int32_t iii=0; iiirefName==_refName) { @@ -1650,9 +1636,8 @@ etk::UString etk::theme::getName(etk::UString _refName) } // get the list of all the theme folder availlable in the user Home/appl -etk::Vector etk::theme::list(void) -{ - etk::Vector tmpp; +std::vector etk::theme::list(void) { + std::vector tmpp; return tmpp; // TODO : } @@ -1663,7 +1648,7 @@ etk::Vector etk::theme::list(void) * Simple direct wrapper on the FileSystem node access : * * -------------------------------------------------------------------------- */ -bool etk::FSNodeRemove(const etk::UString& _path) +bool etk::FSNodeRemove(const std::u32string& _path) { etk::FSNode tmpNode(_path); if (false==tmpNode.exist()) { @@ -1672,7 +1657,7 @@ bool etk::FSNodeRemove(const etk::UString& _path) return tmpNode.remove(); } -int64_t etk::FSNodeGetCount(const etk::UString& _path) +int64_t etk::FSNodeGetCount(const std::u32string& _path) { etk::FSNode tmpNode(_path); if (false==tmpNode.exist()) { @@ -1681,19 +1666,19 @@ int64_t etk::FSNodeGetCount(const etk::UString& _path) return tmpNode.folderCount(); } -bool etk::FSNodeCreate(const etk::UString& _path, etk::FSNodeRight _right, enum etk::typeNode _type) +bool etk::FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type) { // TODO : return false; } -bool etk::FSNodeExist(const etk::UString& _path) +bool etk::FSNodeExist(const std::u32string& _path) { etk::FSNode tmpNode(_path); return tmpNode.exist(); } -bool etk::FSNodeMove(const etk::UString& _path1, const etk::UString& _path2) +bool etk::FSNodeMove(const std::u32string& _path1, const std::u32string& _path2) { etk::FSNode tmpNode(_path1); if (false==tmpNode.exist()) { @@ -1706,43 +1691,43 @@ bool etk::FSNodeMove(const etk::UString& _path1, const etk::UString& _path2) return tmpNode.move(_path2); } -etk::FSNodeRight etk::FSNodeGetRight(const etk::UString& _path) +etk::FSNodeRight etk::FSNodeGetRight(const std::u32string& _path) { etk::FSNode tmpNode(_path); return tmpNode.getRight(); } -enum etk::typeNode etk::FSNodeGetType(const etk::UString& _path) +enum etk::typeNode etk::FSNodeGetType(const std::u32string& _path) { etk::FSNode tmpNode(_path); return tmpNode.getNodeType(); } -uint64_t etk::FSNodeGetTimeCreated(const etk::UString& _path) +uint64_t etk::FSNodeGetTimeCreated(const std::u32string& _path) { etk::FSNode tmpNode(_path); return tmpNode.timeCreated(); } -uint64_t etk::FSNodeGetTimeModified(const etk::UString& _path) +uint64_t etk::FSNodeGetTimeModified(const std::u32string& _path) { etk::FSNode tmpNode(_path); return tmpNode.timeModified(); } -uint64_t etk::FSNodeGetTimeAccessed(const etk::UString& _path) +uint64_t etk::FSNodeGetTimeAccessed(const std::u32string& _path) { etk::FSNode tmpNode(_path); return tmpNode.timeAccessed(); } -bool etk::FSNodeTouch(const etk::UString& _path) +bool etk::FSNodeTouch(const std::u32string& _path) { etk::FSNode tmpNode(_path); return tmpNode.touch(); } -bool etk::FSNodeEcho(const etk::UString& _path, const etk::UString& _dataTowrite) +bool etk::FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite) { etk::FSNode tmpNode(_path); if (false==tmpNode.exist()) { @@ -1755,16 +1740,15 @@ bool etk::FSNodeEcho(const etk::UString& _path, const etk::UString& _dataTowrite return false; } // convert in UTF8 : - etk::Char tmpChar = _dataTowrite.c_str(); - int32_t nbChar = strlen(tmpChar); - if (nbChar != tmpNode.fileWrite(tmpChar, 1, nbChar)) { + std::string tmpChar = to_u8string(_dataTowrite); + if (tmpChar.size() != tmpNode.fileWrite((char*)tmpChar.c_str(), 1, tmpChar.size())) { tmpNode.fileClose(); return false; } return tmpNode.fileClose(); } -bool etk::FSNodeEchoAdd(const etk::UString& _path, const etk::UString& _dataTowrite) +bool etk::FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite) { etk::FSNode tmpNode(_path); if (false==tmpNode.exist()) { @@ -1777,25 +1761,24 @@ bool etk::FSNodeEchoAdd(const etk::UString& _path, const etk::UString& _dataTowr return false; } // convert in UTF8 : - etk::Char tmpChar = _dataTowrite.c_str(); - int32_t nbChar = strlen(tmpChar); - if (nbChar != tmpNode.fileWrite(tmpChar, 1, nbChar)) { + std::string tmpChar = to_u8string(_dataTowrite); + if (tmpChar.size() != tmpNode.fileWrite((char*)tmpChar.c_str(), 1, tmpChar.size())) { tmpNode.fileClose(); return false; } return tmpNode.fileClose(); } -void etk::FSNodeHistory(const etk::UString& _path, int32_t _historyCount) +void etk::FSNodeHistory(const std::u32string& _path, int32_t _historyCount) { // step 1 : Move the file to prevent writing error //Get the first oldest save : for (int32_t iii=_historyCount-1; iii>0 ; iii--) { - if (true==etk::FSNodeExist(_path+"-"+iii) ) { - etk::FSNodeMove(_path+"-"+iii,_path+"-"+(iii+1)); + if (true==etk::FSNodeExist(_path + U"-" + to_u32string(iii)) ) { + etk::FSNodeMove(_path + U"-" + to_u32string(iii), _path + U"-" + to_u32string(iii+1)); } } if (true==etk::FSNodeExist(_path) ) { - etk::FSNodeMove(_path,_path+"-1"); + etk::FSNodeMove(_path, _path + U"-1"); } } diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index abeb3f4..b572ad7 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -22,7 +22,7 @@ namespace etk { - void setArgZero(const etk::UString& _val); + void setArgZero(const std::u32string& _val); /** * List of Type that a node can have (this wrap some type that not exist on Windows) */ @@ -123,8 +123,8 @@ namespace etk class FSNode { private: - etk::UString m_userFileName; //!< the name requested by the User - etk::UString m_systemFileName; //!< the compleate filename for the system + std::u32string m_userFileName; //!< the name requested by the User + std::u32string m_systemFileName; //!< the compleate filename for the system enum FSNType m_type; //!< the Type of data requested by the User enum typeNode m_typeNode; //!< type of the current file/Folder/Link etk::FSNodeRight m_rights; //!< IO right of the current file @@ -140,7 +140,7 @@ namespace etk * @brief Constructor * @param[in] _path Path of the curent file /folder ... */ - FSNode(const etk::UString& _path="~"); + FSNode(const std::u32string& _path = U"~"); /** * @brief Destructor * @note you will have some warning if you did not close your files @@ -159,7 +159,7 @@ namespace etk * @brief Common set name of the Node (if the user decide to change the node selection * @param[in] _newName Name of the Node */ - void privateSetName(const etk::UString& _newName); + void privateSetName(const std::u32string& _newName); private: #ifdef __TARGET_OS__Android /** @@ -177,17 +177,23 @@ namespace etk * @return true : The node existed. * @return false : The node does not exist. */ - bool exist(void) const { return (m_typeNode!=etk::FSN_UNKNOW); }; + bool exist(void) const { + return (m_typeNode!=etk::FSN_UNKNOW); + }; /** * @brief Get the node type * @return the requested type, FSN_UNKNOW if it does not existed */ - enum typeNode getNodeType(void) const { return m_typeNode; }; + enum typeNode getNodeType(void) const { + return m_typeNode; + }; /** * @brief Get the node Right * @return the requested right */ - etk::FSNodeRight getRight(void) const { return m_rights; }; + etk::FSNodeRight getRight(void) const { + return m_rights; + }; /** * @brief Set the specific right of the node * @param[in] _newRight new right to set @@ -201,35 +207,35 @@ namespace etk * @return true : action done * @return false : action not done */ - void setName(const etk::UString& _newName); + void setName(const std::u32string& _newName); /** * @brief Get the Generate FileSystem name * @return the requested filename */ - etk::UString getFileSystemName(void) const; + std::u32string getFileSystemName(void) const; /** * @brief Get the current folder of the Node. (file system name) * @return the common name define (like /xxxxx/xxxxx/ or c:/xxxxx/xxxxx/) * @note Auto remove of ../../../ and // */ - etk::UString getNameFolder(void) const; + std::u32string getNameFolder(void) const; /** * @brief Get the current compleate node name (file system name) * @return All the user name definition (like /xxxxx/xxxxx/myFile.kkk or c:/xxxxx/xxxxx/myFile.kkk) * @note Auto remove of ../../../ and // */ - etk::UString getName(void) const; + std::u32string getName(void) const; /** * @brief Get the file or current folder name (if it was a folder) * @return the name of the node (like myFile.kkk) */ - etk::UString getNameFile(void) const; + std::u32string getNameFile(void) const; /** * @brief Get the current folder of the Node. * @return the common name define (like DATA:xxxxx/xxxxx/) * @note Auto remove of ../../../ and // */ - etk::UString getRelativeFolder(void) const; + std::u32string getRelativeFolder(void) const; /** * @brief update the Time of the file with the current time * @return true : action done @@ -242,12 +248,14 @@ namespace etk * @return true : action done * @return false : action not done */ - bool move(const etk::UString& _path); + bool move(const std::u32string& _path); /** * @brief Get the node type (DATA/DIRECT...) * @return the requested type */ - enum FSNType getTypeAccess(void) const { return m_type; }; + enum FSNType getTypeAccess(void) const { + return m_type; + }; /** * @brief Remove the current node ( if folder, this remove all subfolder but not the Link subfolder) * @return true : action done @@ -263,7 +271,7 @@ namespace etk * @brief Get the creating time of the File * @return The time requested (in string) */ - etk::UString timeCreatedString(void) const; + std::u32string timeCreatedString(void) const; /** * @brief Get the modifying time of the File * @return The time requested @@ -273,7 +281,7 @@ namespace etk * @brief Get the modifying time of the File * @return The time requested (in string) */ - etk::UString timeModifiedString(void) const; + std::u32string timeModifiedString(void) const; /** * @brief Get the Accessed time of the File * @return The time requested @@ -283,7 +291,7 @@ namespace etk * @brief Get the Accessed time of the File * @return The time requested (in string) */ - etk::UString timeAccessedString(void) const; + std::u32string timeAccessedString(void) const; /** * @brief copy the other FSnode ==> for vector * @param[in] _obj input node @@ -324,10 +332,10 @@ namespace etk * @param[in] _temporaryFile add Tmp file like .bck or ~ * @return The requested list */ - etk::Vector folderGetSubList(bool _showHidenFile=true, - bool _getFolderAndOther=true, - bool _getFile=true, - bool _temporaryFile=true); + std::vector folderGetSubList(bool _showHidenFile = true, + bool _getFolderAndOther = true, + bool _getFile = true, + bool _temporaryFile = true); /** * @brief Get the father node of this node * @return The requested node @@ -338,7 +346,7 @@ namespace etk * @param[out] _output List of all the File names (You must clear it before set it in) * @param[in] _recursiveEnable Activate the recursive mode (enable by default) */ - void folderGetRecursiveFiles(etk::Vector& _output, bool _recursiveEnable=true); + void folderGetRecursiveFiles(std::vector& _output, bool _recursiveEnable=true); /** * @brief Check if the file have an extention ( ***.ccc) * @return true The file have an extention. @@ -349,7 +357,7 @@ namespace etk * @brief Get the extention of the Node * @return the requested extention */ - etk::UString fileGetExtention(void); + std::u32string fileGetExtention(void); /** * @brief Get the File size * @return the requested size @@ -426,7 +434,7 @@ namespace etk * @brief Order the list of subnode the folder first and the alphabetical order * @param[in,out] _list The list to order */ - void sortElementList(etk::Vector& _list); + void sortElementList(std::vector& _list); }; etk::CCout& operator <<(etk::CCout &_os, const etk::FSNode &_obj); @@ -455,33 +463,32 @@ namespace etk * @brief Get the home folder of the user * @return the home folder : like : "/home/machin/" */ - etk::UString getUserHomeFolder(void); + std::u32string getUserHomeFolder(void); /** * @brief Get the folder of the Program is running * @return the basic folder name (ex : run ./appl in the pwd=/home/machin/sousFolder ==> this return the pwd folder) */ - etk::UString getUserRunFolder(void); + std::u32string getUserRunFolder(void); - namespace theme - { + namespace theme { // TODO : Add an INIT ... /** * @brief Set the Folder of a subset of a theme ... * @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT" * @param[in] _folderName The associated folder of the Theme (like "myTheme/folder/folder2/") */ - void setName(etk::UString _refName, etk::UString _folderName); + void setName(std::u32string _refName, std::u32string _folderName); /** * @brief get the folder from a Reference theme * @param[in] _refName Theme cathegorie ex : "GUI" "SHADER" "DEFAULT" * @return the path of the theme */ - etk::UString getName(etk::UString _refName); + std::u32string getName(std::u32string _refName); /** * @brief Get the list of all the theme folder availlable in the user Home/appl * @return The list of elements */ - etk::Vector list(void); + std::vector list(void); }; /** @@ -490,14 +497,14 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ - bool FSNodeRemove(const etk::UString& _path); + bool FSNodeRemove(const std::u32string& _path); /** * @brief Simple access for : count the number of element in a path (if it is not a path ==> return -1) * @param[in] _path Folder/File/Pipe path of the node * @return number of File inside * @return -1 : An error occured */ - int64_t FSNodeGetCount(const etk::UString& _path); + int64_t FSNodeGetCount(const std::u32string& _path); /** * @brief Simple access for : Create a file or a folder depending of the request * @param[in] _path Folder/File/Pipe path of the node @@ -506,14 +513,14 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ - bool FSNodeCreate(const etk::UString& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); + bool FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::FSN_FOLDER); /** * @brief Simple access for : chexk the exestance of an element * @param[in] _path Folder/File/Pipe path of the node * @return true : Action done corectly * @return false : An error occured */ - bool FSNodeExist(const etk::UString& _path); + bool FSNodeExist(const std::u32string& _path); /** * @brief Simple access for : chexk the exestance of an element * @param[in] _path1 Folder/File/Pipe path of the node sources @@ -521,49 +528,49 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ - bool FSNodeMove(const etk::UString& _path1, const etk::UString& _path2); + bool FSNodeMove(const std::u32string& _path1, const std::u32string& _path2); /** * @brief Simple access for : Get right of the current Node * @param[in] _path Folder/File/Pipe path of the node * @return true : Action done corectly * @return false : An error occured */ - etk::FSNodeRight FSNodeGetRight(const etk::UString& _path); + etk::FSNodeRight FSNodeGetRight(const std::u32string& _path); /** * @brief Simple access for : Get type of the current node * @param[in] _path Folder/File/Pipe path of the node * @return true : Action done corectly * @return false : An error occured */ - enum etk::typeNode FSNodeGetType(const etk::UString& _path); + enum etk::typeNode FSNodeGetType(const std::u32string& _path); /** * @brief Simple access for : Getting creation time of the current node * @param[in] _path Folder/File/Pipe path of the node * @return true : Action done corectly * @return false : An error occured */ - uint64_t FSNodeGetTimeCreated(const etk::UString& _path); + uint64_t FSNodeGetTimeCreated(const std::u32string& _path); /** * @brief Simple access for : Getting Modification time of the current node * @param[in] _path Folder/File/Pipe path of the node * @return true : Action done corectly * @return false : An error occured */ - uint64_t FSNodeGetTimeModified(const etk::UString& _path); + uint64_t FSNodeGetTimeModified(const std::u32string& _path); /** * @brief Simple access for : Getting Accessing time of the current node * @param[in] _path Folder/File/Pipe path of the node * @return true : Action done corectly * @return false : An error occured */ - uint64_t FSNodeGetTimeAccessed(const etk::UString& _path); + uint64_t FSNodeGetTimeAccessed(const std::u32string& _path); /** * @brief Simple access for : Update Modification time with the current time of the node (>) * @param[in] _path Folder/File/Pipe path of the node * @return true : Action done corectly * @return false : An error occured */ - bool FSNodeTouch(const etk::UString& _path); + bool FSNodeTouch(const std::u32string& _path); /** * @brief Simple access for : Basic write on the node (like console echo) * @param[in] _path Folder/File/Pipe path of the node @@ -571,7 +578,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ - bool FSNodeEcho(const etk::UString& _path, const etk::UString& _dataTowrite); + bool FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite); /** * @brief Simple access for : Basic write on the node (like console echo) in adding mode (>>) * @param[in] _path Folder/File/Pipe path of the node @@ -579,13 +586,13 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ - bool FSNodeEchoAdd(const etk::UString& _path, const etk::UString& _dataTowrite); + bool FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite); /** * @brief move file to generate an history of the current file * @param[in] _path Folder/File/Pipe path of the node * @param[in] _historyCount number of saved file in the history (-xxx) */ - void FSNodeHistory(const etk::UString& _path, int32_t _historyCount); + void FSNodeHistory(const std::u32string& _path, int32_t _historyCount); }; #endif diff --git a/etk/os/FSNodeRight.cpp b/etk/os/FSNodeRight.cpp index 5315c12..ef9b950 100644 --- a/etk/os/FSNodeRight.cpp +++ b/etk/os/FSNodeRight.cpp @@ -176,53 +176,53 @@ void etk::FSNodeRight::setOtherRunable(bool _newStatus) m_rights |= RIGHT_OTHER_EXECUTE; } } -etk::UString etk::FSNodeRight::getRight(void) const +std::u32string etk::FSNodeRight::getRight(void) const { - etk::UString tmp; + std::u32string tmp; if (isUserReadable() == true) { - tmp += "r"; + tmp += U"r"; } else { - tmp += "-"; + tmp += U"-"; } if (isUserWritable() == true) { - tmp += "w"; + tmp += U"w"; } else { - tmp += "-"; + tmp += U"-"; } if (isUserRunable() == true) { - tmp += "x"; + tmp += U"x"; } else { - tmp += "-"; + tmp += U"-"; } if (isGroupReadable() == true) { - tmp += "r"; + tmp += U"r"; } else { - tmp += "-"; + tmp += U"-"; } if (isGroupWritable() == true) { - tmp += "w"; + tmp += U"w"; } else { - tmp += "-"; + tmp += U"-"; } if (isGroupRunable() == true) { - tmp += "x"; + tmp += U"x"; } else { - tmp += "-"; + tmp += U"-"; } if (isOtherReadable() == true) { - tmp += "r"; + tmp += U"r"; } else { - tmp += "-"; + tmp += U"-"; } if (isOtherWritable() == true) { - tmp += "w"; + tmp += U"w"; } else { - tmp += "-"; + tmp += U"-"; } if (isOtherRunable() == true) { - tmp += "x"; + tmp += U"x"; } else { - tmp += "-"; + tmp += U"-"; } return tmp; } diff --git a/etk/os/FSNodeRight.h b/etk/os/FSNodeRight.h index 70c4cd1..26bfcb5 100644 --- a/etk/os/FSNodeRight.h +++ b/etk/os/FSNodeRight.h @@ -49,7 +49,7 @@ namespace etk void setOtherWritable(bool _newStatus); void setOtherRunable(bool _newStatus); - etk::UString getRight(void) const; + std::u32string getRight(void) const; }; etk::CCout& operator <<(etk::CCout &_os, const etk::FSNodeRight &_obj); }; diff --git a/etk/tool.cpp b/etk/tool.cpp index a312112..5fab0b2 100644 --- a/etk/tool.cpp +++ b/etk/tool.cpp @@ -25,9 +25,9 @@ int32_t etk::tool::irand(int32_t _a, int32_t _b) return (int32_t)(( rand()/(float)RAND_MAX ) * ((float)_b-(float)_a) + (float)_a); } -void etk::tool::sortList(etk::Vector &_list) +void etk::tool::sortList(std::vector &_list) { - etk::Vector tmpList = _list; + std::vector tmpList = _list; _list.clear(); for(int32_t iii=0; iii &_list) } } //EWOL_DEBUG("position="<5000) { TK_CRITICAL("ERROR when getting the small path ... this is loop prevention..."); @@ -119,12 +119,12 @@ etk::UString etk::tool::simplifyPath(etk::UString _input) // for the target that supported the Realpath system : char buf[MAX_FILE_NAME]; memset(buf, 0, MAX_FILE_NAME); - char * ok = realpath(_input.c_str(), buf); + char * ok = realpath(to_u8string(_input).c_str(), buf); if (!ok) { TK_ERROR("Error to get the real path"); - _input = "/"; + _input = U"/"; } else { - _input = buf; + _input = to_u32string(buf); } #endif diff --git a/etk/tool.h b/etk/tool.h index 91d8df0..6a08aba 100644 --- a/etk/tool.h +++ b/etk/tool.h @@ -11,15 +11,16 @@ #include #include +#include namespace etk { namespace tool { float frand(float _a, float _b); int32_t irand(int32_t _a, int32_t _b); - void sortList(etk::Vector& _list); + void sortList(std::vector& _list); bool strnCmpNoCase(const char* _input1, const char* _input2, int32_t _maxLen); - etk::UString simplifyPath(etk::UString _input); + std::u32string simplifyPath(std::u32string _input); }; }; diff --git a/etk/types.h b/etk/types.h index 4f14ee9..6e89bff 100644 --- a/etk/types.h +++ b/etk/types.h @@ -9,6 +9,18 @@ #ifndef __ETK_TYPES_H__ #define __ETK_TYPES_H__ +#ifdef __TARGET_OS__Android + // NOTE : This is for compatibility with the C++ stdlib (missing this declaration on android ... + namespace std { + typedef struct { + int dummy; + } mbstate_t; + }; + #include + #include +#endif +#include + #include #include #include diff --git a/etk/unicode.cpp b/etk/unicode.cpp index 9295f16..fb8db8c 100644 --- a/etk/unicode.cpp +++ b/etk/unicode.cpp @@ -15,24 +15,24 @@ -void unicode::convertIsoToUnicode(enum charset _inputCharset, const char _input_ISO, etk::UChar & _output_Unicode) +void unicode::convertIsoToUnicode(enum charset _inputCharset, const char _input_ISO, char32_t & _output_Unicode) { switch(_inputCharset) { - case charsetIso8859_1: _output_Unicode.set(tableIso8859_1[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_2: _output_Unicode.set(tableIso8859_2[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_3: _output_Unicode.set(tableIso8859_3[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_4: _output_Unicode.set(tableIso8859_4[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_5: _output_Unicode.set(tableIso8859_5[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_6: _output_Unicode.set(tableIso8859_6[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_7: _output_Unicode.set(tableIso8859_7[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_8: _output_Unicode.set(tableIso8859_8[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_9: _output_Unicode.set(tableIso8859_9[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_10: _output_Unicode.set(tableIso8859_10[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_11: _output_Unicode.set(tableIso8859_11[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_13: _output_Unicode.set(tableIso8859_13[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_14: _output_Unicode.set(tableIso8859_14[(uint32_t)_input_ISO&0xFF]); break; - case charsetIso8859_15: _output_Unicode.set(tableIso8859_15[(uint32_t)_input_ISO&0xFF]); break; + case charsetIso8859_1: _output_Unicode = tableIso8859_1[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_2: _output_Unicode = tableIso8859_2[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_3: _output_Unicode = tableIso8859_3[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_4: _output_Unicode = tableIso8859_4[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_5: _output_Unicode = tableIso8859_5[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_6: _output_Unicode = tableIso8859_6[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_7: _output_Unicode = tableIso8859_7[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_8: _output_Unicode = tableIso8859_8[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_9: _output_Unicode = tableIso8859_9[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_10: _output_Unicode = tableIso8859_10[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_11: _output_Unicode = tableIso8859_11[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_13: _output_Unicode = tableIso8859_13[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_14: _output_Unicode = tableIso8859_14[(uint32_t)_input_ISO&0xFF]; break; + case charsetIso8859_15: _output_Unicode = tableIso8859_15[(uint32_t)_input_ISO&0xFF]; break; default : TK_WARNING("Unknow charset ... " << _inputCharset); _output_Unicode = '?'; @@ -41,7 +41,7 @@ void unicode::convertIsoToUnicode(enum charset _inputCharset, const char _input_ } -void unicode::convertUnicodeToIso(enum charset _inputCharset, const etk::UChar _input_Unicode, char & _output_ISO) +void unicode::convertUnicodeToIso(enum charset _inputCharset, const char32_t _input_Unicode, char & _output_ISO) { const uint32_t *tmpTable = NULL; switch(_inputCharset) @@ -67,7 +67,7 @@ void unicode::convertUnicodeToIso(enum charset _inputCharset, const etk::UChar _ } int32_t i; for (i=0; i<256; i++) { - if (tmpTable[i] == _input_Unicode.get()) { + if (tmpTable[i] == _input_Unicode) { _output_ISO = (char)i; return; } @@ -75,107 +75,111 @@ void unicode::convertUnicodeToIso(enum charset _inputCharset, const etk::UChar _ } -int32_t unicode::convertIsoToUnicode(enum charset _inputCharset, const etk::Vector& _input_ISO, etk::Vector& _output_Unicode) +int32_t unicode::convertIsoToUnicode(enum charset _inputCharset, const std::vector& _input_ISO, std::vector& _output_Unicode) { _output_Unicode.clear(); - etk::UChar output; + char32_t output; for(int32_t iii=0; iii<_input_ISO.size(); iii++) { convertIsoToUnicode(_inputCharset, (char)_input_ISO[iii], output); - _output_Unicode.pushBack(output); + _output_Unicode.push_back(output); } if (_output_Unicode.size() == 0) { - _output_Unicode.pushBack(0); + _output_Unicode.push_back(0); } else if (_output_Unicode[_output_Unicode.size()-1] != 0) { - _output_Unicode.pushBack(0); + _output_Unicode.push_back(0); } return _output_Unicode.size(); } -int32_t unicode::convertIsoToUnicode(enum charset _inputCharset, const etk::Vector& _input_ISO, etk::Vector& _output_Unicode) +int32_t unicode::convertIsoToUnicode(enum charset _inputCharset, const std::vector& _input_ISO, std::vector& _output_Unicode) { _output_Unicode.clear(); - etk::UChar output; + char32_t output; for(int32_t iii=0; iii<_input_ISO.size(); iii++) { convertIsoToUnicode(_inputCharset, (char)_input_ISO[iii], output); - _output_Unicode.pushBack(output); + _output_Unicode.push_back(output); } if (_output_Unicode.size() == 0) { - _output_Unicode.pushBack(0); + _output_Unicode.push_back(0); } else if (_output_Unicode[_output_Unicode.size()-1] != 0) { - _output_Unicode.pushBack(0); + _output_Unicode.push_back(0); } return _output_Unicode.size(); } -int32_t unicode::convertUnicodeToIso(enum charset _inputCharset, const etk::Vector& _input_Unicode, etk::Vector& _output_ISO) +int32_t unicode::convertUnicodeToIso(enum charset _inputCharset, const std::vector& _input_Unicode, std::vector& _output_ISO) { +/* _output_ISO.clear(); char output[10]; for(int32_t iii=0; iii<_input_Unicode.size(); iii++) { _input_Unicode[iii].getUtf8(output); char * tmp = output; while(*tmp != '\0') { - _output_ISO.pushBack(*tmp); + _output_ISO.push_back(*tmp); tmp++; } } - _output_ISO.pushBack(0); + _output_ISO.push_back(0); return _output_ISO.size(); +*/ } -int32_t unicode::convertUnicodeToIso(enum charset _inputCharset, const etk::Vector& _input_Unicode, etk::Vector& _output_ISO) +int32_t unicode::convertUnicodeToIso(enum charset _inputCharset, const std::vector& _input_Unicode, std::vector& _output_ISO) { +/* _output_ISO.clear(); char output[10]; for(int32_t iii=0; iii<_input_Unicode.size(); iii++) { _input_Unicode[iii].getUtf8(output); char * tmp = output; while(*tmp != '\0') { - _output_ISO.pushBack(*tmp); + _output_ISO.push_back(*tmp); tmp++; } } - _output_ISO.pushBack(0); + _output_ISO.push_back(0); return _output_ISO.size(); +*/ } -int32_t unicode::convertUnicodeToUtf8(const etk::Vector& _input_Unicode, etk::Vector& _output_UTF8) +int32_t unicode::convertUnicodeToUtf8(const std::vector& _input_Unicode, std::vector& _output_UTF8) { char output[10]; for (int32_t iii=0; iii<_input_Unicode.size(); iii++) { - _input_Unicode[iii].getUtf8(output); + etk::getUtf8(_input_Unicode[iii], output); char * tmp = output ; while (*tmp != '\0') { - _output_UTF8.pushBack(*tmp); + _output_UTF8.push_back(*tmp); tmp++; } } - _output_UTF8.pushBack('\0'); + _output_UTF8.push_back('\0'); return _output_UTF8.size()-1; } -int32_t unicode::convertUnicodeToUtf8(const etk::Vector& _input_Unicode, etk::Vector& _output_UTF8) +int32_t unicode::convertUnicodeToUtf8(const std::vector& _input_Unicode, std::vector& _output_UTF8) { char output[10]; for (int32_t iii=0; iii<_input_Unicode.size(); iii++) { - _input_Unicode[iii].getUtf8(output); + etk::getUtf8(_input_Unicode[iii], output); char * tmp = output ; while (*tmp != '\0') { - _output_UTF8.pushBack((int8_t)*tmp); + _output_UTF8.push_back((int8_t)*tmp); tmp++; } } - _output_UTF8.pushBack('\0'); + _output_UTF8.push_back('\0'); return _output_UTF8.size()-1; } -int32_t unicode::convertUtf8ToUnicode(const etk::Vector& _input_UTF8, etk::Vector& _output_Unicode) +int32_t unicode::convertUtf8ToUnicode(const std::vector& _input_UTF8, std::vector& _output_Unicode) { char tmpData[20]; int32_t pos = 0; @@ -219,14 +223,12 @@ int32_t unicode::convertUtf8ToUnicode(const etk::Vector& _input_UTF8, etk: tmpData[0] = '\0'; pos += 1; } - etk::UChar tmpUnicode; - tmpUnicode.setUtf8(tmpData); - _output_Unicode.pushBack(tmpUnicode); + _output_Unicode.push_back(etk::setUtf8(tmpData)); } return 0; } -int32_t unicode::convertUtf8ToUnicode(const etk::Vector& _input_UTF8, etk::Vector& _output_Unicode) +int32_t unicode::convertUtf8ToUnicode(const std::vector& _input_UTF8, std::vector& _output_Unicode) { char tmpData[20]; int32_t pos = 0; @@ -270,14 +272,12 @@ int32_t unicode::convertUtf8ToUnicode(const etk::Vector& _input_UTF8, et tmpData[0] = '\0'; pos += 1; } - etk::UChar tmpUnicode; - tmpUnicode.setUtf8(tmpData); - _output_Unicode.pushBack(tmpUnicode); + _output_Unicode.push_back(etk::setUtf8(tmpData)); } return 0; } -int32_t unicode::convertUtf8ToUnicode(const char * _input_UTF8, etk::Vector& _output_Unicode) +int32_t unicode::convertUtf8ToUnicode(const char * _input_UTF8, std::vector& _output_Unicode) { char tmpData[20]; int32_t pos = 0; @@ -325,9 +325,7 @@ int32_t unicode::convertUtf8ToUnicode(const char * _input_UTF8, etk::Vector UTF-8 void unicode::convertIsoToUtf8(enum charset _inputCharset, const char _input_ISO, char * _output_UTF8) { - etk::UChar tmpUnicode; + /* + char32_t tmpUnicode; // concert Iso in UniCode convertIsoToUnicode(_inputCharset, _input_ISO, tmpUnicode ); // convert UniCode in Utf-8 tmpUnicode.getUtf8(_output_UTF8); + */ } void unicode::convertUtf8ToIso(enum charset _inputCharset, const char * _input_UTF8, char & _output_ISO) { - etk::UChar tmpUnicode; + /* + char32_t tmpUnicode; // convert Utf-8 in UniCode tmpUnicode.setUtf8(_input_UTF8); // concert UniCode in Iso convertUnicodeToIso(_inputCharset, tmpUnicode, _output_ISO); + */ } -int32_t unicode::convertIsoToUtf8(enum charset _inputCharset, const etk::Vector& _input_ISO, etk::Vector& _output_UTF8) +int32_t unicode::convertIsoToUtf8(enum charset _inputCharset, const std::vector& _input_ISO, std::vector& _output_UTF8) { TK_WARNING("TODO : not coded..."); return 0; } -int32_t unicode::convertUtf8ToIso(enum charset _inputCharset, const etk::Vector& _input_UTF8, etk::Vector& _output_ISO) +int32_t unicode::convertUtf8ToIso(enum charset _inputCharset, const std::vector& _input_UTF8, std::vector& _output_ISO) { TK_WARNING("TODO : not coded..."); return 0; diff --git a/etk/unicode.h b/etk/unicode.h index 0d3199a..549cea9 100644 --- a/etk/unicode.h +++ b/etk/unicode.h @@ -10,7 +10,7 @@ #define __UNICODE_H__ #include -#include +#include namespace unicode { enum charset { @@ -32,23 +32,23 @@ namespace unicode { }; // transform ISO <==> Unicode - void convertIsoToUnicode(enum charset _inputCharset, const char _input_ISO, etk::UChar & _output_Unicode); - void convertUnicodeToIso(enum charset _inputCharset, const etk::UChar _input_Unicode, char & _output_ISO); - int32_t convertIsoToUnicode(enum charset _inputCharset, const etk::Vector& _input_ISO, etk::Vector& _output_Unicode); - int32_t convertIsoToUnicode(enum charset _inputCharset, const etk::Vector& _input_ISO, etk::Vector& _output_Unicode); - int32_t convertUnicodeToIso(enum charset _inputCharset, const etk::Vector& _input_Unicode, etk::Vector& _output_ISO); - int32_t convertUnicodeToIso(enum charset _inputCharset, const etk::Vector& _input_Unicode, etk::Vector& _output_ISO); + void convertIsoToUnicode(enum charset _inputCharset, const char _input_ISO, char32_t & _output_Unicode); + void convertUnicodeToIso(enum charset _inputCharset, const char32_t _input_Unicode, char & _output_ISO); + int32_t convertIsoToUnicode(enum charset _inputCharset, const std::vector& _input_ISO, std::vector& _output_Unicode); + int32_t convertIsoToUnicode(enum charset _inputCharset, const std::vector& _input_ISO, std::vector& _output_Unicode); + int32_t convertUnicodeToIso(enum charset _inputCharset, const std::vector& _input_Unicode, std::vector& _output_ISO); + int32_t convertUnicodeToIso(enum charset _inputCharset, const std::vector& _input_Unicode, std::vector& _output_ISO); // Transform UTF-8 <==> Unicode - int32_t convertUnicodeToUtf8( const etk::Vector& _input_Unicode, etk::Vector& _output_UTF8); - int32_t convertUnicodeToUtf8( const etk::Vector& _input_Unicode, etk::Vector& _output_UTF8); - int32_t convertUtf8ToUnicode( const etk::Vector& _input_UTF8, etk::Vector& _output_Unicode); - int32_t convertUtf8ToUnicode( const etk::Vector& _input_UTF8, etk::Vector& _output_Unicode); - int32_t convertUtf8ToUnicode( const char * _input_UTF8, etk::Vector& _output_Unicode); + int32_t convertUnicodeToUtf8( const std::vector& _input_Unicode, std::vector& _output_UTF8); + int32_t convertUnicodeToUtf8( const std::vector& _input_Unicode, std::vector& _output_UTF8); + int32_t convertUtf8ToUnicode( const std::vector& _input_UTF8, std::vector& _output_Unicode); + int32_t convertUtf8ToUnicode( const std::vector& _input_UTF8, std::vector& _output_Unicode); + int32_t convertUtf8ToUnicode( const char * _input_UTF8, std::vector& _output_Unicode); // Transform ISO <==> UTF-8 void convertIsoToUtf8( enum charset _inputCharset, const char _input_ISO, char * _output_UTF8); void convertUtf8ToIso( enum charset _inputCharset, const char * _input_UTF8, char & _output_ISO); - int32_t convertIsoToUtf8( enum charset _inputCharset, const etk::Vector& _input_ISO, etk::Vector& _output_UTF8); - int32_t convertUtf8ToIso( enum charset _inputCharset, const etk::Vector& _input_UTF8, etk::Vector& _output_ISO); + int32_t convertIsoToUtf8( enum charset _inputCharset, const std::vector& _input_ISO, std::vector& _output_UTF8); + int32_t convertUtf8ToIso( enum charset _inputCharset, const std::vector& _input_UTF8, std::vector& _output_ISO); void utf8_SizeElement(const char * _data, int32_t _lenMax , uint8_t &_size, bool &_baseValid); int32_t strUtf8Len(const char *_input_UTF8); diff --git a/test/main.cpp b/test/main.cpp index 5bf1be6..d1b19f8 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -7,8 +7,8 @@ */ #include -#include -#include +#include +#include #include #include #include @@ -16,33 +16,30 @@ #undef __class__ #define __class__ "etktest" -void testVector(void) -{ +void testVector(void) { } -void testUChar(void) -{ +void testUChar(void) { } -void testUString(void) -{ +void testUString(void) { for(int32_t iii=0; iii<64; iii++) { int64_t kkk=((int64_t)1)< Start test of Hach table"); - etk::Hash testData; + etk::Hash testData; testData.add("TEST", "testData"); testData.add("TEST", "testData333"); testData.add("TEST2", "22222222222222222"); @@ -74,10 +70,9 @@ void testHash(void) TK_INFO("==> End test of Hach table"); } -void testFSNode(void) -{ +void testFSNode(void) { TK_INFO("==> Start test of FSNode"); - etk::UString fileName("USERDATA:myFileTest.txt"); + std::u32string fileName("USERDATA:myFileTest.txt"); etk::FSNode myNodeTest1(fileName); TK_INFO("********************************************"); TK_INFO("** Filename=\"" << fileName << "\""); @@ -116,8 +111,7 @@ void testFSNode(void) } -void testArchive(void) -{ +void testArchive(void) { TK_INFO("==> Start test of archive"); etk::Archive* tmpArchive = etk::Archive::load("testzip.zip"); tmpArchive->display(); @@ -126,8 +120,7 @@ void testArchive(void) } /* -void testDimension(void) -{ +void testDimension(void) { TK_INFO("==> test of Dimension (START)"); ewol::Dimension myDimention(vec2(5,5), ewol::Dimension::Centimeter); @@ -145,10 +138,9 @@ void testDimension(void) exit(0); } */ -int main(int argc, const char *argv[]) -{ +int main(int argc, const char *argv[]) { // the only one init for etk: - debug::setGeneralLevel(etk::LOG_LEVEL_VERBOSE); + debug::setGeneralLevel(etk::logLevelVerbose); //testVector(); //testUChar(); //testUString();