[DEV] integarate std x11

This commit is contained in:
Edouard DUPIN 2013-11-11 20:16:55 +01:00
parent 51606313ab
commit b83c99e371
36 changed files with 1649 additions and 2070 deletions

View File

@ -211,18 +211,18 @@ namespace etk
* @param[in] _nbElement Number of element needed.
* @return The data requested
*/
etk::Vector<int8_t> get(int32_t _pos, int32_t _nbElement) {
etk::Vector<int8_t> tmpBuffer;
std::vector<int8_t> get(int32_t _pos, int32_t _nbElement) {
std::vector<int8_t> 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<int8_t>& _items) {
void insert(int32_t _pos, std::vector<int8_t>& _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<int8_t>& _items) {
void replace(int32_t _pos, int32_t _nbRemoveElement, std::vector<int8_t>& _items) {
replace(_pos, _nbRemoveElement, _items.dataPointer(), _items.size());
}
/**

View File

@ -6,45 +6,4 @@
* @license BSD v3 (see license file)
*/
#include <etk/Char.h>
#include <etk/debug.h>
#include <etk/Stream.h>
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<char>& _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;
}

View File

@ -9,24 +9,6 @@
#ifndef __ETK_CHAR_H__
#define __ETK_CHAR_H__
#include <etk/Vector.h>
namespace etk
{
class Char
{
private:
etk::Vector<char> m_data;
public:
Char(void);
~Char(void);
operator const char *();
operator void *();
void setValue(const etk::Vector<char>& _data);
int64_t size(void);
};
};
#endif

View File

@ -10,9 +10,10 @@
#include <etk/tool.h>
#include <etk/Color.h>
#include <etk/debug.h>
#include <string>
#include <sstream>
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<uint8_t>::set(float _r, float _g, float _b, float _a)
{
namespace etk {
template<> void Color<uint8_t>::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<float>::set(float _r, float _g, float _b, float _a)
{
template<> void Color<float>::set(float _r, float _g, float _b, float _a) {
m_r = _r;
m_g = _g;
m_b = _b;
m_a = _a;
}
template<> void Color<uint8_t>::set(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a)
{
template<> void Color<uint8_t>::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<float>::set(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a)
{
template<> void Color<float>::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<uint8_t>::get(void) const
{
template<> uint32_t Color<uint8_t>::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<float>::get(void) const
{
template<> uint32_t Color<float>::get(void) const {
return Color<uint8_t>(*this).get();
}
template<> Color<uint8_t>::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<uint8_t>::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<getColorSize(); iii++) {
if (strnCmpNoCase(getColorList()[iii].colorName, inputData, strlen(getColorList()[iii].colorName)) == true) {
if (strnCmpNoCase(getColorList()[iii].colorName, tmputf8string.c_str(), strlen(getColorList()[iii].colorName)) == true) {
findIt = true;
*this = getColorList()[iii].color;
// stop searching
@ -190,13 +186,13 @@ namespace etk
}
// not find color ...
if (findIt == false) {
TK_ERROR(" pb in parsing the color : \"" << inputData << "\" not find ...");
TK_ERROR(" pb in parsing the color : \"" << _input << "\" not find ...");
}
}
TK_VERBOSE("Parse color : \"" << inputData << "\" ==> " << *this);
TK_VERBOSE("Parse color : \"" << _input << "\" ==> " << *this);
}
template<> Color<float>::Color(const etk::UString& _input)
template<> Color<float>::Color(std::u32string _input)
{
etk::Color<uint8_t> tmpColor(_input);
*this = tmpColor;

View File

@ -34,7 +34,7 @@ namespace etk {
};
Color(const etk::Color<float>& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); };
Color(const etk::Color<uint8_t>& _obj) { set(_obj.r(), _obj.g(), _obj.b(), _obj.a()); };
Color(const etk::UString& _input);
Color(std::u32string _input);
~Color(void) { };
Color<MY_TYPE>& operator=(const etk::Color<MY_TYPE>& _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<uint32_t>(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<uint32_t>(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<uint8_t>& _obj);
etk::CCout& operator <<(etk::CCout &_os, const Color<float>& _obj);

View File

@ -11,7 +11,7 @@
#include <etk/types.h>
#include <etk/debug.h>
#include <etk/Vector.h>
#include <vector>
#include <etk/UString.h>
#undef __class__
@ -21,9 +21,9 @@
namespace etk {
template<class MY_TYPE> 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 MY_TYPE> class Hash {
private:
etk::Vector<HashData<MY_TYPE>* > 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<HashData<MY_TYPE>* > 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; iii<m_data.size(); iii++) {
if (m_data[iii] != NULL) {
//TK_INFO("Compare key : '" << m_data[iii]->m_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<MY_TYPE>* tmp = new HashData<MY_TYPE>(_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()){

View File

@ -11,7 +11,7 @@
#include <etk/os/Mutex.h>
#include <etk/os/Semaphore.h>
#include <etk/Vector.h>
#include <vector>
namespace etk
{
@ -20,7 +20,7 @@ namespace etk
private :
etk::Mutex m_mutex;
etk::Semaphore m_semaphore;
etk::Vector<MY_TYPE> m_data;
std::vector<MY_TYPE> 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();
};

View File

@ -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_size.x()*m_size.y(); iii++) {
m_data[iii] = etk::tool::frand(_min, _max);
@ -98,7 +98,7 @@ etk::Noise::Noise(enum noise _type, ivec2 _size, int32_t _depth) :
m_size(_size),
m_type(_type)
{
m_data.reSize(_size.x()*_size.y(), 0);
m_data.resize(_size.x()*_size.y(), 0);
switch(m_type) {
default:
case etk::Noise::NOISE_BASE:

View File

@ -17,7 +17,7 @@ namespace etk {
class BaseNoise
{
private:
etk::Vector<float> m_data;
std::vector<float> m_data;
ivec2 m_size;
public:
BaseNoise(ivec2 _size, float _min, float _max);
@ -37,7 +37,7 @@ namespace etk {
NOISE_WOOD
};
private:
etk::Vector<float> m_data;
std::vector<float> m_data;
ivec2 m_size;
enum noise m_type;
float smoothNoise(float _x, float _y, const etk::BaseNoise& _noise);

View File

@ -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<etk::UChar>& _data, esize_t _start, esize_t _stop)
{
void etk::displayElem(const std::vector<char32_t>& _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<<ETK_BASH_COLOR_RED << (char*)"(" << ETK_BASH_COLOR_NORMAL; break;
case REGEXP_OPCODE_PTHESE_OUT: etk::cout<<ETK_BASH_COLOR_RED << (char*)")" << ETK_BASH_COLOR_NORMAL; break;
@ -99,8 +98,8 @@ void etk::displayElem(const etk::Vector<etk::UChar>& _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<etk::UChar>& _data, esize_t _startPos)
{
esize_t etk::getLenOfPTheseElem(const std::vector<char32_t>& _data, esize_t _startPos) {
if (_startPos>=_data.size()){
return 0;
}
@ -166,8 +164,7 @@ esize_t etk::getLenOfPTheseElem(const etk::Vector<etk::UChar>& _data, esize_t _s
return pos - _startPos;
}
esize_t etk::getLenOfPThese(const etk::Vector<etk::UChar>& _data, esize_t _startPos)
{
esize_t etk::getLenOfPThese(const std::vector<char32_t>& _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<etk::UChar>& _data, esize_t _start
}
esize_t etk::getLenOfBracket(const etk::Vector<etk::UChar>& _data, esize_t _startPos)
{
esize_t etk::getLenOfBracket(const std::vector<char32_t>& _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<etk::UChar>& _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<etk::UChar>& _data, esize_t _star
}
esize_t etk::getLenOfBrace(const etk::Vector<etk::UChar>& _data, esize_t _startPos)
{
esize_t etk::getLenOfBrace(const std::vector<char32_t>& _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<etk::UChar>& _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<etk::UChar>& _data, esize_t _startP
}
esize_t etk::getLenOfNormal(const etk::Vector<etk::UChar>& _data, esize_t _startPos)
{
esize_t etk::getLenOfNormal(const std::vector<char32_t>& _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<etk::UChar>& _data, esize_t _start
}
bool etk::parseBrace(const etk::Vector<etk::UChar>& _data, uint32_t& _min, uint32_t& _max)
bool etk::parseBrace(const std::vector<char32_t>& _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<etk::UChar>& _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;

View File

@ -12,7 +12,7 @@
#include <etk/types.h>
#include <etk/debug.h>
#include <etk/UString.h>
#include <etk/Vector.h>
#include <vector>
#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<etk::UChar>& _data, esize_t _start=0, esize_t _stop=0x7FFFFFFF);
void displayElem(const std::vector<char32_t>& _data, esize_t _start=0, esize_t _stop=0x7FFFFFFF);
char * levelSpace(uint32_t _level);
esize_t getLenOfPTheseElem(const etk::Vector<etk::UChar>& _data, esize_t _startPos);
esize_t getLenOfPThese(const etk::Vector<etk::UChar>& _data, esize_t _startPos);
esize_t getLenOfBracket(const etk::Vector<etk::UChar>& _data, esize_t _startPos);
esize_t getLenOfBrace(const etk::Vector<etk::UChar>& _data, esize_t _startPos);
esize_t getLenOfNormal(const etk::Vector<etk::UChar>& _data, esize_t _startPos);
bool parseBrace(const etk::Vector<etk::UChar>& _data, uint32_t& _min, uint32_t& _max);
esize_t getLenOfPTheseElem(const std::vector<char32_t>& _data, esize_t _startPos);
esize_t getLenOfPThese(const std::vector<char32_t>& _data, esize_t _startPos);
esize_t getLenOfBracket(const std::vector<char32_t>& _data, esize_t _startPos);
esize_t getLenOfBrace(const std::vector<char32_t>& _data, esize_t _startPos);
esize_t getLenOfNormal(const std::vector<char32_t>& _data, esize_t _startPos);
bool parseBrace(const std::vector<char32_t>& _data, uint32_t& _min, uint32_t& _max);
#undef __class__
@ -78,7 +78,7 @@ template<class CLASS_TYPE> class RegExpNode
uint32_t m_multipleMin; //!< minimum repetition (included)
uint32_t m_multipleMax; //!< maximum repetition (included)
// Data Section ... (can have no data...)
etk::Vector<etk::UChar> m_RegExpData; //!< data to parse and compare in some case ...
std::vector<char32_t> m_RegExpData; //!< data to parse and compare in some case ...
public :
/**
* @brief Constructor
@ -98,7 +98,7 @@ template<class CLASS_TYPE> class RegExpNode
* @param[in] _data Property of the regexp
* @return the number of element used
*/
virtual int32_t generate(const etk::Vector<etk::UChar>& _data)
virtual int32_t generate(const std::vector<char32_t>& _data)
{
return 0;
};
@ -151,7 +151,7 @@ template<class CLASS_TYPE> class RegExpNodeValue : public RegExpNode<CLASS_TYPE>
{
protected :
// SubNodes :
etk::Vector<etk::UChar> m_data;
std::vector<char32_t> m_data;
public :
/**
@ -164,13 +164,13 @@ template<class CLASS_TYPE> class RegExpNodeValue : public RegExpNode<CLASS_TYPE>
*/
~RegExpNodeValue(void) { };
int32_t generate(const etk::Vector<etk::UChar>& _data)
int32_t generate(const std::vector<char32_t>& _data)
{
RegExpNode<CLASS_TYPE>::m_RegExpData = _data;
TK_REG_EXP_DBG_MODE("Request Parse \"Value\" data="; displayElem(RegExpNode<CLASS_TYPE>::m_RegExpData););
m_data.clear();
for (int32_t i=0; i<RegExpNode<CLASS_TYPE>::m_RegExpData.size(); i++) {
m_data.pushBack(RegExpNode<CLASS_TYPE>::m_RegExpData[i]);
m_data.push_back(RegExpNode<CLASS_TYPE>::m_RegExpData[i]);
}
return _data.size();
};
@ -234,7 +234,7 @@ template<class CLASS_TYPE> class RegExpNodeBracket : public RegExpNode<CLASS_TYP
{
protected :
// SubNodes :
etk::Vector<etk::UChar> m_data;
std::vector<char32_t> m_data;
public :
/**
@ -247,13 +247,13 @@ template<class CLASS_TYPE> class RegExpNodeBracket : public RegExpNode<CLASS_TYP
*/
~RegExpNodeBracket(void) { };
int32_t generate(const etk::Vector<etk::UChar>& _data)
int32_t generate(const std::vector<char32_t>& _data)
{
RegExpNode<CLASS_TYPE>::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<RegExpNode<CLASS_TYPE>::m_RegExpData.size(); kkk++) {
@ -261,16 +261,16 @@ template<class CLASS_TYPE> class RegExpNodeBracket : public RegExpNode<CLASS_TYP
TK_ERROR("Can not have 2 consecutive - in [...]");
return 0;
} else if (multipleElement == true) {
etk::UChar jjj='\0';
char32_t jjj='\0';
for (jjj=lastElement+1; jjj <= RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]; jjj+=1) {
m_data.pushBack(jjj);
m_data.push_back(jjj);
}
multipleElement = false;
} else if(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk] == REGEXP_OPCODE_TO) {
multipleElement = true;
} else {
lastElement = RegExpNode<CLASS_TYPE>::m_RegExpData[kkk];
m_data.pushBack(lastElement);
m_data.push_back(lastElement);
}
}
// check size ...
@ -347,7 +347,7 @@ template<class CLASS_TYPE> class RegExpNodeDigit : public RegExpNode<CLASS_TYPE>
bool tmpFind = true;
uint32_t jjj;
for (jjj=0; jjj<RegExpNode<CLASS_TYPE>::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 CLASS_TYPE> class RegExpNodeDigitNot : public RegExpNode<CLASS_TY
bool tmpFind = true;
uint32_t jjj;
for (jjj=0; jjj<RegExpNode<CLASS_TYPE>::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 CLASS_TYPE> class RegExpNodeLetter : public RegExpNode<CLASS_TYPE
bool tmpFind = true;
uint32_t jjj;
for (jjj=0; jjj<RegExpNode<CLASS_TYPE>::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 CLASS_TYPE> class RegExpNodeLetterNot : public RegExpNode<CLASS_T
bool tmpFind = true;
uint32_t jjj;
for (jjj=0; jjj<RegExpNode<CLASS_TYPE>::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 CLASS_TYPE> class RegExpNodeWhiteSpace : public RegExpNode<CLASS_
bool tmpFind = true;
uint32_t jjj;
for (jjj=0; jjj<RegExpNode<CLASS_TYPE>::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 CLASS_TYPE> class RegExpNodeWhiteSpaceNot : public RegExpNode<CLA
bool tmpFind = true;
uint32_t jjj;
for (jjj=0; jjj<RegExpNode<CLASS_TYPE>::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 CLASS_TYPE> class RegExpNodeWordChar : public RegExpNode<CLASS_TY
bool tmpFind = true;
uint32_t jjj;
for (jjj=0; jjj<RegExpNode<CLASS_TYPE>::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 CLASS_TYPE> class RegExpNodeWordCharNot : public RegExpNode<CLASS
bool tmpFind = true;
uint32_t jjj;
for (jjj=0; jjj<RegExpNode<CLASS_TYPE>::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 CLASS_TYPE> class RegExpNodeDot : public RegExpNode<CLASS_TYPE>
bool tmpFind = true;
uint32_t jjj;
for (jjj=0; jjj<RegExpNode<CLASS_TYPE>::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 CLASS_TYPE> class RegExpNodePTheseElem : public RegExpNode<CLASS_
{
protected :
// SubNodes :
etk::Vector<RegExpNode<CLASS_TYPE>*> m_subNode;
std::vector<RegExpNode<CLASS_TYPE>*> m_subNode;
public :
/**
* @brief Constructor
@ -908,13 +908,13 @@ template<class CLASS_TYPE> class RegExpNodePTheseElem : public RegExpNode<CLASS_
*/
~RegExpNodePTheseElem(void) { };
int32_t generate(const etk::Vector<etk::UChar>& _data)
int32_t generate(const std::vector<char32_t>& _data)
{
RegExpNode<CLASS_TYPE>::m_RegExpData = _data;
TK_REG_EXP_DBG_MODE("Request Parse (elem) data="; displayElem(RegExpNode<CLASS_TYPE>::m_RegExpData););
esize_t pos = 0;
esize_t elementSize = 0;
etk::Vector<etk::UChar> tmpData;
std::vector<char32_t> tmpData;
while (pos < RegExpNode<CLASS_TYPE>::m_RegExpData.size()) {
tmpData.clear();
switch (RegExpNode<CLASS_TYPE>::m_RegExpData[pos].get()) {
@ -922,12 +922,12 @@ template<class CLASS_TYPE> class RegExpNodePTheseElem : public RegExpNode<CLASS_
{
elementSize=getLenOfPThese(RegExpNode<CLASS_TYPE>::m_RegExpData, pos);
for (esize_t kkk=pos+1; kkk<pos+elementSize+1; kkk++) {
tmpData.pushBack(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
tmpData.push_back(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
}
RegExpNodePThese<CLASS_TYPE> * myElem = new RegExpNodePThese<CLASS_TYPE>();
(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 CLASS_TYPE> class RegExpNodePTheseElem : public RegExpNode<CLASS_
{
elementSize=getLenOfBracket(RegExpNode<CLASS_TYPE>::m_RegExpData, pos);
for (esize_t kkk=pos+1; kkk<pos+elementSize+1; kkk++) {
tmpData.pushBack(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
tmpData.push_back(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
}
RegExpNodeBracket<CLASS_TYPE> * myElem = new RegExpNodeBracket<CLASS_TYPE>();
(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 CLASS_TYPE> class RegExpNodePTheseElem : public RegExpNode<CLASS_
{
elementSize=getLenOfBrace(RegExpNode<CLASS_TYPE>::m_RegExpData, pos);
for (esize_t kkk=pos+1; kkk<pos+elementSize+1; kkk++) {
tmpData.pushBack(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
tmpData.push_back(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
}
uint32_t min = 0;
uint32_t max = 0;
@ -986,49 +986,49 @@ template<class CLASS_TYPE> class RegExpNodePTheseElem : public RegExpNode<CLASS_
TK_ERROR("Impossible case : '|' " << pos);
return false;
case REGEXP_OPCODE_DOT:
m_subNode.pushBack(new RegExpNodeDot<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeDot<CLASS_TYPE>());
break;
case REGEXP_OPCODE_START_OF_LINE:
m_subNode.pushBack(new RegExpNodeSOL<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeSOL<CLASS_TYPE>());
break;
case REGEXP_OPCODE_END_OF_LINE:
m_subNode.pushBack(new RegExpNodeEOL<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeEOL<CLASS_TYPE>());
break;
case REGEXP_OPCODE_DIGIT:
m_subNode.pushBack(new RegExpNodeDigit<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeDigit<CLASS_TYPE>());
break;
case REGEXP_OPCODE_DIGIT_NOT:
m_subNode.pushBack(new RegExpNodeDigitNot<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeDigitNot<CLASS_TYPE>());
break;
case REGEXP_OPCODE_LETTER:
m_subNode.pushBack(new RegExpNodeLetter<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeLetter<CLASS_TYPE>());
break;
case REGEXP_OPCODE_LETTER_NOT:
m_subNode.pushBack(new RegExpNodeLetterNot<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeLetterNot<CLASS_TYPE>());
break;
case REGEXP_OPCODE_SPACE:
m_subNode.pushBack(new RegExpNodeWhiteSpace<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeWhiteSpace<CLASS_TYPE>());
break;
case REGEXP_OPCODE_SPACE_NOT:
m_subNode.pushBack(new RegExpNodeWhiteSpaceNot<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeWhiteSpaceNot<CLASS_TYPE>());
break;
case REGEXP_OPCODE_WORD:
m_subNode.pushBack(new RegExpNodeWordChar<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeWordChar<CLASS_TYPE>());
break;
case REGEXP_OPCODE_WORD_NOT:
m_subNode.pushBack(new RegExpNodeWordCharNot<CLASS_TYPE>());
m_subNode.push_back(new RegExpNodeWordCharNot<CLASS_TYPE>());
break;
default:
{
elementSize = getLenOfNormal(RegExpNode<CLASS_TYPE>::m_RegExpData, pos);
for (esize_t kkk=pos; kkk<pos+elementSize; kkk++) {
tmpData.pushBack(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
tmpData.push_back(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
}
RegExpNodeValue<CLASS_TYPE> * myElem = new RegExpNodeValue<CLASS_TYPE>();
(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 CLASS_TYPE> class RegExpNodePTheseElem : public RegExpNode<CLASS_
template<class CLASS_TYPE> class RegExpNodePThese : public RegExpNode<CLASS_TYPE>
{
protected :
etk::Vector<RegExpNode<CLASS_TYPE>*> m_subNode; //!< Subnode list
std::vector<RegExpNode<CLASS_TYPE>*> m_subNode; //!< Subnode list
public :
/**
* @brief Constructor
@ -1123,7 +1123,7 @@ template<class CLASS_TYPE> class RegExpNodePThese : public RegExpNode<CLASS_TYPE
};
int32_t generate(const etk::Vector<etk::UChar>& _data)
int32_t generate(const std::vector<char32_t>& _data)
{
RegExpNode<CLASS_TYPE>::m_RegExpData = _data;
TK_REG_EXP_DBG_MODE("Request Parse (...) data="; displayElem(RegExpNode<CLASS_TYPE>::m_RegExpData););
@ -1133,14 +1133,14 @@ template<class CLASS_TYPE> class RegExpNodePThese : public RegExpNode<CLASS_TYPE
// generate all the "elemTypePTheseElem" of the Node
while (elementSize>0) {
// geerate output deta ...
etk::Vector<etk::UChar> tmpData;
std::vector<char32_t> tmpData;
for (esize_t kkk=pos; kkk<pos+elementSize; kkk++) {
tmpData.pushBack(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
tmpData.push_back(RegExpNode<CLASS_TYPE>::m_RegExpData[kkk]);
}
RegExpNodePTheseElem<CLASS_TYPE> * myElem = new RegExpNodePTheseElem<CLASS_TYPE>();
(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<CLASS_TYPE>::m_RegExpData, pos);
@ -1207,7 +1207,7 @@ template<class CLASS_TYPE> class RegExpNodePThese : public RegExpNode<CLASS_TYPE
template<class CLASS_TYPE> 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<CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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<etk::UChar> tmpExp;
std::vector<char32_t> tmpExp;
TK_REG_EXP_DBG_MODE("---------------------------------------------------------------------");
TK_REG_EXP_DBG_MODE("Parse RegExp : (" << _regexp << ")" );
@ -1279,9 +1279,9 @@ template<class CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> 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 CLASS_TYPE> class RegExp
* @param[in,out]
* @return
*/
bool checkGoodPosition(const etk::Vector<etk::UChar>& _tmpExp, esize_t& _pos)
bool checkGoodPosition(const std::vector<char32_t>& _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 CLASS_TYPE> 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 CLASS_TYPE> class RegExp
* @param[in,out]
* @return
*/
bool checkGoodPosition(const etk::Vector<etk::UChar>& _tmpExp)
bool checkGoodPosition(const std::vector<char32_t>& _tmpExp)
{
esize_t pos = 0;
while (pos < _tmpExp.size()) {

View File

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

View File

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

View File

@ -12,150 +12,104 @@
#include <etk/debug.h>
#include <etk/Stream.h>
#include <etk/Vector.h>
#include <vector>
#include <etk/Char.h>
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<int8_t> etk::UChar::GetUtf8(void) const
uint8_t sizeElement(const char* _data, int32_t _lenMax)
{
etk::Vector<int8_t> 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<int8_t> char32_t::GetUtf8(void) const
{
std::vector<int8_t> 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

View File

@ -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<int8_t> GetUtf8(void) const;
//std::vector<int8_t> 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

File diff suppressed because it is too large Load Diff

View File

@ -10,11 +10,24 @@
#define __ETK_USTRING_H__
#include <etk/debug.h>
#include <etk/Vector.h>
#include <etk/Char.h>
#include <etk/unicode.h>
#include <string>
#include <vector>
#include <sstream>
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<etk::UChar> m_data; //!< internal data is stored in the Unicode properties ...
std::vector<char32_t> 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<char>& _inputData);
UString(const etk::Vector<int8_t>& _inputData);
UString(const etk::Vector<etk::UChar>& _inputData);
UString(const std::vector<char>& _inputData);
UString(const std::vector<int8_t>& _inputData);
UString(const std::vector<char32_t>& _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<char>& _inputData);
void set(const etk::Vector<int8_t>& _inputData);
void set(const etk::Vector<etk::UChar>& _inputData);
void set(const std::vector<char>& _inputData);
void set(const std::vector<int8_t>& _inputData);
void set(const std::vector<char32_t>& _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<etk::UString> split(const etk::UChar& _val);
std::vector<std::string> 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<etk::UChar> getVector(void);
etk::UChar* pointer(void) { return &m_data[0]; };
std::vector<char32_t> 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<etk::UString>& _obj);
etk::CCout& operator <<(etk::CCout& _os, const std::u32string& _obj);
etk::CCout& operator <<(etk::CCout& _os, const std::vector<std::u32string>& _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<class T> 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<class T> 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

View File

@ -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 <etk/types.h>
#include <etk/debug.h>
#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 MY_TYPE=int32_t> class Vector
{
public:
class Iterator {
// Private data :
private:
esize_t m_current; //!< curent Id on the vector
Vector<MY_TYPE>* 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<MY_TYPE> * _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<MY_TYPE>& _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<m_allocated; iii++) {
// copy operator ...
m_data[iii] = _obj.m_data[iii];
}
}
/**
* @brief Destructor of the current Class
*/
~Vector(void) {
if (NULL!=m_data) {
delete [] m_data;
m_data = NULL;
}
m_allocated = 0;
m_size = 0;
}
/**
* @brief Swap the data of 2 Vectors
* @param[in] _obj second vector to swap data.
*/
void swap(etk::Vector<MY_TYPE>& _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<MY_TYPE> & _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<m_allocated; iii++) {
// copy operator ...
m_data[iii] = _obj.m_data[iii];
}
}
// Return the curent pointer
return *this;
}
/**
* @brief Add at the Last position of the Vector
* @param[in] _obj Element to add at the end of vector
*/
Vector& operator+= (const etk::Vector<MY_TYPE> & _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<nbElememt; iii++) {
// copy operator ...
m_data[idx+iii] = _obj.m_data[iii];
}
// Return the curent pointer
return *this;
}
/**
* @brief Get the number of element in the vector
* @return The number requested
*/
esize_t size(void) const {
return m_size;
}
/**
* @brief Get the number of element in the vector
* @return The number requested
*/
void reSize(esize_t _newSize, const MY_TYPE& _basicElement) {
esize_t idx = m_size;
resize(_newSize);
if (m_size != _newSize) {
TK_CRITICAL("error to resize vector");
return;
}
if (_newSize > 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; iii<sizeToMove; iii++) {
m_data[_pos+iii] = m_data[_pos+_nbElement+iii];
}
}
// Request resize of the current buffer
resize(m_size-_nbElement);
}
/**
* @brief Remove one element
* @param[in] _pos Position to remove the data
*/
inline void erase(esize_t _pos) {
eraseLen(_pos, 1);
}
/**
* @brief Remove one element
* @param[in] _pos Position to remove the data
*/
inline void remove(esize_t _pos) {
eraseLen(_pos, 1);
}
/**
* @brief Remove N elements
* @param[in] _pos Position to remove the data
* @param[in] _posEnd Last position number
*/
void erase(esize_t _pos, esize_t _posEnd) {
if (_pos>m_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<sizeToMove; iii++) {
m_data[_pos+iii] = m_data[_pos+nbElement+iii];
}
}
// Request resize of the current buffer
resize(m_size-nbElement);
}
/**
* @brief extract data between two point :
* @param[in] _posStart start position to extract data
* @param[in] _posEnd End position to extract data
* @return the extracted vector
*/
Vector<MY_TYPE> extract(esize_t _posStart = 0, esize_t _posEnd=0x7FFFFFFF) const {
Vector<MY_TYPE> 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<nbElements; iii++) {
m_dataTmp[iii] = m_data[iii];
}
// switch pointer:
MY_TYPE* m_dataTmp2 = m_data;
m_data = m_dataTmp;
// remove old pool
if (m_dataTmp2!= NULL) {
delete [] m_dataTmp2;
}
}
// set the new allocation size
m_allocated = requestSize;
}
public :
/*****************************************************
* == operator
*****************************************************/
bool operator== (const Vector<MY_TYPE>& _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<m_size; iii++) {
if (m_data[iii]!=_obj.m_data[iii]) {
return false;
}
}
return true;
}
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const Vector<MY_TYPE>& _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<m_size; iii++) {
if (m_data[iii]!=_obj.m_data[iii]) {
return true;
}
}
return false;
}
};
/**
* @brief List classes ...
*
* @tparam[in] T The type of objects to store.
*
* m_data
* ---------- |-----------------------|
* | 0 |-------->| Class Data |
* |--------| |-----------------------|
* | 1 |----|
* |--------| |
* | 2 |====|==============| |-----------------------|
* |--------| | --->| Class Data |
* m_count | 3 |-| | |-----------------------|
* |--------| | |
* | x | | | |-----------------------|
* |--------| | -------->| Class Data |
* | x | | |-----------------------|
* |--------| |
* | x | |
* |--------| | |-----------------------|
* | x | --------------------->| Class Data |
* |--------| |-----------------------|
* | x |
* |--------|
* | x |
* |--------|
* m_size | x |
* ----------
*
*/
/*
template<class MY_CLASS> class List
{
};
*/
}
#undef __class__
#define __class__ NULL
#endif

View File

@ -10,8 +10,7 @@
#include <etk/archive/Zip.h>
#include <etk/debug.h>
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;

View File

@ -10,7 +10,7 @@
#define __ETK_ARCHIVE_H__
#include <etk/UString.h>
#include <etk/Vector.h>
#include <vector>
#include <etk/Hash.h>
namespace etk
@ -31,24 +31,24 @@ namespace etk
public:
esize_t getTheoricSize(void) const { return m_theoricSize; };
private:
etk::Vector<char> m_data;
std::vector<char> 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<char>& getDataVector(void) { return m_data; };
std::vector<char>& 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<Content> 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

View File

@ -8,13 +8,14 @@
#include <etk/archive/Zip.h>
#include <etk/debug.h>
#include <etk/UString.h>
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...");

View File

@ -14,17 +14,14 @@ extern "C" {
#include <minizip/unzip.h>
}
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);

View File

@ -11,7 +11,7 @@
#include <etk/types.h>
#include <etk/math/Vector2D.h>
#include <etk/Vector.h>
#include <vector>
namespace etk
{
@ -19,7 +19,7 @@ namespace etk
{
private:
etk::Vector2D<int32_t> m_size;
etk::Vector<T> m_data;
std::vector<T> m_data;
public:
/*****************************************************
* Constructor

View File

@ -10,7 +10,7 @@
#define __ETK_TYPES_PLANE_H__
#include <etk/debug.h>
#include <etk/Vector.h>
#include <vector>
namespace etk {
template <typename T> class Plane {

View File

@ -49,153 +49,145 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector2D<bool>& _obj)
}
namespace etk
{
template<> Vector2D<bool>::operator etk::UString(void) const
{
etk::UString str;
str = "(";
namespace etk {
template<> Vector2D<bool>::operator std::u32string(void) const {
std::u32string str;
str = U"(";
str += x();
str += ",";
str += U",";
str += y();
str += ")";
str += U")";
return str;
}
template<> Vector2D<bool>::Vector2D(const etk::UString& _str)
{
template<> Vector2D<bool>::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<int32_t>::operator etk::UString(void) const
{
etk::UString str;
str = "(";
template<> Vector2D<int32_t>::operator std::u32string(void) const {
std::u32string str;
str = U"(";
str += x();
str += ",";
str += U",";
str += y();
str += ")";
str += U")";
return str;
}
template<> Vector2D<int32_t>::Vector2D(const etk::UString& _str)
{
template<> Vector2D<int32_t>::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<uint32_t>::operator etk::UString(void) const
{
etk::UString str;
str = "(";
template<> Vector2D<uint32_t>::operator std::u32string(void) const {
std::u32string str;
str = U"(";
str += x();
str += ",";
str += U",";
str += y();
str += ")";
str += U")";
return str;
}
template<> Vector2D<uint32_t>::Vector2D(const etk::UString& _str)
template<> Vector2D<uint32_t>::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<float>::operator etk::UString(void) const
{
etk::UString str;
str = "(";
template<> Vector2D<float>::operator std::u32string(void) const {
std::u32string str;
str = U"(";
str += x();
str += ",";
str += U",";
str += y();
str += ")";
str += U")";
return str;
}
template<> Vector2D<float>::Vector2D(const etk::UString& _str)
{
template<> Vector2D<float>::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);
}

View File

@ -42,7 +42,7 @@ namespace etk
Vector2D(const Vector2D<double>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); };
Vector2D(const Vector2D<float>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); };
Vector2D(const Vector2D<int32_t>& 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

File diff suppressed because it is too large Load Diff

View File

@ -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<etk::FSNode*> folderGetSubList(bool _showHidenFile=true,
bool _getFolderAndOther=true,
bool _getFile=true,
bool _temporaryFile=true);
std::vector<etk::FSNode*> 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<etk::UString>& _output, bool _recursiveEnable=true);
void folderGetRecursiveFiles(std::vector<std::u32string>& _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<etk::FSNode *>& _list);
void sortElementList(std::vector<etk::FSNode *>& _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<etk::UString> list(void);
std::vector<std::u32string> 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

View File

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

View File

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

View File

@ -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<etk::UString *> &_list)
void etk::tool::sortList(std::vector<std::u32string *> &_list)
{
etk::Vector<etk::UString *> tmpList = _list;
std::vector<std::u32string *> tmpList = _list;
_list.clear();
for(int32_t iii=0; iii<tmpList.size(); iii++) {
@ -39,7 +39,7 @@ void etk::tool::sortList(etk::Vector<etk::UString *> &_list)
}
}
//EWOL_DEBUG("position="<<findPos);
_list.insert(findPos, tmpList[iii]);
_list.insert(_list.begin()+findPos, tmpList[iii]);
}
}
@ -69,13 +69,13 @@ bool etk::tool::strnCmpNoCase(const char * _input1, const char * _input2, int32_
}
etk::UString etk::tool::simplifyPath(etk::UString _input)
std::u32string etk::tool::simplifyPath(std::u32string _input)
{
int32_t findStartPos = _input.findForward('/') + 1;
int32_t findPos = _input.findForward('/', findStartPos);
size_t findStartPos = _input.find('/') + 1;
size_t findPos = _input.find('/', findStartPos);
//TK_DEBUG("Siplify : \"" << input << "\"");
int32_t preventBadCode = 0;
while (findPos!=-1)
while (findPos!=0)
{
//TK_DEBUG(" string=\"" << input << "\"");
//TK_DEBUG(" '/' @" << findPos);
@ -87,7 +87,7 @@ etk::UString etk::tool::simplifyPath(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()<findPos+2) {
@ -97,18 +97,18 @@ etk::UString etk::tool::simplifyPath(etk::UString _input)
if( _input[findPos+1] == '.'
&& _input[findPos+2] == '.') {
// cleane the element path
_input.remove(findStartPos, findPos+3 - findStartPos );
_input.erase(findStartPos, findPos+3 - findStartPos );
//TK_DEBUG(" Remove xxx/.. string=\"" << input << "\"");
} else if( _input[findPos+1] == '.'
&& _input[findPos+2] == '/') {
// cleane the element path
_input.remove(findPos+1, 2);
_input.erase(findPos+1, 2);
//TK_DEBUG(" Remove ./ string=\"" << input << "\"");
} else {
findStartPos = findPos+1;
}
}
findPos = _input.findForward('/', findStartPos);
findPos = _input.find('/', findStartPos);
preventBadCode++;
if (preventBadCode>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

View File

@ -11,15 +11,16 @@
#include <etk/types.h>
#include <etk/UString.h>
#include <vector>
namespace etk {
namespace tool {
float frand(float _a, float _b);
int32_t irand(int32_t _a, int32_t _b);
void sortList(etk::Vector<etk::UString *>& _list);
void sortList(std::vector<std::u32string *>& _list);
bool strnCmpNoCase(const char* _input1, const char* _input2, int32_t _maxLen);
etk::UString simplifyPath(etk::UString _input);
std::u32string simplifyPath(std::u32string _input);
};
};

View File

@ -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 <wchar.h>
#include <stdio.h>
#endif
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

View File

@ -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<char>& _input_ISO, etk::Vector<etk::UChar>& _output_Unicode)
int32_t unicode::convertIsoToUnicode(enum charset _inputCharset, const std::vector<char>& _input_ISO, std::vector<char32_t>& _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<int8_t>& _input_ISO, etk::Vector<etk::UChar>& _output_Unicode)
int32_t unicode::convertIsoToUnicode(enum charset _inputCharset, const std::vector<int8_t>& _input_ISO, std::vector<char32_t>& _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<etk::UChar>& _input_Unicode, etk::Vector<char>& _output_ISO)
int32_t unicode::convertUnicodeToIso(enum charset _inputCharset, const std::vector<char32_t>& _input_Unicode, std::vector<char>& _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<etk::UChar>& _input_Unicode, etk::Vector<int8_t>& _output_ISO)
int32_t unicode::convertUnicodeToIso(enum charset _inputCharset, const std::vector<char32_t>& _input_Unicode, std::vector<int8_t>& _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<etk::UChar>& _input_Unicode, etk::Vector<char>& _output_UTF8)
int32_t unicode::convertUnicodeToUtf8(const std::vector<char32_t>& _input_Unicode, std::vector<char>& _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<etk::UChar>& _input_Unicode, etk::Vector<int8_t>& _output_UTF8)
int32_t unicode::convertUnicodeToUtf8(const std::vector<char32_t>& _input_Unicode, std::vector<int8_t>& _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<char>& _input_UTF8, etk::Vector<etk::UChar>& _output_Unicode)
int32_t unicode::convertUtf8ToUnicode(const std::vector<char>& _input_UTF8, std::vector<char32_t>& _output_Unicode)
{
char tmpData[20];
int32_t pos = 0;
@ -219,14 +223,12 @@ int32_t unicode::convertUtf8ToUnicode(const etk::Vector<char>& _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<int8_t>& _input_UTF8, etk::Vector<etk::UChar>& _output_Unicode)
int32_t unicode::convertUtf8ToUnicode(const std::vector<int8_t>& _input_UTF8, std::vector<char32_t>& _output_Unicode)
{
char tmpData[20];
int32_t pos = 0;
@ -270,14 +272,12 @@ int32_t unicode::convertUtf8ToUnicode(const etk::Vector<int8_t>& _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<etk::UChar>& _output_Unicode)
int32_t unicode::convertUtf8ToUnicode(const char * _input_UTF8, std::vector<char32_t>& _output_Unicode)
{
char tmpData[20];
int32_t pos = 0;
@ -325,9 +325,7 @@ int32_t unicode::convertUtf8ToUnicode(const char * _input_UTF8, etk::Vector<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;
}
@ -336,32 +334,36 @@ int32_t unicode::convertUtf8ToUnicode(const char * _input_UTF8, etk::Vector<etk:
// Transform ISO <==> 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<char>& _input_ISO, etk::Vector<char>& _output_UTF8)
int32_t unicode::convertIsoToUtf8(enum charset _inputCharset, const std::vector<char>& _input_ISO, std::vector<char>& _output_UTF8)
{
TK_WARNING("TODO : not coded...");
return 0;
}
int32_t unicode::convertUtf8ToIso(enum charset _inputCharset, const etk::Vector<char>& _input_UTF8, etk::Vector<char>& _output_ISO)
int32_t unicode::convertUtf8ToIso(enum charset _inputCharset, const std::vector<char>& _input_UTF8, std::vector<char>& _output_ISO)
{
TK_WARNING("TODO : not coded...");
return 0;

View File

@ -10,7 +10,7 @@
#define __UNICODE_H__
#include <etk/types.h>
#include <etk/Vector.h>
#include <vector>
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<char>& _input_ISO, etk::Vector<etk::UChar>& _output_Unicode);
int32_t convertIsoToUnicode(enum charset _inputCharset, const etk::Vector<int8_t>& _input_ISO, etk::Vector<etk::UChar>& _output_Unicode);
int32_t convertUnicodeToIso(enum charset _inputCharset, const etk::Vector<etk::UChar>& _input_Unicode, etk::Vector<char>& _output_ISO);
int32_t convertUnicodeToIso(enum charset _inputCharset, const etk::Vector<etk::UChar>& _input_Unicode, etk::Vector<int8_t>& _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<char>& _input_ISO, std::vector<char32_t>& _output_Unicode);
int32_t convertIsoToUnicode(enum charset _inputCharset, const std::vector<int8_t>& _input_ISO, std::vector<char32_t>& _output_Unicode);
int32_t convertUnicodeToIso(enum charset _inputCharset, const std::vector<char32_t>& _input_Unicode, std::vector<char>& _output_ISO);
int32_t convertUnicodeToIso(enum charset _inputCharset, const std::vector<char32_t>& _input_Unicode, std::vector<int8_t>& _output_ISO);
// Transform UTF-8 <==> Unicode
int32_t convertUnicodeToUtf8( const etk::Vector<etk::UChar>& _input_Unicode, etk::Vector<char>& _output_UTF8);
int32_t convertUnicodeToUtf8( const etk::Vector<etk::UChar>& _input_Unicode, etk::Vector<int8_t>& _output_UTF8);
int32_t convertUtf8ToUnicode( const etk::Vector<char>& _input_UTF8, etk::Vector<etk::UChar>& _output_Unicode);
int32_t convertUtf8ToUnicode( const etk::Vector<int8_t>& _input_UTF8, etk::Vector<etk::UChar>& _output_Unicode);
int32_t convertUtf8ToUnicode( const char * _input_UTF8, etk::Vector<etk::UChar>& _output_Unicode);
int32_t convertUnicodeToUtf8( const std::vector<char32_t>& _input_Unicode, std::vector<char>& _output_UTF8);
int32_t convertUnicodeToUtf8( const std::vector<char32_t>& _input_Unicode, std::vector<int8_t>& _output_UTF8);
int32_t convertUtf8ToUnicode( const std::vector<char>& _input_UTF8, std::vector<char32_t>& _output_Unicode);
int32_t convertUtf8ToUnicode( const std::vector<int8_t>& _input_UTF8, std::vector<char32_t>& _output_Unicode);
int32_t convertUtf8ToUnicode( const char * _input_UTF8, std::vector<char32_t>& _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<char>& _input_ISO, etk::Vector<char>& _output_UTF8);
int32_t convertUtf8ToIso( enum charset _inputCharset, const etk::Vector<char>& _input_UTF8, etk::Vector<char>& _output_ISO);
int32_t convertIsoToUtf8( enum charset _inputCharset, const std::vector<char>& _input_ISO, std::vector<char>& _output_UTF8);
int32_t convertUtf8ToIso( enum charset _inputCharset, const std::vector<char>& _input_UTF8, std::vector<char>& _output_ISO);
void utf8_SizeElement(const char * _data, int32_t _lenMax , uint8_t &_size, bool &_baseValid);
int32_t strUtf8Len(const char *_input_UTF8);

View File

@ -7,8 +7,8 @@
*/
#include <etk/debug.h>
#include <etk/Vector.h>
#include <etk/UString.h>
#include <vector>
#include <string>
#include <etk/Hash.h>
#include <etk/os/FSNode.h>
#include <etk/archive/Archive.h>
@ -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)<<iii;
etk::UString plop(kkk, etk::UString::printModeBinary);
std::u32string plop(kkk, std::u32string::printModeBinary);
TK_DEBUG(" test : " << plop);
}
for(int32_t iii=0; iii<64; iii++) {
int64_t kkk=((int64_t)1)<<iii;
etk::UString plop(kkk, etk::UString::printModeOctal);
std::u32string plop(kkk, std::u32string::printModeOctal);
TK_DEBUG(" test : " << plop);
}
for(int32_t iii=0; iii<64; iii++) {
int64_t kkk=((int64_t)1)<<iii;
etk::UString plop(kkk, etk::UString::printModeDecimal);
std::u32string plop(kkk, std::u32string::printModeDecimal);
TK_DEBUG(" test : " << plop);
int64_t resTest = plop.toInt32();
TK_DEBUG(" test : " << resTest);
@ -50,15 +47,14 @@ void testUString(void)
for(int32_t iii=0; iii<64; iii++) {
int64_t kkk=((int64_t)1)<<iii;
etk::UString plop(kkk, etk::UString::printModeHexadecimal);
std::u32string plop(kkk, std::u32string::printModeHexadecimal);
TK_DEBUG(" test : " << plop);
}
}
void testHash(void)
{
void testHash(void) {
TK_INFO("==> Start test of Hach table");
etk::Hash<etk::UString> testData;
etk::Hash<std::u32string> 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();