[DEV] add String and Vector 2D capabilities

This commit is contained in:
Edouard DUPIN 2013-04-11 22:48:22 +02:00
parent 2b19ef4bc8
commit 32da0ffb78
4 changed files with 182 additions and 2 deletions

View File

@ -346,6 +346,34 @@ bool etk::UString::operator== (const etk::UString& etkS) const
return true;
}
bool etk::UString::CompareNoCase(const etk::UString& etkS) const
{
if( this != &etkS ) {
if (etkS.m_data.Size() != m_data.Size()) {
//TK_DEBUG(" not the same size : " << etkS.m_data.Size() << "!=" << m_data.Size());
return false;
}
for (int32_t iii= 0; iii<m_data.Size(); iii++) {
//TK_DEBUG(" check : " << etkS.m_data[iii] << "!=" << m_data[iii]);
uniChar_t in1 = etkS.m_data[iii];
uniChar_t in2 = m_data[iii];
if( in1>=(uniChar_t)'A'
&& in1<=(uniChar_t)'Z') {
in1 += (uniChar_t)'a' - (uniChar_t)'A';
}
if( in2>=(uniChar_t)'A'
&& in2<=(uniChar_t)'Z') {
in2 += (uniChar_t)'a' - (uniChar_t)'A';
}
if (in1!=in2){
return false;
}
}
return true;
}
return true;
}
bool etk::UString::operator!= (const etk::UString& etkS) const
{

View File

@ -46,11 +46,12 @@ namespace etk
/*****************************************************
* == operator
*****************************************************/
bool operator== (const etk::UString& etkS) const;
bool operator== (const etk::UString& etkS) const;
bool CompareNoCase(const etk::UString& etkS) const;
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const etk::UString& etkS) const;
bool operator!= (const etk::UString& etkS) const;
/*****************************************************
* > < >= <= operator
*****************************************************/

View File

@ -48,3 +48,152 @@ etk::CCout& etk::operator <<(etk::CCout &os, const etk::Vector2D<bool> obj)
return os;
}
namespace etk {
template<> Vector2D<bool>::Vector2D(const etk::UString& str)
{
m_floats[0] = false;
m_floats[1] = false;
if (str.StartWith("(")) {
if (str.StartWith("(t")) {
if (str.CompareNoCase("(true,true)")) {
m_floats[0] = true;
m_floats[1] = true;
} else if (str.CompareNoCase("(true,false)")) {
m_floats[0] = true;
m_floats[1] = false;
} else if (str.CompareNoCase("(true)")) {
m_floats[0] = true;
m_floats[1] = true;
}
} else if (str.StartWith("(f")) {
if (str.CompareNoCase("(false,true)")) {
m_floats[0] = false;
m_floats[1] = true;
} else if (str.CompareNoCase("(false,false)")) {
m_floats[0] = false;
m_floats[1] = false;
} else if (str.CompareNoCase("(false)")) {
m_floats[0] = false;
m_floats[1] = false;
}
} else {
if (str.CompareNoCase("(1,1)")) {
m_floats[0] = true;
m_floats[1] = true;
} else if (str.CompareNoCase("(1)")) {
m_floats[0] = true;
m_floats[1] = true;
} else if (str.CompareNoCase("(1,0)")) {
m_floats[0] = true;
m_floats[1] = false;
} else if (str.CompareNoCase("(0,1)")) {
m_floats[0] = false;
m_floats[1] = true;
} else if (str.CompareNoCase("(0,0)")) {
m_floats[0] = false;
m_floats[1] = false;
} else if (str.CompareNoCase("(0)")) {
m_floats[0] = false;
m_floats[1] = false;
}
}
} else {
if (str.StartWith("t")) {
if (str.CompareNoCase("true,true")) {
m_floats[0] = true;
m_floats[1] = true;
} else if (str.CompareNoCase("true,false")) {
m_floats[0] = true;
m_floats[1] = false;
} else if (str.CompareNoCase("true")) {
m_floats[0] = true;
m_floats[1] = true;
}
} else if (str.StartWith("f")) {
if (str.CompareNoCase("false,true")) {
m_floats[0] = false;
m_floats[1] = true;
} else if (str.CompareNoCase("false,false")) {
m_floats[0] = false;
m_floats[1] = false;
} else if (str.CompareNoCase("false")) {
m_floats[0] = false;
m_floats[1] = false;
}
} else {
if (str.CompareNoCase("1,1")) {
m_floats[0] = true;
m_floats[1] = true;
} else if (str.CompareNoCase("1")) {
m_floats[0] = true;
m_floats[1] = true;
} else if (str.CompareNoCase("1,0")) {
m_floats[0] = true;
m_floats[1] = false;
} else if (str.CompareNoCase("0,1")) {
m_floats[0] = false;
m_floats[1] = true;
} else if (str.CompareNoCase("0,0")) {
m_floats[0] = false;
m_floats[1] = false;
} else if (str.CompareNoCase("0")) {
m_floats[0] = false;
m_floats[1] = false;
}
}
}
}
template<> Vector2D<int32_t>::Vector2D(const etk::UString& str)
{
m_floats[0] = 0;
m_floats[1] = 0;
if (str.StartWith("(")) {
int32_t val1=0;
int32_t val2=0;
sscanf(str.c_str(), "(%d,%d)", &val1, &val2);
m_floats[0] = val1;
m_floats[1] = val2;
} else {
int32_t val1=0;
int32_t val2=0;
sscanf(str.c_str(), "%d,%d", &val1, &val2);
m_floats[0] = val1;
m_floats[1] = val2;
}
}
template<> Vector2D<uint32_t>::Vector2D(const etk::UString& str)
{
m_floats[0] = 0;
m_floats[1] = 0;
if (str.StartWith("(")) {
int32_t val1=0;
int32_t val2=0;
sscanf(str.c_str(), "(%d,%d)", &val1, &val2);
m_floats[0] = etk_max(0,val1);
m_floats[1] = etk_max(0,val2);
} else {
int32_t val1=0;
int32_t val2=0;
sscanf(str.c_str(), "%d,%d", &val1, &val2);
m_floats[0] = etk_max(0,val1);
m_floats[1] = etk_max(0,val2);
}
}
template<> Vector2D<float>::Vector2D(const etk::UString& str)
{
m_floats[0] = 0;
m_floats[1] = 0;
if (str.StartWith("(")) {
sscanf(str.c_str(), "(%f,%f)", &m_floats[0], &m_floats[1]);
} else {
sscanf(str.c_str(), "(%f,%f)", &m_floats[0], &m_floats[1]);
}
}
};

View File

@ -12,6 +12,7 @@
#include <etk/types.h>
#include <etk/Stream.h>
#include <etk/math/Vector3D.h>
#include <etk/UString.h>
#include <math.h>
namespace etk
@ -41,6 +42,7 @@ namespace etk
Vector2D(const Vector2D<double>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); };
Vector2D(const Vector2D<float>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); };
Vector2D(const Vector2D<int32_t>& obj) { m_floats[0] = (T)obj.x(); m_floats[1] = (T)obj.y(); };
Vector2D(const etk::UString& str);
~Vector2D(void) { };
/*****************************************************
* = assigment