[DEV] correct english
This commit is contained in:
parent
4b8e0397f7
commit
ffff4f5a27
233
.prude
233
.prude
@ -1,4 +1,235 @@
|
||||
# This file is for prude parsing (must start with .prude_* or project file .prude)
|
||||
# some possibiliries:
|
||||
# - Check the compleate name with case sensitive [a-zA-Z0-9_] ==> to ignore it. format +ABC_def
|
||||
# - not case-sensitive separate word camel-case and snake-case (set direct word)
|
||||
# - with # simple comment
|
||||
# - start with ! for global parameter
|
||||
etk
|
||||
obj
|
||||
rgb
|
||||
rgba
|
||||
rgba
|
||||
+TK_PRINT
|
||||
+TK_ERROR
|
||||
+TK_WARNING
|
||||
+TK_INFO
|
||||
+TK_DEBUG
|
||||
+TK_VERBOSE
|
||||
+TK_CRITICAL
|
||||
+TK_ASSERT
|
||||
+TK_HIDDEN
|
||||
+TK_REG_DEBUG
|
||||
+TK_REG_DEBUG_2
|
||||
+TK_REG_DEBUG_3
|
||||
+TK_CHECK_INOUT
|
||||
+ELOG_BASE
|
||||
+TK_TODO
|
||||
+_obj
|
||||
+anjdi
|
||||
+abghjkh
|
||||
+abgh
|
||||
+gt
|
||||
+getURegEx
|
||||
# Add generic color
|
||||
+Peru
|
||||
+peru
|
||||
+NavajoWhite
|
||||
+navajowhite
|
||||
+IndianRed
|
||||
+indianred
|
||||
+Gainsboro
|
||||
+gainsboro
|
||||
+Darkorange
|
||||
+darkorange
|
||||
+Cornsilk
|
||||
+cornsilk
|
||||
+AliceBlue
|
||||
+aliceblue
|
||||
|
||||
# color in a description:
|
||||
+F6780FFF
|
||||
+FEDCBA98
|
||||
+rrggbb
|
||||
+rrggbbaa
|
||||
+color:aliceBlue
|
||||
+color:antiqueWhite
|
||||
+color:aqua
|
||||
+color:aquamarine
|
||||
+color:azure
|
||||
+color:beige
|
||||
+color:bisque
|
||||
+color:black
|
||||
+color:blanchedAlmond
|
||||
+color:blue
|
||||
+color:blueViolet
|
||||
+color:brown
|
||||
+color:burlyWood
|
||||
+color:cadetBlue
|
||||
+color:chartreuse
|
||||
+color:chocolate
|
||||
+color:coral
|
||||
+color:cornflowerBlue
|
||||
+color:cornsilk
|
||||
+color:crimson
|
||||
+color:cyan
|
||||
+color:darkBlue
|
||||
+color:darkCyan
|
||||
+color:darkGoldenRod
|
||||
+color:darkGray
|
||||
+color:darkGrey
|
||||
+color:darkGreen
|
||||
+color:darkKhaki
|
||||
+color:darkMagenta
|
||||
+color:darkOliveGreen
|
||||
+color:darkorange
|
||||
+color:darkOrchid
|
||||
+color:darkRed
|
||||
+color:darkSalmon
|
||||
+color:darkSeaGreen
|
||||
+color:darkSlateBlue
|
||||
+color:darkSlateGray
|
||||
+color:darkSlateGrey
|
||||
+color:darkTurquoise
|
||||
+color:darkViolet
|
||||
+color:deepPink
|
||||
+color:deepSkyBlue
|
||||
+color:dimGray
|
||||
+color:dimGrey
|
||||
+color:dodgerBlue
|
||||
+color:fireBrick
|
||||
+color:floralWhite
|
||||
+color:forestGreen
|
||||
+color:fuchsia
|
||||
+color:gainsboro
|
||||
+color:ghostWhite
|
||||
+color:gold
|
||||
+color:goldenRod
|
||||
+color:gray
|
||||
+color:grey
|
||||
+color:green
|
||||
+color:greenYellow
|
||||
+color:honeyDew
|
||||
+color:hotPink
|
||||
+color:indianRed
|
||||
+color:indigo
|
||||
+color:ivory
|
||||
+color:khaki
|
||||
+color:lavender
|
||||
+color:lavenderBlush
|
||||
+color:lawnGreen
|
||||
+color:lemonChiffon
|
||||
+color:lightBlue
|
||||
+color:lightCoral
|
||||
+color:lightCyan
|
||||
+color:lightGoldenRodYellow
|
||||
+color:lightGray
|
||||
+color:lightGrey
|
||||
+color:lightGreen
|
||||
+color:lightPink
|
||||
+color:lightSalmon
|
||||
+color:lightSeaGreen
|
||||
+color:lightSkyBlue
|
||||
+color:lightSlateGray
|
||||
+color:lightSlateGrey
|
||||
+color:lightSteelBlue
|
||||
+color:lightYellow
|
||||
+color:lime
|
||||
+color:limeGreen
|
||||
+color:linen
|
||||
+color:magenta
|
||||
+color:maroon
|
||||
+color:mediumAquaMarine
|
||||
+color:mediumBlue
|
||||
+color:mediumOrchid
|
||||
+color:mediumPurple
|
||||
+color:mediumSeaGreen
|
||||
+color:mediumSlateBlue
|
||||
+color:mediumSpringGreen
|
||||
+color:mediumTurquoise
|
||||
+color:mediumVioletRed
|
||||
+color:midnightBlue
|
||||
+color:mintCream
|
||||
+color:mistyRose
|
||||
+color:moccasin
|
||||
+color:navajoWhite
|
||||
+color:navy
|
||||
+color:oldLace
|
||||
+color:olive
|
||||
+color:oliveDrab
|
||||
+color:orange
|
||||
+color:orangeRed
|
||||
+color:orchid
|
||||
+color:paleGoldenRod
|
||||
+color:paleGreen
|
||||
+color:paleTurquoise
|
||||
+color:paleVioletRed
|
||||
+color:papayaWhip
|
||||
+color:peachPuff
|
||||
+color:peru
|
||||
+color:pink
|
||||
+color:plum
|
||||
+color:powderBlue
|
||||
+color:purple
|
||||
+color:red
|
||||
+color:rosyBrown
|
||||
+color:royalBlue
|
||||
+color:saddleBrown
|
||||
+color:salmon
|
||||
+color:sandyBrown
|
||||
+color:seaGreen
|
||||
+color:seaShell
|
||||
+color:sienna
|
||||
+color:silver
|
||||
+color:skyBlue
|
||||
+color:slateBlue
|
||||
+color:slateGray
|
||||
+color:slateGrey
|
||||
+color:snow
|
||||
+color:springGreen
|
||||
+color:steelBlue
|
||||
+color:tan
|
||||
+color:teal
|
||||
+color:thistle
|
||||
+color:tomato
|
||||
+color:turquoise
|
||||
+color:violet
|
||||
+color:wheat
|
||||
+color:white
|
||||
+color:whiteSmoke
|
||||
+color:yellow
|
||||
+color:yellowGreen
|
||||
|
||||
+parseStringStartWithRGBGen
|
||||
+parseStringStartWithRGBUnsigned32
|
||||
+parseStringStartWithRGBUnsigned16
|
||||
+parseStringStartWithRGBUnsigned8
|
||||
+navajoWhite
|
||||
+indianRed
|
||||
+aliceBlue
|
||||
# specific regex:
|
||||
pthese
|
||||
+string_to_int8_t
|
||||
+string_to_int16_t
|
||||
+string_to_int32_t
|
||||
+string_to_int64_t
|
||||
+string_to_uint8_t
|
||||
+string_to_uint16_t
|
||||
+string_to_uint32_t
|
||||
+string_to_uint64_t
|
||||
+string_to_bool
|
||||
std
|
||||
+u32char
|
||||
+BS
|
||||
+ESC
|
||||
+stod
|
||||
+stof
|
||||
+stoi
|
||||
+stol
|
||||
+stold
|
||||
+stoll
|
||||
+stoul
|
||||
+stoull
|
||||
+tolower
|
||||
+toupper
|
||||
+srand
|
||||
+irand
|
||||
+frand
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
// minimum gapSize when allocated
|
||||
#define GAP_SIZE_MIN (80)
|
||||
// maximum gap that is automaticly resize
|
||||
// maximum gap that is automatically resize
|
||||
#define GAP_SIZE_MAX (GAP_SIZE_MIN*4)
|
||||
|
||||
/*
|
||||
@ -43,7 +43,7 @@ namespace etk {
|
||||
*/
|
||||
class Buffer {
|
||||
private:
|
||||
int8_t* m_data; //!< pointer on the curetn table of Data
|
||||
int8_t* m_data; //!< pointer on the current table of Data
|
||||
int32_t m_allocated; //!< Current allocated size
|
||||
// empty part of the buffer data
|
||||
int32_t m_gapStart; //!< points to the first character of the gap
|
||||
@ -90,8 +90,8 @@ namespace etk {
|
||||
/**
|
||||
* @brief Store the selected data in the requested file.
|
||||
* @param[in] _file Name of the file that might be written.
|
||||
* @return true if the data corectly stored
|
||||
* @return false if an error occured
|
||||
* @return true if the data correctly stored
|
||||
* @return false if an error occurred
|
||||
*/
|
||||
bool dumpIn(const std::string& _file) {
|
||||
etk::FSNode file(_file);
|
||||
@ -106,10 +106,10 @@ namespace etk {
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @brief Load data fron a selected file name.
|
||||
* @brief Load data from a selected file name.
|
||||
* @param[in] _file Name of the file to store buffer data.
|
||||
* @return true if the data corectly stored
|
||||
* @return false if an error occured
|
||||
* @return true if the data correctly stored
|
||||
* @return false if an error occurred
|
||||
*/
|
||||
bool dumpFrom(const std::string& _file) {
|
||||
etk::FSNode file(_file);
|
||||
@ -126,13 +126,13 @@ namespace etk {
|
||||
changeAllocation(length + GAP_SIZE_MIN);
|
||||
// insert Data
|
||||
int32_t nbReadData = file.fileRead(&m_data[GAP_SIZE_MIN], sizeof(int8_t), length);
|
||||
TK_INFO("load data : filesize=" << length << ", readData=" << nbReadData);
|
||||
TK_INFO("load data : fileSize=" << length << ", readData=" << nbReadData);
|
||||
// check ERROR
|
||||
if (nbReadData != length) {
|
||||
TK_ERROR("load data pb : filesize=" << length << ", readData=" << nbReadData);
|
||||
TK_ERROR("load data error: fileSize=" << length << ", readData=" << nbReadData);
|
||||
ret = false;
|
||||
}
|
||||
// set the gapsize at the fd ...
|
||||
// set the gap size at the buffer ...
|
||||
m_gapStart = 0;
|
||||
m_gapEnd = GAP_SIZE_MIN;
|
||||
file.fileClose();
|
||||
@ -142,7 +142,7 @@ namespace etk {
|
||||
/**
|
||||
* @brief Re-copy operator
|
||||
* @param[in] _obj Buffer that might be copy
|
||||
* @return reference on the curent copied Buffer
|
||||
* @return reference on the current copied Buffer
|
||||
*/
|
||||
etk::Buffer& operator=(const etk::Buffer& _obj) {
|
||||
if( this == &_obj ) {// avoid copy to itself
|
||||
@ -161,7 +161,7 @@ namespace etk {
|
||||
TK_ASSERT(NULL!=m_data, "Error in data allocation");
|
||||
// Copy all data ...
|
||||
memcpy(m_data, _obj.m_data, m_allocated * sizeof(int8_t) );
|
||||
// Return the curent pointer
|
||||
// Return the current pointer
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
@ -170,7 +170,7 @@ namespace etk {
|
||||
* @return Element at the request pos.
|
||||
*/
|
||||
int8_t operator[] (int32_t _pos) const {
|
||||
TK_ASSERT(0 <= _pos || _pos < size(), "try to read an element non existing");
|
||||
TK_ASSERT(0 <= _pos || _pos < size(), "try to read an element not existing");
|
||||
if (_pos < m_gapStart) {
|
||||
return m_data[_pos];
|
||||
}
|
||||
@ -183,7 +183,7 @@ namespace etk {
|
||||
* @return Reference on the Element
|
||||
*/
|
||||
int8_t& get(int32_t _pos) const {
|
||||
TK_ASSERT(0 <= _pos || _pos < size(), "try to read an element non existing");
|
||||
TK_ASSERT(0 <= _pos || _pos < size(), "try to read an element not existing");
|
||||
if (_pos < m_gapStart) {
|
||||
return m_data[_pos];
|
||||
}
|
||||
@ -245,7 +245,7 @@ namespace etk {
|
||||
} else if( _pos == m_gapStart
|
||||
&& _pos == m_gapEnd-1 )
|
||||
{
|
||||
// mothing to do ...
|
||||
// Nothing to do ...
|
||||
} else {
|
||||
if (gapMove(_pos) == false) {
|
||||
return;
|
||||
@ -414,22 +414,22 @@ namespace etk {
|
||||
* @param[in] _newSize Minimum number of element needed
|
||||
*/
|
||||
void changeAllocation(int32_t _newSize) {
|
||||
// set the minimal size to 1
|
||||
// Set the minimal size to 1
|
||||
if(_newSize <= 0) {
|
||||
_newSize = 1;
|
||||
}
|
||||
// set the size with the corect chose type :
|
||||
// Set the size with the correct chose type:
|
||||
if (_newSize == m_allocated) {
|
||||
return;
|
||||
}
|
||||
//TODO : use new and delete and multiple of power of 2.
|
||||
TK_DEBUG("Change Allocation : " << m_allocated << " ==> " << _newSize);
|
||||
// check if something is allocated :
|
||||
// Check if something is allocated:
|
||||
if (m_data == NULL) {
|
||||
// no data allocated ==> request an allocation (might be the first)
|
||||
m_data = (int8_t *)malloc( _newSize * sizeof(int8_t) );
|
||||
} else {
|
||||
// move datas
|
||||
// move data
|
||||
m_data = (int8_t *)realloc( m_data, _newSize* sizeof(int8_t) );
|
||||
}
|
||||
// Check result with assert :
|
||||
@ -440,7 +440,7 @@ namespace etk {
|
||||
/**
|
||||
* @brief Move the current gap at an other position
|
||||
* @param[in] _pos Position of the new Gap.
|
||||
* @return false The operation can not be proccesed.
|
||||
* @return false The operation can not be processed.
|
||||
* @return true The operation done correctly.
|
||||
*/
|
||||
bool gapMove(int32_t _pos) {
|
||||
@ -478,7 +478,7 @@ namespace etk {
|
||||
return true;
|
||||
} else {
|
||||
if (_newGapLen > gapSize() ) {
|
||||
// reallocation
|
||||
// Change allocation size.
|
||||
changeAllocation( previousSize + _newGapLen);
|
||||
}
|
||||
// move Data
|
||||
@ -499,7 +499,7 @@ namespace etk {
|
||||
memmove(&m_data[m_gapStart + _newGapLen], &m_data[m_gapEnd], previousSize - m_gapStart);
|
||||
}
|
||||
if (_newGapLen < gapSize() ) {
|
||||
// rellocation
|
||||
// Change allocation size.
|
||||
changeAllocation(previousSize + _newGapLen);
|
||||
}
|
||||
}
|
||||
|
155
etk/Color.cpp
155
etk/Color.cpp
@ -13,13 +13,14 @@
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
typedef struct {
|
||||
const char * colorName;
|
||||
etk::Color<> color;
|
||||
} colorList_ts;
|
||||
class ColorList {
|
||||
public:
|
||||
const char * colorName;
|
||||
etk::Color<> color;
|
||||
};
|
||||
|
||||
static int32_t getColorSize();
|
||||
static const colorList_ts* getColorList();
|
||||
static const ColorList* getColorList();
|
||||
|
||||
etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input) {
|
||||
TK_VERBOSE("parseStringStartWithSharp('" << _input << "'");
|
||||
@ -33,7 +34,7 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input)
|
||||
outputValue.setB(blue | blue << 4);
|
||||
outputValue.setA(0xFF);
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "'");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "'");
|
||||
}
|
||||
} else if (len==4) {
|
||||
uint32_t red=0, green=0, blue=0, alpha=0;
|
||||
@ -43,7 +44,7 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input)
|
||||
outputValue.setB(blue | blue << 4);
|
||||
outputValue.setA(alpha | alpha << 4);
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "'");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "'");
|
||||
}
|
||||
} else if (len == 6) {
|
||||
uint32_t red=0, green=0, blue=0;
|
||||
@ -53,7 +54,7 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input)
|
||||
outputValue.setB(blue);
|
||||
outputValue.setA(0xFF);
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "'");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "'");
|
||||
}
|
||||
} else if (len == 8) {
|
||||
uint32_t red=0, green=0, blue=0, alpha=0;
|
||||
@ -63,10 +64,10 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input)
|
||||
outputValue.setB(blue);
|
||||
outputValue.setA(alpha);
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "'");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "'");
|
||||
}
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
|
||||
}
|
||||
TK_VERBOSE(" result: '" << outputValue << "'");
|
||||
return outputValue;
|
||||
@ -76,7 +77,7 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const std::string& _input
|
||||
TK_VERBOSE("parseStringStartWithRGB('" << _input << "'");
|
||||
etk::Color<uint8_t, 4> outputValue(0,0,0,0);
|
||||
int32_t red=0, green=0, blue=0, alpha=0;
|
||||
float fred=0, fgreen=0, fblue=0, falpha=0;
|
||||
float float_red=0, float_green=0, float_blue=0, float_alpha=0;
|
||||
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
|
||||
outputValue.setR(std::min(0xFF, red));
|
||||
outputValue.setG(std::min(0xFF, green));
|
||||
@ -95,24 +96,24 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const std::string& _input
|
||||
outputValue.setR(std::min(0xFF, red));
|
||||
outputValue.setG(std::min(0xFF, green));
|
||||
outputValue.setB(std::min(0xFF, blue));
|
||||
} else if (sscanf(_input.c_str(), "%f,%f,%f,%f", &fred, &fgreen, &fblue, &falpha) == 4) {
|
||||
fred = std::avg(0.0f, fred, 1.0f);
|
||||
fgreen = std::avg(0.0f, fgreen, 1.0f);
|
||||
fblue = std::avg(0.0f, fblue, 1.0f);
|
||||
falpha = std::avg(0.0f, falpha, 1.0f);
|
||||
outputValue.setR((uint8_t)(fred * 255.f));
|
||||
outputValue.setG((uint8_t)(fgreen * 255.f));
|
||||
outputValue.setB((uint8_t)(fblue * 255.f));
|
||||
outputValue.setR((uint8_t)(falpha * 255.f));
|
||||
} else if (sscanf(_input.c_str(), "%f,%f,%f", &fred, &fgreen, &fblue) == 3) {
|
||||
fred = std::avg(0.0f, fred, 1.0f);
|
||||
fgreen= std::avg(0.0f, fgreen, 1.0f);
|
||||
fblue = std::avg(0.0f, fblue, 1.0f);
|
||||
outputValue.setR((uint8_t)(fred * 255.f));
|
||||
outputValue.setG((uint8_t)(fgreen * 255.f));
|
||||
outputValue.setB((uint8_t)(fblue * 255.f));
|
||||
} else if (sscanf(_input.c_str(), "%f,%f,%f,%f", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
|
||||
float_red = std::avg(0.0f, float_red, 1.0f);
|
||||
float_green = std::avg(0.0f, float_green, 1.0f);
|
||||
float_blue = std::avg(0.0f, float_blue, 1.0f);
|
||||
float_alpha = std::avg(0.0f, float_alpha, 1.0f);
|
||||
outputValue.setR((uint8_t)(float_red * 255.f));
|
||||
outputValue.setG((uint8_t)(float_green * 255.f));
|
||||
outputValue.setB((uint8_t)(float_blue * 255.f));
|
||||
outputValue.setR((uint8_t)(float_alpha * 255.f));
|
||||
} else if (sscanf(_input.c_str(), "%f,%f,%f", &float_red, &float_green, &float_blue) == 3) {
|
||||
float_red = std::avg(0.0f, float_red, 1.0f);
|
||||
float_green= std::avg(0.0f, float_green, 1.0f);
|
||||
float_blue = std::avg(0.0f, float_blue, 1.0f);
|
||||
outputValue.setR((uint8_t)(float_red * 255.f));
|
||||
outputValue.setG((uint8_t)(float_green * 255.f));
|
||||
outputValue.setB((uint8_t)(float_blue * 255.f));
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
|
||||
}
|
||||
return outputValue;
|
||||
}
|
||||
@ -120,17 +121,17 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const std::string& _input
|
||||
etk::Color<double, 4> etk::parseStringStartWithRGB(const std::string& _input) {
|
||||
TK_VERBOSE("parseStringStartWithRGB('" << _input << "')");
|
||||
etk::Color<double, 4> outputValue(0,0,0,0);
|
||||
double fred=0, fgreen=0, fblue=0, falpha=0;
|
||||
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
|
||||
int32_t red=0, green=0, blue=0, alpha=0;
|
||||
if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
|
||||
outputValue.setR(fred);
|
||||
outputValue.setG(fgreen);
|
||||
outputValue.setB(fblue);
|
||||
outputValue.setA(falpha);
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
|
||||
outputValue.setR(fred);
|
||||
outputValue.setG(fgreen);
|
||||
outputValue.setB(fblue);
|
||||
if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
|
||||
outputValue.setR(float_red);
|
||||
outputValue.setG(float_green);
|
||||
outputValue.setB(float_blue);
|
||||
outputValue.setA(float_alpha);
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
|
||||
outputValue.setR(float_red);
|
||||
outputValue.setG(float_green);
|
||||
outputValue.setB(float_blue);
|
||||
} else if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
|
||||
outputValue.setR(std::min(0xFF, red)/255.0);
|
||||
outputValue.setG(std::min(0xFF, green)/255.0);
|
||||
@ -150,14 +151,14 @@ etk::Color<double, 4> etk::parseStringStartWithRGB(const std::string& _input) {
|
||||
outputValue.setG(std::min(0xFF, green)/255.0);
|
||||
outputValue.setB(std::min(0xFF, blue)/255.0);
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
|
||||
}
|
||||
return outputValue;
|
||||
}
|
||||
etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const std::string& _input) {
|
||||
etk::Color<uint32_t, 4> outputValue(0,0,0,0);
|
||||
int32_t red=0, green=0, blue=0, alpha=0;
|
||||
double fred=0, fgreen=0, fblue=0, falpha=0;
|
||||
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
|
||||
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
|
||||
outputValue.setR(red);
|
||||
outputValue.setG(green);
|
||||
@ -176,17 +177,17 @@ etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const std::string
|
||||
outputValue.setR(red);
|
||||
outputValue.setG(green);
|
||||
outputValue.setB(blue);
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
|
||||
outputValue.setR((uint32_t)(std::min(1.0, fred)*0xFFFFFFFF));
|
||||
outputValue.setG((uint32_t)(std::min(1.0, fgreen)*0xFFFFFFFF));
|
||||
outputValue.setB((uint32_t)(std::min(1.0, fblue)*0xFFFFFFFF));
|
||||
outputValue.setA((uint32_t)(std::min(1.0, falpha)*0xFFFFFFFF));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
|
||||
outputValue.setR((uint32_t)(std::min(1.0, fred)*0xFFFFFFFF));
|
||||
outputValue.setG((uint32_t)(std::min(1.0, fgreen)*0xFFFFFFFF));
|
||||
outputValue.setB((uint32_t)(std::min(1.0, fblue)*0xFFFFFFFF));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
|
||||
outputValue.setR((uint32_t)(std::min(1.0, float_red)*0xFFFFFFFF));
|
||||
outputValue.setG((uint32_t)(std::min(1.0, float_green)*0xFFFFFFFF));
|
||||
outputValue.setB((uint32_t)(std::min(1.0, float_blue)*0xFFFFFFFF));
|
||||
outputValue.setA((uint32_t)(std::min(1.0, float_alpha)*0xFFFFFFFF));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
|
||||
outputValue.setR((uint32_t)(std::min(1.0, float_red)*0xFFFFFFFF));
|
||||
outputValue.setG((uint32_t)(std::min(1.0, float_green)*0xFFFFFFFF));
|
||||
outputValue.setB((uint32_t)(std::min(1.0, float_blue)*0xFFFFFFFF));
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
|
||||
}
|
||||
return outputValue;
|
||||
}
|
||||
@ -194,7 +195,7 @@ etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const std::string
|
||||
etk::Color<uint16_t, 4> etk::parseStringStartWithRGBUnsigned16(const std::string& _input) {
|
||||
etk::Color<uint16_t, 4> outputValue(0,0,0,0);
|
||||
int32_t red=0, green=0, blue=0, alpha=0;
|
||||
double fred=0, fgreen=0, fblue=0, falpha=0;
|
||||
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
|
||||
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
|
||||
outputValue.setR(std::min(0xFFFF, red));
|
||||
outputValue.setG(std::min(0xFFFF, green));
|
||||
@ -213,17 +214,17 @@ etk::Color<uint16_t, 4> etk::parseStringStartWithRGBUnsigned16(const std::string
|
||||
outputValue.setR(std::min(0xFFFF, red));
|
||||
outputValue.setG(std::min(0xFFFF, green));
|
||||
outputValue.setB(std::min(0xFFFF, blue));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
|
||||
outputValue.setR((uint16_t)(std::min(1.0, fred)*0xFFFF));
|
||||
outputValue.setG((uint16_t)(std::min(1.0, fgreen)*0xFFFF));
|
||||
outputValue.setB((uint16_t)(std::min(1.0, fblue)*0xFFFF));
|
||||
outputValue.setA((uint16_t)(std::min(1.0, falpha)*0xFFFF));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
|
||||
outputValue.setR((uint16_t)(std::min(1.0, fred)*0xFFFF));
|
||||
outputValue.setG((uint16_t)(std::min(1.0, fgreen)*0xFFFF));
|
||||
outputValue.setB((uint16_t)(std::min(1.0, fblue)*0xFFFF));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
|
||||
outputValue.setR((uint16_t)(std::min(1.0, float_red)*0xFFFF));
|
||||
outputValue.setG((uint16_t)(std::min(1.0, float_green)*0xFFFF));
|
||||
outputValue.setB((uint16_t)(std::min(1.0, float_blue)*0xFFFF));
|
||||
outputValue.setA((uint16_t)(std::min(1.0, float_alpha)*0xFFFF));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
|
||||
outputValue.setR((uint16_t)(std::min(1.0, float_red)*0xFFFF));
|
||||
outputValue.setG((uint16_t)(std::min(1.0, float_green)*0xFFFF));
|
||||
outputValue.setB((uint16_t)(std::min(1.0, float_blue)*0xFFFF));
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
|
||||
}
|
||||
return outputValue;
|
||||
}
|
||||
@ -231,7 +232,7 @@ etk::Color<uint16_t, 4> etk::parseStringStartWithRGBUnsigned16(const std::string
|
||||
etk::Color<uint8_t, 4> etk::parseStringStartWithRGBUnsigned8(const std::string& _input) {
|
||||
etk::Color<uint8_t, 4> outputValue(0,0,0,0);
|
||||
int32_t red=0, green=0, blue=0, alpha=0;
|
||||
double fred=0, fgreen=0, fblue=0, falpha=0;
|
||||
double float_red=0, float_green=0, float_blue=0, float_alpha=0;
|
||||
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
|
||||
outputValue.setR(std::min(0xFF, red));
|
||||
outputValue.setG(std::min(0xFF, green));
|
||||
@ -250,17 +251,17 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBUnsigned8(const std::string&
|
||||
outputValue.setR(std::min(0xFF, red));
|
||||
outputValue.setG(std::min(0xFF, green));
|
||||
outputValue.setB(std::min(0xFF, blue));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
|
||||
outputValue.setR((uint8_t)(std::min(1.0, fred)*0xFF));
|
||||
outputValue.setG((uint8_t)(std::min(1.0, fgreen)*0xFF));
|
||||
outputValue.setB((uint8_t)(std::min(1.0, fblue)*0xFF));
|
||||
outputValue.setA((uint8_t)(std::min(1.0, falpha)*0xFF));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
|
||||
outputValue.setR((uint8_t)(std::min(1.0, fred)*0xFF));
|
||||
outputValue.setG((uint8_t)(std::min(1.0, fgreen)*0xFF));
|
||||
outputValue.setB((uint8_t)(std::min(1.0, fblue)*0xFF));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &float_red, &float_green, &float_blue, &float_alpha) == 4) {
|
||||
outputValue.setR((uint8_t)(std::min(1.0, float_red)*0xFF));
|
||||
outputValue.setG((uint8_t)(std::min(1.0, float_green)*0xFF));
|
||||
outputValue.setB((uint8_t)(std::min(1.0, float_blue)*0xFF));
|
||||
outputValue.setA((uint8_t)(std::min(1.0, float_alpha)*0xFF));
|
||||
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &float_red, &float_green, &float_blue) == 3) {
|
||||
outputValue.setR((uint8_t)(std::min(1.0, float_red)*0xFF));
|
||||
outputValue.setG((uint8_t)(std::min(1.0, float_green)*0xFF));
|
||||
outputValue.setB((uint8_t)(std::min(1.0, float_blue)*0xFF));
|
||||
} else {
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "' ==> unknown method ...");
|
||||
}
|
||||
return outputValue;
|
||||
}
|
||||
@ -272,7 +273,7 @@ etk::Color<uint8_t, 4> etk::parseStringColorNamed(const std::string& _input) {
|
||||
return getColorList()[iii].color;
|
||||
}
|
||||
}
|
||||
TK_ERROR(" pb in parsing the color : '" << _input << "' not find ...");
|
||||
TK_ERROR("Error in parsing the color : '" << _input << "' not find ...");
|
||||
return etk::Color<uint8_t, 4>(0,0,0,0);
|
||||
}
|
||||
|
||||
@ -432,7 +433,7 @@ const etk::Color<> etk::color::whiteSmoke(0xF5, 0xF5, 0xF5, 0xFF);
|
||||
const etk::Color<> etk::color::yellow(0xFF, 0xFF, 0x00, 0xFF);
|
||||
const etk::Color<> etk::color::yellowGreen(0x9A, 0xCD, 0x32, 0xFF);
|
||||
|
||||
static const colorList_ts listOfColor[] = {
|
||||
static const ColorList listOfColor[] = {
|
||||
{ "none", etk::color::none},
|
||||
{ "AliceBlue", etk::color::aliceBlue},
|
||||
{ "AntiqueWhite", etk::color::antiqueWhite},
|
||||
@ -583,15 +584,15 @@ static const colorList_ts listOfColor[] = {
|
||||
{ "YellowGreen", etk::color::yellowGreen}
|
||||
};
|
||||
|
||||
static const colorList_ts* getColorList()
|
||||
static const ColorList* getColorList()
|
||||
{
|
||||
return listOfColor;
|
||||
}
|
||||
|
||||
static int32_t getColorSize()
|
||||
{
|
||||
static const int32_t tmpp = sizeof(listOfColor) / sizeof(colorList_ts);
|
||||
return tmpp;
|
||||
static const int32_t tmp = sizeof(listOfColor) / sizeof(ColorList);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
namespace etk {
|
||||
|
120
etk/Color.hpp
120
etk/Color.hpp
@ -14,15 +14,15 @@ namespace etk {
|
||||
/**
|
||||
* @brief The color class is a template to abstract the color implementation choice.
|
||||
*
|
||||
* It is important to note that the color choice denpznd on the level of developent.
|
||||
* It is important to note that the color choice depend on the level of development.
|
||||
* For example :
|
||||
* - Graphic application use:
|
||||
* - Image in 3/4 bytes for rgb(a)
|
||||
* - Color description in char : '\#F6780FFF' or the equivalent number:0xF6780FFF
|
||||
* - middleware will mainely use a the 4 separate value with 1 byte for each.
|
||||
* - middle-ware will mainly use a the 4 separate value with 1 byte for each.
|
||||
* - graphic interface (openGL) store image in 1/2/3/4 bytes color and interpolate it in 'n' float. And note that the user color is sored in float.
|
||||
*
|
||||
* Then with this class we abstract the transformation format and set an easy same way to use the color independing of the developpement level.
|
||||
* Then with this class we abstract the transformation format and set an easy same way to use the color independent of the development level.
|
||||
*
|
||||
* Some of the basic color is defined in the namespace: @ref etk::color.
|
||||
*
|
||||
@ -37,11 +37,11 @@ namespace etk {
|
||||
MY_TYPE m_element[MY_TYPE_SIZE]; //!< all the color.
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor. It does not initialise element of class.
|
||||
* @brief Constructor. It does not initialize element of class.
|
||||
*/
|
||||
Color() { };
|
||||
/**
|
||||
* @brief Contructor with request initialisation.
|
||||
* @brief Constructor with request initialization.
|
||||
* @param[in] _r Red color.
|
||||
* @param[in] _g Green color.
|
||||
* @param[in] _b Blue color.
|
||||
@ -51,7 +51,7 @@ namespace etk {
|
||||
set(_r, _g, _b, _a);
|
||||
};
|
||||
/**
|
||||
* @brief Contructor with request initialisation.
|
||||
* @brief Constructor with request initialization.
|
||||
* @param[in] _r Red color.
|
||||
* @param[in] _g Green color.
|
||||
* @param[in] _b Blue color.
|
||||
@ -60,7 +60,7 @@ namespace etk {
|
||||
set(_r, _g, _b);
|
||||
};
|
||||
/**
|
||||
* @brief Contructor with request initialisation.
|
||||
* @brief Constructor with request initialization.
|
||||
* @param[in] _r Red color.
|
||||
* @param[in] _g Green color.
|
||||
*/
|
||||
@ -68,25 +68,25 @@ namespace etk {
|
||||
set(_r, _g);
|
||||
};
|
||||
/**
|
||||
* @brief Contructor with request initialisation.
|
||||
* @brief Constructor with request initialization.
|
||||
* @param[in] _r Red color.
|
||||
*/
|
||||
Color(MY_TYPE _r) {
|
||||
set(_r);
|
||||
};
|
||||
/**
|
||||
* @brief Copy contructor or convert contructor
|
||||
* @brief Copy constructor or convert constructor
|
||||
* @param[in] _obj Element to copy in this new color class.
|
||||
*/
|
||||
template<typename MY_TYPE_2, int MY_TYPE_SIZE_2>
|
||||
Color(const etk::Color<MY_TYPE_2, MY_TYPE_SIZE_2>& _obj);
|
||||
/**
|
||||
* @brief String extractor constructor.
|
||||
* @param[in] _input Color string to parse. it can be : "#rrggbb", "rgb", "rrggbbaa", "rgba", "blueviolet" ...
|
||||
* @param[in] _input Color string to parse. it can be : "#rrggbb", "rgb", "rrggbbaa", "rgba", "yellow" ...
|
||||
*/
|
||||
Color(const std::string& _input);
|
||||
/**
|
||||
* @brief Asignemement operator
|
||||
* @brief Assignment operator
|
||||
* @param[in] _input Color object to set in this class.
|
||||
* @return reference on this element.
|
||||
*/
|
||||
@ -97,7 +97,7 @@ namespace etk {
|
||||
return *this;
|
||||
};
|
||||
/**
|
||||
* @brief Different comparaison operator.
|
||||
* @brief Different comparison operator.
|
||||
* @param[in] _obj Color object to compare.
|
||||
* @return true This is not the same color
|
||||
* @return false This is the same color.
|
||||
@ -111,7 +111,7 @@ namespace etk {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @brief Equality comparaison operator.
|
||||
* @brief Equality comparison operator.
|
||||
* @param[in] _obj Color object to compare.
|
||||
* @return true This is the same color.
|
||||
* @return false The color are different.
|
||||
@ -208,22 +208,22 @@ namespace etk {
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @brief Convert the color in an hexedecimal string ("0xFEDCBA98")
|
||||
* @return The formated string
|
||||
* @brief Convert the color in an hexadecimal string ("0xFEDCBA98")
|
||||
* @return The formatted string
|
||||
*/
|
||||
std::string getHexString() const {
|
||||
std::ostringstream oss;
|
||||
oss << "0x" << std::setw(8) << std::setfill('0') << std::hex << get();
|
||||
return oss.str();
|
||||
std::ostringstream os;
|
||||
os << "0x" << std::setw(8) << std::setfill('0') << std::hex << get();
|
||||
return os.str();
|
||||
};
|
||||
/**
|
||||
* @brief Convert the color in an generic string value ("#FEDCBA98")
|
||||
* @return The formated string
|
||||
* @return The formatted string
|
||||
*/
|
||||
std::string getString() const {
|
||||
std::ostringstream oss;
|
||||
oss << "#" << std::setw(8) << std::setfill('0') << std::hex << get();
|
||||
return oss.str();
|
||||
std::ostringstream os;
|
||||
os << "#" << std::setw(8) << std::setfill('0') << std::hex << get();
|
||||
return os.str();
|
||||
};
|
||||
/**
|
||||
* @brief Get red color.
|
||||
@ -308,7 +308,7 @@ namespace etk {
|
||||
/**
|
||||
* @brief Operator+= Addition an other etk::color with this one
|
||||
* @param[in] _obj Reference on the external object
|
||||
* @return Local reference of the vector additionned
|
||||
* @return Local reference of the vector addition
|
||||
*/
|
||||
const etk::Color<MY_TYPE,MY_TYPE_SIZE>& operator+= (const etk::Color<MY_TYPE,MY_TYPE_SIZE>& _obj) {
|
||||
if (MY_TYPE_SIZE >= 1) {
|
||||
@ -331,9 +331,9 @@ namespace etk {
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
etk::Color<MY_TYPE,MY_TYPE_SIZE> operator+ (const etk::Color<MY_TYPE,MY_TYPE_SIZE>& _obj) const {
|
||||
etk::Color<MY_TYPE,MY_TYPE_SIZE> tmpp(*this);
|
||||
tmpp += _obj;
|
||||
return tmpp;
|
||||
etk::Color<MY_TYPE,MY_TYPE_SIZE> tmp(*this);
|
||||
tmp += _obj;
|
||||
return tmp;
|
||||
}
|
||||
/**
|
||||
* @brief Operator*= Multiply 2 color together
|
||||
@ -381,9 +381,9 @@ namespace etk {
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
etk::Color<MY_TYPE,MY_TYPE_SIZE> operator* (const etk::Color<MY_TYPE,MY_TYPE_SIZE>& _obj) const {
|
||||
etk::Color<MY_TYPE,MY_TYPE_SIZE> tmpp(*this);
|
||||
tmpp *= _obj;
|
||||
return tmpp;
|
||||
etk::Color<MY_TYPE,MY_TYPE_SIZE> tmp(*this);
|
||||
tmp *= _obj;
|
||||
return tmp;
|
||||
}
|
||||
/**
|
||||
* @brief Operator*= Multiply the color With a specific value
|
||||
@ -391,9 +391,9 @@ namespace etk {
|
||||
* @return New vector containing the value
|
||||
*/
|
||||
etk::Color<MY_TYPE,MY_TYPE_SIZE> operator* (const MY_TYPE _val) const {
|
||||
etk::Color<MY_TYPE,MY_TYPE_SIZE> tmpp(*this);
|
||||
tmpp *= _val;
|
||||
return tmpp;
|
||||
etk::Color<MY_TYPE,MY_TYPE_SIZE> tmp(*this);
|
||||
tmp *= _val;
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
@ -404,7 +404,7 @@ namespace etk {
|
||||
*/
|
||||
etk::Color<uint8_t, 4> parseStringStartWithSharp(const std::string& _input);
|
||||
/**
|
||||
* @brief Get a color value started with a "rgb()" converted in uint8
|
||||
* @brief Get a color value started with a "rgb()" converted in unsigned 8 bits integer
|
||||
* @param[in] _input String to parse
|
||||
* @return Value parsed
|
||||
*/
|
||||
@ -416,33 +416,33 @@ namespace etk {
|
||||
*/
|
||||
etk::Color<double, 4> parseStringStartWithRGB(const std::string& _input);
|
||||
/**
|
||||
* @brief Get a color value started with a "rgb()" converted in uint32
|
||||
* @brief Get a color value started with a "rgb()" converted in unsigned 32 bits integer
|
||||
* @param[in] _input String to parse
|
||||
* @return Value parsed
|
||||
*/
|
||||
etk::Color<uint32_t, 4> parseStringStartWithRGBUnsigned32(const std::string& _input);
|
||||
/**
|
||||
* @brief Get a color value started with a "rgb()" converted in uint16
|
||||
* @brief Get a color value started with a "rgb()" converted in unsigned 16 bits integer
|
||||
* @param[in] _input String to parse
|
||||
* @return Value parsed
|
||||
*/
|
||||
etk::Color<uint16_t, 4> parseStringStartWithRGBUnsigned16(const std::string& _input);
|
||||
/**
|
||||
* @brief Get a color value started with a "rgb()" converted in uint6
|
||||
* @brief Get a color value started with a "rgb()" converted in unsigned 8 bits integer
|
||||
* @param[in] _input String to parse
|
||||
* @return Value parsed
|
||||
*/
|
||||
etk::Color<uint8_t, 4> parseStringStartWithRGBUnsigned8(const std::string& _input);
|
||||
/**
|
||||
* @brief Get a color value started with a "named" converted in uint8 like red, geen ...
|
||||
* @brief Get a color value started with a "named" converted in unsigned 8 bits integer like red, green ...
|
||||
* @param[in] _input String to parse
|
||||
* @return Value parsed
|
||||
*/
|
||||
etk::Color<uint8_t, 4> parseStringColorNamed(const std::string& _input);
|
||||
|
||||
/**
|
||||
* @brief Specify that the Get intance is specialized for uint8_t/4 template
|
||||
* @return unsignad iterger containing the color value in RGBA
|
||||
* @brief Specify that the Get instance is specialized for unsigned 8 bits integer on RGBA template
|
||||
* @return unsigned integer containing the color value in RGBA
|
||||
* @internal
|
||||
*/
|
||||
template<> uint32_t Color<uint8_t, 4>::get() const;
|
||||
@ -506,20 +506,20 @@ namespace etk {
|
||||
|
||||
//! @not_in_doc
|
||||
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<uint8_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
|
||||
std::ostringstream oss;
|
||||
std::ostringstream os;
|
||||
if (MY_TYPE_SIZE >= 3) {
|
||||
_os << "#";
|
||||
oss << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.r());
|
||||
os << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.r());
|
||||
if (MY_TYPE_SIZE >= 2) {
|
||||
oss << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.g());
|
||||
os << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.g());
|
||||
}
|
||||
if (MY_TYPE_SIZE >= 3) {
|
||||
oss << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.b());
|
||||
os << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.b());
|
||||
}
|
||||
if (MY_TYPE_SIZE >= 4) {
|
||||
oss << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.a());
|
||||
os << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.a());
|
||||
}
|
||||
_os << oss.str();
|
||||
_os << os.str();
|
||||
} else {
|
||||
if (MY_TYPE_SIZE >= 2) {
|
||||
_os << "be";
|
||||
@ -527,19 +527,19 @@ namespace etk {
|
||||
_os << "Mono";
|
||||
}
|
||||
_os << "[U8](";
|
||||
oss << "0x" << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.r());
|
||||
os << "0x" << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.r());
|
||||
if (MY_TYPE_SIZE >= 2) {
|
||||
_os << ",";
|
||||
oss << "0x" << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.g());
|
||||
os << "0x" << std::setw(2) << std::setfill('0') << std::hex << uint32_t(_obj.g());
|
||||
}
|
||||
_os << oss.str();
|
||||
_os << os.str();
|
||||
_os << ")";
|
||||
}
|
||||
return _os;
|
||||
}
|
||||
//! @not_in_doc
|
||||
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<uint16_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
|
||||
std::ostringstream oss;
|
||||
std::ostringstream os;
|
||||
if (MY_TYPE_SIZE >= 4) {
|
||||
_os << "rgba";
|
||||
} else if (MY_TYPE_SIZE >= 3) {
|
||||
@ -550,22 +550,22 @@ namespace etk {
|
||||
_os << "Mono";
|
||||
}
|
||||
_os << "[U16](";
|
||||
oss << "0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.r();
|
||||
os << "0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.r();
|
||||
if (MY_TYPE_SIZE >= 2) {
|
||||
oss << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.g();
|
||||
os << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.g();
|
||||
}
|
||||
if (MY_TYPE_SIZE >= 3) {
|
||||
oss << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.b();
|
||||
os << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.b();
|
||||
}
|
||||
if (MY_TYPE_SIZE >= 4) {
|
||||
oss << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.a();
|
||||
os << ",0x" << std::setw(4) << std::setfill('0') << std::hex << _obj.a();
|
||||
}
|
||||
_os << oss.str() << ")";
|
||||
_os << os.str() << ")";
|
||||
return _os;
|
||||
}
|
||||
//! @not_in_doc
|
||||
template<int MY_TYPE_SIZE> std::ostream& operator <<(std::ostream& _os, const Color<uint32_t, MY_TYPE_SIZE>& _obj) { // RGB & RGBA 8 bits
|
||||
std::ostringstream oss;
|
||||
std::ostringstream os;
|
||||
if (MY_TYPE_SIZE >= 4) {
|
||||
_os << "rgba";
|
||||
} else if (MY_TYPE_SIZE >= 3) {
|
||||
@ -576,17 +576,17 @@ namespace etk {
|
||||
_os << "Mono";
|
||||
}
|
||||
_os << "[U32](";
|
||||
oss << "0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.r();
|
||||
os << "0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.r();
|
||||
if (MY_TYPE_SIZE >= 2) {
|
||||
oss << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.g();
|
||||
os << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.g();
|
||||
}
|
||||
if (MY_TYPE_SIZE >= 3) {
|
||||
oss << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.b();
|
||||
os << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.b();
|
||||
}
|
||||
if (MY_TYPE_SIZE >= 4) {
|
||||
oss << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.a();
|
||||
os << ",0x" << std::setw(8) << std::setfill('0') << std::hex << _obj.a();
|
||||
}
|
||||
_os << oss.str() << ")";
|
||||
_os << os.str() << ")";
|
||||
return _os;
|
||||
}
|
||||
//! @not_in_doc
|
||||
|
28
etk/Hash.hpp
28
etk/Hash.hpp
@ -10,7 +10,7 @@
|
||||
|
||||
namespace etk {
|
||||
/**
|
||||
* @brief internel data of the [class[etk::hash]] class, it contain
|
||||
* @brief Internal data of the [class[etk::hash]] class, it contain
|
||||
* the name and the value of the hash vector.
|
||||
* @internal
|
||||
*/
|
||||
@ -30,17 +30,17 @@ namespace etk {
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @brief Hash table tamplate is a simple classical hash interface.
|
||||
* @brief Hash table template is a simple classical hash interface.
|
||||
* A hash table is a equivalent of the dictionary in python, this is a
|
||||
* simple interfaace between a name and a value:
|
||||
* simple interface between a name and a value:
|
||||
* - "name" : 19
|
||||
* - "name 2" : 99
|
||||
*
|
||||
* @note The name is unique and the value is what you want
|
||||
*
|
||||
* @todo check if something ele exist in the STD. (not the std::map and the std::unordered_map
|
||||
* @todo check if something else exist in the generic library. (not the std::map and the std::unordered_map
|
||||
*
|
||||
* @note The index are all time availlable since they are created. The order is the the one created
|
||||
* @note The index are all time available since they are created. The order is the the one created
|
||||
*
|
||||
* A simple example of use:
|
||||
* @code{.cpp}
|
||||
@ -61,18 +61,18 @@ namespace etk {
|
||||
*/
|
||||
template<class MY_TYPE> class Hash {
|
||||
private:
|
||||
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 ...
|
||||
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 vector ...
|
||||
public:
|
||||
/**
|
||||
* @brief Contructor of the Hach table.
|
||||
* @param[in] _count Number ob basic elent in the vector.
|
||||
* @brief Constructor of the Hash table.
|
||||
* @param[in] _count Number of basic element in the table.
|
||||
*/
|
||||
Hash(int32_t _count = 0) :
|
||||
m_data(_count) {
|
||||
// nothing to do
|
||||
}
|
||||
/**
|
||||
* @brief Destructor of the Hash table(clear all element in the table)
|
||||
* @brief Destructor of the Hash table (clear all element in the table)
|
||||
*/
|
||||
~Hash() {
|
||||
clear();
|
||||
@ -131,7 +131,7 @@ namespace etk {
|
||||
static MY_TYPE g_error;
|
||||
int64_t elementId = getId(_key);
|
||||
if (elementId<0) {
|
||||
//TK_ERROR("try to acces at an unexistant hash element : " << _key);
|
||||
//TK_ERROR("try to access at an inexistent hash element : " << _key);
|
||||
return g_error;
|
||||
}
|
||||
return m_data[elementId]->m_value;
|
||||
@ -228,7 +228,7 @@ namespace etk {
|
||||
// NOTE :Do not change log level, this generate error only in debug mode
|
||||
#if DEBUG_LEVEL > 2
|
||||
if(_pos>m_data.size()){
|
||||
//TK_CRITICAL("Access to an unexistant data in hach : " << _pos << "/ " << m_data.size());
|
||||
//TK_CRITICAL("Access to an inexistent data in hash : " << _pos << "/ " << m_data.size());
|
||||
}
|
||||
#endif
|
||||
return m_data[_pos]->m_key;
|
||||
@ -249,13 +249,13 @@ namespace etk {
|
||||
/**
|
||||
* @brief Get a value of the hash table at a specific position.
|
||||
* @param[in] _pos of the element in the hash table.
|
||||
* @return Value availlable at this position.
|
||||
* @return Value available at this position.
|
||||
*/
|
||||
const MY_TYPE& getValue(size_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()){
|
||||
//TK_CRITICAL("Access to an unexistant data in hach : " << _pos << "/ " << m_data.size());
|
||||
//TK_CRITICAL("Access to an inexistent data in hash : " << _pos << "/ " << m_data.size());
|
||||
}
|
||||
#endif
|
||||
return m_data[_pos]->m_value;
|
||||
@ -267,7 +267,7 @@ namespace etk {
|
||||
// NOTE :Do not change log level, this generate error only in debug mode
|
||||
#if DEBUG_LEVEL > 2
|
||||
if(_pos>m_data.size()){
|
||||
//TK_CRITICAL("Access to an unexistant data in hach : " << _pos << "/ " << m_data.size());
|
||||
//TK_CRITICAL("Access to an inexistent data in hash : " << _pos << "/ " << m_data.size());
|
||||
}
|
||||
#endif
|
||||
return m_data[_pos]->m_value;
|
||||
|
@ -25,7 +25,7 @@ etk::BaseNoise::BaseNoise(const ivec2& _size, float _min, float _max) :
|
||||
}
|
||||
|
||||
float etk::BaseNoise::get(int32_t _x, int32_t _y) const {
|
||||
// We increment of the size to prevent the <0 result due to the "%" methode ...
|
||||
// We increment of the size to prevent the <0 result due to the "%" method ...
|
||||
_x += m_size.x();
|
||||
_y += m_size.y();
|
||||
_x %= m_size.x();
|
||||
@ -35,8 +35,8 @@ float etk::BaseNoise::get(int32_t _x, int32_t _y) const {
|
||||
|
||||
float etk::Noise::smoothNoise(float _x, float _y, const etk::BaseNoise& _noise) {
|
||||
//get fractional part of x and y
|
||||
float fractX = _x - (int32_t)_x;
|
||||
float fractY = _y - (int32_t)_y;
|
||||
float fractionX = _x - (int32_t)_x;
|
||||
float fractionY = _y - (int32_t)_y;
|
||||
|
||||
//wrap around
|
||||
int32_t x1 = (int32_t)_x;
|
||||
@ -48,10 +48,10 @@ float etk::Noise::smoothNoise(float _x, float _y, const etk::BaseNoise& _noise)
|
||||
|
||||
//smooth the noise with bilinear interpolation
|
||||
float value = 0.0f;
|
||||
value += fractX * fractY * _noise.get(x1,y1);
|
||||
value += fractX * (1 - fractY) * _noise.get(x1,y2);
|
||||
value += (1 - fractX) * fractY * _noise.get(x2,y1);
|
||||
value += (1 - fractX) * (1 - fractY) * _noise.get(x2,y2);
|
||||
value += fractionX * fractionY * _noise.get(x1,y1);
|
||||
value += fractionX * (1 - fractionY) * _noise.get(x1,y2);
|
||||
value += (1 - fractionX) * fractionY * _noise.get(x2,y1);
|
||||
value += (1 - fractionX) * (1 - fractionY) * _noise.get(x2,y2);
|
||||
|
||||
return value;
|
||||
}
|
||||
@ -142,7 +142,7 @@ etk::Noise::Noise(enum etk::noiseType _type, ivec2 _size, int32_t _depth) :
|
||||
|
||||
float etk::Noise::get(int32_t _x, int32_t _y) const
|
||||
{
|
||||
// We increment of the size to prevent the <0 result due to the "%" methode ...
|
||||
// We increment of the size to prevent the <0 result due to the "%" method ...
|
||||
_x += m_size.x();
|
||||
_y += m_size.y();
|
||||
_x %= m_size.x();
|
||||
|
@ -22,7 +22,7 @@ namespace etk {
|
||||
ivec2 m_size; //!< Size of the noise data
|
||||
public:
|
||||
/**
|
||||
* @brief basic constructor with randon settings
|
||||
* @brief Basic constructor with random settings.
|
||||
* @param[in] _size Size of the basic noise
|
||||
* @param[in] _min Minimum value of the random
|
||||
* @param[in] _max Maximum value of the random
|
||||
@ -68,7 +68,7 @@ namespace etk {
|
||||
*/
|
||||
float smoothNoise(float _x, float _y, const etk::BaseNoise& _noise);
|
||||
/**
|
||||
* @brief Calculate the Tubulence noise at a specific position
|
||||
* @brief Calculate the turbulence noise at a specific position
|
||||
* @param[in] _x X position
|
||||
* @param[in] _y Y position
|
||||
* @param[in] _size Turbulence ratio value
|
||||
@ -77,7 +77,7 @@ namespace etk {
|
||||
*/
|
||||
float turbulence(float _x, float _y, float _size, const etk::BaseNoise& _noise);
|
||||
/**
|
||||
* @brief Calculate the Tubulence Not Smooth noise at a specific position
|
||||
* @brief Calculate the turbulence Not Smooth noise at a specific position
|
||||
* @param[in] _x X position
|
||||
* @param[in] _y Y position
|
||||
* @param[in] _size Turbulence ratio value
|
||||
@ -87,7 +87,7 @@ namespace etk {
|
||||
float turbulenceNoSmooth(float _x, float _y, float _size, const etk::BaseNoise& _noise);
|
||||
public:
|
||||
/**
|
||||
* @brief Contructor of a noise specific
|
||||
* @brief Constructor of a noise specific
|
||||
* @param[in] _type Type of noise
|
||||
* @param[in] _size Size of the image output
|
||||
* @param[in] _depth Depth calculation
|
||||
|
487
etk/RegEx.cpp
Normal file
487
etk/RegEx.cpp
Normal file
@ -0,0 +1,487 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <etk/RegEx.hpp>
|
||||
|
||||
const struct etk::conversionTable etk::regex::constConversionTable[] = {
|
||||
// haveBackSlash, inputValue, newValue
|
||||
{ false , '(' , 0 , etk::regexOpcodePTheseIn},
|
||||
{ true , '(' , '(' , etk::regexOpcodeError},
|
||||
{ false , ')' , 0 , etk::regexOpcodePTheseOut},
|
||||
{ true , ')' , ')' , etk::regexOpcodeError},
|
||||
{ false , '[' , 0 , etk::regexOpcodeBracketIn},
|
||||
{ true , '[' , '[' , etk::regexOpcodeError},
|
||||
{ false , ']' , 0 , etk::regexOpcodeBracketOut},
|
||||
{ true , ']' , ']' , etk::regexOpcodeError},
|
||||
{ false , '{' , 0 , etk::regexOpcodeBraceIn},
|
||||
{ true , '{' , '{' , etk::regexOpcodeError},
|
||||
{ false , '}' , 0 , etk::regexOpcodeBraceOut},
|
||||
{ true , '}' , '}' , etk::regexOpcodeError},
|
||||
{ false , '-' , 0 , etk::regexOpcodeTo},
|
||||
{ true , '-' , '-' , etk::regexOpcodeError},
|
||||
{ false , '*' , 0 , etk::regexOpcodeStar},
|
||||
{ true , '*' , '*' , etk::regexOpcodeError},
|
||||
{ false , '.' , 0 , etk::regexOpcodeDot},
|
||||
{ true , '.' , '.' , etk::regexOpcodeError},
|
||||
{ true , 'e' , 0 , etk::regexOpcodeEOF},
|
||||
{ false , 'e' , 'e' , etk::regexOpcodeError},
|
||||
{ false , '?' , 0 , etk::regexOpcodeQuestion},
|
||||
{ true , '?' , '?' , etk::regexOpcodeError},
|
||||
{ false , '+' , 0 , etk::regexOpcodePlus},
|
||||
{ true , '+' , '+' , etk::regexOpcodeError},
|
||||
{ false , '|' , 0 , etk::regexOpcodePipe},
|
||||
{ true , '|' , '|' , etk::regexOpcodeError},
|
||||
{ false , '^' , 0 , etk::regexOpcodeStartOfLine},
|
||||
{ true , '^' , '^' , etk::regexOpcodeError},
|
||||
{ false , '$' , 0 , etk::regexOpcodeEndOfLine},
|
||||
{ true , '$' , '$' , etk::regexOpcodeError},
|
||||
{ true , 'd' , 0 , etk::regexOpcodeDigit},
|
||||
{ true , 'D' , 0 , etk::regexOpcodeDigitNot},
|
||||
{ true , 'l' , 0 , etk::regexOpcodeLetter},
|
||||
{ true , 'L' , 0 , etk::regexOpcodeLetterNot},
|
||||
{ true , 's' , 0 , etk::regexOpcodeSpace},
|
||||
{ true , 'S' , 0 , etk::regexOpcodeSpaceNot},
|
||||
{ true , 'w' , 0 , etk::regexOpcodeWord},
|
||||
{ true , 'W' , 0 , etk::regexOpcodeWordNot},
|
||||
{ true , 'a' , '\a', etk::regexOpcodeError},
|
||||
{ true , 'b' , '\b', etk::regexOpcodeError},
|
||||
{ true , 'e' , 0x1B, etk::regexOpcodeError}, // Escape character <Esc>
|
||||
{ true , 'f' , '\f', etk::regexOpcodeError},
|
||||
{ true , 'n' , '\n', etk::regexOpcodeError},
|
||||
{ true , 'r' , '\r', etk::regexOpcodeError},
|
||||
{ true , 't' , '\t', etk::regexOpcodeError},
|
||||
{ true , 'v' , '\v', etk::regexOpcodeError},
|
||||
{ true , '\\' , '\\', etk::regexOpcodeError},
|
||||
{ true , '&' , '&' , etk::regexOpcodeError},
|
||||
{ true , '0' , '\0', etk::regexOpcodeError},
|
||||
{ true , '@' , 0 , etk::regexOpcodeNoChar},
|
||||
};
|
||||
const int64_t etk::regex::constConversionTableSize = sizeof(etk::regex::constConversionTable) / sizeof(struct etk::conversionTable) ;
|
||||
|
||||
static const char* parseStatusTable[] = {
|
||||
"parseStatusUnknown",
|
||||
"parseStatusNone",
|
||||
"parseStatusPartial",
|
||||
"parseStatusFull"
|
||||
};
|
||||
std::ostream& etk::regex::operator <<(std::ostream& _os, enum etk::regex::parseStatus _obj) {
|
||||
_os << parseStatusTable[_obj];
|
||||
return _os;
|
||||
}
|
||||
std::ostream& etk::regex::operator <<(std::ostream& _os, const etk::regex::FindProperty& _obj) {
|
||||
_os << "property([" << _obj.getPositionStart() << "," << _obj.getPositionStop() << "]*" << _obj.getMultiplicity() << " " << _obj.getStatus() << ")";
|
||||
return _os;
|
||||
}
|
||||
|
||||
std::string etk::regex::createString(const std::vector<char32_t>& _data, int64_t _start, int64_t _stop) {
|
||||
std::string output(ETK_BASH_COLOR_NORMAL);
|
||||
for (int64_t iii=_start; iii<(int64_t)_data.size() && iii<_stop ; iii++) {
|
||||
switch(_data[iii]) {
|
||||
case regexOpcodePTheseIn: output += std::string(ETK_BASH_COLOR_RED) + (char*)"(" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodePTheseOut: output += std::string(ETK_BASH_COLOR_RED) + (char*)")" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeBracketIn: output += std::string(ETK_BASH_COLOR_YELLOW) + (char*)"[" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeBracketOut: output += std::string(ETK_BASH_COLOR_YELLOW) + (char*)"]" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeTo: output += std::string(ETK_BASH_COLOR_YELLOW) + (char*)"-" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeBraceIn: output += std::string(ETK_BASH_COLOR_GREEN) + (char*)"{" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeBraceOut: output += std::string(ETK_BASH_COLOR_GREEN) + (char*)"}" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeStar: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"*" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeDot: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"." + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeQuestion: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"?" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodePlus: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"+" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodePipe: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"|" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeNoChar: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"@" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeStartOfLine: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"^" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeEndOfLine: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"$" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeDigit: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\d" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeDigitNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\D" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeLetter: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\l" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeLetterNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\L" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeSpace: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\s" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeSpaceNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\S" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeWord: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\w" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeWordNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\W" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexOpcodeEOF: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\e" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case '\n': output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\n" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case '\t': output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\t" + ETK_BASH_COLOR_NORMAL; break;
|
||||
default:
|
||||
char plop[10];
|
||||
int8_t nb = u32char::convertUtf8(_data[iii], plop);
|
||||
plop[nb] = '\0';
|
||||
output += plop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
char* etk::regex::levelSpace(uint32_t _level) {
|
||||
static char* tmpSpace = " ";
|
||||
if (_level>30) {
|
||||
return tmpSpace;
|
||||
}
|
||||
return tmpSpace + 60 - 2*_level;
|
||||
}
|
||||
|
||||
|
||||
int64_t etk::regex::getLenOfPTheseElement(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
if (_startPos>=(int64_t)_data.size()){
|
||||
return 0;
|
||||
}
|
||||
int64_t pos = _startPos;
|
||||
int32_t nbOpen = 0;
|
||||
// special case of the (...) or | ==> we search '|' or ')'
|
||||
if( _data[pos] == regexOpcodePTheseOut
|
||||
|| _data[pos] == regexOpcodePipe) {
|
||||
return 0;
|
||||
}
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
if(_data[pos] == regexOpcodePTheseIn) {
|
||||
// find a sub section :
|
||||
nbOpen++;
|
||||
} else if(0 < nbOpen) {
|
||||
if (_data[pos] == regexOpcodePTheseOut) {
|
||||
nbOpen--;
|
||||
if (0 > nbOpen) {
|
||||
TK_ERROR("Error in the (...) find element at "<< pos);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else if( _data[pos] == regexOpcodePTheseOut
|
||||
|| _data[pos] == regexOpcodePipe) {
|
||||
// Find the end of the (...)
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the (...) no data at "<< pos-1);
|
||||
return 0;
|
||||
}
|
||||
return sizeInside;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return pos - _startPos;
|
||||
}
|
||||
|
||||
int64_t etk::regex::getLenOfPThese(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
int64_t pos = _startPos;
|
||||
int32_t nbOpen = 0;
|
||||
// special case of the (...) or | ==> we search '|' or ')'
|
||||
if(_data[pos]==regexOpcodePTheseOut) {
|
||||
return 0;
|
||||
}
|
||||
if(_data[pos]!=regexOpcodePTheseIn) {
|
||||
TK_ERROR(" find error in PThese");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
if(_data[pos]==regexOpcodePTheseIn) {
|
||||
// find a sub section :
|
||||
nbOpen++;
|
||||
} else if(0 < nbOpen) {
|
||||
if (_data[pos]==regexOpcodePTheseOut) {
|
||||
nbOpen--;
|
||||
if (0 > nbOpen) {
|
||||
TK_ERROR("Error in the (...) find element at "<< pos);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if(_data[pos]==regexOpcodePTheseOut) {
|
||||
// Find the end of the (...)
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos-1;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the (...) no data at "<< pos-1);
|
||||
return 0;
|
||||
}
|
||||
return sizeInside;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int64_t etk::regex::getLenOfBracket(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
int64_t pos = _startPos;
|
||||
// special case of the (...) or | ==> we search '|' or ')'
|
||||
if(_data[pos]==regexOpcodeBracketOut) {
|
||||
return 0;
|
||||
}
|
||||
if(_data[pos] != regexOpcodeBracketIn) {
|
||||
TK_ERROR("find no [...");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
if(_data[pos] == regexOpcodeBracketOut) {
|
||||
// Find the end of the [...]
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos -1 ;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the [...] no data at "<< pos-1);
|
||||
return 0;
|
||||
}
|
||||
return sizeInside;
|
||||
} else if ( _data[pos] == regexOpcodeStartOfLine
|
||||
|| _data[pos] == regexOpcodeDigit
|
||||
|| _data[pos] == regexOpcodeLetter
|
||||
|| _data[pos] == regexOpcodeSpace
|
||||
|| _data[pos] == regexOpcodeWord
|
||||
|| _data[pos] == regexOpcodeTo) {
|
||||
// nothing to do ... it is permitted
|
||||
} else if(_data[pos] > 0xFF ) {
|
||||
std::string displayElement;
|
||||
if (_data[pos] == regexOpcodeStartOfLine) {
|
||||
displayElement = "^";
|
||||
} else if (_data[pos] == regexOpcodeDigitNot) {
|
||||
displayElement = "\\D";
|
||||
} else if (_data[pos] == regexOpcodeLetterNot) {
|
||||
displayElement = "\\L";
|
||||
} else if (_data[pos] == regexOpcodeSpaceNot) {
|
||||
displayElement = "\\S";
|
||||
} else if (_data[pos] == regexOpcodeWordNot) {
|
||||
displayElement = "\\W";
|
||||
} else {
|
||||
displayElement = (char)_data[pos];
|
||||
}
|
||||
TK_ERROR("Error in the [...] not permitted element at "<< pos << " '" << displayElement << "'");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int64_t etk::regex::getLenOfBrace(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
int32_t pos = _startPos;
|
||||
// special case of the (...) or | ==> we search '|' or ')'
|
||||
if(_data[pos]==regexOpcodeBraceOut) {
|
||||
return 0;
|
||||
}
|
||||
if(_data[pos]!=regexOpcodeBraceIn) {
|
||||
TK_ERROR(" did not find brace IN { ");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
if(_data[pos]==regexOpcodeBraceOut) {
|
||||
// Find the end of the [...]
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos -1 ;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the {...} no data at "<< pos-1);
|
||||
return 0;
|
||||
}
|
||||
return sizeInside;
|
||||
} else if( _data[pos] != ','
|
||||
&& ( _data[pos] < '0'
|
||||
|| _data[pos] > '9') ) {
|
||||
TK_ERROR("Error in the {...} not permitted element at "<< pos << " '" << _data[pos] << "'");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int64_t etk::regex::getLenOfNormal(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
int64_t pos = _startPos;
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
switch(_data[pos]) {
|
||||
case regexOpcodePTheseIn:
|
||||
case regexOpcodePTheseOut:
|
||||
case regexOpcodeBracketIn:
|
||||
case regexOpcodeBracketOut:
|
||||
case regexOpcodeBraceIn:
|
||||
case regexOpcodeBraceOut:
|
||||
case regexOpcodeTo:
|
||||
case regexOpcodeStar:
|
||||
case regexOpcodeDot:
|
||||
case regexOpcodeQuestion:
|
||||
case regexOpcodePlus:
|
||||
case regexOpcodePipe:
|
||||
case regexOpcodeStartOfLine:
|
||||
case regexOpcodeEndOfLine:
|
||||
case regexOpcodeDigit:
|
||||
case regexOpcodeDigitNot:
|
||||
case regexOpcodeLetter:
|
||||
case regexOpcodeLetterNot:
|
||||
case regexOpcodeSpace:
|
||||
case regexOpcodeSpaceNot:
|
||||
case regexOpcodeWord:
|
||||
case regexOpcodeWordNot:
|
||||
{
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the normal data : no data ...");
|
||||
}
|
||||
return sizeInside;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
// nothing to do ...
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
if ((int64_t)pos - (int64_t)_startPos < 0) {
|
||||
return 0;
|
||||
}
|
||||
return pos - _startPos ;
|
||||
}
|
||||
|
||||
|
||||
bool etk::regex::parseBrace(const std::vector<char32_t>& _data, uint32_t& _min, uint32_t& _max) {
|
||||
int64_t k=0;
|
||||
int32_t firstElement = 0;
|
||||
int32_t SecondElement = 0;
|
||||
while(k < (int64_t)_data.size()) {
|
||||
if (_data[k] == ',') {
|
||||
k++;
|
||||
break;
|
||||
} if (_data[k] == '}' ) {
|
||||
SecondElement = firstElement;
|
||||
goto allIsSet;
|
||||
} else if(u32char::isInteger(_data[k]) == true) {
|
||||
firstElement *= 10;
|
||||
firstElement += u32char::toInt(_data[k]);
|
||||
} else {
|
||||
TK_ERROR("Can not parse this element " << (char)_data[k] << " at pos " << k);
|
||||
return false;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
if (k == (int64_t)_data.size()) {
|
||||
SecondElement = firstElement;
|
||||
}
|
||||
while(k < (int64_t)_data.size()) {
|
||||
if (_data[k] == ',') {
|
||||
TK_ERROR("Can not find a second , in {} at pos " << k);
|
||||
return false;
|
||||
} if (_data[k] == '}') {
|
||||
goto allIsSet;
|
||||
} else if (true == u32char::isInteger(_data[k])) {
|
||||
SecondElement *= 10;
|
||||
SecondElement += u32char::toInt(_data[k]);
|
||||
} else {
|
||||
TK_ERROR("Can not parse this element " << _data[k] << " at pos " << k);
|
||||
return false;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
|
||||
allIsSet:
|
||||
if (SecondElement == 0 && firstElement != 0) {
|
||||
_min = 0;
|
||||
_max = firstElement;
|
||||
} else {
|
||||
_min = firstElement;
|
||||
_max = SecondElement;
|
||||
}
|
||||
if (_min > _max) {
|
||||
TK_ERROR("Minimum=" << _min << " can not be < maximum=" << _max );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string etk::regex::autoStr(const std::string& _data) {
|
||||
std::string out;
|
||||
for (auto &it : _data) {
|
||||
if (it == '\n') {
|
||||
out += "\\n";
|
||||
} else if (it == '\t') {
|
||||
out += "\\t";
|
||||
} else if (it == '\r') {
|
||||
out += "\\r";
|
||||
} else if (it == '\0') {
|
||||
out += "\\0";
|
||||
} else if (it == ' ') {
|
||||
out += " ";
|
||||
} else if (it <= 0x20) {
|
||||
out += std::to_string((int32_t)it);
|
||||
} else {
|
||||
out += it;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
std::string etk::regex::autoStr(char _data) {
|
||||
std::string out;
|
||||
if (_data == '\n') {
|
||||
out += "\\n";
|
||||
} else if (_data == '\t') {
|
||||
out += "\\t";
|
||||
} else if (_data == '\r') {
|
||||
out += "\\r";
|
||||
} else if (_data == '\0') {
|
||||
out += "\\0";
|
||||
} else if (_data == ' ') {
|
||||
out += " ";
|
||||
} else if (_data <= 0x20) {
|
||||
out += std::to_string((int32_t)_data);
|
||||
} else {
|
||||
out += _data;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string etk::regex::strTick(int32_t _pos) {
|
||||
std::string out;
|
||||
for (int32_t iii=0; iii<_pos; ++iii) {
|
||||
out += " ";
|
||||
}
|
||||
out += "^";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<etk::RegEx<std::string>>(const etk::RegEx<std::string>& _val) {
|
||||
return _val.getRegEx();
|
||||
}
|
||||
template<> std::string to_string<etk::RegEx<std::u32string>>(const etk::RegEx<std::u32string>& _val) {
|
||||
return _val.getRegEx();
|
||||
}
|
||||
template<> std::u32string to_u32string<etk::RegEx<std::string>>(const etk::RegEx<std::string>& _val) {
|
||||
return _val.getURegEx();
|
||||
}
|
||||
template<> std::u32string to_u32string<etk::RegEx<std::u32string>>(const etk::RegEx<std::u32string>& _val) {
|
||||
return _val.getURegEx();
|
||||
}
|
||||
|
||||
template<> bool from_string<etk::RegEx<std::string>>(etk::RegEx<std::string>& _variableRet, const std::u32string& _value) {
|
||||
_variableRet.compile(_value);
|
||||
return true;
|
||||
}
|
||||
template<> bool from_string<etk::RegEx<std::u32string>>(etk::RegEx<std::u32string>& _variableRet, const std::u32string& _value) {
|
||||
_variableRet.compile(_value);
|
||||
return true;
|
||||
}
|
||||
template<> bool from_string<etk::RegEx<std::string>>(etk::RegEx<std::string>& _variableRet, const std::string& _value) {
|
||||
_variableRet.compile(_value);
|
||||
return true;
|
||||
}
|
||||
template<> bool from_string<etk::RegEx<std::u32string>>(etk::RegEx<std::u32string>& _variableRet, const std::string& _value) {
|
||||
_variableRet.compile(_value);
|
||||
return true;
|
||||
}
|
||||
};
|
File diff suppressed because it is too large
Load Diff
490
etk/RegExp.cpp
490
etk/RegExp.cpp
@ -1,490 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <etk/RegExp.hpp>
|
||||
|
||||
const struct etk::convertionTable etk::regexp::constConvertionTable[] = {
|
||||
// haveBackSlash, inputValue, newValue
|
||||
{ false , '(' , 0 , etk::regexpOpcodePTheseIn},
|
||||
{ true , '(' , '(' , etk::regexpOpcodeError},
|
||||
{ false , ')' , 0 , etk::regexpOpcodePTheseOut},
|
||||
{ true , ')' , ')' , etk::regexpOpcodeError},
|
||||
{ false , '[' , 0 , etk::regexpOpcodeBracketIn},
|
||||
{ true , '[' , '[' , etk::regexpOpcodeError},
|
||||
{ false , ']' , 0 , etk::regexpOpcodeBracketOut},
|
||||
{ true , ']' , ']' , etk::regexpOpcodeError},
|
||||
{ false , '{' , 0 , etk::regexpOpcodeBracetIn},
|
||||
{ true , '{' , '{' , etk::regexpOpcodeError},
|
||||
{ false , '}' , 0 , etk::regexpOpcodeBracetOut},
|
||||
{ true , '}' , '}' , etk::regexpOpcodeError},
|
||||
{ false , '-' , 0 , etk::regexpOpcodeTo},
|
||||
{ true , '-' , '-' , etk::regexpOpcodeError},
|
||||
{ false , '*' , 0 , etk::regexpOpcodeStar},
|
||||
{ true , '*' , '*' , etk::regexpOpcodeError},
|
||||
{ false , '.' , 0 , etk::regexpOpcodeDot},
|
||||
{ true , '.' , '.' , etk::regexpOpcodeError},
|
||||
{ true , 'e' , 0 , etk::regexpOpcodeEOF},
|
||||
{ false , 'e' , 'e' , etk::regexpOpcodeError},
|
||||
{ false , '?' , 0 , etk::regexpOpcodeQuestion},
|
||||
{ true , '?' , '?' , etk::regexpOpcodeError},
|
||||
{ false , '+' , 0 , etk::regexpOpcodePlus},
|
||||
{ true , '+' , '+' , etk::regexpOpcodeError},
|
||||
{ false , '|' , 0 , etk::regexpOpcodePipe},
|
||||
{ true , '|' , '|' , etk::regexpOpcodeError},
|
||||
{ false , '^' , 0 , etk::regexpOpcodeStartOfLine},
|
||||
{ true , '^' , '^' , etk::regexpOpcodeError},
|
||||
{ false , '$' , 0 , etk::regexpOpcodeEndOfLine},
|
||||
{ true , '$' , '$' , etk::regexpOpcodeError},
|
||||
{ true , 'd' , 0 , etk::regexpOpcodeDigit},
|
||||
{ true , 'D' , 0 , etk::regexpOpcodeDigitNot},
|
||||
{ true , 'l' , 0 , etk::regexpOpcodeLetter},
|
||||
{ true , 'L' , 0 , etk::regexpOpcodeLetterNot},
|
||||
{ true , 's' , 0 , etk::regexpOpcodeSpace},
|
||||
{ true , 'S' , 0 , etk::regexpOpcodeSpaceNot},
|
||||
{ true , 'w' , 0 , etk::regexpOpcodeWord},
|
||||
{ true , 'W' , 0 , etk::regexpOpcodeWordNot},
|
||||
{ true , 'a' , '\a', etk::regexpOpcodeError},
|
||||
{ true , 'b' , '\b', etk::regexpOpcodeError},
|
||||
{ true , 'e' , 0x1B, etk::regexpOpcodeError}, // Escape character <Esc>
|
||||
{ true , 'f' , '\f', etk::regexpOpcodeError},
|
||||
{ true , 'n' , '\n', etk::regexpOpcodeError},
|
||||
{ true , 'r' , '\r', etk::regexpOpcodeError},
|
||||
{ true , 't' , '\t', etk::regexpOpcodeError},
|
||||
{ true , 'v' , '\v', etk::regexpOpcodeError},
|
||||
{ true , '\\' , '\\', etk::regexpOpcodeError},
|
||||
{ true , '&' , '&' , etk::regexpOpcodeError},
|
||||
{ true , '0' , '\0', etk::regexpOpcodeError},
|
||||
{ true , '@' , 0 , etk::regexpOpcodeNoChar},
|
||||
};
|
||||
const int64_t etk::regexp::constConvertionTableSize = sizeof(etk::regexp::constConvertionTable) / sizeof(struct etk::convertionTable) ;
|
||||
|
||||
static const char* parseStatusTable[] = {
|
||||
"parseStatusUnknow",
|
||||
"parseStatusNone",
|
||||
"parseStatusPartial",
|
||||
"parseStatusFull"
|
||||
};
|
||||
std::ostream& etk::regexp::operator <<(std::ostream& _os, enum etk::regexp::parseStatus _obj) {
|
||||
_os << parseStatusTable[_obj];
|
||||
return _os;
|
||||
}
|
||||
std::ostream& etk::regexp::operator <<(std::ostream& _os, const etk::regexp::FindProperty& _obj) {
|
||||
_os << "property([" << _obj.getPositionStart() << "," << _obj.getPositionStop() << "]*" << _obj.getMultiplicity() << " " << _obj.getStatus() << ")";
|
||||
return _os;
|
||||
}
|
||||
|
||||
std::string etk::regexp::createString(const std::vector<char32_t>& _data, int64_t _start, int64_t _stop) {
|
||||
std::string output(ETK_BASH_COLOR_NORMAL);
|
||||
for (int64_t iii=_start; iii<(int64_t)_data.size() && iii<_stop ; iii++) {
|
||||
switch(_data[iii]) {
|
||||
case regexpOpcodePTheseIn: output += std::string(ETK_BASH_COLOR_RED) + (char*)"(" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodePTheseOut: output += std::string(ETK_BASH_COLOR_RED) + (char*)")" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeBracketIn: output += std::string(ETK_BASH_COLOR_YELLOW) + (char*)"[" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeBracketOut: output += std::string(ETK_BASH_COLOR_YELLOW) + (char*)"]" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeTo: output += std::string(ETK_BASH_COLOR_YELLOW) + (char*)"-" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeBracetIn: output += std::string(ETK_BASH_COLOR_GREEN) + (char*)"{" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeBracetOut: output += std::string(ETK_BASH_COLOR_GREEN) + (char*)"}" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeStar: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"*" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeDot: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"." + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeQuestion: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"?" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodePlus: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"+" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodePipe: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"|" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeNoChar: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"@" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeStartOfLine: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"^" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeEndOfLine: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"$" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeDigit: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\d" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeDigitNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\D" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeLetter: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\l" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeLetterNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\L" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeSpace: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\s" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeSpaceNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\S" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeWord: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\w" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeWordNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\W" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case regexpOpcodeEOF: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\e" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case '\n': output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\n" + ETK_BASH_COLOR_NORMAL; break;
|
||||
case '\t': output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\t" + ETK_BASH_COLOR_NORMAL; break;
|
||||
default:
|
||||
char plop[10];
|
||||
int8_t nb = u32char::convertUtf8(_data[iii], plop);
|
||||
plop[nb] = '\0';
|
||||
output += plop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
char* etk::regexp::levelSpace(uint32_t _level) {
|
||||
static char* tmpSpace = " ";
|
||||
if (_level>30) {
|
||||
return tmpSpace;
|
||||
}
|
||||
return tmpSpace + 60 - 2*_level;
|
||||
}
|
||||
|
||||
|
||||
int64_t etk::regexp::getLenOfPTheseElem(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
if (_startPos>=(int64_t)_data.size()){
|
||||
return 0;
|
||||
}
|
||||
int64_t pos = _startPos;
|
||||
int32_t nbOpen = 0;
|
||||
// special case of the (...) or | ==> we search '|' or ')'
|
||||
if( _data[pos] == regexpOpcodePTheseOut
|
||||
|| _data[pos] == regexpOpcodePipe) {
|
||||
return 0;
|
||||
}
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
if(_data[pos] == regexpOpcodePTheseIn) {
|
||||
// find a sub section :
|
||||
nbOpen++;
|
||||
} else if(0 < nbOpen) {
|
||||
if (_data[pos] == regexpOpcodePTheseOut) {
|
||||
nbOpen--;
|
||||
if (0 > nbOpen) {
|
||||
TK_ERROR("Error in the (...) find element at "<< pos);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else if( _data[pos] == regexpOpcodePTheseOut
|
||||
|| _data[pos] == regexpOpcodePipe) {
|
||||
// Find the end of the (...)
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the (...) no data at "<< pos-1);
|
||||
return 0;
|
||||
}
|
||||
return sizeInside;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return pos - _startPos;
|
||||
}
|
||||
|
||||
int64_t etk::regexp::getLenOfPThese(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
int64_t pos = _startPos;
|
||||
int32_t nbOpen = 0;
|
||||
// special case of the (...) or | ==> we search '|' or ')'
|
||||
if(_data[pos]==regexpOpcodePTheseOut) {
|
||||
return 0;
|
||||
}
|
||||
if(_data[pos]!=regexpOpcodePTheseIn) {
|
||||
TK_ERROR(" find error in PThese");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
if(_data[pos]==regexpOpcodePTheseIn) {
|
||||
// find a sub section :
|
||||
nbOpen++;
|
||||
} else if(0 < nbOpen) {
|
||||
if (_data[pos]==regexpOpcodePTheseOut) {
|
||||
nbOpen--;
|
||||
if (0 > nbOpen) {
|
||||
TK_ERROR("Error in the (...) find element at "<< pos);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else if(_data[pos]==regexpOpcodePTheseOut) {
|
||||
// Find the end of the (...)
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos-1;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the (...) no data at "<< pos-1);
|
||||
return 0;
|
||||
}
|
||||
return sizeInside;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int64_t etk::regexp::getLenOfBracket(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
int64_t pos = _startPos;
|
||||
// special case of the (...) or | ==> we search '|' or ')'
|
||||
if(_data[pos]==regexpOpcodeBracketOut) {
|
||||
return 0;
|
||||
}
|
||||
if(_data[pos] != regexpOpcodeBracketIn) {
|
||||
TK_ERROR("find no {...");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
if(_data[pos] == regexpOpcodeBracketOut) {
|
||||
// Find the end of the [...]
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos -1 ;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the [...] no data at "<< pos-1);
|
||||
return 0;
|
||||
}
|
||||
return sizeInside;
|
||||
} else if ( _data[pos] == regexpOpcodeStartOfLine
|
||||
|| _data[pos] == regexpOpcodeDigit
|
||||
|| _data[pos] == regexpOpcodeLetter
|
||||
|| _data[pos] == regexpOpcodeSpace
|
||||
|| _data[pos] == regexpOpcodeWord
|
||||
|| _data[pos] == regexpOpcodeTo) {
|
||||
// nothing to do ... it is permited
|
||||
} else if(_data[pos] > 0xFF ) {
|
||||
std::string displayElement;
|
||||
if (_data[pos] == regexpOpcodeStartOfLine) {
|
||||
displayElement = "^";
|
||||
} else if (_data[pos] == regexpOpcodeDigitNot) {
|
||||
displayElement = "\\D";
|
||||
} else if (_data[pos] == regexpOpcodeLetterNot) {
|
||||
displayElement = "\\L";
|
||||
} else if (_data[pos] == regexpOpcodeSpaceNot) {
|
||||
displayElement = "\\S";
|
||||
} else if (_data[pos] == regexpOpcodeWordNot) {
|
||||
displayElement = "\\W";
|
||||
} else {
|
||||
displayElement = (char)_data[pos];
|
||||
}
|
||||
TK_ERROR("Error in the [...] not permited element at "<< pos << " '" << displayElement << "'");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int64_t etk::regexp::getLenOfBrace(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
int32_t pos = _startPos;
|
||||
// special case of the (...) or | ==> we search '|' or ')'
|
||||
if(_data[pos]==regexpOpcodeBracetOut) {
|
||||
return 0;
|
||||
}
|
||||
if(_data[pos]!=regexpOpcodeBracetIn) {
|
||||
TK_ERROR(" did not find brace IN { ");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
if(_data[pos]==regexpOpcodeBracetOut) {
|
||||
// Find the end of the [...]
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos -1 ;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the {...} no data at "<< pos-1);
|
||||
return 0;
|
||||
}
|
||||
return sizeInside;
|
||||
} else if( _data[pos] != ','
|
||||
&& ( _data[pos] < '0'
|
||||
|| _data[pos] > '9') ) {
|
||||
TK_ERROR("Error in the {...} not permited element at "<< pos << " '" << _data[pos] << "'");
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int64_t etk::regexp::getLenOfNormal(const std::vector<char32_t>& _data, int64_t _startPos) {
|
||||
int64_t pos = _startPos;
|
||||
// find size ...
|
||||
while (pos < (int64_t)_data.size() ) {
|
||||
switch(_data[pos]) {
|
||||
case regexpOpcodePTheseIn:
|
||||
case regexpOpcodePTheseOut:
|
||||
case regexpOpcodeBracketIn:
|
||||
case regexpOpcodeBracketOut:
|
||||
case regexpOpcodeBracetIn:
|
||||
case regexpOpcodeBracetOut:
|
||||
case regexpOpcodeTo:
|
||||
case regexpOpcodeStar:
|
||||
case regexpOpcodeDot:
|
||||
case regexpOpcodeQuestion:
|
||||
case regexpOpcodePlus:
|
||||
case regexpOpcodePipe:
|
||||
case regexpOpcodeStartOfLine:
|
||||
case regexpOpcodeEndOfLine:
|
||||
case regexpOpcodeDigit:
|
||||
case regexpOpcodeDigitNot:
|
||||
case regexpOpcodeLetter:
|
||||
case regexpOpcodeLetterNot:
|
||||
case regexpOpcodeSpace:
|
||||
case regexpOpcodeSpaceNot:
|
||||
case regexpOpcodeWord:
|
||||
case regexpOpcodeWordNot:
|
||||
{
|
||||
// just return the size inside
|
||||
int32_t sizeInside = pos - _startPos;
|
||||
if (0 >= sizeInside) {
|
||||
TK_ERROR("Error in the normal data : no data ...");
|
||||
}
|
||||
return sizeInside;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
// nothing to do ...
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
if ((int64_t)pos - (int64_t)_startPos < 0) {
|
||||
return 0;
|
||||
}
|
||||
return pos - _startPos ;
|
||||
}
|
||||
|
||||
|
||||
bool etk::regexp::parseBrace(const std::vector<char32_t>& _data, uint32_t& _min, uint32_t& _max) {
|
||||
//TK_INFO("parse {...} in "; DisplayElem(data); );
|
||||
int64_t k=0;
|
||||
|
||||
int32_t firstElement = 0;
|
||||
int32_t SecondElement = 0;
|
||||
|
||||
while(k < (int64_t)_data.size()) {
|
||||
if (_data[k] == ',') {
|
||||
k++;
|
||||
break;
|
||||
} if (_data[k] == '}' ) {
|
||||
SecondElement = firstElement;
|
||||
goto allIsSet;
|
||||
} else if(u32char::isInteger(_data[k]) == true) {
|
||||
firstElement *= 10;
|
||||
firstElement += u32char::toInt(_data[k]);
|
||||
} else {
|
||||
TK_ERROR("Can not parse this element " << (char)_data[k] << " at pos " << k);
|
||||
return false;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
if (k == (int64_t)_data.size()) {
|
||||
SecondElement = firstElement;
|
||||
}
|
||||
while(k < (int64_t)_data.size()) {
|
||||
if (_data[k] == ',') {
|
||||
TK_ERROR("Can not find a second , in {} at pos " << k);
|
||||
return false;
|
||||
} if (_data[k] == '}') {
|
||||
goto allIsSet;
|
||||
} else if (true == u32char::isInteger(_data[k])) {
|
||||
SecondElement *= 10;
|
||||
SecondElement += u32char::toInt(_data[k]);
|
||||
} else {
|
||||
TK_ERROR("Can not parse this element " << _data[k] << " at pos " << k);
|
||||
return false;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
|
||||
allIsSet:
|
||||
if (SecondElement == 0 && firstElement != 0) {
|
||||
_min = 0;
|
||||
_max = firstElement;
|
||||
} else {
|
||||
_min = firstElement;
|
||||
_max = SecondElement;
|
||||
}
|
||||
if (_min > _max) {
|
||||
TK_ERROR("Minimum=" << _min << " can not be < maximum=" << _max );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string etk::regexp::autoStr(const std::string& _data) {
|
||||
std::string out;
|
||||
for (auto &it : _data) {
|
||||
if (it == '\n') {
|
||||
out += "\\n";
|
||||
} else if (it == '\t') {
|
||||
out += "\\t";
|
||||
} else if (it == '\r') {
|
||||
out += "\\r";
|
||||
} else if (it == '\0') {
|
||||
out += "\\0";
|
||||
} else if (it == ' ') {
|
||||
out += " ";
|
||||
} else if (it <= 0x20) {
|
||||
out += std::to_string((int32_t)it);
|
||||
} else {
|
||||
out += it;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
std::string etk::regexp::autoStr(char _data) {
|
||||
std::string out;
|
||||
if (_data == '\n') {
|
||||
out += "\\n";
|
||||
} else if (_data == '\t') {
|
||||
out += "\\t";
|
||||
} else if (_data == '\r') {
|
||||
out += "\\r";
|
||||
} else if (_data == '\0') {
|
||||
out += "\\0";
|
||||
} else if (_data == ' ') {
|
||||
out += " ";
|
||||
} else if (_data <= 0x20) {
|
||||
out += std::to_string((int32_t)_data);
|
||||
} else {
|
||||
out += _data;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string etk::regexp::strTick(int32_t _pos) {
|
||||
std::string out;
|
||||
for (int32_t iii=0; iii<_pos; ++iii) {
|
||||
out += " ";
|
||||
}
|
||||
out += "^";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace etk {
|
||||
template<> std::string to_string<etk::RegExp<std::string>>(const etk::RegExp<std::string>& _val) {
|
||||
return _val.getRegExp();
|
||||
}
|
||||
template<> std::string to_string<etk::RegExp<std::u32string>>(const etk::RegExp<std::u32string>& _val) {
|
||||
return _val.getRegExp();
|
||||
}
|
||||
template<> std::u32string to_u32string<etk::RegExp<std::string>>(const etk::RegExp<std::string>& _val) {
|
||||
return _val.getURegExp();
|
||||
}
|
||||
template<> std::u32string to_u32string<etk::RegExp<std::u32string>>(const etk::RegExp<std::u32string>& _val) {
|
||||
return _val.getURegExp();
|
||||
}
|
||||
|
||||
template<> bool from_string<etk::RegExp<std::string>>(etk::RegExp<std::string>& _variableRet, const std::u32string& _value) {
|
||||
_variableRet.compile(_value);
|
||||
return true;
|
||||
}
|
||||
template<> bool from_string<etk::RegExp<std::u32string>>(etk::RegExp<std::u32string>& _variableRet, const std::u32string& _value) {
|
||||
_variableRet.compile(_value);
|
||||
return true;
|
||||
}
|
||||
template<> bool from_string<etk::RegExp<std::string>>(etk::RegExp<std::string>& _variableRet, const std::string& _value) {
|
||||
_variableRet.compile(_value);
|
||||
return true;
|
||||
}
|
||||
template<> bool from_string<etk::RegExp<std::u32string>>(etk::RegExp<std::u32string>& _variableRet, const std::string& _value) {
|
||||
_variableRet.compile(_value);
|
||||
return true;
|
||||
}
|
||||
};
|
@ -12,7 +12,7 @@ namespace etk {
|
||||
/**
|
||||
* @brief Vector class ...
|
||||
*
|
||||
* @tparam[in] ETK_VECTOR_TYPE class type of the current element.
|
||||
* @param[in] ETK_VECTOR_TYPE class type of the current element.
|
||||
*
|
||||
* m_data
|
||||
* <------------ m_dataSize ------------>
|
||||
@ -44,11 +44,11 @@ namespace etk {
|
||||
public:
|
||||
class Iterator {
|
||||
private:
|
||||
size_t m_current; //!< curent Id on the vector
|
||||
Vector<ETK_VECTOR_TYPE>* m_vector; //!< Pointer on the curent element of the vectorBin
|
||||
size_t m_current; //!< current Id on the vector
|
||||
Vector<ETK_VECTOR_TYPE>* m_vector; //!< Pointer on the current element of the vectorBin
|
||||
public:
|
||||
/**
|
||||
* @brief Basic itarator constructor with no link with an etkVector
|
||||
* @brief Basic iterator constructor with no link with an etk::Vector
|
||||
*/
|
||||
Iterator():
|
||||
m_current(0),
|
||||
@ -65,9 +65,9 @@ namespace etk {
|
||||
// nothing to do ...
|
||||
}
|
||||
/**
|
||||
* @brief Asignation operator.
|
||||
* @brief Assignation operator.
|
||||
* @param[in] _otherIterator The Iterator that might be copy
|
||||
* @return reference on the curent Iterator
|
||||
* @return reference on the current Iterator
|
||||
*/
|
||||
Iterator& operator=(const Iterator & _otherIterator) {
|
||||
m_current = _otherIterator.m_current;
|
||||
@ -90,7 +90,7 @@ namespace etk {
|
||||
}
|
||||
/**
|
||||
* @brief Incremental operator
|
||||
* @return Reference on the current iterator incremented
|
||||
* @return Reference on the current iterator increment
|
||||
*/
|
||||
Iterator& operator++ () {
|
||||
if ( m_vector != nullptr
|
||||
@ -102,7 +102,7 @@ namespace etk {
|
||||
}
|
||||
/**
|
||||
* @brief Decremental operator
|
||||
* @return Reference on the current iterator decremented
|
||||
* @return Reference on the current iterator decrement
|
||||
*/
|
||||
Iterator& operator-- () {
|
||||
if ( m_vector != nullptr
|
||||
@ -154,8 +154,8 @@ namespace etk {
|
||||
friend class Vector;
|
||||
};
|
||||
private:
|
||||
ETK_VECTOR_TYPE* m_data; //!< pointer on the curetn table of Data
|
||||
size_t m_size; //!< nb Element in the buffer
|
||||
ETK_VECTOR_TYPE* m_data; //!< pointer on the current table of Data
|
||||
size_t m_size; //!< Number of element in the buffer
|
||||
size_t m_allocated; //!< Current allocated size
|
||||
public:
|
||||
/**
|
||||
@ -180,7 +180,7 @@ namespace etk {
|
||||
// allocate all same data
|
||||
m_data = new ETK_VECTOR_TYPE[m_allocated];
|
||||
if (m_data == nullptr) {
|
||||
TK_CRITICAL("Vector : Error in data allocation ... might nor work corectly anymore");
|
||||
TK_CRITICAL("Vector : Error in data allocation ... might nor work correctly anymore");
|
||||
return;
|
||||
}
|
||||
// Copy all data ...
|
||||
@ -221,7 +221,7 @@ namespace etk {
|
||||
/**
|
||||
* @brief Re-copy operator
|
||||
* @param[in] _obj Vector that might be copy
|
||||
* @return reference on the curent re-copy vector
|
||||
* @return reference on the current re-copy vector
|
||||
*/
|
||||
Vector& operator=(const etk::Vector<ETK_VECTOR_TYPE> & _obj) {
|
||||
//TK_DEBUG("USE RECOPY vector ... Evb.m_size=" << Evb.m_size << " Evb.m_increment=" << Evb.m_increment);
|
||||
@ -236,7 +236,7 @@ namespace etk {
|
||||
// allocate all same data
|
||||
m_data = new ETK_VECTOR_TYPE[m_allocated];
|
||||
if (m_data == nullptr) {
|
||||
TK_CRITICAL("Vector : Error in data allocation ... might nor work corectly anymore");
|
||||
TK_CRITICAL("Vector : Error in data allocation ... might nor work correctly anymore");
|
||||
return *this;
|
||||
}
|
||||
for(size_t iii=0; iii<m_allocated; iii++) {
|
||||
@ -253,18 +253,18 @@ namespace etk {
|
||||
* @param[in] _obj Element to add at the end of vector
|
||||
*/
|
||||
Vector& operator+= (const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
|
||||
size_t nbElememt = _obj.size();
|
||||
size_t idx = m_size;
|
||||
resize(m_size+nbElememt);
|
||||
if (m_size<=idx) {
|
||||
size_t numberElement = _obj.size();
|
||||
size_t idElement = m_size;
|
||||
resize(m_size+numberElement);
|
||||
if (m_size<=idElement) {
|
||||
TK_CRITICAL("allocation error");
|
||||
return *this;
|
||||
}
|
||||
for(size_t iii=0; iii<nbElememt; iii++) {
|
||||
for(size_t iii=0; iii<numberElement; iii++) {
|
||||
// copy operator ...
|
||||
m_data[idx+iii] = _obj.m_data[iii];
|
||||
m_data[idElement+iii] = _obj.m_data[iii];
|
||||
}
|
||||
// Return the curent pointer
|
||||
// Return the current pointer
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
@ -279,15 +279,15 @@ namespace etk {
|
||||
* @param[in] _newSize New size of the vector
|
||||
*/
|
||||
void resize(size_t _newSize, const ETK_VECTOR_TYPE& _basicElement) {
|
||||
size_t idx = m_size;
|
||||
size_t idElement = m_size;
|
||||
resize(_newSize);
|
||||
if (m_size != _newSize) {
|
||||
TK_CRITICAL("error to resize vector");
|
||||
return;
|
||||
}
|
||||
if (_newSize > idx) {
|
||||
if (_newSize > idElement) {
|
||||
// initialize data ...
|
||||
for(size_t iii=idx; iii<_newSize; iii++) {
|
||||
for(size_t iii=idElement; iii<_newSize; iii++) {
|
||||
m_data[iii] = _basicElement;
|
||||
}
|
||||
}
|
||||
@ -308,7 +308,7 @@ namespace etk {
|
||||
// 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);
|
||||
TK_CRITICAL("[CRITICAL] Access to an inexistent data in vector : " << _pos << "/ " << m_size);
|
||||
}
|
||||
#endif
|
||||
return m_data[_pos];
|
||||
@ -330,7 +330,7 @@ namespace etk {
|
||||
// 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);
|
||||
TK_CRITICAL("[CRITICAL] Access to an inexistent data in vector : " << _pos << "/ " << m_size);
|
||||
}
|
||||
#endif
|
||||
return m_data[_pos];
|
||||
@ -355,12 +355,12 @@ namespace etk {
|
||||
* @param[in] _item Element to add at the end of vector
|
||||
*/
|
||||
void pushBack(const ETK_VECTOR_TYPE& _item) {
|
||||
size_t idx = m_size;
|
||||
size_t idElement = m_size;
|
||||
resize(m_size+1);
|
||||
if (idx < m_size) {
|
||||
m_data[idx] = _item;
|
||||
if (idElement < m_size) {
|
||||
m_data[idElement] = _item;
|
||||
} else {
|
||||
TK_ERROR("Resize does not work corectly ... not added item");
|
||||
TK_ERROR("Resize does not work correctly ... not added item");
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -372,14 +372,14 @@ namespace etk {
|
||||
if (_item == nullptr) {
|
||||
return;
|
||||
}
|
||||
size_t idx = m_size;
|
||||
size_t idElement = m_size;
|
||||
resize(m_size+_nbElement);
|
||||
if (idx > m_size) {
|
||||
TK_ERROR("Resize does not work corectly ... not added item");
|
||||
if (idElement > m_size) {
|
||||
TK_ERROR("Resize does not work correctly ... not added item");
|
||||
return;
|
||||
}
|
||||
for (size_t iii=0; iii<_nbElement; iii++) {
|
||||
m_data[idx+iii] = _item[iii];
|
||||
m_data[idElement+iii] = _item[iii];
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -391,7 +391,7 @@ namespace etk {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Remove all alement in the current vector
|
||||
* @brief Remove all element in the current vector
|
||||
*/
|
||||
void clear() {
|
||||
if(m_size>0) {
|
||||
@ -410,18 +410,18 @@ namespace etk {
|
||||
pushBack(_item, _nbElement);
|
||||
return;
|
||||
}
|
||||
size_t idx = m_size;
|
||||
size_t idElement = 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");
|
||||
if (idElement>=m_size) {
|
||||
TK_ERROR("Resize does not work correctly ... not added item");
|
||||
return;
|
||||
}
|
||||
// move curent data (after the position)
|
||||
size_t sizeToMove = (idx - _pos);
|
||||
// move current data (after the position)
|
||||
size_t sizeToMove = (idElement - _pos);
|
||||
if ( 0 < sizeToMove) {
|
||||
for (size_t iii=1; iii<=sizeToMove; iii++) {
|
||||
m_data[m_size-iii] = m_data[idx-iii];
|
||||
m_data[m_size-iii] = m_data[idElement-iii];
|
||||
}
|
||||
}
|
||||
// affectation of all input element
|
||||
@ -450,9 +450,9 @@ namespace etk {
|
||||
if (_pos+_nbElement>m_size) {
|
||||
_nbElement = m_size - _pos;
|
||||
}
|
||||
size_t idx = m_size;
|
||||
// move curent data
|
||||
size_t sizeToMove = (idx - (_pos+_nbElement));
|
||||
size_t idElement = m_size;
|
||||
// move current data
|
||||
size_t sizeToMove = (idElement - (_pos+_nbElement));
|
||||
if ( 0 < sizeToMove) {
|
||||
for (size_t iii=0; iii<sizeToMove; iii++) {
|
||||
m_data[_pos+iii] = m_data[_pos+_nbElement+iii];
|
||||
@ -490,7 +490,7 @@ namespace etk {
|
||||
}
|
||||
size_t nbElement = m_size - _pos;
|
||||
size_t tmpSize = m_size;
|
||||
// move curent data
|
||||
// move current data
|
||||
size_t sizeToMove = (tmpSize - (_pos+nbElement));
|
||||
if ( 0 < sizeToMove) {
|
||||
for (size_t iii=0; iii<sizeToMove; iii++) {
|
||||
@ -518,7 +518,7 @@ namespace etk {
|
||||
return out;
|
||||
}
|
||||
/**
|
||||
* @brief Get the pointer on the sata
|
||||
* @brief Get the pointer on the data
|
||||
* @return the type pointer on data
|
||||
*/
|
||||
ETK_VECTOR_TYPE* dataPointer() {
|
||||
@ -559,7 +559,7 @@ namespace etk {
|
||||
m_size = _newSize;
|
||||
}
|
||||
/**
|
||||
* @brief Change the current allocation to the corect one (depend on the current size)
|
||||
* @brief Change the current allocation to the correct one (depend on the current size)
|
||||
* @param[in] _newSize Minimum number of element needed
|
||||
*/
|
||||
void changeAllocation(size_t _newSize) {
|
||||
@ -568,7 +568,7 @@ namespace etk {
|
||||
_newSize = 1;
|
||||
}
|
||||
size_t requestSize = m_allocated;
|
||||
// set the size with the corect chose type :
|
||||
// set the size with the correct chose type :
|
||||
if (_newSize == requestSize) {
|
||||
return;
|
||||
} else if (_newSize < requestSize) {
|
||||
@ -629,7 +629,7 @@ namespace etk {
|
||||
if( this == &_obj ) {
|
||||
return true;
|
||||
}
|
||||
// fiist step : check the size ...
|
||||
// first step : check the size ...
|
||||
if (m_size != _obj.m_size) {
|
||||
return false;
|
||||
}
|
||||
@ -652,7 +652,7 @@ namespace etk {
|
||||
if( this == &_obj ) {
|
||||
return false;
|
||||
}
|
||||
// fiist step : check the size ...
|
||||
// first step : check the size ...
|
||||
if (m_size!=_obj.m_size) {
|
||||
return true;
|
||||
}
|
||||
|
@ -34,11 +34,11 @@ namespace etk {
|
||||
|
||||
#define TK_HIDDEN(data) do { } while(false)
|
||||
|
||||
#define TK_ASSERT(cond,data) \
|
||||
#define TK_ASSERT(condition,data) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
if (!(condition)) { \
|
||||
TK_CRITICAL(data); \
|
||||
assert(!#cond); \
|
||||
assert(!#condition); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
14
etk/etk.cpp
14
etk/etk.cpp
@ -16,17 +16,17 @@ static int32_t nbTimeInit = 0;
|
||||
void etk::unInit() {
|
||||
if (nbTimeInit > 1) {
|
||||
nbTimeInit--;
|
||||
// not the time to uninit
|
||||
// not the time to un-init
|
||||
return;
|
||||
}
|
||||
nbTimeInit--;
|
||||
if (nbTimeInit < 0) {
|
||||
TK_ERROR("E-TK system un-init More un-init than init ...");
|
||||
TK_ERROR("ETK system un-init More un-init than init ...");
|
||||
nbTimeInit = 0;
|
||||
return;
|
||||
}
|
||||
TK_INFO("E-TK system un-init (BEGIN)");
|
||||
TK_INFO("E-TK system un-init (END)");
|
||||
TK_INFO("ETK system un-init (BEGIN)");
|
||||
TK_INFO("ETK system un-init (END)");
|
||||
}
|
||||
|
||||
void etk::init(int _argc, const char** _argv) {
|
||||
@ -37,9 +37,9 @@ void etk::init(int _argc, const char** _argv) {
|
||||
}
|
||||
nbTimeInit++;
|
||||
if (_argc >= 1) {
|
||||
TK_INFO("E-TK system init (BEGIN) " << _argv[0]);
|
||||
TK_INFO("ETK system init (BEGIN) " << _argv[0]);
|
||||
} else {
|
||||
TK_INFO("E-TK system init (BEGIN) ");
|
||||
TK_INFO("ETK system init (BEGIN) ");
|
||||
}
|
||||
elog::init(_argc, _argv);
|
||||
#if !defined(__TARGET_OS__Android) and !defined(__TARGET_OS__IOs)
|
||||
@ -67,7 +67,7 @@ void etk::init(int _argc, const char** _argv) {
|
||||
TK_ERROR("Can not parse the argument : '" << data << "'");
|
||||
}
|
||||
}
|
||||
TK_INFO("E-TK system init (END)");
|
||||
TK_INFO("ETK system init (END)");
|
||||
}
|
||||
|
||||
std::string etk::getApplicationName() {
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <string>
|
||||
/**
|
||||
* @brief basic namespace of the etk library. (it might contain all the etk fuctions/class/structures without macro)
|
||||
* @brief basic namespace of the etk library. (it might contain all the etk functions/class/structures without macro)
|
||||
*/
|
||||
namespace etk {
|
||||
/**
|
||||
|
@ -92,11 +92,11 @@ static uint32_t getUtf8Val(char32_t _val) {
|
||||
output+= (_val & 0x00000FC0)<<2;
|
||||
output+= _val & 0x0000003F;
|
||||
} else {
|
||||
//TK_ERROR("NON UTF8 caracter input...");
|
||||
//TK_ERROR("NOT UTF8 character input...");
|
||||
printf("not an utf8 char : %#08x\n", _val);
|
||||
return 0;
|
||||
}
|
||||
//printf("utf8convertion : %d=%08x ==> %08x\n",value, value, output);
|
||||
//printf("utf-8 conversion : %d=%08x ==> %08x\n",value, value, output);
|
||||
return output;
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ char32_t utf8::convertChar32(const char* _input) {
|
||||
len = sizeElement(_input, len);
|
||||
switch (len) {
|
||||
default:
|
||||
// case 0 : An error occured...
|
||||
// case 0 : An error occurred...
|
||||
value = _input[0];
|
||||
return value;
|
||||
case 1:
|
||||
@ -196,7 +196,7 @@ char32_t utf8::convertChar32(const char* _input) {
|
||||
}
|
||||
}
|
||||
|
||||
int8_t utf8::theoricLen(const char _input) {
|
||||
int8_t utf8::length(const char _input) {
|
||||
if((_input&0x80) == 0x00 ) {
|
||||
return 1;
|
||||
}
|
||||
@ -212,8 +212,8 @@ int8_t utf8::theoricLen(const char _input) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool utf8::theoricFirst(const char _input) {
|
||||
// When started with the bit 0 then the size is signle element.
|
||||
bool utf8::first(const char _input) {
|
||||
// When started with the bit 0 then the size is single element.
|
||||
if((_input&0x80) == 0x00 ) {
|
||||
return true;
|
||||
}
|
||||
@ -525,11 +525,12 @@ bool etk::compare_no_case(const std::string& _obj, const std::string& _val) {
|
||||
return true;
|
||||
}
|
||||
|
||||
struct doublette {
|
||||
char32_t lower;
|
||||
char32_t upper;
|
||||
class DoubleChar {
|
||||
public:
|
||||
char32_t lower;
|
||||
char32_t upper;
|
||||
};
|
||||
struct doublette convertionTable[] = {
|
||||
DoubleChar conversionTable[] = {
|
||||
#if __CPP_VERSION__ >= 2011
|
||||
{U'ç', U'Ç'},
|
||||
|
||||
@ -553,15 +554,15 @@ struct doublette convertionTable[] = {
|
||||
{U'ø', U'Ø'}
|
||||
#endif
|
||||
};
|
||||
size_t convertionTableSize = sizeof(convertionTable)/sizeof(struct doublette);
|
||||
size_t conversionTableSize = sizeof(conversionTable)/sizeof(DoubleChar);
|
||||
|
||||
static char32_t localToUpper(char32_t _input) {
|
||||
if (_input >= 'a' && _input <= 'z') {
|
||||
return _input + ((int)'A'-(int)'a');
|
||||
}
|
||||
for (size_t iii = 0; iii < convertionTableSize; ++iii) {
|
||||
if (convertionTable[iii].lower == _input) {
|
||||
return convertionTable[iii].upper;
|
||||
for (size_t iii = 0; iii < conversionTableSize; ++iii) {
|
||||
if (conversionTable[iii].lower == _input) {
|
||||
return conversionTable[iii].upper;
|
||||
}
|
||||
}
|
||||
return _input;
|
||||
@ -571,9 +572,9 @@ static char32_t localToLower(char32_t _input) {
|
||||
if (_input >= 'A' && _input <= 'Z') {
|
||||
return _input + ((int)'a'-(int)'A');
|
||||
}
|
||||
for (size_t iii = 0; iii < convertionTableSize; ++iii) {
|
||||
if (convertionTable[iii].upper == _input) {
|
||||
return convertionTable[iii].lower;
|
||||
for (size_t iii = 0; iii < conversionTableSize; ++iii) {
|
||||
if (conversionTable[iii].upper == _input) {
|
||||
return conversionTable[iii].lower;
|
||||
}
|
||||
}
|
||||
return _input;
|
||||
@ -936,12 +937,12 @@ void etk::sort(std::vector<std::string *> &_list) {
|
||||
for(size_t iii=0; iii<tmpList.size(); iii++) {
|
||||
size_t findPos = 0;
|
||||
for(size_t jjj=0; jjj<_list.size(); jjj++) {
|
||||
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
|
||||
//TK_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
|
||||
if (*tmpList[iii] > *_list[jjj]) {
|
||||
findPos = jjj+1;
|
||||
}
|
||||
}
|
||||
//EWOL_DEBUG("position="<<findPos);
|
||||
//TK_DEBUG("position="<<findPos);
|
||||
_list.insert(_list.begin()+findPos, tmpList[iii]);
|
||||
}
|
||||
}
|
||||
@ -952,12 +953,12 @@ void etk::sort(std::vector<std::string *> &_list) {
|
||||
for(size_t iii=0; iii<tmpList.size(); iii++) {
|
||||
size_t findPos = 0;
|
||||
for(size_t jjj=0; jjj<_list.size(); jjj++) {
|
||||
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
|
||||
//TK_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
|
||||
if (*tmpList[iii] > *_list[jjj]) {
|
||||
findPos = jjj+1;
|
||||
}
|
||||
}
|
||||
//EWOL_DEBUG("position="<<findPos);
|
||||
//TK_DEBUG("position="<<findPos);
|
||||
_list.insert(_list.begin()+findPos, tmpList[iii]);
|
||||
}
|
||||
}
|
||||
@ -1277,42 +1278,42 @@ std::ostream& std::operator <<(std::ostream& _os, const std::vector<uint8_t>& _o
|
||||
return tmpVal;
|
||||
}
|
||||
|
||||
double std::stod(const std::string& _str, size_t* _idx) {
|
||||
double std::stod(const std::string& _str, size_t* _id) {
|
||||
double ret = 0;
|
||||
sscanf(_str.c_str(), "%lf", &ret);
|
||||
return ret;
|
||||
}
|
||||
float std::stof(const std::string& _str, size_t* _idx) {
|
||||
float std::stof(const std::string& _str, size_t* _id) {
|
||||
float ret = 0;
|
||||
sscanf(_str.c_str(), "%f", &ret);
|
||||
return ret;
|
||||
}
|
||||
int std::stoi(const std::string& _str, size_t* _idx, int _base) {
|
||||
int std::stoi(const std::string& _str, size_t* _id, int _base) {
|
||||
int ret = 0;
|
||||
sscanf(_str.c_str(), "%d", &ret);
|
||||
return ret;
|
||||
}
|
||||
long std::stol(const std::string& _str, size_t* _idx, int _base) {
|
||||
long std::stol(const std::string& _str, size_t* _id, int _base) {
|
||||
long ret = 0;
|
||||
sscanf(_str.c_str(), "%ld", &ret);
|
||||
return ret;
|
||||
}
|
||||
long double std::stold(const std::string& _str, size_t* _idx) {
|
||||
long double std::stold(const std::string& _str, size_t* _id) {
|
||||
long double ret = 0;
|
||||
sscanf(_str.c_str(), "%Lf", &ret);
|
||||
return ret;
|
||||
}
|
||||
long long std::stoll(const std::string& _str, size_t* _idx, int _base) {
|
||||
long long std::stoll(const std::string& _str, size_t* _id, int _base) {
|
||||
long long ret = 0;
|
||||
sscanf(_str.c_str(), "%lld", &ret);
|
||||
return ret;
|
||||
}
|
||||
unsigned long std::stoul(const std::string& _str, size_t* _idx, int _base) {
|
||||
unsigned long std::stoul(const std::string& _str, size_t* _id, int _base) {
|
||||
unsigned long ret = 0;
|
||||
sscanf(_str.c_str(), "%lu", &ret);
|
||||
return ret;
|
||||
}
|
||||
unsigned long long std::stoull(const std::string& _str, size_t* _idx, int _base) {
|
||||
unsigned long long std::stoull(const std::string& _str, size_t* _id, int _base) {
|
||||
unsigned long long ret = 0;
|
||||
sscanf(_str.c_str(), "%llu", &ret);
|
||||
return ret;
|
||||
|
112
etk/stdTools.hpp
112
etk/stdTools.hpp
@ -28,39 +28,39 @@ namespace u32char {
|
||||
extern const char32_t Escape; //!< Value ESC Escape
|
||||
/**
|
||||
* @brief check if the current element is white or not : '\\t' '\\n' '\\r' ' '
|
||||
* @param[in] _val Value to interprete
|
||||
* @param[in] _val Value to interpret
|
||||
* @return true if it is white char
|
||||
* @return false otherwise
|
||||
*/
|
||||
bool isWhiteChar(char32_t _val);
|
||||
/**
|
||||
* @brief check if the current element is NOT [a-zA-Z0-9]
|
||||
* @param[in] _val Value to interprete
|
||||
* @param[in] _val Value to interpret
|
||||
* @return true Not in the previous list
|
||||
* @return false otherwise
|
||||
*/
|
||||
bool isSpecialChar(char32_t _val);
|
||||
/**
|
||||
* @brief check if the curent element is number or not [0-9]
|
||||
* @param[in] _val Value to interprete
|
||||
* @brief check if the current element is number or not [0-9]
|
||||
* @param[in] _val Value to interpret
|
||||
* @return true if it is a number char
|
||||
* @return false otherwise
|
||||
*/
|
||||
bool isInteger(char32_t _val);
|
||||
/**
|
||||
* @brief Convert char32_t in an interfer
|
||||
* @param[in] _val Value to interprete
|
||||
* @brief Convert char32_t in an integer
|
||||
* @param[in] _val Value to interpret
|
||||
* @return The parsed Value or ...
|
||||
*/
|
||||
int32_t toInt(char32_t _val);
|
||||
/**
|
||||
* @brief Change order of the value to have an order of display with A->Z and after a->z and after 0->9 and after all the rest ....
|
||||
* @param[in] _val Value in unicode
|
||||
* @return A value usable in interfer only ... to check order...
|
||||
* @return A value usable in integer only ... to check order...
|
||||
*/
|
||||
char32_t changeOrder(char32_t _val);
|
||||
/**
|
||||
* @brief Conver unicode in UTF8 value
|
||||
* @brief Convert unicode in UTF8 value
|
||||
* @param[in] _val Value to convert
|
||||
* @param[out] _output Char data converted
|
||||
* @return Number of char in utf8
|
||||
@ -80,13 +80,13 @@ namespace utf8 {
|
||||
* @param[in] _input Char to parse
|
||||
* @return number of char needed
|
||||
*/
|
||||
int8_t theoricLen(const char _input);
|
||||
int8_t length(const char _input);
|
||||
/**
|
||||
* @brief When parsing a string in a reverse mode, we need to know if we get the first char
|
||||
* @param[in] _input Char to parse.
|
||||
* @return true if it was the first char.
|
||||
*/
|
||||
bool theoricFirst(const char _input);
|
||||
bool first(const char _input);
|
||||
/**
|
||||
* @brief Convert a char* in a unicode value
|
||||
* @param[in] _input pointer on a string C (utf-8) to convert
|
||||
@ -101,9 +101,9 @@ namespace utf8 {
|
||||
*/
|
||||
class iterator {
|
||||
private:
|
||||
char32_t m_value; //!< store vlue to prevent multiple calcule of getting the data
|
||||
char32_t m_value; //!< store value to prevent multiple calculation of getting the data
|
||||
std::string* m_data; //!< Pointer on the current Buffer
|
||||
int64_t m_current; //!< curent Id in the Buffer
|
||||
int64_t m_current; //!< current Id in the Buffer
|
||||
public:
|
||||
/**
|
||||
* @brief Basic constructor that is not link on a string
|
||||
@ -195,9 +195,9 @@ namespace utf8 {
|
||||
// nothing to do ...
|
||||
};
|
||||
/**
|
||||
* @brief Asignation operator.
|
||||
* @brief Assignation operator.
|
||||
* @param[in] _obj The Iterator that might be copy
|
||||
* @return reference on the curent Iterator
|
||||
* @return reference on the current Iterator
|
||||
*/
|
||||
iterator& operator=(const iterator & _obj) {
|
||||
m_current = _obj.m_current;
|
||||
@ -231,12 +231,12 @@ namespace utf8 {
|
||||
};
|
||||
/**
|
||||
* @brief Incremental operator
|
||||
* @return Reference on the current iterator incremented
|
||||
* @return Reference on the current iterator increment
|
||||
*/
|
||||
iterator& operator++ ();
|
||||
/**
|
||||
* @brief Decremental operator
|
||||
* @return Reference on the current iterator decremented
|
||||
* @return Reference on the current iterator decrement
|
||||
*/
|
||||
iterator& operator-- ();
|
||||
/**
|
||||
@ -258,7 +258,7 @@ namespace utf8 {
|
||||
return it;
|
||||
};
|
||||
/**
|
||||
* @brief egality iterator
|
||||
* @brief equality iterator
|
||||
* @param[in] _obj Iterator to compare
|
||||
* @return true if the iterator is identical pos
|
||||
*/
|
||||
@ -270,7 +270,7 @@ namespace utf8 {
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* @brief egality iterator
|
||||
* @brief equality iterator
|
||||
* @param[in] _obj Iterator to compare
|
||||
* @return true if the iterator is identical pos
|
||||
*/
|
||||
@ -364,64 +364,64 @@ namespace utf8 {
|
||||
* @return a new iterator.
|
||||
*/
|
||||
iterator operator+ (const int64_t _val) const {
|
||||
iterator tmpp(*this);
|
||||
iterator tmp(*this);
|
||||
for (int64_t iii=0; iii<_val; ++iii) {
|
||||
++tmpp;
|
||||
++tmp;
|
||||
}
|
||||
return tmpp;
|
||||
return tmp;
|
||||
};
|
||||
/**
|
||||
* @copydoc utf8::iterator::operator+ (const int64_t)
|
||||
*/
|
||||
iterator operator+ (const int32_t _val) const {
|
||||
iterator tmpp(*this);
|
||||
iterator tmp(*this);
|
||||
for (int64_t iii=0; iii<_val; ++iii) {
|
||||
++tmpp;
|
||||
++tmp;
|
||||
}
|
||||
return tmpp;
|
||||
};
|
||||
return tmp;
|
||||
}
|
||||
/**
|
||||
* @copydoc utf8::iterator::operator+ (const int64_t)
|
||||
*/
|
||||
iterator operator+ (const size_t _val) const {
|
||||
iterator tmpp(*this);
|
||||
iterator tmp(*this);
|
||||
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
|
||||
++tmpp;
|
||||
++tmp;
|
||||
}
|
||||
return tmpp;
|
||||
};
|
||||
return tmp;
|
||||
}
|
||||
/**
|
||||
* @brief move the element position
|
||||
* @param[in] _val Value to remove on the Iterator
|
||||
* @return a new iterator.
|
||||
*/
|
||||
iterator operator- (const int64_t _val) const {
|
||||
iterator tmpp(*this);
|
||||
iterator tmp(*this);
|
||||
for (int64_t iii=0; iii<_val; ++iii) {
|
||||
--tmpp;
|
||||
--tmp;
|
||||
}
|
||||
return tmpp;
|
||||
};
|
||||
return tmp;
|
||||
}
|
||||
/**
|
||||
* @copydoc utf8::iterator::operator- (const int64_t)
|
||||
*/
|
||||
iterator operator- (const int32_t _val) const {
|
||||
iterator tmpp(*this);
|
||||
iterator tmp(*this);
|
||||
for (int64_t iii=0; iii<_val; ++iii) {
|
||||
--tmpp;
|
||||
--tmp;
|
||||
}
|
||||
return tmpp;
|
||||
};
|
||||
return tmp;
|
||||
}
|
||||
/**
|
||||
* @copydoc utf8::iterator::operator- (const int64_t)
|
||||
*/
|
||||
iterator operator- (const size_t _val) const {
|
||||
iterator tmpp(*this);
|
||||
iterator tmp(*this);
|
||||
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
|
||||
--tmpp;
|
||||
--tmp;
|
||||
}
|
||||
return tmpp;
|
||||
};
|
||||
return tmp;
|
||||
}
|
||||
/*
|
||||
iterator begin() const {
|
||||
return iterator(m_data);
|
||||
@ -457,34 +457,34 @@ namespace std {
|
||||
//! @not_in_doc
|
||||
std::string to_string(long double _val);
|
||||
//! @not_in_doc
|
||||
double stod(const std::string& _str, size_t* _idx = 0);
|
||||
double stod(const std::string& _str, size_t* _id = 0);
|
||||
//! @not_in_doc
|
||||
float stof(const std::string& _str, size_t* _idx = 0);
|
||||
float stof(const std::string& _str, size_t* _id = 0);
|
||||
//! @not_in_doc
|
||||
int stoi(const std::string& _str, size_t* _idx = 0, int _base = 10);
|
||||
int stoi(const std::string& _str, size_t* _id = 0, int _base = 10);
|
||||
//! @not_in_doc
|
||||
long stol(const std::string& _str, size_t* _idx = 0, int _base = 10);
|
||||
long stol(const std::string& _str, size_t* _id = 0, int _base = 10);
|
||||
//! @not_in_doc
|
||||
long double stold(const std::string& _str, size_t* _idx = 0);
|
||||
long double stold(const std::string& _str, size_t* _id = 0);
|
||||
//! @not_in_doc
|
||||
long long stoll(const std::string& _str, size_t* _idx = 0, int _base = 10);
|
||||
long long stoll(const std::string& _str, size_t* _id = 0, int _base = 10);
|
||||
//! @not_in_doc
|
||||
unsigned long stoul(const std::string& _str, size_t* _idx = 0, int _base = 10);
|
||||
unsigned long stoul(const std::string& _str, size_t* _id = 0, int _base = 10);
|
||||
//! @not_in_doc
|
||||
unsigned long long stoull(const std::string& _str, size_t* _idx = 0, int _base = 10);
|
||||
unsigned long long stoull(const std::string& _str, size_t* _id = 0, int _base = 10);
|
||||
#endif
|
||||
};
|
||||
namespace etk {
|
||||
// these declaration is to prevent some under template declaration of unknown type
|
||||
/**
|
||||
* @brief Template to declare convertion from anything in std::string
|
||||
* @brief Template to declare conversion from anything in std::string
|
||||
* @param[in] _variable Variable to convert
|
||||
* @return String of the value
|
||||
*/
|
||||
template <class TYPE>
|
||||
std::string to_string(const TYPE& _variable);
|
||||
/**
|
||||
* @brief Template to declare convertion from std::vector<anything> in std::string
|
||||
* @brief Template to declare conversion from std::vector<anything> in std::string
|
||||
* @param[in] _list Variable to convert
|
||||
* @return String of the value: {...,...,...}
|
||||
*/
|
||||
@ -506,7 +506,7 @@ namespace etk {
|
||||
#endif
|
||||
// these declaration is to prevent some under template declaration of unknown type
|
||||
/**
|
||||
* @brief Template to declare convertion from string to anything
|
||||
* @brief Template to declare conversion from string to anything
|
||||
* @param[out] _variableRet Output value
|
||||
* @param[in] _value input property
|
||||
* @return true if the can be converted.
|
||||
@ -652,7 +652,7 @@ namespace etk {
|
||||
|
||||
namespace std {
|
||||
/**
|
||||
* @brief in std, we have min, max but not avg ==> it is missing... the Defineing avg template.
|
||||
* @brief in std, we have min, max but not avg ==> it is missing... the define of avg template.
|
||||
* @param[in] _min Minimum value of the range
|
||||
* @param[in] _val The value that we want a min/max
|
||||
* @param[in] _max Maximum value of the range
|
||||
@ -665,7 +665,7 @@ namespace std {
|
||||
|
||||
namespace etk {
|
||||
/**
|
||||
* @brief in std, we have min, max but not avg ==> it is missing... the Defineing avg template.
|
||||
* @brief in std, we have min, max but not avg ==> it is missing... the Define of avg template.
|
||||
* @param[in] _min Minimum value of the range
|
||||
* @param[in] _val The value that we want a min/max
|
||||
* @param[in] _max Maximum value of the range
|
||||
@ -714,9 +714,9 @@ namespace std {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Claculate the size of a string (unicode)
|
||||
* @brief Calculate the size of a string (unicode)
|
||||
* @param[in] _data Data to parse to find the end of string
|
||||
* @return the Number of char32_t befor the '\\0' value
|
||||
* @return The Number of char32_t before the '\\0' value
|
||||
*/
|
||||
int32_t strlen(const char32_t* _data);
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
namespace etk {
|
||||
/**
|
||||
* @brief Some un-usefull tools
|
||||
* @brief Some useful tools
|
||||
* @todo Remove all of this use std11 random
|
||||
*/
|
||||
namespace tool {
|
||||
|
@ -34,7 +34,7 @@ def configure(target, my_module):
|
||||
'etk/tool.cpp',
|
||||
'etk/Noise.cpp',
|
||||
'etk/Color.cpp',
|
||||
'etk/RegExp.cpp',
|
||||
'etk/RegEx.cpp',
|
||||
'etk/math/Matrix2x2.cpp',
|
||||
'etk/math/Matrix2x3.cpp',
|
||||
'etk/math/Matrix3x3.cpp',
|
||||
@ -57,7 +57,7 @@ def configure(target, my_module):
|
||||
'etk/tool.hpp',
|
||||
'etk/Noise.hpp',
|
||||
'etk/Color.hpp',
|
||||
'etk/RegExp.hpp',
|
||||
'etk/RegEx.hpp',
|
||||
'etk/Buffer.hpp',
|
||||
'etk/Hash.hpp',
|
||||
'etk/math/Matrix2x2.hpp',
|
||||
|
@ -7,18 +7,18 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <etk/RegExp.hpp>
|
||||
#include <etk/RegEx.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
|
||||
#define NAME "Hash"
|
||||
|
||||
std::pair<int32_t, int32_t> testRegExpSingle(const std::string& _expression, const std::string& _search) {
|
||||
etk::RegExp<std::string> expression(_expression);
|
||||
std::pair<int32_t, int32_t> testRegExSingle(const std::string& _expression, const std::string& _search) {
|
||||
etk::RegEx<std::string> expression(_expression);
|
||||
TK_INFO("Parse RegEx: \"" << expression.getRegExDecorated() << "\"");
|
||||
TK_INFO(" IN: \"" << etk::regexp::autoStr(_search) << "\"");
|
||||
TK_INFO(" IN: \"" << etk::regex::autoStr(_search) << "\"");
|
||||
if (expression.parse(_search, 0, _search.size()) == true) {
|
||||
TK_INFO(" match [" << expression.start() << ".." << expression.stop() << "] ");
|
||||
TK_INFO(" ==> '" << etk::regexp::autoStr(std::string(_search, expression.start(), expression.stop() - expression.start())) << "'");
|
||||
TK_INFO(" ==> '" << etk::regex::autoStr(std::string(_search, expression.start(), expression.stop() - expression.start())) << "'");
|
||||
return std::make_pair(expression.start(), expression.stop());
|
||||
}
|
||||
TK_INFO(" ==> ---------------");
|
||||
@ -29,95 +29,95 @@ static std::string data1 = " a /* plop */ \n int eee = 22; // error value \nint
|
||||
static std::string data2 = "alpha /* plop */ test";
|
||||
static std::string data3 = "pp \n // qdfqdfsdf \nde";
|
||||
|
||||
TEST(TestEtkRegExp, MultipleLineComment ) {
|
||||
TEST(TestEtkRegEx, MultipleLineComment ) {
|
||||
std::string expression = "/\\*.*\\*/";
|
||||
std::pair<int32_t, int32_t> res;
|
||||
res = testRegExpSingle(expression, data1);
|
||||
res = testRegExSingle(expression, data1);
|
||||
EXPECT_EQ(res, std::make_pair(3,13));
|
||||
res = testRegExpSingle(expression, data2);
|
||||
res = testRegExSingle(expression, data2);
|
||||
EXPECT_EQ(res, std::make_pair(6,16));
|
||||
res = testRegExpSingle(expression, data3);
|
||||
res = testRegExSingle(expression, data3);
|
||||
EXPECT_EQ(res, std::make_pair(0,0));
|
||||
}
|
||||
TEST(TestEtkRegExp, MultipleEndDollar ) {
|
||||
TEST(TestEtkRegEx, MultipleEndDollar ) {
|
||||
std::string expression = "//.*$";
|
||||
std::pair<int32_t, int32_t> res;
|
||||
res = testRegExpSingle(expression, data1);
|
||||
res = testRegExSingle(expression, data1);
|
||||
EXPECT_EQ(res, std::make_pair(30,46));
|
||||
res = testRegExpSingle(expression, data2);
|
||||
res = testRegExSingle(expression, data2);
|
||||
EXPECT_EQ(res, std::make_pair(0,0));
|
||||
res = testRegExpSingle(expression, data3);
|
||||
res = testRegExSingle(expression, data3);
|
||||
EXPECT_EQ(res, std::make_pair(5,19));
|
||||
}
|
||||
|
||||
TEST(TestEtkRegExp, MultipleNoEnd ) {
|
||||
TEST(TestEtkRegEx, MultipleNoEnd ) {
|
||||
std::string expression = "/\\*.*";
|
||||
std::pair<int32_t, int32_t> res;
|
||||
res = testRegExpSingle(expression, data1);
|
||||
res = testRegExSingle(expression, data1);
|
||||
EXPECT_EQ(res, std::make_pair(3,5));
|
||||
res = testRegExpSingle(expression, data2);
|
||||
res = testRegExSingle(expression, data2);
|
||||
EXPECT_EQ(res, std::make_pair(6,8));
|
||||
res = testRegExpSingle(expression, data3);
|
||||
res = testRegExSingle(expression, data3);
|
||||
EXPECT_EQ(res, std::make_pair(0,0));
|
||||
}
|
||||
|
||||
TEST(TestEtkRegExp, aToZ ) {
|
||||
TEST(TestEtkRegEx, aToZ ) {
|
||||
std::string expression = "[a-z]";
|
||||
std::pair<int32_t, int32_t> res;
|
||||
res = testRegExpSingle(expression, data1);
|
||||
res = testRegExSingle(expression, data1);
|
||||
EXPECT_EQ(res, std::make_pair(1,2));
|
||||
res = testRegExpSingle(expression, data2);
|
||||
res = testRegExSingle(expression, data2);
|
||||
EXPECT_EQ(res, std::make_pair(0,1));
|
||||
res = testRegExpSingle(expression, data3);
|
||||
res = testRegExSingle(expression, data3);
|
||||
EXPECT_EQ(res, std::make_pair(0,1));
|
||||
}
|
||||
|
||||
TEST(TestEtkRegExp, complexString ) {
|
||||
TEST(TestEtkRegEx, complexString ) {
|
||||
std::string expression = "a.*plop(z{2,3}|h+)+r";
|
||||
std::string dataToParse = " eesd a lzzml plophzzzzzhhhhhrlkmlkml";
|
||||
std::pair<int32_t, int32_t> res;
|
||||
res = testRegExpSingle(expression, dataToParse);
|
||||
res = testRegExSingle(expression, dataToParse);
|
||||
EXPECT_EQ(res, std::make_pair(7,31));
|
||||
}
|
||||
|
||||
TEST(TestEtkRegExp, multipleUnderscore ) {
|
||||
TEST(TestEtkRegEx, multipleUnderscore ) {
|
||||
std::string expression = "\\@\\w+_\\@";
|
||||
std::string dataToParse = " aaa_bbb_ plop_ ";
|
||||
std::pair<int32_t, int32_t> res;
|
||||
res = testRegExpSingle(expression, dataToParse);
|
||||
res = testRegExSingle(expression, dataToParse);
|
||||
EXPECT_EQ(res, std::make_pair(2,10));
|
||||
}
|
||||
|
||||
|
||||
TEST(TestEtkRegExp, endError ) {
|
||||
TEST(TestEtkRegEx, endError ) {
|
||||
std::string expression = "\\@((0(x|X)[0-9a-fA-F]*)|(\\d+\\.?\\d*|\\.\\d+)((e|E)(\\+|\\-)?\\d+)?)(LL|L|l|UL|ul|u|U|F|f)?\\@";
|
||||
std::string dataToParse = "(95";
|
||||
std::pair<int32_t, int32_t> res;
|
||||
res = testRegExpSingle(expression, dataToParse);
|
||||
res = testRegExSingle(expression, dataToParse);
|
||||
EXPECT_EQ(res, std::make_pair(7,31));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void testRegExp() {
|
||||
void testRegEx() {
|
||||
std::string data;
|
||||
|
||||
//std::string data = "pp \n# plop // qdfqdfsdf \nde";
|
||||
//std::string data = "pp \n# plop //\\\n qdfqdfsdf \nde";
|
||||
//std::string data = "p#\ne";
|
||||
//testRegExpSingle("#(\\\\\\\\|\\\\\\n|.)*$", data);
|
||||
//testRegExpSingle("#.*$", data);
|
||||
//testRegExSingle("#(\\\\\\\\|\\\\\\n|.)*$", data);
|
||||
//testRegExSingle("#.*$", data);
|
||||
|
||||
//std::string data = "p//TODO:\ndse";
|
||||
//std::string data = "p// TODO:\ndse";
|
||||
//std::string data = "p// TODO :\ndse";
|
||||
//std::string data = "p// TODO : sdfgsdfsd \ndse";
|
||||
//testRegExpSingle("//[ \\t]*TODO[ \\t]*:.*$", data);
|
||||
//testRegExSingle("//[ \\t]*TODO[ \\t]*:.*$", data);
|
||||
|
||||
data = "abc m_def ghi";
|
||||
data = " protected:\n"
|
||||
" vec2 m_offset; \n";
|
||||
//testRegExpSingle("\\@m_[A-Za-z_0-9]*\\@", data);
|
||||
//testRegExSingle("\\@m_[A-Za-z_0-9]*\\@", data);
|
||||
|
||||
|
||||
data = " * @param[in] _mode Configuring mode.\n"
|
||||
@ -126,7 +126,7 @@ void testRegExp() {
|
||||
" void setAnnimationTime(enum ";
|
||||
data = "virtual vec2 relativePosition(const vec2& _pos);";
|
||||
|
||||
//testRegExpSingle("\\@(\\w|_)+[ \\t]*\\(", data);
|
||||
//testRegExSingle("\\@(\\w|_)+[ \\t]*\\(", data);
|
||||
|
||||
data = "include <ewol/Dimensio2n.h>\n"
|
||||
"#include <ewol/Dimension.h>\n"
|
||||
@ -142,17 +142,17 @@ void testRegExp() {
|
||||
" };\n"
|
||||
"};\n"
|
||||
"#include <etk/types.h>\n";
|
||||
//testRegExpSingle("#(\\\\[\\\\\\n]|.)*$", data);
|
||||
//testRegExSingle("#(\\\\[\\\\\\n]|.)*$", data);
|
||||
|
||||
|
||||
data = " 'dfgd\\'fg' \n"
|
||||
" vec2 m_offset; \n";
|
||||
//testRegExpSingle("'((\\\\[\\\\'])|.)*'", data);
|
||||
//testRegExSingle("'((\\\\[\\\\'])|.)*'", data);
|
||||
|
||||
|
||||
/*
|
||||
data = "ddfgdfgh";
|
||||
etk::RegExp<std::string> reg(".*");
|
||||
etk::RegEx<std::string> reg(".*");
|
||||
reg.setMaximize(true);
|
||||
|
||||
TK_INFO("Parse RegEx : '" << reg.getRegExDecorated() << "'");
|
||||
@ -163,7 +163,7 @@ void testRegExp() {
|
||||
}
|
||||
|
||||
data = "plop \"\" sdfsdf s\"swdfsqd sdfgsdfg \" \" sdfsf";
|
||||
reg = etk::RegExp<std::string>("\"(\\\\[\\\\\"]|.)*\"");
|
||||
reg = etk::RegEx<std::string>("\"(\\\\[\\\\\"]|.)*\"");
|
||||
reg.setMaximize(false);
|
||||
TK_INFO("Parse RegEx : '" << reg.getRegExDecorated() << "'");
|
||||
if (reg.parse(data, 0, data.size()) == true) {
|
||||
@ -174,7 +174,7 @@ void testRegExp() {
|
||||
//TODO : good : "(\\+|[0-9])*" ==> really bad : "(+|[0-9])*"
|
||||
|
||||
data = "void limit(const vec2& _origin, const vec2& _size);\n";
|
||||
reg = etk::RegExp<std::string>("\\@(\\w|_)+[ \\t]*\\(");
|
||||
reg = etk::RegEx<std::string>("\\@(\\w|_)+[ \\t]*\\(");
|
||||
reg.setMaximize(false);
|
||||
TK_INFO("Parse RegEx : '" << reg.getRegExDecorated() << "'");
|
||||
if (reg.parse(data, 0, data.size()) == true) {
|
||||
|
Loading…
Reference in New Issue
Block a user