[DEV] add capacity at string
This commit is contained in:
parent
d2099c51e9
commit
c60fe0326d
@ -43,4 +43,8 @@ void etk::Char::SetValue(const etk::Vector<char>& _data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int64_t etk::Char::Size(void)
|
||||||
|
{
|
||||||
|
return m_data.Size()-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ namespace etk
|
|||||||
operator const char *();
|
operator const char *();
|
||||||
operator void *();
|
operator void *();
|
||||||
void SetValue(const etk::Vector<char>& _data);
|
void SetValue(const etk::Vector<char>& _data);
|
||||||
|
int64_t Size(void);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,6 +39,20 @@ etk::CCout& etk::operator <<(etk::CCout& _os, const etk::UString& _obj)
|
|||||||
return _os;
|
return _os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
etk::CCout& etk::operator <<(etk::CCout& _os, const etk::Vector<etk::UString>& _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)
|
etk::UString::UString(void)
|
||||||
{
|
{
|
||||||
//TK_INFO("new etk::UString()");
|
//TK_INFO("new etk::UString()");
|
||||||
@ -154,7 +168,7 @@ etk::UString::UString(const double _inputData)
|
|||||||
Set(tmpVal);
|
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();
|
m_data.Clear();
|
||||||
if (true==_negative) {
|
if (true==_negative) {
|
||||||
@ -218,19 +232,28 @@ void etk::UString::SetNumber(bool _negative, const uint64_t& _inputData, etk::US
|
|||||||
base=16;
|
base=16;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
//printf("lmkmlj %llX\n", _inputData);
|
||||||
|
//printf("lmkmlk %s\n", ploppp);
|
||||||
uint64_t tmpVal = _inputData;
|
uint64_t tmpVal = _inputData;
|
||||||
etk::UString tmpString;
|
etk::UString tmpString;
|
||||||
while (tmpVal>0) {
|
while (tmpVal>0) {
|
||||||
uint64_t quotient = tmpVal / base;
|
uint64_t quotient = tmpVal / base;
|
||||||
uint64_t rest = tmpVal - quotient*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;
|
tmpVal = quotient;
|
||||||
}
|
}
|
||||||
if (tmpString.Size() == 0) {
|
if (tmpString.Size() == 0) {
|
||||||
m_data.PushBack('0');
|
tmpString = "0";
|
||||||
} else {
|
|
||||||
*this += tmpString;
|
|
||||||
}
|
}
|
||||||
|
for (int32_t iii=tmpString.Size(); iii<_leadingZero; iii++){
|
||||||
|
tmpString.Add(0,'0');
|
||||||
|
}
|
||||||
|
*this += tmpString;
|
||||||
|
|
||||||
//TK_ERROR (" " << ploppp);
|
//TK_ERROR (" " << ploppp);
|
||||||
}
|
}
|
||||||
if (m_data.Size()==0) {
|
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());
|
//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) {
|
if (_preset==true && _mode != etk::UString::printModeString) {
|
||||||
SetNumber(false, (uint64_t)_inputData, _mode, _preset);
|
SetNumber(false, (uint64_t)_inputData, _mode, _preset, _leadingZero);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_inputData < 0) {
|
if (_inputData < 0) {
|
||||||
uint64_t tmpData = (uint64_t)((int64_t)_inputData * (int64_t)(-1));
|
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 {
|
} 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
|
// multiple element add
|
||||||
@ -765,6 +788,22 @@ etk::Char etk::UString::c_str(void) const
|
|||||||
return tmpVar;
|
return tmpVar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
etk::Vector<etk::UString> etk::UString::Split(const etk::UniChar& _val)
|
||||||
|
{
|
||||||
|
etk::Vector<etk::UString> list;
|
||||||
|
int32_t lastStartPos=0;
|
||||||
|
for(int32_t iii=0; iii<Size(); iii++) {
|
||||||
|
if (m_data[iii]==_val) {
|
||||||
|
list.PushBack(Extract(lastStartPos, iii));
|
||||||
|
lastStartPos = iii+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (lastStartPos<Size()) {
|
||||||
|
list.PushBack(Extract(lastStartPos));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void etk::UString::Lower(void)
|
void etk::UString::Lower(void)
|
||||||
{
|
{
|
||||||
|
@ -43,14 +43,14 @@ namespace etk
|
|||||||
UString(const char* _data, unicode::charset_te _inputCharset);
|
UString(const char* _data, unicode::charset_te _inputCharset);
|
||||||
UString(const float _inputData);
|
UString(const float _inputData);
|
||||||
UString(const double _inputData);
|
UString(const double _inputData);
|
||||||
UString(const int8_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false) { Set((int64_t)_inputData, _mode, _preset); };
|
UString(const int8_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0) { Set((int64_t)_inputData, _mode, _preset, _leadingZero); };
|
||||||
UString(const int16_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false) { Set((int64_t)_inputData, _mode, _preset); };
|
UString(const int16_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0) { Set((int64_t)_inputData, _mode, _preset, _leadingZero); };
|
||||||
UString(const int32_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false) { Set((int64_t)_inputData, _mode, _preset); };
|
UString(const int32_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0) { Set((int64_t)_inputData, _mode, _preset, _leadingZero); };
|
||||||
UString(const int64_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false) { Set(_inputData, _mode, _preset); };
|
UString(const int64_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0) { Set(_inputData, _mode, _preset, _leadingZero); };
|
||||||
UString(const uint8_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false) { Set((uint64_t)_inputData, _mode, _preset); };
|
UString(const uint8_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0) { Set((uint64_t)_inputData, _mode, _preset, _leadingZero); };
|
||||||
UString(const uint16_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false) { Set((uint64_t)_inputData, _mode, _preset); };
|
UString(const uint16_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0) { Set((uint64_t)_inputData, _mode, _preset, _leadingZero); };
|
||||||
UString(const uint32_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false) { Set((uint64_t)_inputData, _mode, _preset); };
|
UString(const uint32_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0) { Set((uint64_t)_inputData, _mode, _preset, _leadingZero); };
|
||||||
UString(const uint64_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false) { Set(_inputData, _mode, _preset); };
|
UString(const uint64_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0) { Set(_inputData, _mode, _preset, _leadingZero); };
|
||||||
// multiple element add
|
// multiple element add
|
||||||
UString(const etk::UniChar* _inputData, int32_t _len = -1);
|
UString(const etk::UniChar* _inputData, int32_t _len = -1);
|
||||||
UString(const char* _inputData, int32_t _len = -1);
|
UString(const char* _inputData, int32_t _len = -1);
|
||||||
@ -64,10 +64,10 @@ namespace etk
|
|||||||
void Set(const etk::Vector<int8_t>& _inputData);
|
void Set(const etk::Vector<int8_t>& _inputData);
|
||||||
void Set(const etk::Vector<etk::UniChar>& _inputData);
|
void Set(const etk::Vector<etk::UniChar>& _inputData);
|
||||||
private:
|
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:
|
public:
|
||||||
void Set(const int64_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);
|
void Set(const uint64_t& _inputData, printMode_te _mode=printModeDecimal, bool _preset=false, int32_t _leadingZero=0);
|
||||||
|
|
||||||
/*****************************************************
|
/*****************************************************
|
||||||
* = assigment
|
* = assigment
|
||||||
@ -148,6 +148,13 @@ namespace etk
|
|||||||
void Clear(void);
|
void Clear(void);
|
||||||
void Append(const etk::UniChar& _inputData);
|
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<etk::UString> Split(const etk::UniChar& _val);
|
||||||
|
|
||||||
etk::Vector<etk::UniChar> GetVector(void);
|
etk::Vector<etk::UniChar> GetVector(void);
|
||||||
etk::UniChar* pointer(void) { return &m_data[0]; };
|
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::UString& _obj);
|
||||||
|
etk::CCout& operator <<(etk::CCout& _os, const etk::Vector<etk::UString>& _obj);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1831,3 +1831,16 @@ bool etk::FSNodeEchoAdd(const etk::UString& path, const etk::UString& dataTowrit
|
|||||||
return tmpNode.FileClose();
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -573,6 +573,12 @@ namespace etk
|
|||||||
* @return false : An error occured
|
* @return false : An error occured
|
||||||
*/
|
*/
|
||||||
bool FSNodeEchoAdd(const etk::UString& path, const etk::UString& dataTowrite);
|
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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user