From c60fe0326dd06a8750494ee995f90209537049ce Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 27 Jun 2013 21:08:26 +0200 Subject: [PATCH] [DEV] add capacity at string --- etk/Char.cpp | 4 ++++ etk/Char.h | 1 + etk/UString.cpp | 61 ++++++++++++++++++++++++++++++++++++++--------- etk/UString.h | 30 ++++++++++++++--------- etk/os/FSNode.cpp | 13 ++++++++++ etk/os/FSNode.h | 6 +++++ 6 files changed, 93 insertions(+), 22 deletions(-) diff --git a/etk/Char.cpp b/etk/Char.cpp index 03fa9d4..cc864d6 100644 --- a/etk/Char.cpp +++ b/etk/Char.cpp @@ -43,4 +43,8 @@ void etk::Char::SetValue(const etk::Vector& _data) } +int64_t etk::Char::Size(void) +{ + return m_data.Size()-1; +} diff --git a/etk/Char.h b/etk/Char.h index 741baa5..b84298f 100644 --- a/etk/Char.h +++ b/etk/Char.h @@ -25,6 +25,7 @@ namespace etk operator const char *(); operator void *(); void SetValue(const etk::Vector& _data); + int64_t Size(void); }; }; diff --git a/etk/UString.cpp b/etk/UString.cpp index 28fa64c..d49c775 100644 --- a/etk/UString.cpp +++ b/etk/UString.cpp @@ -39,6 +39,20 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::UString& _obj) return _os; } +etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector& _obj) +{ + _os << "{"; + for (int32_t iii=0; iii< _obj.Size(); iii++) { + if (iii>0) { + _os << " ~ "; + } + _os << _obj[iii]; + } + _os << "}"; + return _os; +} + + etk::UString::UString(void) { //TK_INFO("new etk::UString()"); @@ -154,7 +168,7 @@ etk::UString::UString(const double _inputData) Set(tmpVal); } -void etk::UString::SetNumber(bool _negative, const uint64_t& _inputData, etk::UString::printMode_te _mode, bool _preset) +void etk::UString::SetNumber(bool _negative, const uint64_t& _inputData, etk::UString::printMode_te _mode, bool _preset, int32_t _leadingZero) { m_data.Clear(); if (true==_negative) { @@ -218,19 +232,28 @@ void etk::UString::SetNumber(bool _negative, const uint64_t& _inputData, etk::US base=16; break; } + //printf("lmkmlj %llX\n", _inputData); + //printf("lmkmlk %s\n", ploppp); uint64_t tmpVal = _inputData; etk::UString tmpString; while (tmpVal>0) { uint64_t quotient = tmpVal / base; uint64_t rest = tmpVal - quotient*base; - tmpString.Add(0,(rest+'0')); + if (rest<=9) { + tmpString.Add(0,(char)(rest+'0')); + } else { + tmpString.Add(0,(char)(rest-10+'A')); + } tmpVal = quotient; } if (tmpString.Size() == 0) { - m_data.PushBack('0'); - } else { - *this += tmpString; + tmpString = "0"; } + for (int32_t iii=tmpString.Size(); iii<_leadingZero; iii++){ + tmpString.Add(0,'0'); + } + *this += tmpString; + //TK_ERROR (" " << ploppp); } if (m_data.Size()==0) { @@ -241,23 +264,23 @@ void etk::UString::SetNumber(bool _negative, const uint64_t& _inputData, etk::US //TK_ERROR(" convert : " << _inputData << " in : " << *this << " len=" << m_data.Size()); } -void etk::UString::Set(const int64_t& _inputData, etk::UString::printMode_te _mode, bool _preset) +void etk::UString::Set(const int64_t& _inputData, etk::UString::printMode_te _mode, bool _preset, int32_t _leadingZero) { if (_preset==true && _mode != etk::UString::printModeString) { - SetNumber(false, (uint64_t)_inputData, _mode, _preset); + SetNumber(false, (uint64_t)_inputData, _mode, _preset, _leadingZero); return; } if (_inputData < 0) { uint64_t tmpData = (uint64_t)((int64_t)_inputData * (int64_t)(-1)); - SetNumber(true, (uint64_t)tmpData, _mode, _preset); + SetNumber(true, (uint64_t)tmpData, _mode, _preset, _leadingZero); } else { - SetNumber(false, (uint64_t)_inputData, _mode, _preset); + SetNumber(false, (uint64_t)_inputData, _mode, _preset, _leadingZero); } } -void etk::UString::Set(const uint64_t& _inputData, etk::UString::printMode_te _mode, bool _preset) +void etk::UString::Set(const uint64_t& _inputData, etk::UString::printMode_te _mode, bool _preset, int32_t _leadingZero) { - SetNumber(false, (uint64_t)_inputData, _mode, _preset); + SetNumber(false, (uint64_t)_inputData, _mode, _preset, _leadingZero); } // multiple element add @@ -765,6 +788,22 @@ etk::Char etk::UString::c_str(void) const return tmpVar; } +etk::Vector etk::UString::Split(const etk::UniChar& _val) +{ + etk::Vector list; + int32_t lastStartPos=0; + for(int32_t iii=0; iii& _inputData); void Set(const etk::Vector& _inputData); private: - void SetNumber(bool _negative, const uint64_t& _inputData, etk::UString::printMode_te _mode, bool _preset); + void SetNumber(bool _negative, const uint64_t& _inputData, etk::UString::printMode_te _mode, bool _preset, int32_t _leadingZero); public: - void Set(const int64_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false); - void Set(const uint64_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false); + void Set(const int64_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0); + void Set(const uint64_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0); /***************************************************** * = assigment @@ -148,6 +148,13 @@ namespace etk void Clear(void); void Append(const etk::UniChar& _inputData); + /** + * @brief Split a string in multiple separate by a specific char + * @param[in] _val Separate value of the string + * @return The list of all sthe string splited. + */ + etk::Vector Split(const etk::UniChar& _val); + etk::Vector GetVector(void); etk::UniChar* pointer(void) { return &m_data[0]; }; @@ -219,6 +226,7 @@ namespace etk }; etk::CCout& operator <<(etk::CCout& _os, const etk::UString& _obj); + etk::CCout& operator <<(etk::CCout& _os, const etk::Vector& _obj); } diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 36a81b4..1d2d022 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -1831,3 +1831,16 @@ bool etk::FSNodeEchoAdd(const etk::UString& path, const etk::UString& dataTowrit return tmpNode.FileClose(); } +void etk::FSNodeHistory(const etk::UString& _path, int32_t _historyCount) +{ + // step 1 : Move the file to prevent writing error + //Get the first oldest save : + for (int32_t iii=_historyCount-1; iii>0 ; iii--) { + if (true==etk::FSNodeExist(_path+"-"+iii) ) { + etk::FSNodeMove(_path+"-"+iii,_path+"-"+(iii+1)); + } + } + if (true==etk::FSNodeExist(_path) ) { + etk::FSNodeMove(_path,_path+"-1"); + } +} diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index f4488a0..26a1557 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -573,6 +573,12 @@ namespace etk * @return false : An error occured */ bool FSNodeEchoAdd(const etk::UString& path, const etk::UString& dataTowrite); + /** + * @brief move file to generate an history of the current file + * @param[in] _path Folder/File/Pipe path of the node + * @param[in] _historyCount number of saved file in the history (-xxx) + */ + void FSNodeHistory(const etk::UString& _path, int32_t _historyCount); }; #endif