[DEV] some correct and add string converter
This commit is contained in:
parent
249870fc13
commit
91c6690daa
@ -79,7 +79,8 @@ etk::UString::UString(const uniChar_t inputData)
|
||||
void etk::UString::Set(const char * inputData, int32_t len)
|
||||
{
|
||||
if (NULL == inputData) {
|
||||
// nothing to add ...
|
||||
// nothing to add ... ==> clear all the data ...
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
// overwrite the len if needed :
|
||||
@ -105,7 +106,8 @@ void etk::UString::Set(const char * inputData, int32_t len)
|
||||
void etk::UString::Set(const uniChar_t * inputData, int32_t len)
|
||||
{
|
||||
if (NULL == inputData) {
|
||||
// nothing to add ...
|
||||
// nothing to add ... ==> clear all the data ...
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
// overwrite the len if needed :
|
||||
@ -639,3 +641,90 @@ etk::Char etk::UString::c_str(void) const
|
||||
}
|
||||
|
||||
|
||||
int64_t etk::UString::ToInt64(void) const
|
||||
{
|
||||
int64_t ret=0;
|
||||
bool isOdd = false;
|
||||
for (int32_t iii=0; iii<m_data.Size(); iii++) {
|
||||
if( iii==0
|
||||
&& ( m_data[iii] == '-'
|
||||
|| m_data[iii] == '+') ) {
|
||||
if(m_data[iii] == '-') {
|
||||
isOdd = true;
|
||||
}
|
||||
} else {
|
||||
if (m_data[iii]>='0' && m_data[iii]<='9') {
|
||||
int32_t val = m_data[iii] - '0';
|
||||
ret = ret*10 + val;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isOdd == true) {
|
||||
ret *= -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t etk::UString::ToInt32(void) const
|
||||
{
|
||||
int64_t parse = ToInt64();
|
||||
return etk_avg((int64_t)INT32_MIN, parse, (int64_t)INT32_MAX);
|
||||
}
|
||||
int16_t etk::UString::ToInt16(void) const
|
||||
{
|
||||
int64_t parse = ToInt64();
|
||||
return etk_avg((int64_t)INT16_MIN, parse, (int64_t)INT16_MAX);
|
||||
}
|
||||
int8_t etk::UString::ToInt8(void) const
|
||||
{
|
||||
int64_t parse = ToInt64();
|
||||
return etk_avg((int64_t)INT8_MIN, parse, (int64_t)INT8_MAX);
|
||||
}
|
||||
|
||||
double etk::UString::ToDouble(void) const
|
||||
{
|
||||
double ret=0;
|
||||
bool isOdd = false;
|
||||
int32_t dotPos = -1;
|
||||
for (int32_t iii=0; iii<m_data.Size(); iii++) {
|
||||
if( iii==0
|
||||
&& ( m_data[iii] == '-'
|
||||
|| m_data[iii] == '+') ) {
|
||||
if(m_data[iii] == '-') {
|
||||
isOdd = true;
|
||||
}
|
||||
} else {
|
||||
if (dotPos == -1) {
|
||||
if (m_data[iii] == '.') {
|
||||
dotPos = 1;
|
||||
// jump at the next element
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (m_data[iii]>='0' && m_data[iii]<='9') {
|
||||
int32_t val = m_data[iii] - '0';
|
||||
double val2 = val;
|
||||
if (dotPos>=0) {
|
||||
ret += (val2*(((double)dotPos)*0.1));
|
||||
dotPos++;
|
||||
} else {
|
||||
ret = ret*10.0 + val2;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isOdd == true) {
|
||||
ret *= -1.0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
float etk::UString::ToFloat(void) const
|
||||
{
|
||||
return (float)ToDouble();
|
||||
}
|
||||
|
@ -127,6 +127,36 @@ namespace etk
|
||||
|
||||
// Sting operation :
|
||||
etk::UString Extract(int32_t posStart=0, int32_t posEnd=0x7FFFFFFF) const;
|
||||
/**
|
||||
* @brief Transform the current string in an int64_t
|
||||
* @return the requested int
|
||||
*/
|
||||
int64_t ToInt64(void) const;
|
||||
/**
|
||||
* @brief Transform the current string in an int32_t (if the number is higher, then it is limited at the int32_t max)
|
||||
* @return the requested int
|
||||
*/
|
||||
int32_t ToInt32(void) const;
|
||||
/**
|
||||
* @brief Transform the current string in an int16_t (if the number is higher, then it is limited at the int16_t max)
|
||||
* @return the requested int
|
||||
*/
|
||||
int16_t ToInt16(void) const;
|
||||
/**
|
||||
* @brief Transform the current string in an int8_t (if the number is higher, then it is limited at the int8_t max)
|
||||
* @return the requested int
|
||||
*/
|
||||
int8_t ToInt8(void) const;
|
||||
/**
|
||||
* @brief Transform the current string in a double
|
||||
* @return the requested double
|
||||
*/
|
||||
double ToDouble(void) const;
|
||||
/**
|
||||
* @brief Transform the current string in a float
|
||||
* @return the requested float
|
||||
*/
|
||||
float ToFloat(void) const;
|
||||
};
|
||||
|
||||
etk::CCout& operator <<(etk::CCout &os, const etk::UString &obj);
|
||||
|
@ -984,7 +984,8 @@ bool etk::FSNode::Move(const etk::UString& path)
|
||||
if (tmpDst.Exist()==true) {
|
||||
tmpDst.Remove();
|
||||
}
|
||||
int32_t res = rename(GetName().c_str(), tmpDst.GetName().c_str());
|
||||
TK_DEBUG("Move : \"" << GetFileSystemName() << "\" ==> \"" << tmpDst.GetFileSystemName() << "\"");
|
||||
int32_t res = rename(GetFileSystemName().c_str(), tmpDst.GetFileSystemName().c_str());
|
||||
if (res!=0) {
|
||||
return false;
|
||||
} else {
|
||||
@ -1730,6 +1731,7 @@ bool etk::FSNodeMove(const etk::UString& path1, const etk::UString& path2)
|
||||
{
|
||||
etk::FSNode tmpNode(path1);
|
||||
if (false==tmpNode.Exist()) {
|
||||
TK_DEBUG("try to move un existant file \"" << path1 << "\"");
|
||||
return false;
|
||||
}
|
||||
// no check error in every case
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
// defien type : uintXX_t and intXX_t
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint32_t uniChar_t;
|
||||
|
Loading…
x
Reference in New Issue
Block a user