diff --git a/etk/UString.cpp b/etk/UString.cpp index ac066f6..71de4bd 100644 --- a/etk/UString.cpp +++ b/etk/UString.cpp @@ -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='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='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(); +} diff --git a/etk/UString.h b/etk/UString.h index 2918a9b..197084c 100644 --- a/etk/UString.h +++ b/etk/UString.h @@ -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); diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 92d8199..b3af04e 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -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 diff --git a/etk/types.h b/etk/types.h index 8bc5373..aa595cf 100644 --- a/etk/types.h +++ b/etk/types.h @@ -15,6 +15,7 @@ #include #include // defien type : uintXX_t and intXX_t +#define __STDC_LIMIT_MACROS #include typedef uint32_t uniChar_t;