[DEV] continue removing std

This commit is contained in:
Edouard DUPIN 2017-08-24 22:27:27 +02:00
parent 9db3d1daa9
commit 7ac3ef06c4
28 changed files with 3608 additions and 1815 deletions

View File

@ -9,6 +9,7 @@
#pragma once #pragma once
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/UString.hpp>
#include <iomanip> #include <iomanip>
namespace etk { namespace etk {

View File

@ -389,11 +389,11 @@ template<> etk::String toString<Color<uint16_t, 1> >(const Color<uint16_t, 1>& _
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint16_t, 1>>(const Color<uint16_t, 1>& _val) { template<> etk::UString toUString<Color<uint16_t, 1>>(const Color<uint16_t, 1>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint16_t, 1>>(Color<uint16_t, 1>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint16_t, 1>>(Color<uint16_t, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint16_t, 1>(toString(_value)); _variableRet = Color<uint16_t, 1>(toString(_value));
return true; return true;
} }
@ -409,11 +409,11 @@ template<> etk::String toString<Color<uint16_t, 2> >(const Color<uint16_t, 2>& _
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint16_t, 2>>(const Color<uint16_t, 2>& _val) { template<> etk::UString toUString<Color<uint16_t, 2>>(const Color<uint16_t, 2>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint16_t, 2>>(Color<uint16_t, 2>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint16_t, 2>>(Color<uint16_t, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint16_t, 2>(toString(_value)); _variableRet = Color<uint16_t, 2>(toString(_value));
return true; return true;
} }
@ -429,11 +429,11 @@ template<> etk::String toString<Color<uint16_t, 3> >(const Color<uint16_t, 3>& _
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint16_t, 3>>(const Color<uint16_t, 3>& _val) { template<> etk::UString toUString<Color<uint16_t, 3>>(const Color<uint16_t, 3>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint16_t, 3>>(Color<uint16_t, 3>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint16_t, 3>>(Color<uint16_t, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint16_t, 3>(toString(_value)); _variableRet = Color<uint16_t, 3>(toString(_value));
return true; return true;
} }
@ -449,11 +449,11 @@ template<> etk::String toString<Color<uint16_t, 4> >(const Color<uint16_t, 4>& _
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint16_t, 4>>(const Color<uint16_t, 4>& _val) { template<> etk::UString toUString<Color<uint16_t, 4>>(const Color<uint16_t, 4>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint16_t, 4>>(Color<uint16_t, 4>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint16_t, 4>>(Color<uint16_t, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint16_t, 4>(toString(_value)); _variableRet = Color<uint16_t, 4>(toString(_value));
return true; return true;
} }

View File

@ -389,10 +389,10 @@ template<> etk::String toString<Color<uint32_t, 1> >(const Color<uint32_t, 1>& _
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint32_t, 1>>(const Color<uint32_t, 1>& _val) { template<> etk::UString toUString<Color<uint32_t, 1>>(const Color<uint32_t, 1>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint32_t, 1>>(Color<uint32_t, 1>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint32_t, 1>>(Color<uint32_t, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint32_t, 1>(toString(_value)); _variableRet = Color<uint32_t, 1>(toString(_value));
return true; return true;
} }
@ -406,10 +406,10 @@ template<> etk::String toString<Color<uint32_t, 2> >(const Color<uint32_t, 2>& _
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint32_t, 2>>(const Color<uint32_t, 2>& _val) { template<> etk::UString toUString<Color<uint32_t, 2>>(const Color<uint32_t, 2>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint32_t, 2>>(Color<uint32_t, 2>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint32_t, 2>>(Color<uint32_t, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint32_t, 2>(toString(_value)); _variableRet = Color<uint32_t, 2>(toString(_value));
return true; return true;
} }
@ -425,10 +425,10 @@ template<> etk::String toString<Color<uint32_t, 3> >(const Color<uint32_t, 3>& _
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint32_t, 3>>(const Color<uint32_t, 3>& _val) { template<> etk::UString toUString<Color<uint32_t, 3>>(const Color<uint32_t, 3>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint32_t, 3>>(Color<uint32_t, 3>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint32_t, 3>>(Color<uint32_t, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint32_t, 3>(toString(_value)); _variableRet = Color<uint32_t, 3>(toString(_value));
return true; return true;
} }
@ -444,10 +444,10 @@ template<> etk::String toString<Color<uint32_t, 4> >(const Color<uint32_t, 4>& _
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint32_t, 4>>(const Color<uint32_t, 4>& _val) { template<> etk::UString toUString<Color<uint32_t, 4>>(const Color<uint32_t, 4>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint32_t, 4>>(Color<uint32_t, 4>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint32_t, 4>>(Color<uint32_t, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint32_t, 4>(toString(_value)); _variableRet = Color<uint32_t, 4>(toString(_value));
return true; return true;
} }

View File

@ -388,10 +388,10 @@ template<> etk::String toString<Color<uint8_t, 1> >(const Color<uint8_t, 1>& _va
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint8_t, 1>>(const Color<uint8_t, 1>& _val) { template<> etk::UString toUString<Color<uint8_t, 1>>(const Color<uint8_t, 1>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint8_t, 1>>(Color<uint8_t, 1>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint8_t, 1>>(Color<uint8_t, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint8_t, 1>(toString(_value)); _variableRet = Color<uint8_t, 1>(toString(_value));
return true; return true;
} }
@ -408,10 +408,10 @@ template<> etk::String toString<Color<uint8_t, 2> >(const Color<uint8_t, 2>& _va
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint8_t, 2>>(const Color<uint8_t, 2>& _val) { template<> etk::UString toUString<Color<uint8_t, 2>>(const Color<uint8_t, 2>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint8_t, 2>>(Color<uint8_t, 2>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint8_t, 2>>(Color<uint8_t, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint8_t, 2>(toString(_value)); _variableRet = Color<uint8_t, 2>(toString(_value));
return true; return true;
} }
@ -427,10 +427,10 @@ template<> etk::String toString<Color<uint8_t, 3> >(const Color<uint8_t, 3>& _va
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint8_t, 3>>(const Color<uint8_t, 3>& _val) { template<> etk::UString toUString<Color<uint8_t, 3>>(const Color<uint8_t, 3>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint8_t, 3>>(Color<uint8_t, 3>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint8_t, 3>>(Color<uint8_t, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint8_t, 3>(toString(_value)); _variableRet = Color<uint8_t, 3>(toString(_value));
return true; return true;
} }
@ -445,10 +445,10 @@ template<> etk::String toString<Color<uint8_t, 4> >(const Color<uint8_t, 4>& _va
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<uint8_t, 4>>(const Color<uint8_t, 4>& _val) { template<> etk::UString toUString<Color<uint8_t, 4>>(const Color<uint8_t, 4>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<uint8_t, 4>>(Color<uint8_t, 4>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<uint8_t, 4>>(Color<uint8_t, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<uint8_t, 4>(toString(_value)); _variableRet = Color<uint8_t, 4>(toString(_value));
return true; return true;
} }

View File

@ -389,10 +389,10 @@ template<> etk::String toString<Color<double, 1> >(const Color<double, 1>& _val)
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<double, 1>>(const Color<double, 1>& _val) { template<> etk::UString toUString<Color<double, 1>>(const Color<double, 1>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<double, 1>>(Color<double, 1>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<double, 1>>(Color<double, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<double, 1>(toString(_value)); _variableRet = Color<double, 1>(toString(_value));
return true; return true;
} }
@ -409,10 +409,10 @@ template<> etk::String toString<Color<double, 2> >(const Color<double, 2>& _val)
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<double, 2>>(const Color<double, 2>& _val) { template<> etk::UString toUString<Color<double, 2>>(const Color<double, 2>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<double, 2>>(Color<double, 2>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<double, 2>>(Color<double, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<double, 2>(toString(_value)); _variableRet = Color<double, 2>(toString(_value));
return true; return true;
} }
@ -429,10 +429,10 @@ template<> etk::String toString<Color<double, 3> >(const Color<double, 3>& _val)
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<double, 3>>(const Color<double, 3>& _val) { template<> etk::UString toUString<Color<double, 3>>(const Color<double, 3>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<double, 3>>(Color<double, 3>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<double, 3>>(Color<double, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<double, 3>(toString(_value)); _variableRet = Color<double, 3>(toString(_value));
return true; return true;
} }
@ -448,10 +448,10 @@ template<> etk::String toString<Color<double, 4> >(const Color<double, 4>& _val)
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<double, 4>>(const Color<double, 4>& _val) { template<> etk::UString toUString<Color<double, 4>>(const Color<double, 4>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<double, 4>>(Color<double, 4>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<double, 4>>(Color<double, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<double, 4>(toString(_value)); _variableRet = Color<double, 4>(toString(_value));
return true; return true;
} }

View File

@ -387,10 +387,10 @@ template<> etk::String toString<Color<float, 1> >(const Color<float, 1>& _val) {
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<float, 1>>(const Color<float, 1>& _val) { template<> etk::UString toUString<Color<float, 1>>(const Color<float, 1>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<float, 1>>(Color<float, 1>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<float, 1>>(Color<float, 1>& _variableRet, const etk::UString& _value) {
_variableRet = Color<float, 1>(toString(_value)); _variableRet = Color<float, 1>(toString(_value));
return true; return true;
} }
@ -405,10 +405,10 @@ template<> etk::String toString<Color<float, 2> >(const Color<float, 2>& _val) {
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<float, 2>>(const Color<float, 2>& _val) { template<> etk::UString toUString<Color<float, 2>>(const Color<float, 2>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<float, 2>>(Color<float, 2>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<float, 2>>(Color<float, 2>& _variableRet, const etk::UString& _value) {
_variableRet = Color<float, 2>(toString(_value)); _variableRet = Color<float, 2>(toString(_value));
return true; return true;
} }
@ -423,10 +423,10 @@ template<> etk::String toString<Color<float, 3> >(const Color<float, 3>& _val) {
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<float, 3>>(const Color<float, 3>& _val) { template<> etk::UString toUString<Color<float, 3>>(const Color<float, 3>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<float, 3>>(Color<float, 3>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<float, 3>>(Color<float, 3>& _variableRet, const etk::UString& _value) {
_variableRet = Color<float, 3>(toString(_value)); _variableRet = Color<float, 3>(toString(_value));
return true; return true;
} }
@ -441,10 +441,10 @@ template<> etk::String toString<Color<float, 4> >(const Color<float, 4>& _val) {
return _val.getString(); return _val.getString();
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<> std::u32string to_u32string<Color<float, 4>>(const Color<float, 4>& _val) { template<> etk::UString toUString<Color<float, 4>>(const Color<float, 4>& _val) {
return to_u32string(_val.getString()); return toUString(_val.getString());
} }
template<> bool from_string<Color<float, 4>>(Color<float, 4>& _variableRet, const std::u32string& _value) { template<> bool from_string<Color<float, 4>>(Color<float, 4>& _variableRet, const etk::UString& _value) {
_variableRet = Color<float, 4>(toString(_value)); _variableRet = Color<float, 4>(toString(_value));
return true; return true;
} }

View File

@ -7,6 +7,7 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#pragma once #pragma once
#include <etk/String.hpp>
namespace etk { namespace etk {
/** /**
@ -61,7 +62,7 @@ namespace etk {
*/ */
template<class MY_TYPE> class Hash { template<class MY_TYPE> class Hash {
private: private:
std::vector<HashData<MY_TYPE>* > m_data; //!< Data of the hash ==> the Hash table is composed of pointer, this permit to have high speed when resize the vector ... etk::Vector<HashData<MY_TYPE>* > m_data; //!< Data of the hash ==> the Hash table is composed of pointer, this permit to have high speed when resize the vector ...
public: public:
/** /**
* @brief Constructor of the Hash table. * @brief Constructor of the Hash table.
@ -166,7 +167,7 @@ namespace etk {
//TK_ERROR("allocation error in Hash table : '" << _key << "'"); //TK_ERROR("allocation error in Hash table : '" << _key << "'");
return; return;
} }
m_data.push_back(tmp); m_data.pushBack(tmp);
return; return;
} }
m_data[elementId]->m_value = _value; m_data[elementId]->m_value = _value;
@ -237,11 +238,11 @@ namespace etk {
* @brief Get all the element name (keys). * @brief Get all the element name (keys).
* @return a vector of all name (key). * @return a vector of all name (key).
*/ */
std::vector<etk::String> getKeys() const { etk::Vector<etk::String> getKeys() const {
std::vector<etk::String> keys; etk::Vector<etk::String> keys;
for (auto &it : m_data) { for (auto &it : m_data) {
if (it != nullptr) { if (it != nullptr) {
keys.push_back(it->m_key); keys.pushBack(it->m_key);
} }
} }
return keys; return keys;

View File

@ -375,7 +375,7 @@ bool etk::regex::parseBrace(const std::vector<char32_t>& _data, uint32_t& _min,
return false; return false;
} if (_data[k] == '}') { } if (_data[k] == '}') {
goto allIsSet; goto allIsSet;
} else if (true == u32char::isInteger(_data[k])) { } else if (u32char::isInteger(_data[k]) == true) {
SecondElement *= 10; SecondElement *= 10;
SecondElement += u32char::toInt(_data[k]); SecondElement += u32char::toInt(_data[k]);
} else { } else {
@ -458,21 +458,21 @@ namespace etk {
template<> etk::String toString<etk::RegEx<etk::String>>(const etk::RegEx<etk::String>& _val) { template<> etk::String toString<etk::RegEx<etk::String>>(const etk::RegEx<etk::String>& _val) {
return _val.getRegEx(); return _val.getRegEx();
} }
template<> etk::String toString<etk::RegEx<std::u32string>>(const etk::RegEx<std::u32string>& _val) { template<> etk::String toString<etk::RegEx<etk::UString>>(const etk::RegEx<etk::UString>& _val) {
return _val.getRegEx(); return _val.getRegEx();
} }
template<> std::u32string to_u32string<etk::RegEx<etk::String>>(const etk::RegEx<etk::String>& _val) { template<> etk::UString toUString<etk::RegEx<etk::String>>(const etk::RegEx<etk::String>& _val) {
return _val.getURegEx(); return _val.getURegEx();
} }
template<> std::u32string to_u32string<etk::RegEx<std::u32string>>(const etk::RegEx<std::u32string>& _val) { template<> etk::UString toUString<etk::RegEx<etk::UString>>(const etk::RegEx<etk::UString>& _val) {
return _val.getURegEx(); return _val.getURegEx();
} }
template<> bool from_string<etk::RegEx<etk::String>>(etk::RegEx<etk::String>& _variableRet, const std::u32string& _value) { template<> bool from_string<etk::RegEx<etk::String>>(etk::RegEx<etk::String>& _variableRet, const etk::UString& _value) {
_variableRet.compile(_value); _variableRet.compile(_value);
return true; return true;
} }
template<> bool from_string<etk::RegEx<std::u32string>>(etk::RegEx<std::u32string>& _variableRet, const std::u32string& _value) { template<> bool from_string<etk::RegEx<etk::UString>>(etk::RegEx<etk::UString>& _variableRet, const etk::UString& _value) {
_variableRet.compile(_value); _variableRet.compile(_value);
return true; return true;
} }
@ -480,7 +480,7 @@ namespace etk {
_variableRet.compile(_value); _variableRet.compile(_value);
return true; return true;
} }
template<> bool from_string<etk::RegEx<std::u32string>>(etk::RegEx<std::u32string>& _variableRet, const etk::String& _value) { template<> bool from_string<etk::RegEx<etk::UString>>(etk::RegEx<etk::UString>& _variableRet, const etk::String& _value) {
_variableRet.compile(_value); _variableRet.compile(_value);
return true; return true;
} }

View File

@ -11,7 +11,7 @@
#include <etk/debug.hpp> #include <etk/debug.hpp>
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
#include <etk/String.hpp> #include <etk/String.hpp>
#include <vector> #include <etk/UString.hpp>
#include <memory> #include <memory>
#define TK_REG_DEBUG TK_HIDDEN #define TK_REG_DEBUG TK_HIDDEN
@ -1378,7 +1378,7 @@ template<class CLASS_TYPE> class NodePThese : public Node<CLASS_TYPE> {
*/ */
template<class CLASS_TYPE> class RegEx { template<class CLASS_TYPE> class RegEx {
private: private:
std::u32string m_expressionRequested; //!< Regular expression parsed ... etk::UString m_expressionRequested; //!< Regular expression parsed ...
regex::ElementPos m_areaFind; //!< position around selection regex::ElementPos m_areaFind; //!< position around selection
regex::NodePThese<CLASS_TYPE> m_expressionRootNode; //!< The tree where data is set regex::NodePThese<CLASS_TYPE> m_expressionRootNode; //!< The tree where data is set
bool m_isOk; //!< Known if we can process with this regEx bool m_isOk; //!< Known if we can process with this regEx
@ -1391,7 +1391,7 @@ template<class CLASS_TYPE> class RegEx {
* @brief Constructor * @brief Constructor
* @param[in,out] _expression Regular expression to parse * @param[in,out] _expression Regular expression to parse
*/ */
RegEx(const std::u32string &_expression=U"") : RegEx(const etk::UString &_expression=U"") :
m_expressionRequested(U""), m_expressionRequested(U""),
m_isOk(false), m_isOk(false),
m_notBeginWithChar(false), m_notBeginWithChar(false),
@ -1415,7 +1415,7 @@ template<class CLASS_TYPE> class RegEx {
m_areaFind.start=0; m_areaFind.start=0;
m_areaFind.stop=0; m_areaFind.stop=0;
if (_expression.size() != 0) { if (_expression.size() != 0) {
compile(etk::to_u32string(_expression)); compile(etk::toUString(_expression));
} }
}; };
/** /**
@ -1440,13 +1440,13 @@ template<class CLASS_TYPE> class RegEx {
void compile(const etk::String &_expression) { void compile(const etk::String &_expression) {
if (_expression.size() != 0) { if (_expression.size() != 0) {
TK_REG_DEBUG("normal string parse : '" << _expression << "'"); TK_REG_DEBUG("normal string parse : '" << _expression << "'");
compile(etk::to_u32string(_expression)); compile(etk::toUString(_expression));
} }
} }
/** /**
* @previous * @previous
*/ */
void compile(const std::u32string &_expression) { void compile(const etk::UString &_expression) {
m_expressionRequested = _expression; m_expressionRequested = _expression;
std::vector<char32_t> tmpExpression; std::vector<char32_t> tmpExpression;
@ -1587,7 +1587,7 @@ template<class CLASS_TYPE> class RegEx {
/** /**
* @previous * @previous
*/ */
const std::u32string& getURegEx() const { const etk::UString& getURegEx() const {
return m_expressionRequested; return m_expressionRequested;
}; };

View File

@ -2,7 +2,466 @@
#include <etk/String.hpp> #include <etk/String.hpp>
etk::String::String():
m_data() {
m_data.resize(1, '\0');
}
etk::String::String(const etk::String& _obj) {
m_data = _obj.m_data;
}
etk::String::String(const etk::String& _obj, size_t _pos, size_t _size) {
if (_pos + _size >= _obj.size()) {
_size = etk::String::npos;
}
if (_size != etk::String::npos) {
resize(_size);
for (size_t iii=0; iii<_size; ++iii) {
m_data[iii] = _obj.m_data[_pos+iii];
}
return;
}
resize(_obj.size()-_pos);
for (size_t iii=0; iii<_obj.size()-_pos; ++iii) {
m_data[iii] = _obj.m_data[_pos+iii];
}
}
etk::String::String(const char* _obj) {
if (_obj == nullptr) {
resize(0);
return;
}
uint32_t size = strlen(_obj);
resize(size);
for (size_t iii=0; iii<size; ++iii) {
m_data[iii] = _obj[iii];
}
}
etk::String::String(const std::string _obj) {
resize(_obj.size());
for (size_t iii=0; iii<_obj.size(); ++iii) {
m_data[iii] = _obj[iii];
}
}
etk::String::String(const char* _obj, size_t _size) {
if ( _obj == nullptr
|| _size == 0) {
resize(0);
return;
}
uint32_t size = strlen(_obj);
if (_size < size) {
size = _size;
}
resize(size);
for (size_t iii=0; iii<size; ++iii) {
m_data[iii] = _obj[iii];
}
}
etk::String::String(size_t _size, char _val) {
resize(_size);
for (size_t iii=0; iii<_size; ++iii) {
m_data[iii] = _val;
}
}
etk::String::String(Iterator _start, Iterator _stop) {
size_t size = etk::distance(_start, _stop);
resize(size);
Iterator it = begin();
while (_start != _stop) {
*it++ = *_start++;
}
}
etk::String::String(etk::String&& _obj) noexcept {
m_data = std::move(_obj.m_data);
}
etk::String::String(char _value) {
resize(1);
m_data[0] = _value;
}
etk::String::~String() {
// nothing to do...
}
void etk::String::swap(etk::String& _obj) {
// avoid Swap of itself
if(this != &_obj) {
m_data.swap(_obj.m_data);
}
}
etk::String& etk::String::operator=(const etk::String& _obj) {
if (this != &_obj) {
m_data = _obj.m_data;
}
// Return the current pointer
return *this;
}
etk::String& etk::String::operator=(const char* _obj) {
clear();
if (_obj == nullptr) {
return *this;
}
size_t numberElement = strlen(_obj);
resize(numberElement);
for (size_t iii=0; iii<numberElement; ++iii) {
m_data[iii] = _obj[iii];
}
// Return the current pointer
return *this;
}
etk::String& etk::String::operator=(char _value) {
resize(1);
m_data[0] = _value;
// Return the current pointer
return *this;
}
etk::String& etk::String::operator+= (const etk::String& _obj) {
size_t numberElement = _obj.size();
size_t idElement = size();
resize(size()+_obj.size());
for (size_t iii=0; iii<_obj.size(); ++iii) {
m_data[idElement+iii] = _obj[iii];
}
// Return the current pointer
return *this;
}
etk::String& etk::String::operator+= (const char* _obj) {
if (_obj == nullptr) {
return *this;
}
size_t numberElement = strlen(_obj);
size_t idElement = size();
resize(size() + numberElement);
for (size_t iii=0; iii<numberElement; ++iii) {
m_data[idElement+iii] = _obj[iii];
}
// Return the current pointer
return *this;
}
etk::String& etk::String::operator+= (char _value) {
pushBack(_value);
// Return the current pointer
return *this;
}
size_t etk::String::size() const {
return m_data.size() - 1; // remove '\0'
}
void etk::String::pushFront(char _item) {
insert(0, &_item, 1);
}
void etk::String::pushFront(const char * _item, size_t _nbElement) {
insert(0, _item, _nbElement);
}
void etk::String::pushBack(const char _item) {
size_t idElement = size();
resize(size()+1);
if (idElement < size()) {
m_data[idElement] = _item;
} else {
TK_ERROR("Resize does not work correctly ... not added item");
}
}
void etk::String::pushBack(const char* _item, size_t _nbElement) {
if (_item == nullptr) {
return;
}
size_t idElement = size();
resize(size()+_nbElement);
if (idElement > size()) {
TK_ERROR("Resize does not work correctly ... not added item");
return;
}
for (size_t iii=0; iii<_nbElement; iii++) {
m_data[idElement+iii] = _item[iii];
}
}
void etk::String::popBack() {
if(size()>0) {
resize(size()-1);
}
}
void etk::String::clear() {
resize(0);
}
void etk::String::insert(size_t _pos, const char* _item, size_t _nbElement) {
if (_pos>size()) {
TK_WARNING(" can not insert Element at this position : " << _pos << " > " << size() << " add it at the end ... ");
pushBack(_item, _nbElement);
return;
}
size_t idElement = size();
// Request resize of the current buffer
resize(size()+_nbElement);
if (idElement>=size()) {
TK_ERROR("Resize does not work correctly ... not added item");
return;
}
// move current data (after the position)
size_t sizeToMove = (idElement - _pos);
if ( 0 < sizeToMove) {
for (size_t iii=1; iii<=sizeToMove; iii++) {
m_data[size()-iii] = m_data[idElement-iii];
}
}
// affectation of all input element
for (size_t iii=0; iii<_nbElement; iii++) {
m_data[_pos+iii] = _item[iii];
}
}
void etk::String::insert(size_t _pos, const char _item) {
insert(_pos, &_item, 1);
}
void etk::String::insert(size_t _pos, const etk::String& _value) {
insert(_pos, &_value[0], _value.size());
}
void etk::String::erase(size_t _pos, size_t _nbElement) {
if (_pos>size()) {
TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << size());
return;
}
if (_pos+_nbElement>size()) {
_nbElement = size() - _pos;
}
size_t idElement = size();
// move current data
size_t sizeToMove = (idElement - (_pos+_nbElement));
if ( 0 < sizeToMove) {
for (size_t iii=0; iii<sizeToMove; iii++) {
m_data[_pos+iii] = m_data[_pos+_nbElement+iii];
}
}
// Request resize of the current buffer
resize(size() - _nbElement);
}
void etk::String::eraseRange(size_t _pos, size_t _posEnd) {
if (_pos>size()) {
TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << size());
return;
}
if (_posEnd > size()) {
_posEnd = size();
}
size_t nbElement = size() - _pos;
size_t tmpSize = size();
// move current data
size_t sizeToMove = (tmpSize - (_pos+nbElement));
if ( 0 < sizeToMove) {
for (size_t iii=0; iii<sizeToMove; iii++) {
m_data[_pos+iii] = m_data[_pos+nbElement+iii];
}
}
// Request resize of the current buffer
resize(size()-nbElement);
}
etk::String etk::String::extract(size_t _posStart, size_t _posEnd) const {
etk::String out;
if (_posStart >= size() ) {
return out;
}
if (_posEnd >= size() ) {
_posEnd = size();
}
out.pushBack(&m_data[_posStart], _posEnd-_posStart);
return out;
}
const char* etk::String::c_str() const {
return &m_data[0];
}
etk::String::Iterator etk::String::position(size_t _pos) {
return etk::String::Iterator(this, _pos);
}
const etk::String::Iterator etk::String::position(size_t _pos) const {
return etk::String::Iterator(this, _pos);
}
etk::String::Iterator etk::String::begin() {
return position(0);
}
const etk::String::Iterator etk::String::begin() const {
return position(0);
}
etk::String::Iterator etk::String::end() {
return position( size()-1 );
}
const etk::String::Iterator etk::String::end() const {
return position( size()-1 );
}
void etk::String::resize(size_t _newSize, char _value) {
size_t oldSize = m_data.size();
m_data[m_data.size()-1] = _value;
m_data.resize(_newSize + 1, _value);
// in all case ==> we have the last element that is '\0'
m_data[_newSize] = '\0';
}
bool etk::String::operator== (const etk::String& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return true;
}
// first step : check the size ...
if (m_data.size() != _obj.m_data.size()) {
return false;
}
for (size_t iii=0; iii<m_data.size(); ++iii) {
if (m_data[iii] != _obj.m_data[iii]) {
return false;
}
}
return true;
}
bool etk::String::operator!= (const etk::String& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return false;
}
// first step : check the size ...
if (m_data.size() != _obj.m_data.size()) {
return true;
}
for (size_t iii=0; iii<m_data.size(); ++iii) {
if (m_data[iii] != _obj.m_data[iii]) {
return true;
}
}
return false;
}
char etk::toLower(char _value) {
if ( _value >= 'A'
&& _value <= 'Z') {
return _value + ('a' - 'A');
}
return _value;
}
char etk::toUpper(char _value) {
if ( _value >= 'a'
&& _value <= 'z') {
return _value + ('A' - 'z');
}
return _value;
}
etk::String etk::String::toLower() const {
etk::String tmp(*this);
for (auto &it: tmp) {
it = etk::toLower(it);
}
return tmp;
}
etk::String& etk::String::lower() {
for (auto &it: m_data) {
it = etk::toLower(it);
}
return *this;
}
etk::String etk::String::toUpper() const {
etk::String tmp(*this);
for (auto &it: tmp) {
it = etk::toUpper(it);
}
return tmp;
}
etk::String& etk::String::upper() {
for (auto &it: m_data) {
it = etk::toUpper(it);
}
return *this;
}
bool etk::String::endWith(const etk::String& _val, bool _caseSensitive) const {
if (_val.size() == 0) {
return false;
}
if (_val.size() > size()) {
return false;
}
if (_caseSensitive == true) {
for( int64_t iii=_val.size()-1, jjj=size()-1;
iii>=0 && jjj>=0;
iii--, jjj--) {
if (m_data[jjj] != _val[iii]) {
return false;
}
}
return true;
}
for( int64_t iii=_val.size()-1, jjj=size()-1;
iii>=0 && jjj>=0;
iii--, jjj--) {
if (etk::toLower(_val[iii]) != etk::toLower(m_data[jjj])) {
return false;
}
}
return true;
}
bool etk::String::startWith(const etk::String& _val, bool _caseSensitive) const {
if (_val.size() == 0) {
return false;
}
if (_val.size() > size()) {
return false;
}
if (_caseSensitive == true) {
for( size_t iii = 0;
iii < size();
iii++) {
if (m_data[iii] != _val[iii]) {
return false;
}
}
return true;
}
for( size_t iii = 0;
iii < _val.size();
iii++) {
if (etk::toLower(_val[iii]) != etk::toLower(m_data[iii])) {
return false;
}
}
return true;
}
template <> template <>
long double etk::String::to<long double>() const { long double etk::String::to<long double>() const {
long double ret = 0; long double ret = 0;
@ -94,6 +553,16 @@ uint64_t etk::String::to<uint64_t>() const {
return ret; return ret;
} }
template <>
bool etk::String::to<bool>() const {
if( compare("true", false) == true
|| compare("enable", false) == true
|| compare("yes", false) == true
|| compare("1") == true) {
return true;
}
return false;
}
std::ostream& etk::operator <<(std::ostream& _os, const etk::String& _obj) { std::ostream& etk::operator <<(std::ostream& _os, const etk::String& _obj) {
_os << _obj.c_str(); _os << _obj.c_str();
@ -116,6 +585,22 @@ void etk::sort(etk::Vector<etk::String *> &_list) {
} }
} }
void etk::sort(etk::Vector<etk::String> &_list) {
etk::Vector<etk::String> tmpList(_list);
_list.clear();
for(size_t iii=0; iii<tmpList.size(); iii++) {
size_t findPos = 0;
for(size_t jjj=0; jjj<_list.size(); jjj++) {
//TK_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
if (tmpList[iii] > _list[jjj]) {
findPos = jjj+1;
}
}
//TK_DEBUG("position="<<findPos);
_list.insert(_list.begin()+findPos, tmpList[iii]);
}
}
namespace etk { namespace etk {
@ -181,41 +666,60 @@ etk::String etk::toString(const bool& _val) {
return "false"; return "false";
} }
template<> template<>
etk::String etk::toString(const int& _val) { etk::String etk::toString(const int8_t& _val) {
char tmpVal[256]; char tmpVal[256];
sprintf(tmpVal, "%d", _val); sprintf(tmpVal, "%d", _val);
return tmpVal; return tmpVal;
} }
template<> template<>
etk::String etk::toString(const long& _val) { etk::String etk::toString(const int16_t& _val) {
char tmpVal[256]; char tmpVal[256];
sprintf(tmpVal, "%ld", _val); sprintf(tmpVal, "%d", _val);
return tmpVal; return tmpVal;
} }
template<> template<>
etk::String etk::toString(const long long& _val) { etk::String etk::toString(const int32_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%d", _val);
return tmpVal;
}
template<>
etk::String etk::toString(const int64_t& _val) {
char tmpVal[256]; char tmpVal[256];
sprintf(tmpVal, "%lld", _val); sprintf(tmpVal, "%lld", _val);
return tmpVal; return tmpVal;
} }
template<> template<>
etk::String etk::toString(const unsigned& _val) { etk::String etk::toString(const uint8_t& _val) {
char tmpVal[256]; char tmpVal[256];
sprintf(tmpVal, "%u", _val); sprintf(tmpVal, "%u", _val);
return tmpVal; return tmpVal;
} }
template<> template<>
etk::String etk::toString(const unsigned long& _val) { etk::String etk::toString(const uint16_t& _val) {
char tmpVal[256]; char tmpVal[256];
sprintf(tmpVal, "%lu", _val); sprintf(tmpVal, "%u", _val);
return tmpVal; return tmpVal;
} }
template<> template<>
etk::String etk::toString(const unsigned long long& _val) { etk::String etk::toString(const uint32_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%u", _val);
return tmpVal;
}
template<>
etk::String etk::toString(const uint64_t& _val) {
char tmpVal[256]; char tmpVal[256];
sprintf(tmpVal, "%llu", _val); sprintf(tmpVal, "%llu", _val);
return tmpVal; return tmpVal;
} }
template<>
etk::String etk::toString(const size_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%zu", _val);
return tmpVal;
}
template<> template<>
etk::String etk::toString(const float& _val) { etk::String etk::toString(const float& _val) {
char tmpVal[256]; char tmpVal[256];
@ -357,6 +861,25 @@ etk::String etk::String::getLine(int32_t _pos) const {
return etk::String(*this, startPos, stopPos - startPos); return etk::String(*this, startPos, stopPos - startPos);
} }
bool etk::String::compare(const etk::String& _val, bool _caseSensitive) const {
if (_val.size() != size()) {
return false;
}
if (_caseSensitive == true) {
for(size_t iii=0; iii<_val.size(); ++iii) {
if (_val[iii] != m_data[iii]) {
return false;
}
}
return true;
}
for(size_t iii=0; iii<_val.size(); ++iii) {
if (etk::toLower(_val[iii]) != etk::toLower(m_data[iii])) {
return false;
}
}
return true;
}
etk::Vector<etk::String> etk::String::split(char _val) const { etk::Vector<etk::String> etk::String::split(char _val) const {
etk::Vector<etk::String> list; etk::Vector<etk::String> list;
@ -389,3 +912,154 @@ etk::Vector<etk::String> etk::String::split(etk::String _val) const {
return list; return list;
} }
namespace etk {
long double string_to_long_double(const etk::String& _obj) {
return _obj.to<long double>();
}
double string_to_double(const etk::String& _obj) {
return _obj.to<double>();
}
float string_to_float(const etk::String& _obj) {
return _obj.to<float>();
}
int8_t string_to_int8_t(const etk::String& _obj) {
return _obj.to<int8_t>();
}
int16_t string_to_int16_t(const etk::String& _obj) {
return _obj.to<int16_t>();
}
int32_t string_to_int32_t(const etk::String& _obj) {
return _obj.to<int32_t>();
}
int64_t string_to_int64_t(const etk::String& _obj) {
return _obj.to<int64_t>();
}
uint8_t string_to_uint8_t(const etk::String& _obj) {
return _obj.to<uint8_t>();
}
uint16_t string_to_uint16_t(const etk::String& _obj) {
return _obj.to<uint16_t>();
}
uint32_t string_to_uint32_t(const etk::String& _obj) {
return _obj.to<uint32_t>();
}
uint64_t string_to_uint64_t(const etk::String& _obj) {
return _obj.to<uint64_t>();
}
bool string_to_bool(const etk::String& _obj) {
return _obj.to<bool>();
}
etk::String tolower(etk::String _obj) {
return _obj.toLower();
}
etk::String toupper(etk::String _obj) {
return _obj.toUpper();
}
bool compare_no_case(const etk::String& _obj, const etk::String& _val) {
return _obj.compare(_val, false);
}
bool end_with(const etk::String& _obj, const etk::String& _val, bool _caseSensitive) {
return _obj.endWith(_val, _caseSensitive);
}
bool start_with(const etk::String& _obj, const etk::String& _val, bool _caseSensitive) {
return _obj.startWith(_val, _caseSensitive);
}
etk::String replace(const etk::String& _obj, char _val, char _replace) {
etk::String tmp = _obj;
tmp.replace(_val, _replace);
return tmp;
}
etk::String extract_line(const etk::String& _obj, int32_t _pos) {
return _obj.getLine(_pos);
}
etk::Vector<etk::String> split(const etk::String& _obj, char _val) {
return _obj.split(_val);
}
}
bool etk::operator> (const etk::String& _left, const etk::String& _right) {
for (size_t iii=0; iii<_left.size() && iii<_right.size(); ++iii) {
if (_left[iii] > _right[iii]) {
return true;
}
if (_left[iii] < _right[iii]) {
return false;
}
}
if (_left.size() > _right.size()) {
return true;
}
return false;
}
bool etk::operator>= (const etk::String& _left, const etk::String& _right) {
for (size_t iii=0; iii<_left.size() && iii<_right.size(); ++iii) {
if (_left[iii] > _right[iii]) {
return true;
}
if (_left[iii] < _right[iii]) {
return false;
}
}
if (_left.size() >= _right.size()) {
return true;
}
return false;
}
bool etk::operator< (const etk::String& _left, const etk::String& _right) {
for (size_t iii=0; iii<_left.size() && iii<_right.size(); ++iii) {
if (_left[iii] < _right[iii]) {
return true;
}
if (_left[iii] > _right[iii]) {
return false;
}
}
if (_left.size() < _right.size()) {
return true;
}
return false;
}
bool etk::operator<= (const etk::String& _left, const etk::String& _right) {
for (size_t iii=0; iii<_left.size() && iii<_right.size(); ++iii) {
if (_left[iii] < _right[iii]) {
return true;
}
if (_left[iii] > _right[iii]) {
return false;
}
}
if (_left.size() <= _right.size()) {
return true;
}
return false;
}
etk::String etk::operator+ (const etk::String& _left, const etk::String& _right) {
etk::String tmp = _left;
tmp += _right;
return tmp;
}
etk::String etk::operator+ (const etk::String& _left, const char* _right) {
etk::String tmp = _left;
tmp += _right;
return tmp;
}
etk::String etk::operator+ (const char* _left, const etk::String& _right) {
etk::String tmp = _left;
tmp += _right;
return tmp;
}
etk::String etk::operator+ (const etk::String& _left, char _right) {
etk::String tmp = _left;
tmp.pushBack(_right);
return tmp;
}
etk::String etk::operator+ (char _left, const etk::String& _right) {
etk::String tmp = _left;
tmp += _right;
return tmp;
}

View File

@ -8,18 +8,9 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/debug.hpp> #include <etk/debug.hpp>
#include <etk/Vector.hpp> #include <etk/Vector.hpp>
#include <etk/stdTools.hpp>
namespace etk { namespace etk {
template<class ETK_ITERATOR_TYPE>
size_t distance(const ETK_ITERATOR_TYPE& _start, const ETK_ITERATOR_TYPE& _stop) {
size_t out = 0;
ETK_ITERATOR_TYPE tmp = _start;
while (tmp != _stop) {
out++;
++tmp;
}
return out;
}
/** /**
* @brief string class ... * @brief string class ...
*/ */
@ -98,7 +89,7 @@ namespace etk {
* @brief Incremental operator * @brief Incremental operator
* @return Reference on a new iterator and increment the other one * @return Reference on a new iterator and increment the other one
*/ */
Iterator operator++ (int32_t) { Iterator operator++ (int) {
Iterator it(*this); Iterator it(*this);
++(*this); ++(*this);
return it; return it;
@ -107,7 +98,7 @@ namespace etk {
* @brief Decremental operator * @brief Decremental operator
* @return Reference on a new iterator and decrement the other one * @return Reference on a new iterator and decrement the other one
*/ */
Iterator operator-- (int32_t) { Iterator operator-- (int) {
Iterator it(*this); Iterator it(*this);
--(*this); --(*this);
return it; return it;
@ -122,11 +113,11 @@ namespace etk {
tmp -= _offset; tmp -= _offset;
return tmp; return tmp;
} }
Iterator& operator-= (int64_t _offset) { Iterator& operator-= (int _offset) {
m_current -= _offset; m_current -= _offset;
return *this; return *this;
} }
Iterator operator- (int64_t _offset) const { Iterator operator- (int _offset) const {
Iterator tmp(*this); Iterator tmp(*this);
tmp -= _offset; tmp -= _offset;
return tmp; return tmp;
@ -140,11 +131,11 @@ namespace etk {
tmp += _offset; tmp += _offset;
return tmp; return tmp;
} }
Iterator& operator+= (int64_t _offset) { Iterator& operator+= (int _offset) {
m_current += _offset; m_current += _offset;
return *this; return *this;
} }
Iterator operator+ (int64_t _offset) const { Iterator operator+ (int _offset) const {
Iterator tmp(*this); Iterator tmp(*this);
tmp += _offset; tmp += _offset;
return tmp; return tmp;
@ -212,226 +203,101 @@ namespace etk {
/** /**
* @brief Create an empty string * @brief Create an empty string
*/ */
String(): String();
m_data() {
m_data.resize(1, '\0');
}
/** /**
* @brief Copy constructor (copy all data) * @brief Copy constructor (copy all data)
* @param[in] _obj String that might be copy * @param[in] _obj String that might be copy
*/ */
String(const etk::String& _obj) { String(const etk::String& _obj);
m_data = _obj.m_data;
}
/** /**
* @brief Partial copy constructor (copy all needed data) * @brief Partial copy constructor (copy all needed data)
* @param[in] _obj String that might be copy (part of it) * @param[in] _obj String that might be copy (part of it)
* @param[in] _pos Start position to copy data * @param[in] _pos Start position to copy data
* @param[in] _size Number of element to copy in the string * @param[in] _size Number of element to copy in the string
*/ */
String(const etk::String& _obj, size_t _pos, size_t _size = etk::String::npos) { String(const etk::String& _obj, size_t _pos, size_t _size = etk::String::npos);
if (_pos + _size >= _obj.size()) {
_size = etk::String::npos;
}
if (_size != etk::String::npos) {
resize(_size);
for (size_t iii=0; iii<_size; ++iii) {
m_data[iii] = _obj.m_data[_pos+iii];
}
return;
}
resize(_obj.size()-_pos);
for (size_t iii=0; iii<_obj.size()-_pos; ++iii) {
m_data[iii] = _obj.m_data[_pos+iii];
}
}
/** /**
* @brief Copy the null-terminated C string. * @brief Copy the null-terminated C string.
* @param[in] _obj C string that might be copy (end by '\0') * @param[in] _obj C string that might be copy (end by '\0')
*/ */
String(const char* _obj) { String(const char* _obj);
if (_obj == nullptr) {
resize(0);
return;
}
uint32_t size = strlen(_obj);
resize(size);
for (size_t iii=0; iii<size; ++iii) {
m_data[iii] = _obj[iii];
}
}
// TODO : remove this when ready // TODO : remove this when ready
String(const std::string _obj) { String(const std::string _obj);
resize(_obj.size());
for (size_t iii=0; iii<_obj.size(); ++iii) {
m_data[iii] = _obj[iii];
}
}
/** /**
* @brief Partial copy of the null-terminated C string. * @brief Partial copy of the null-terminated C string.
* @param[in] _obj String that might be copyC string that might be copy (end by '\0') * @param[in] _obj String that might be copyC string that might be copy (end by '\0')
* @param[in] _size Number of element to copy. * @param[in] _size Number of element to copy.
*/ */
String(const char* _obj, size_t _size) { String(const char* _obj, size_t _size);
if ( _obj == nullptr
|| _size == 0) {
resize(0);
return;
}
uint32_t size = strlen(_obj);
if (_size < size) {
size = _size;
}
resize(size);
for (size_t iii=0; iii<size; ++iii) {
m_data[iii] = _obj[iii];
}
}
/** /**
* @brief Fills the string with _size consecutive copies of character _val. * @brief Fills the string with _size consecutive copies of character _val.
* @param[in] _size Number of element in the string * @param[in] _size Number of element in the string
* @param[in] _val Value to set in the string * @param[in] _val Value to set in the string
*/ */
String(size_t _size, char _val) { String(size_t _size, char _val);
resize(_size);
for (size_t iii=0; iii<_size; ++iii) {
m_data[iii] = _val;
}
}
/** /**
* @brief Copy all element betewwen the 2 iterator of the new string. * @brief Copy all element betewwen the 2 iterator of the new string.
* @param[in] _start Start iterator of adding value. * @param[in] _start Start iterator of adding value.
* @param[in] _stop Start iterator of adding value. * @param[in] _stop Start iterator of adding value.
*/ */
String(Iterator _start, Iterator _stop) { String(Iterator _start, Iterator _stop);
size_t size = etk::distance(_start, _stop);
resize(size);
Iterator it = begin();
while (_start != _stop) {
*it++ = *_start++;
}
}
/** /**
* @brief Move constructor * @brief Move constructor
* @param[in] _obj String that might be move inside * @param[in] _obj String that might be move inside
*/ */
String(String&& _obj) noexcept { String(String&& _obj) noexcept;
m_data = std::move(_obj.m_data);
}
/** /**
* @brief Set constructor * @brief Set constructor
* @param[in] _value Char element to set in the string * @param[in] _value Char element to set in the string
*/ */
String(char _value) { String(char _value);
resize(1);
m_data[0] = _value;
}
/** /**
* @brief Destructor of the current Class * @brief Destructor of the current Class
*/ */
~String() { ~String();
// nothing to do...
}
/** /**
* @brief Swap the data of 2 Strings * @brief Swap the data of 2 Strings
* @param[in] _obj second string to swap data. * @param[in] _obj second string to swap data.
*/ */
void swap(etk::String& _obj) { void swap(etk::String& _obj);
// avoid Swap of itself
if(this != &_obj) {
m_data.swap(_obj.m_data);
}
}
/** /**
* @brief Re-copy operator * @brief Re-copy operator
* @param[in] _obj String that might be copy * @param[in] _obj String that might be copy
* @return reference on the current re-copy string * @return reference on the current re-copy string
*/ */
String& operator=(const etk::String& _obj) { String& operator=(const etk::String& _obj);
if (this != &_obj) {
m_data = _obj.m_data;
}
// Return the current pointer
return *this;
}
/** /**
* @brief Re-copy operator * @brief Re-copy operator
* @param[in] _obj C string terminated with '\0' * @param[in] _obj C string terminated with '\0'
* @return reference on the current re-copy string * @return reference on the current re-copy string
*/ */
String& operator=(const char* _obj) { String& operator=(const char* _obj);
clear();
if (_obj == nullptr) {
return *this;
}
size_t numberElement = strlen(_obj);
resize(numberElement);
for (size_t iii=0; iii<numberElement; ++iii) {
m_data[iii] = _obj[iii];
}
// Return the current pointer
return *this;
}
/** /**
* @brief Re-copy operator * @brief Re-copy operator
* @param[in] _value Char value to set in the string * @param[in] _value Char value to set in the string
* @return reference on the current re-copy string * @return reference on the current re-copy string
*/ */
String& operator=(char _value) { String& operator=(char _value);
resize(1);
m_data[0] = _value;
// Return the current pointer
return *this;
}
/** /**
* @brief Add at the Last position of the String * @brief Add at the Last position of the String
* @param[in] _obj Element to add at the end of string * @param[in] _obj Element to add at the end of string
*/ */
String& operator+= (const etk::String& _obj) { String& operator+= (const etk::String& _obj);
size_t numberElement = _obj.size();
size_t idElement = size();
resize(size()+_obj.size());
for (size_t iii=0; iii<_obj.size(); ++iii) {
m_data[idElement+iii] = _obj[iii];
}
// Return the current pointer
return *this;
}
/** /**
* @brief Add at the Last position of the String * @brief Add at the Last position of the String
* @param[in] _obj C string terminated with '\0' * @param[in] _obj C string terminated with '\0'
*/ */
String& operator+= (const char* _obj) { String& operator+= (const char* _obj);
if (_obj == nullptr) {
return *this;
}
size_t numberElement = strlen(_obj);
size_t idElement = size();
resize(size() + numberElement);
for (size_t iii=0; iii<numberElement; ++iii) {
m_data[idElement+iii] = _obj[iii];
}
// Return the current pointer
return *this;
}
/** /**
* @brief Add at the Last position of the String * @brief Add at the Last position of the String
* @param[in] _value Simple character to add. * @param[in] _value Simple character to add.
*/ */
String& operator+= (char _value) { String& operator+= (char _value);
pushBack(_value);
// Return the current pointer
return *this;
}
/** /**
* @brief Get the number of element in the string * @brief Get the number of element in the string
* @return The number requested * @return The number requested
*/ */
size_t size() const { size_t size() const;
return m_data.size() - 1; // remove '\0'
}
/** /**
* @brief Get a current element in the string * @brief Get a current element in the string
* @param[in] _pos Desired position read * @param[in] _pos Desired position read
@ -460,268 +326,112 @@ namespace etk {
* @brief Add at the First position of the String * @brief Add at the First position of the String
* @param[in] _item Element to add at the end of string * @param[in] _item Element to add at the end of string
*/ */
void pushFront(char _item) { void pushFront(char _item);
insert(0, &_item, 1);
}
/** /**
* @brief Add at the Last position of the String * @brief Add at the Last position of the String
* @param[in] _item Pointer on a list of Element to add at the start of string * @param[in] _item Pointer on a list of Element to add at the start of string
* @param[in] _nbElement Number of element to add. * @param[in] _nbElement Number of element to add.
*/ */
void pushFront(const char * _item, size_t _nbElement) { void pushFront(const char * _item, size_t _nbElement);
insert(0, _item, _nbElement);
}
/** /**
* @brief Add at the Last position of the String * @brief Add at the Last position of the String
* @param[in] _item Element to add at the end of string * @param[in] _item Element to add at the end of string
*/ */
void pushBack(const char _item) { void pushBack(const char _item);
size_t idElement = size();
resize(size()+1);
if (idElement < size()) {
m_data[idElement] = _item;
} else {
TK_ERROR("Resize does not work correctly ... not added item");
}
}
/** /**
* @brief Add at the Last position of the String * @brief Add at the Last position of the String
* @param[in] _item Pointer on a list of Element to add at the end of string * @param[in] _item Pointer on a list of Element to add at the end of string
* @param[in] _nbElement Number of element to add. * @param[in] _nbElement Number of element to add.
*/ */
void pushBack(const char* _item, size_t _nbElement) { void pushBack(const char* _item, size_t _nbElement);
if (_item == nullptr) {
return;
}
size_t idElement = size();
resize(size()+_nbElement);
if (idElement > size()) {
TK_ERROR("Resize does not work correctly ... not added item");
return;
}
for (size_t iii=0; iii<_nbElement; iii++) {
m_data[idElement+iii] = _item[iii];
}
}
/** /**
* @brief Remove the last element of the string * @brief Remove the last element of the string
*/ */
void popBack() { void popBack();
if(size()>0) {
resize(size()-1);
}
}
/** /**
* @brief Remove all element in the current string * @brief Remove all element in the current string
*/ */
void clear() { void clear();
resize(0);
}
/** /**
* @brief Insert N element in the String. * @brief Insert N element in the String.
* @param[in] _pos Position to add the elements. * @param[in] _pos Position to add the elements.
* @param[in] _item Pointer on a table of the elements to add. * @param[in] _item Pointer on a table of the elements to add.
* @param[in] _nbElement Number of element to add in the String * @param[in] _nbElement Number of element to add in the String
*/ */
void insert(size_t _pos, const char* _item, size_t _nbElement) { void insert(size_t _pos, const char* _item, size_t _nbElement);
if (_pos>size()) {
TK_WARNING(" can not insert Element at this position : " << _pos << " > " << size() << " add it at the end ... ");
pushBack(_item, _nbElement);
return;
}
size_t idElement = size();
// Request resize of the current buffer
resize(size()+_nbElement);
if (idElement>=size()) {
TK_ERROR("Resize does not work correctly ... not added item");
return;
}
// move current data (after the position)
size_t sizeToMove = (idElement - _pos);
if ( 0 < sizeToMove) {
for (size_t iii=1; iii<=sizeToMove; iii++) {
m_data[size()-iii] = m_data[idElement-iii];
}
}
// affectation of all input element
for (size_t iii=0; iii<_nbElement; iii++) {
m_data[_pos+iii] = _item[iii];
}
}
/** /**
* @brief Insert one element in the String at a specific position * @brief Insert one element in the String at a specific position
* @param[in] _pos Position to add the elements. * @param[in] _pos Position to add the elements.
* @param[in] _item Element to add. * @param[in] _item Element to add.
*/ */
void insert(size_t _pos, const char _item) { void insert(size_t _pos, const char _item);
insert(_pos, &_item, 1);
}
/** /**
* @brief Insert one element in the String at a specific position * @brief Insert one element in the String at a specific position
* @param[in] _pos Position to add the elements. * @param[in] _pos Position to add the elements.
* @param[in] _item Element to add. * @param[in] _item Element to add.
*/ */
void insert(size_t _pos, const String& _value) { void insert(size_t _pos, const String& _value);
insert(_pos, &_value[0], _value.size());
}
/** /**
* @brief Remove N element * @brief Remove N element
* @param[in] _pos Position to remove the data * @param[in] _pos Position to remove the data
* @param[in] _nbElement number of element to remove * @param[in] _nbElement number of element to remove
*/ */
void erase(size_t _pos, size_t _nbElement=1) { void erase(size_t _pos, size_t _nbElement=1);
if (_pos>size()) {
TK_ERROR(" can not Erase Len Element at this position : " << _pos << " > " << size());
return;
}
if (_pos+_nbElement>size()) {
_nbElement = size() - _pos;
}
size_t idElement = size();
// move current data
size_t sizeToMove = (idElement - (_pos+_nbElement));
if ( 0 < sizeToMove) {
for (size_t iii=0; iii<sizeToMove; iii++) {
m_data[_pos+iii] = m_data[_pos+_nbElement+iii];
}
}
// Request resize of the current buffer
resize(size() - _nbElement);
}
/** /**
* @brief Remove N elements * @brief Remove N elements
* @param[in] _pos Position to remove the data * @param[in] _pos Position to remove the data
* @param[in] _posEnd Last position number * @param[in] _posEnd Last position number
*/ */
void eraseRange(size_t _pos, size_t _posEnd) { void eraseRange(size_t _pos, size_t _posEnd);
if (_pos>size()) {
TK_ERROR(" can not Erase Element at this position : " << _pos << " > " << size());
return;
}
if (_posEnd > size()) {
_posEnd = size();
}
size_t nbElement = size() - _pos;
size_t tmpSize = size();
// move current data
size_t sizeToMove = (tmpSize - (_pos+nbElement));
if ( 0 < sizeToMove) {
for (size_t iii=0; iii<sizeToMove; iii++) {
m_data[_pos+iii] = m_data[_pos+nbElement+iii];
}
}
// Request resize of the current buffer
resize(size()-nbElement);
}
/** /**
* @brief extract data between two point : * @brief extract data between two point :
* @param[in] _posStart start position to extract data * @param[in] _posStart start position to extract data
* @param[in] _posEnd End position to extract data * @param[in] _posEnd End position to extract data
* @return the extracted string * @return the extracted string
*/ */
etk::String extract(size_t _posStart = 0, size_t _posEnd=etk::String::npos) const { etk::String extract(size_t _posStart = 0, size_t _posEnd=etk::String::npos) const;
etk::String out;
if (_posStart >= size() ) {
return out;
}
if (_posEnd >= size() ) {
_posEnd = size();
}
out.pushBack(&m_data[_posStart], _posEnd-_posStart);
return out;
}
/** /**
* @brief Get the pointer on the data * @brief Get the pointer on the data
* @return pointer on the "C" string * @return pointer on the "C" string
*/ */
const char* c_str() const { const char* c_str() const;
return &m_data[0];
}
/** /**
* @brief Get an iterator an an specific position * @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator in the string * @param[in] _pos Requested position of the iterator in the string
* @return The Iterator * @return The Iterator
*/ */
Iterator position(size_t _pos) { Iterator position(size_t _pos);
return Iterator(this, _pos); const Iterator position(size_t _pos) const;
}
const Iterator position(size_t _pos) const {
return Iterator(this, _pos);
}
/** /**
* @brief Get an Iterator on the start position of the String * @brief Get an Iterator on the start position of the String
* @return The Iterator * @return The Iterator
*/ */
Iterator begin() { Iterator begin();
return position(0); const Iterator begin() const;
}
const Iterator begin() const {
return position(0);
}
/** /**
* @brief Get an Iterator on the end position of the String * @brief Get an Iterator on the end position of the String
* @return The Iterator * @return The Iterator
*/ */
Iterator end() { Iterator end();
return position( size()-1 ); const Iterator end() const;
}
const Iterator end() const {
return position( size()-1 );
}
/** /**
* @brief Change the current size of the string * @brief Change the current size of the string
* @param[in] _newSize New requested size of element in the string * @param[in] _newSize New requested size of element in the string
* @param[in] _value Value to set at the new element * @param[in] _value Value to set at the new element
*/ */
void resize(size_t _newSize, char _value = '\0') { void resize(size_t _newSize, char _value = '\0');
size_t oldSize = m_data.size();
m_data[m_data.size()-1] = _value;
m_data.resize(_newSize + 1, _value);
// in all case ==> we have the last element that is '\0'
m_data[_newSize] = '\0';
}
/***************************************************** /*****************************************************
* == operator * == operator
*****************************************************/ *****************************************************/
bool operator== (const String& _obj) const { bool operator== (const String& _obj) const;
// check if it was the same pointer
if( this == &_obj ) {
return true;
}
// first step : check the size ...
if (m_data.size() != _obj.m_data.size()) {
return false;
}
for (size_t iii=0; iii<m_data.size(); ++iii) {
if (m_data[iii] != _obj.m_data[iii]) {
return false;
}
}
return true;
}
/***************************************************** /*****************************************************
* != operator * != operator
*****************************************************/ *****************************************************/
bool operator!= (const String& _obj) const { bool operator!= (const String& _obj) const;
// check if it was the same pointer size_t find(char _value, size_t _pos=0) const;
if( this == &_obj ) { size_t find(const etk::String& _value, size_t _pos=0) const;
return false; size_t rfind(char _value, size_t _pos=etk::String::npos) const;
} size_t rfind(const etk::String& _value, size_t _pos=etk::String::npos) const;
// first step : check the size ...
if (m_data.size() != _obj.m_data.size()) {
return true;
}
for (size_t iii=0; iii<m_data.size(); ++iii) {
if (m_data[iii] != _obj.m_data[iii]) {
return true;
}
}
return false;
}
size_t find(char _value, size_t _pos) const;
size_t find(const etk::String& _value, size_t _pos) const;
size_t rfind(char _value, size_t _pos) const;
size_t rfind(const etk::String& _value, size_t _pos) const;
etk::String& replace(size_t _pos, size_t _len, char _replace); etk::String& replace(size_t _pos, size_t _len, char _replace);
etk::String& replace(size_t _pos, size_t _len, const etk::String& _replace); etk::String& replace(size_t _pos, size_t _len, const etk::String& _replace);
etk::String& replace(char _val, char _replace); etk::String& replace(char _val, char _replace);
@ -743,87 +453,17 @@ namespace etk {
template <class ETK_STRING_TYPE> template <class ETK_STRING_TYPE>
ETK_STRING_TYPE to() const; ETK_STRING_TYPE to() const;
}; };
bool operator> (const String& _left, const String& _right) { char toLower(char _value);
for (size_t iii=0; iii<_left.size() && iii<_right.size(); ++iii) { char toUpper(char _value);
if (_left[iii] > _right[iii]) { bool operator> (const String& _left, const String& _right);
return true; bool operator>= (const String& _left, const String& _right);
} bool operator< (const String& _left, const String& _right);
if (_left[iii] < _right[iii]) { bool operator<= (const String& _left, const String& _right);
return false; String operator+ (const String& _left, const String& _right);
} String operator+ (const String& _left, const char* _right);
} String operator+ (const char* _left, const String& _right);
if (_left.size() > _right.size()) { String operator+ (const String& _left, char _right);
return true; String operator+ (char _left, const String& _right);
}
return false;
}
bool operator>= (const String& _left, const String& _right) {
for (size_t iii=0; iii<_left.size() && iii<_right.size(); ++iii) {
if (_left[iii] > _right[iii]) {
return true;
}
if (_left[iii] < _right[iii]) {
return false;
}
}
if (_left.size() >= _right.size()) {
return true;
}
return false;
}
bool operator< (const String& _left, const String& _right) {
for (size_t iii=0; iii<_left.size() && iii<_right.size(); ++iii) {
if (_left[iii] < _right[iii]) {
return true;
}
if (_left[iii] > _right[iii]) {
return false;
}
}
if (_left.size() < _right.size()) {
return true;
}
return false;
}
bool operator<= (const String& _left, const String& _right) {
for (size_t iii=0; iii<_left.size() && iii<_right.size(); ++iii) {
if (_left[iii] < _right[iii]) {
return true;
}
if (_left[iii] > _right[iii]) {
return false;
}
}
if (_left.size() <= _right.size()) {
return true;
}
return false;
}
String operator+ (const String& _left, const String& _right) {
String tmp = _left;
tmp += _right;
return tmp;
}
String operator+ (const String& _left, const char* _right) {
String tmp = _left;
tmp += _right;
return tmp;
}
String operator+ (const char* _left, const String& _right) {
String tmp = _left;
tmp += _right;
return tmp;
}
String operator+ (const String& _left, char _right) {
String tmp = _left;
tmp.pushBack(_right);
return tmp;
}
String operator+ (char _left, const String& _right) {
String tmp = _left;
tmp += _right;
return tmp;
}
/** /**
* @brief Template to declare conversion from anything in etk::String * @brief Template to declare conversion from anything in etk::String
* @param[in] _variable Variable to convert * @param[in] _variable Variable to convert
@ -831,13 +471,49 @@ namespace etk {
*/ */
template <class TYPE> template <class TYPE>
etk::String toString(const TYPE& _variable); etk::String toString(const TYPE& _variable);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::String& _obj);
/** /**
* @brief Template to declare conversion from std::vector<anything> in etk::String * @brief Template to declare conversion from string to anything
* @param[out] _variableRet Output value
* @param[in] _value input property
* @return true if the can be converted.
*/
template <class TYPE>
bool from_string(TYPE& _variableRet, const etk::String& _value);
void sort(etk::Vector<etk::String *>& _list);
void sort(etk::Vector<etk::String>& _list);
// TODO: DEPRECATED function:
long double string_to_long_double(const etk::String& _obj);
double string_to_double(const etk::String& _obj);
float string_to_float(const etk::String& _obj);
int8_t string_to_int8_t(const etk::String& _obj);
int16_t string_to_int16_t(const etk::String& _obj);
int32_t string_to_int32_t(const etk::String& _obj);
int64_t string_to_int64_t(const etk::String& _obj);
uint8_t string_to_uint8_t(const etk::String& _obj);
uint16_t string_to_uint16_t(const etk::String& _obj);
uint32_t string_to_uint32_t(const etk::String& _obj);
uint64_t string_to_uint64_t(const etk::String& _obj);
bool string_to_bool(const etk::String& _obj);
etk::String tolower(etk::String _obj);
etk::String toupper(etk::String _obj);
bool compare_no_case(const etk::String& _obj, const etk::String& _val);
bool end_with(const etk::String& _obj, const etk::String& _val, bool _caseSensitive = true);
bool start_with(const etk::String& _obj, const etk::String& _val, bool _caseSensitive = true);
etk::String replace(const etk::String& _obj, char _val, char _replace);
etk::String extract_line(const etk::String& _obj, int32_t _pos);
etk::Vector<etk::String> split(const etk::String& _obj, char _val);
/**
* @brief Template to declare conversion from etk::Vector<anything> in etk::String
* @param[in] _list Variable to convert * @param[in] _list Variable to convert
* @return String of the value: {...,...,...} * @return String of the value: {...,...,...}
*/ */
template <class TYPE> template <class TYPE>
etk::String toString(const std::vector<TYPE>& _list) { etk::String toString(const etk::Vector<TYPE>& _list) {
etk::String out = "{"; etk::String out = "{";
for (size_t iii=0; iii<_list.size(); ++iii) { for (size_t iii=0; iii<_list.size(); ++iii) {
if (iii!=0) { if (iii!=0) {
@ -848,19 +524,4 @@ namespace etk {
out += "}"; out += "}";
return out; return out;
} }
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::String& _obj);
/**
* @brief Template to declare conversion from string to anything
* @param[out] _variableRet Output value
* @param[in] _value input property
* @return true if the can be converted.
*/
template <class TYPE>
bool from_string(TYPE& _variableRet, const etk::String& _value);
void sort(etk::Vector<etk::String *>& _list);
} }

1146
etk/UString.cpp Normal file

File diff suppressed because it is too large Load Diff

526
etk/UString.hpp Normal file
View File

@ -0,0 +1,526 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/debug.hpp>
#include <etk/Vector.hpp>
#include <etk/utf8.hpp>
#include <etk/stdTools.hpp>
namespace etk {
/**
* @brief string class ...
*/
class UString {
public:
class Iterator {
private:
size_t m_current; //!< current Id on the string
UString* m_string; //!< Pointer on the current element of the stringBin
public:
/**
* @brief Basic iterator constructor with no link with an etk::UString
*/
Iterator():
m_current(0),
m_string(nullptr) {
// nothing to do ...
}
/**
* @brief Recopy constructor on a specific etk::UString.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator & _obj):
m_current(_obj.m_current),
m_string(_obj.m_string) {
// nothing to do ...
}
/**
* @brief Assignation operator.
* @param[in] _otherIterator The Iterator that might be copy
* @return reference on the current Iterator
*/
Iterator& operator=(const Iterator & _otherIterator) {
m_current = _otherIterator.m_current;
m_string = _otherIterator.m_string;
return *this;
}
/**
* @brief Basic destructor
*/
~Iterator() {
m_current = 0;
m_string = nullptr;
}
/**
* @brief basic boolean cast
* @return true if the element is present in the etk::UString size
*/
operator bool () {
return (m_current < m_string->size());
}
/**
* @brief Incremental operator
* @return Reference on the current iterator increment
*/
Iterator& operator++ () {
if ( m_string != nullptr
&& m_current < m_string->size() )
{
m_current++;
}
return *this;
}
/**
* @brief Decremental operator
* @return Reference on the current iterator decrement
*/
Iterator& operator-- () {
if ( m_string != nullptr
&& m_current > 0) {
m_current--;
}
return *this;
}
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
Iterator operator++ (int) {
Iterator it(*this);
++(*this);
return it;
}
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
Iterator operator-- (int) {
Iterator it(*this);
--(*this);
return it;
}
Iterator& operator-= (size_t _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (size_t _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator-= (int _offset) {
m_current -= _offset;
return *this;
}
Iterator operator- (int _offset) const {
Iterator tmp(*this);
tmp -= _offset;
return tmp;
}
Iterator& operator+= (size_t _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (size_t _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
Iterator& operator+= (int _offset) {
m_current += _offset;
return *this;
}
Iterator operator+ (int _offset) const {
Iterator tmp(*this);
tmp += _offset;
return tmp;
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
char32_t operator* () const {
TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/**
* @brief Get reference on the current Element
* @return the reference on the current Element
*/
char32_t& operator* () {
TK_ASSERT(m_current < m_string->size(), "out of range");
return m_string->get(m_current);
}
/*****************************************************
* == operator
*****************************************************/
bool operator== (const Iterator& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return true;
}
if (m_current != _obj.m_current) {
return false;
}
if (m_string != _obj.m_string) {
return false;
}
return true;
}
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const Iterator& _obj) const {
// check if it was the same pointer
if( this == &_obj ) {
return false;
}
if (m_current != _obj.m_current) {
return true;
}
if (m_string != _obj.m_string) {
return true;
}
return false;
}
private:
Iterator(const UString* _obj, int32_t _pos):
m_current(_pos),
m_string(const_cast<UString*>(_obj)) {
// nothing to do ...
}
friend class UString;
};
private:
etk::Vector<char32_t> m_data; //!< pointer on the current data (contain all time 1 element '\0')
public:
static const size_t npos = size_t(-1);
/**
* @brief Create an empty string
*/
UString();
/**
* @brief Copy constructor (copy all data)
* @param[in] _obj String that might be copy
*/
UString(const etk::UString& _obj);
/**
* @brief Partial copy constructor (copy all needed data)
* @param[in] _obj String that might be copy (part of it)
* @param[in] _pos Start position to copy data
* @param[in] _size Number of element to copy in the string
*/
UString(const etk::UString& _obj, size_t _pos, size_t _size = etk::UString::npos);
/**
* @brief Copy the null-terminated C string.
* @param[in] _obj C string that might be copy (end by '\0')
*/
UString(const char32_t* _obj);
/**
* @brief Partial copy of the null-terminated C string.
* @param[in] _obj String that might be copyC string that might be copy (end by '\0')
* @param[in] _size Number of element to copy.
*/
UString(const char32_t* _obj, size_t _size);
/**
* @brief Fills the string with _size consecutive copies of character _val.
* @param[in] _size Number of element in the string
* @param[in] _val Value to set in the string
*/
UString(size_t _size, char32_t _val);
/**
* @brief Copy all element betewwen the 2 iterator of the new string.
* @param[in] _start Start iterator of adding value.
* @param[in] _stop Start iterator of adding value.
*/
UString(Iterator _start, Iterator _stop);
/**
* @brief Move constructor
* @param[in] _obj String that might be move inside
*/
UString(etk::UString&& _obj) noexcept;
/**
* @brief Set constructor
* @param[in] _value Char element to set in the string
*/
UString(char32_t _value);
/**
* @brief Destructor of the current Class
*/
~UString();
/**
* @brief Swap the data of 2 Strings
* @param[in] _obj second string to swap data.
*/
void swap(etk::UString& _obj);
/**
* @brief Re-copy operator
* @param[in] _obj String that might be copy
* @return reference on the current re-copy string
*/
UString& operator=(const etk::UString& _obj);
/**
* @brief Re-copy operator
* @param[in] _obj C string terminated with '\0'
* @return reference on the current re-copy string
*/
UString& operator=(const char32_t* _obj);
/**
* @brief Re-copy operator
* @param[in] _value char32_t value to set in the string
* @return reference on the current re-copy string
*/
UString& operator=(char32_t _value);
/**
* @brief Add at the Last position of the String
* @param[in] _obj Element to add at the end of string
*/
UString& operator+= (const etk::UString& _obj);
/**
* @brief Add at the Last position of the String
* @param[in] _obj C string terminated with '\0'
*/
UString& operator+= (const char32_t* _obj);
/**
* @brief Add at the Last position of the String
* @param[in] _value Simple character to add.
*/
UString& operator+= (char32_t _value);
/**
* @brief Get the number of element in the string
* @return The number requested
*/
size_t size() const;
/**
* @brief Get a current element in the string
* @param[in] _pos Desired position read
* @return Reference on the Element
*/
char32_t& get(size_t _pos) {
return m_data[_pos];
}
/**
* @brief Get an copy Element an a special position
* @param[in] _pos Position in the string that might be get [0..Size()]
* @return An reference on the copy of selected element
*/
char32_t& operator[] (size_t _pos) {
return m_data[_pos];
}
/**
* @brief Get an Element an a special position
* @param[in] _pos Position in the string that might be get [0..Size()]
* @return An reference on the selected element
*/
const char32_t& operator[] (size_t _pos) const {
return m_data[_pos];
}
/**
* @brief Add at the First position of the String
* @param[in] _item Element to add at the end of string
*/
void pushFront(char32_t _item);
/**
* @brief Add at the Last position of the String
* @param[in] _item Pointer on a list of Element to add at the start of string
* @param[in] _nbElement Number of element to add.
*/
void pushFront(const char32_t* _item, size_t _nbElement);
/**
* @brief Add at the Last position of the String
* @param[in] _item Element to add at the end of string
*/
void pushBack(const char32_t _item);
/**
* @brief Add at the Last position of the String
* @param[in] _item Pointer on a list of Element to add at the end of string
* @param[in] _nbElement Number of element to add.
*/
void pushBack(const char32_t* _item, size_t _nbElement);
/**
* @brief Remove the last element of the string
*/
void popBack();
/**
* @brief Remove all element in the current string
*/
void clear();
/**
* @brief Insert N element in the String.
* @param[in] _pos Position to add the elements.
* @param[in] _item Pointer on a table of the elements to add.
* @param[in] _nbElement Number of element to add in the String
*/
void insert(size_t _pos, const char32_t* _item, size_t _nbElement);
/**
* @brief Insert one element in the String at a specific position
* @param[in] _pos Position to add the elements.
* @param[in] _item Element to add.
*/
void insert(size_t _pos, const char32_t _item);
/**
* @brief Insert one element in the String at a specific position
* @param[in] _pos Position to add the elements.
* @param[in] _item Element to add.
*/
void insert(size_t _pos, const etk::UString& _value);
/**
* @brief Remove N element
* @param[in] _pos Position to remove the data
* @param[in] _nbElement number of element to remove
*/
void erase(size_t _pos, size_t _nbElement=1);
/**
* @brief Remove N elements
* @param[in] _pos Position to remove the data
* @param[in] _posEnd Last position number
*/
void eraseRange(size_t _pos, size_t _posEnd);
/**
* @brief extract data between two point :
* @param[in] _posStart start position to extract data
* @param[in] _posEnd End position to extract data
* @return the extracted string
*/
etk::UString extract(size_t _posStart = 0, size_t _posEnd=etk::UString::npos) const;
/**
* @brief Get the pointer on the data
* @return pointer on the "C" string
*/
const char32_t* c_str() const;
/**
* @brief Get an iterator an an specific position
* @param[in] _pos Requested position of the iterator in the string
* @return The Iterator
*/
Iterator position(size_t _pos);
const Iterator position(size_t _pos) const;
/**
* @brief Get an Iterator on the start position of the String
* @return The Iterator
*/
Iterator begin();
const Iterator begin() const;
/**
* @brief Get an Iterator on the end position of the String
* @return The Iterator
*/
Iterator end();
const Iterator end() const;
/**
* @brief Change the current size of the string
* @param[in] _newSize New requested size of element in the string
* @param[in] _value Value to set at the new element
*/
void resize(size_t _newSize, char32_t _value = '\0');
/*****************************************************
* == operator
*****************************************************/
bool operator== (const etk::UString& _obj) const;
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const etk::UString& _obj) const;
size_t find(char32_t _value, size_t _pos=0) const;
size_t find(const etk::UString& _value, size_t _pos=0) const;
size_t rfind(char32_t _value, size_t _pos=etk::UString::npos) const;
size_t rfind(const etk::UString& _value, size_t _pos=etk::UString::npos) const;
etk::UString& replace(size_t _pos, size_t _len, char32_t _replace);
etk::UString& replace(size_t _pos, size_t _len, const etk::UString& _replace);
etk::UString& replace(char32_t _val, char32_t _replace);
etk::UString& replace(const etk::UString& _val, const etk::UString& _replace);
etk::UString getLine(int32_t _pos) const;
etk::UString toLower() const;
etk::UString& lower();
etk::UString toUpper() const;
etk::UString& upper();
bool compare(const etk::UString& _val, bool _caseSensitive = true) const;
bool endWith(const etk::UString& _val, bool _caseSensitive = true) const;
bool startWith(const etk::UString& _val, bool _caseSensitive = true) const;
etk::Vector<etk::UString> split(char32_t _val) const;
etk::Vector<etk::UString> split(etk::UString _val) const;
/**
* @brief Template that permit to convert string in everythings you want
* @param[in] ETK_STRING_TYPE Template type of the convertion output
*/
template <class ETK_STRING_TYPE>
ETK_STRING_TYPE to() const;
};
char32_t toLower(char32_t _value);
char32_t toUpper(char32_t _value);
bool operator> (const UString& _left, const UString& _right);
bool operator>= (const UString& _left, const UString& _right);
bool operator< (const UString& _left, const UString& _right);
bool operator<= (const UString& _left, const UString& _right);
UString operator+ (const UString& _left, const UString& _right);
UString operator+ (const UString& _left, const char32_t* _right);
UString operator+ (const char32_t* _left, const UString& _right);
UString operator+ (const UString& _left, char32_t _right);
UString operator+ (char32_t _left, const UString& _right);
/**
* @brief Template to declare conversion from anything in etk::UString
* @param[in] _variable Variable to convert
* @return String of the value
*/
template <class TYPE>
etk::UString toUString(const TYPE& _variable);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const etk::UString& _obj);
/**
* @brief Template to declare conversion from string to anything
* @param[out] _variableRet Output value
* @param[in] _value input property
* @return true if the can be converted.
*/
template <class TYPE>
bool from_string(TYPE& _variableRet, const etk::UString& _value);
void sort(etk::Vector<etk::UString *>& _list);
void sort(etk::Vector<etk::UString>& _list);
// TODO: DEPRECATED function:
long double string_to_long_double(const etk::UString& _obj);
double string_to_double(const etk::UString& _obj);
float string_to_float(const etk::UString& _obj);
int8_t string_to_int8_t(const etk::UString& _obj);
int16_t string_to_int16_t(const etk::UString& _obj);
int32_t string_to_int32_t(const etk::UString& _obj);
int64_t string_to_int64_t(const etk::UString& _obj);
uint8_t string_to_uint8_t(const etk::UString& _obj);
uint16_t string_to_uint16_t(const etk::UString& _obj);
uint32_t string_to_uint32_t(const etk::UString& _obj);
uint64_t string_to_uint64_t(const etk::UString& _obj);
bool string_to_bool(const etk::UString& _obj);
etk::UString tolower(etk::UString _obj);
etk::UString toupper(etk::UString _obj);
bool compare_no_case(const etk::UString& _obj, const etk::UString& _val);
bool end_with(const etk::UString& _obj, const etk::UString& _val, bool _caseSensitive = true);
bool start_with(const etk::UString& _obj, const etk::UString& _val, bool _caseSensitive = true);
etk::UString replace(const etk::UString& _obj, char32_t _val, char32_t _replace);
etk::UString extract_line(const etk::UString& _obj, int32_t _pos);
etk::Vector<etk::UString> split(const etk::UString& _obj, char32_t _val);
/**
* @brief Template to declare conversion from etk::Vector<anything> in etk::String
* @param[in] _list Variable to convert
* @return String of the value: {...,...,...}
*/
template <class TYPE>
etk::UString toUString(const etk::Vector<TYPE>& _list) {
etk::UString out = U"{";
for (size_t iii=0; iii<_list.size(); ++iii) {
if (iii!=0) {
out += U";";
}
out+= etk::toUString(_list[iii]);
}
out += U"}";
return out;
}
}

View File

@ -713,6 +713,7 @@ namespace etk {
return false; return false;
} }
}; };
//! @not_in_doc
template<class ETK_VECTOR_TYPE> template<class ETK_VECTOR_TYPE>
std::ostream& operator <<(std::ostream& _os, const etk::Vector<ETK_VECTOR_TYPE>& _obj) { std::ostream& operator <<(std::ostream& _os, const etk::Vector<ETK_VECTOR_TYPE>& _obj) {
_os << "{"; _os << "{";
@ -725,4 +726,14 @@ namespace etk {
_os << "}"; _os << "}";
return _os; return _os;
} }
//! @not_in_doc
template<typename T, typename T2>
bool isIn(const T& _val, const etk::Vector<T2>& _list) {
for (size_t iii=0; iii<_list.size(); ++iii) {
if (_list[iii] == _val) {
return true;
}
}
return false;
}
} }

View File

@ -34,6 +34,17 @@ namespace etk {
#define TK_HIDDEN(data) do { } while(false) #define TK_HIDDEN(data) do { } while(false)
#ifdef DEBUG
#define TK_CHECK_INOUT(condition) \
do { \
if (!(condition)) { \
TK_ERROR("Wrong condition : " #condition); \
} \
} while (0)
#else
#define TK_CHECK_INOUT(condition) do { } while(false)
#endif
#define TK_ASSERT(condition,data) \ #define TK_ASSERT(condition,data) \
do { \ do { \
if (!(condition)) { \ if (!(condition)) { \

View File

@ -118,12 +118,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> Vector2D<bool>::operator std::u32string() const { template<> Vector2D<bool>::operator etk::UString() const {
std::u32string str; etk::UString str;
str = U"("; str = U"(";
str += etk::to_u32string(x()); str += etk::toUString(x());
str += U","; str += U",";
str += etk::to_u32string(y()); str += etk::toUString(y());
str += U")"; str += U")";
return str; return str;
} }
@ -154,11 +154,11 @@ namespace etk {
TK_VERBOSE("Parse : '" << _str << "' ==> " << *this); TK_VERBOSE("Parse : '" << _str << "' ==> " << *this);
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> Vector2D<bool>::Vector2D(const std::u32string& _str) { template<> Vector2D<bool>::Vector2D(const etk::UString& _str) {
m_floats[0] = false; m_floats[0] = false;
m_floats[1] = false; m_floats[1] = false;
// copy to permit to modify it : // copy to permit to modify it :
std::u32string tmpStr = _str; etk::UString tmpStr = _str;
if (tmpStr[0] == '(') { if (tmpStr[0] == '(') {
tmpStr.erase(tmpStr.begin()); tmpStr.erase(tmpStr.begin());
} }
@ -172,7 +172,7 @@ namespace etk {
m_floats[0] = etk::string_to_bool(tmpStr); m_floats[0] = etk::string_to_bool(tmpStr);
m_floats[1] = m_floats[0]; m_floats[1] = m_floats[0];
} else { } else {
m_floats[0] = etk::string_to_bool(std::u32string(tmpStr, 0, posComa)); m_floats[0] = etk::string_to_bool(etk::UString(tmpStr, 0, posComa));
tmpStr.erase(0, posComa+1); tmpStr.erase(0, posComa+1);
m_floats[1] = etk::string_to_bool(tmpStr); m_floats[1] = etk::string_to_bool(tmpStr);
} }
@ -190,12 +190,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> Vector2D<int32_t>::operator std::u32string() const { template<> Vector2D<int32_t>::operator etk::UString() const {
std::u32string str; etk::UString str;
str = U"("; str = U"(";
str += etk::to_u32string(x()); str += etk::toUString(x());
str += U","; str += U",";
str += etk::to_u32string(y()); str += etk::toUString(y());
str += U")"; str += U")";
return str; return str;
} }
@ -227,11 +227,11 @@ namespace etk {
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> Vector2D<int32_t>::Vector2D(const std::u32string& _str) { template<> Vector2D<int32_t>::Vector2D(const etk::UString& _str) {
m_floats[0] = 0; m_floats[0] = 0;
m_floats[1] = 0; m_floats[1] = 0;
// copy to permit to modify it : // copy to permit to modify it :
std::u32string tmpStr = _str; etk::UString tmpStr = _str;
if (tmpStr[0] == '(') { if (tmpStr[0] == '(') {
tmpStr.erase(tmpStr.begin()); tmpStr.erase(tmpStr.begin());
} }
@ -246,7 +246,7 @@ namespace etk {
m_floats[0] = etk::string_to_int32_t(tmpStr); m_floats[0] = etk::string_to_int32_t(tmpStr);
m_floats[1] = m_floats[0]; m_floats[1] = m_floats[0];
} else { } else {
m_floats[0] = etk::string_to_int32_t(std::u32string(tmpStr, 0, posComa)); m_floats[0] = etk::string_to_int32_t(etk::UString(tmpStr, 0, posComa));
tmpStr.erase(0,posComa+1); tmpStr.erase(0,posComa+1);
m_floats[1] = etk::string_to_int32_t(tmpStr); m_floats[1] = etk::string_to_int32_t(tmpStr);
} }
@ -264,12 +264,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> Vector2D<uint32_t>::operator std::u32string() const { template<> Vector2D<uint32_t>::operator etk::UString() const {
std::u32string str; etk::UString str;
str = U"("; str = U"(";
str += etk::to_u32string(x()); str += etk::toUString(x());
str += U","; str += U",";
str += etk::to_u32string(y()); str += etk::toUString(y());
str += U")"; str += U")";
return str; return str;
} }
@ -300,11 +300,11 @@ namespace etk {
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> Vector2D<uint32_t>::Vector2D(const std::u32string& _str) { template<> Vector2D<uint32_t>::Vector2D(const etk::UString& _str) {
m_floats[0] = 0; m_floats[0] = 0;
m_floats[1] = 0; m_floats[1] = 0;
// copy to permit to modify it : // copy to permit to modify it :
std::u32string tmpStr = _str; etk::UString tmpStr = _str;
if (tmpStr[0] == '(') { if (tmpStr[0] == '(') {
tmpStr.erase(tmpStr.begin()); tmpStr.erase(tmpStr.begin());
} }
@ -318,7 +318,7 @@ namespace etk {
m_floats[0] = etk::string_to_int32_t(tmpStr); m_floats[0] = etk::string_to_int32_t(tmpStr);
m_floats[1] = m_floats[0]; m_floats[1] = m_floats[0];
} else { } else {
m_floats[0] = etk::string_to_int32_t(std::u32string(tmpStr, 0, posComa)); m_floats[0] = etk::string_to_int32_t(etk::UString(tmpStr, 0, posComa));
tmpStr.erase(0,posComa+1); tmpStr.erase(0,posComa+1);
m_floats[1] = etk::string_to_int32_t(tmpStr); m_floats[1] = etk::string_to_int32_t(tmpStr);
} }
@ -336,12 +336,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> Vector2D<float>::operator std::u32string() const { template<> Vector2D<float>::operator etk::UString() const {
std::u32string str; etk::UString str;
str = U"("; str = U"(";
str += etk::to_u32string(x()); str += etk::toUString(x());
str += U","; str += U",";
str += etk::to_u32string(y()); str += etk::toUString(y());
str += U")"; str += U")";
return str; return str;
} }
@ -372,11 +372,11 @@ namespace etk {
TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this); TK_VERBOSE("Parse : \"" << _str << "\" ==> " << *this);
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> Vector2D<float>::Vector2D(const std::u32string& _str) { template<> Vector2D<float>::Vector2D(const etk::UString& _str) {
m_floats[0] = 0; m_floats[0] = 0;
m_floats[1] = 0; m_floats[1] = 0;
// copy to permit to modify it : // copy to permit to modify it :
std::u32string tmpStr = _str; etk::UString tmpStr = _str;
if (tmpStr[0] == '(') { if (tmpStr[0] == '(') {
tmpStr.erase(tmpStr.begin()); tmpStr.erase(tmpStr.begin());
} }
@ -390,7 +390,7 @@ namespace etk {
m_floats[0] = etk::string_to_float(tmpStr); m_floats[0] = etk::string_to_float(tmpStr);
m_floats[1] = m_floats[0]; m_floats[1] = m_floats[0];
} else { } else {
m_floats[0] = etk::string_to_float(std::u32string(tmpStr, 0, posComa)); m_floats[0] = etk::string_to_float(etk::UString(tmpStr, 0, posComa));
tmpStr.erase(0,posComa+1); tmpStr.erase(0,posComa+1);
m_floats[1] = etk::string_to_float(tmpStr); m_floats[1] = etk::string_to_float(tmpStr);
} }
@ -398,7 +398,7 @@ namespace etk {
} }
#endif #endif
template<> etk::String to_string<vec2>(const vec2& _obj) { template<> etk::String toString<vec2>(const vec2& _obj) {
etk::String str; etk::String str;
str = "("; str = "(";
str += etk::toString(_obj.x()); str += etk::toString(_obj.x());
@ -408,12 +408,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> std::u32string to_u32string<vec2>(const vec2& _obj) { template<> etk::UString toUString<vec2>(const vec2& _obj) {
return etk::to_u32string(etk::toString(_obj)); return etk::toUString(etk::toString(_obj));
} }
#endif #endif
template<> etk::String to_string<ivec2>(const ivec2& _obj) { template<> etk::String toString<ivec2>(const ivec2& _obj) {
etk::String str; etk::String str;
str = "("; str = "(";
str += etk::toString(_obj.x()); str += etk::toString(_obj.x());
@ -423,12 +423,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> std::u32string to_u32string<ivec2>(const ivec2& _obj) { template<> etk::UString toUString<ivec2>(const ivec2& _obj) {
return etk::to_u32string(etk::toString(_obj)); return etk::toUString(etk::toString(_obj));
} }
#endif #endif
template<> etk::String to_string<uivec2>(const uivec2& _obj) { template<> etk::String toString<uivec2>(const uivec2& _obj) {
etk::String str; etk::String str;
str = "("; str = "(";
str += etk::toString(_obj.x()); str += etk::toString(_obj.x());
@ -438,12 +438,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> std::u32string to_u32string<uivec2>(const uivec2& _obj) { template<> etk::UString toUString<uivec2>(const uivec2& _obj) {
return etk::to_u32string(etk::toString(_obj)); return etk::toUString(etk::toString(_obj));
} }
#endif #endif
template<> etk::String to_string<bvec2>(const bvec2& _obj) { template<> etk::String toString<bvec2>(const bvec2& _obj) {
etk::String str; etk::String str;
str = "("; str = "(";
str += etk::toString(_obj.x()); str += etk::toString(_obj.x());
@ -453,8 +453,8 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> std::u32string to_u32string<bvec2>(const bvec2& _obj) { template<> etk::UString toUString<bvec2>(const bvec2& _obj) {
return etk::to_u32string(etk::toString(_obj)); return etk::toUString(etk::toString(_obj));
} }
#endif #endif
@ -463,7 +463,7 @@ namespace etk {
return true; return true;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> bool from_string<vec2>(vec2& _variableRet, const std::u32string& _value) { template<> bool from_string<vec2>(vec2& _variableRet, const etk::UString& _value) {
return from_string(_variableRet, etk::toString(_value)); return from_string(_variableRet, etk::toString(_value));
} }
#endif #endif
@ -473,7 +473,7 @@ namespace etk {
return true; return true;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> bool from_string<ivec2>(ivec2& _variableRet, const std::u32string& _value) { template<> bool from_string<ivec2>(ivec2& _variableRet, const etk::UString& _value) {
return from_string(_variableRet, etk::toString(_value)); return from_string(_variableRet, etk::toString(_value));
} }
#endif #endif
@ -483,7 +483,7 @@ namespace etk {
return true; return true;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> bool from_string<uivec2>(uivec2& _variableRet, const std::u32string& _value) { template<> bool from_string<uivec2>(uivec2& _variableRet, const etk::UString& _value) {
return from_string(_variableRet, etk::toString(_value)); return from_string(_variableRet, etk::toString(_value));
} }
#endif #endif
@ -493,7 +493,7 @@ namespace etk {
return true; return true;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> bool from_string<bvec2>(bvec2& _variableRet, const std::u32string& _value) { template<> bool from_string<bvec2>(bvec2& _variableRet, const etk::UString& _value) {
return from_string(_variableRet, etk::toString(_value)); return from_string(_variableRet, etk::toString(_value));
} }
#endif #endif

View File

@ -138,7 +138,7 @@ vec3 quaternionToEulerXYZ(const btQuaternion& _quat) {
#endif #endif
namespace etk { namespace etk {
template<> etk::String to_string<vec3>(const vec3& _obj) { template<> etk::String toString<vec3>(const vec3& _obj) {
etk::String str; etk::String str;
str = "("; str = "(";
str += etk::toString(_obj.x()); str += etk::toString(_obj.x());
@ -150,12 +150,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> std::u32string to_u32string<vec3>(const vec3& _obj) { template<> etk::UString toUString<vec3>(const vec3& _obj) {
return etk::to_u32string(etk::toString(_obj)); return etk::toUString(etk::toString(_obj));
} }
#endif #endif
template<> etk::String to_string<ivec3>(const ivec3& _obj) { template<> etk::String toString<ivec3>(const ivec3& _obj) {
etk::String str; etk::String str;
str = "("; str = "(";
str += etk::toString(_obj.x()); str += etk::toString(_obj.x());
@ -167,12 +167,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> std::u32string to_u32string<ivec3>(const ivec3& _obj) { template<> etk::UString toUString<ivec3>(const ivec3& _obj) {
return etk::to_u32string(etk::toString(_obj)); return etk::toUString(etk::toString(_obj));
} }
#endif #endif
template<> etk::String to_string<uivec3>(const uivec3& _obj) { template<> etk::String toString<uivec3>(const uivec3& _obj) {
etk::String str; etk::String str;
str = "("; str = "(";
str += etk::toString(_obj.x()); str += etk::toString(_obj.x());
@ -184,12 +184,12 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> std::u32string to_u32string<uivec3>(const uivec3& _obj) { template<> etk::UString toUString<uivec3>(const uivec3& _obj) {
return etk::to_u32string(etk::toString(_obj)); return etk::toUString(etk::toString(_obj));
} }
#endif #endif
template<> etk::String to_string<bvec3>(const bvec3& _obj) { template<> etk::String toString<bvec3>(const bvec3& _obj) {
etk::String str; etk::String str;
str = "("; str = "(";
str += etk::toString(_obj.x()); str += etk::toString(_obj.x());
@ -201,8 +201,8 @@ namespace etk {
return str; return str;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> std::u32string to_u32string<bvec3>(const bvec3& _obj) { template<> etk::UString toUString<bvec3>(const bvec3& _obj) {
return etk::to_u32string(etk::toString(_obj)); return etk::toUString(etk::toString(_obj));
} }
#endif #endif
@ -246,7 +246,7 @@ namespace etk {
return true; return true;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> bool from_string<vec3>(vec3& _variableRet, const std::u32string& _value) { template<> bool from_string<vec3>(vec3& _variableRet, const etk::UString& _value) {
return from_string(_variableRet, etk::toString(_value)); return from_string(_variableRet, etk::toString(_value));
} }
#endif #endif
@ -291,7 +291,7 @@ namespace etk {
return true; return true;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> bool from_string<ivec3>(ivec3& _variableRet, const std::u32string& _value) { template<> bool from_string<ivec3>(ivec3& _variableRet, const etk::UString& _value) {
return from_string(_variableRet, etk::toString(_value)); return from_string(_variableRet, etk::toString(_value));
} }
#endif #endif
@ -336,7 +336,7 @@ namespace etk {
return true; return true;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> bool from_string<uivec3>(uivec3& _variableRet, const std::u32string& _value) { template<> bool from_string<uivec3>(uivec3& _variableRet, const etk::UString& _value) {
return from_string(_variableRet, etk::toString(_value)); return from_string(_variableRet, etk::toString(_value));
} }
#endif #endif
@ -381,7 +381,7 @@ namespace etk {
return true; return true;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> bool from_string<bvec3>(bvec3& _variableRet, const std::u32string& _value) { template<> bool from_string<bvec3>(bvec3& _variableRet, const etk::UString& _value) {
return from_string(_variableRet, etk::toString(_value)); return from_string(_variableRet, etk::toString(_value));
} }
#endif #endif

View File

@ -40,8 +40,8 @@ extern "C" {
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
static std::vector<etk::String> getListDrive() { static etk::Vector<etk::String> getListDrive() {
std::vector<etk::String> out; etk::Vector<etk::String> out;
int dr_type=99; int dr_type=99;
char dr_avail[4096]; char dr_avail[4096];
char *temp=dr_avail; char *temp=dr_avail;
@ -59,23 +59,23 @@ extern "C" {
break; break;
case 2: // Removable Drive case 2: // Removable Drive
TK_WARNING("'" << driveName << "' : Removable Drive type"); TK_WARNING("'" << driveName << "' : Removable Drive type");
out.push_back(driveName); out.pushBack(driveName);
break; break;
case 3: // Fixed case 3: // Fixed
TK_WARNING("'" << driveName << "' : Hard Disk (Fixed) Drive type"); TK_WARNING("'" << driveName << "' : Hard Disk (Fixed) Drive type");
out.push_back(driveName); out.pushBack(driveName);
break; break;
case 4: // Remote case 4: // Remote
TK_WARNING("'" << driveName << "' : Remote (Network) Drive type"); TK_WARNING("'" << driveName << "' : Remote (Network) Drive type");
out.push_back(driveName); out.pushBack(driveName);
break; break;
case 5: // CDROM case 5: // CDROM
TK_WARNING("'" << driveName << "' : CD-Rom/DVD-Rom Drive type"); TK_WARNING("'" << driveName << "' : CD-Rom/DVD-Rom Drive type");
out.push_back(driveName); out.pushBack(driveName);
break; break;
case 6: // RamDrive case 6: // RamDrive
TK_WARNING("'" << driveName << "' : Ram Drive type"); TK_WARNING("'" << driveName << "' : Ram Drive type");
out.push_back(driveName); out.pushBack(driveName);
break; break;
} }
temp += lstrlen(temp) + 1; // incriment the buffer temp += lstrlen(temp) + 1; // incriment the buffer
@ -83,8 +83,8 @@ extern "C" {
return out; return out;
} }
#else #else
static std::vector<etk::String> getListDrive() { static etk::Vector<etk::String> getListDrive() {
std::vector<etk::String> out; etk::Vector<etk::String> out;
return out; return out;
} }
#endif #endif
@ -403,7 +403,7 @@ void etk::setArgZero(const etk::String& _val) {
std::unique_lock<std::mutex> lock(getNodeMutex()); std::unique_lock<std::mutex> lock(getNodeMutex());
l_argZero = _val; l_argZero = _val;
// set defaiult application name ... // set defaiult application name ...
std::vector<etk::String> elems = etk::split(_val, '/'); etk::Vector<etk::String> elems = etk::split(_val, '/');
etk::initDefaultFolder(elems[elems.size()-1].c_str()); etk::initDefaultFolder(elems[elems.size()-1].c_str());
} }
/* /*
@ -490,8 +490,8 @@ etk::String getApplicationPath() {
return binaryName; return binaryName;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string getUApplicationPath() { etk::UString getUApplicationPath() {
return etk::to_u32string(getApplicationPath()); return etk::toUString(getApplicationPath());
} }
#endif #endif
@ -653,8 +653,8 @@ etk::String etk::getUserHomeFolder() {
return baseFolderHome; return baseFolderHome;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::getUUserHomeFolder() { etk::UString etk::getUUserHomeFolder() {
return etk::to_u32string(baseFolderHome); return etk::toUString(baseFolderHome);
} }
#endif #endif
@ -662,8 +662,8 @@ etk::String etk::getUserRunFolder() {
return baseRunPath; return baseRunPath;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::getUUserRunFolder() { etk::UString etk::getUUserRunFolder() {
return etk::to_u32string(baseRunPath); return etk::toUString(baseRunPath);
} }
#endif #endif
@ -705,7 +705,7 @@ etk::FSNode::FSNode(const etk::String& _nodeName) :
privateSetName(_nodeName); privateSetName(_nodeName);
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
etk::FSNode::FSNode(const std::u32string& _nodeName) : etk::FSNode::FSNode(const etk::UString& _nodeName) :
m_userFileName(""), m_userFileName(""),
m_type(etk::FSNType_unknow), m_type(etk::FSNType_unknow),
m_typeNode(etk::typeNode_unknow), m_typeNode(etk::typeNode_unknow),
@ -735,8 +735,8 @@ etk::FSNode::~FSNode() {
} }
void etk::FSNode::sortElementList(std::vector<etk::FSNode *>& _list) { void etk::FSNode::sortElementList(etk::Vector<etk::FSNode *>& _list) {
std::vector<etk::FSNode *> tmpList = _list; etk::Vector<etk::FSNode *> tmpList = _list;
_list.clear(); _list.clear();
for(size_t iii=0; iii<tmpList.size(); iii++) { for(size_t iii=0; iii<tmpList.size(); iii++) {
if (nullptr != tmpList[iii]) { if (nullptr != tmpList[iii]) {
@ -940,8 +940,8 @@ void etk::FSNode::privateSetName(etk::String _newName) {
TK_DBG_MODE("6 : type : [" << m_typeNode << "] right :" << m_rights); TK_DBG_MODE("6 : type : [" << m_typeNode << "] right :" << m_rights);
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void etk::FSNode::privateSetName(const std::u32string& _newName) { void etk::FSNode::privateSetName(const etk::UString& _newName) {
privateSetName(etk::to_string(_newName)); privateSetName(etk::toString(_newName));
} }
#endif #endif
@ -963,8 +963,8 @@ bool directCheckFile(etk::String _tmpFileNameDirect, bool _checkInAPKIfNeeded =
return true; return true;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool directCheckFile(std::u32string _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) { bool directCheckFile(etk::UString _tmpFileNameDirect, bool _checkInAPKIfNeeded = false) {
return directCheckFile(etk::to_string(_tmpFileNameDirect)); return directCheckFile(etk::toString(_tmpFileNameDirect));
} }
#endif #endif
// Now we generate the real FS path: // Now we generate the real FS path:
@ -1026,7 +1026,7 @@ void etk::FSNode::generateFileSystemPath() {
case etk::FSNType_theme: case etk::FSNType_theme:
case etk::FSNType_themeData: case etk::FSNType_themeData:
{ {
//std::u32string myCompleateName=baseFolderData + "/theme/"; //etk::UString myCompleateName=baseFolderData + "/theme/";
etk::String themeName(""); etk::String themeName("");
etk::String basicName(m_userFileName); etk::String basicName(m_userFileName);
size_t firstPos = m_userFileName.find(':'); size_t firstPos = m_userFileName.find(':');
@ -1231,7 +1231,7 @@ void etk::FSNode::setName(const etk::String& _newName) {
privateSetName(_newName); privateSetName(_newName);
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void etk::FSNode::setName(const std::u32string& _newName) { void etk::FSNode::setName(const etk::UString& _newName) {
privateSetName(_newName); privateSetName(_newName);
} }
#endif #endif
@ -1244,8 +1244,8 @@ etk::String etk::FSNode::getNameFolder() const {
return ""; return "";
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNode::getUNameFolder() const { etk::UString etk::FSNode::getUNameFolder() const {
return etk::to_u32string(getNameFolder()); return etk::toUString(getNameFolder());
} }
#endif #endif
@ -1253,8 +1253,8 @@ etk::String etk::FSNode::getFileSystemName() const {
return m_systemFileName; return m_systemFileName;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNode::getUFileSystemName() const { etk::UString etk::FSNode::getUFileSystemName() const {
return etk::to_u32string(getFileSystemName()); return etk::toUString(getFileSystemName());
} }
#endif #endif
@ -1297,8 +1297,8 @@ etk::String etk::FSNode::getName() const {
return output; return output;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNode::getUName() const { etk::UString etk::FSNode::getUName() const {
return etk::to_u32string(getName()); return etk::toUString(getName());
} }
#endif #endif
@ -1310,8 +1310,8 @@ etk::String etk::FSNode::getNameFile() const {
return ""; return "";
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNode::getUNameFile() const { etk::UString etk::FSNode::getUNameFile() const {
return etk::to_u32string(getNameFile()); return etk::toUString(getNameFile());
} }
#endif #endif
@ -1354,8 +1354,8 @@ etk::String etk::FSNode::getRelativeFolder() const {
return ""; return "";
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNode::getURelativeFolder() const { etk::UString etk::FSNode::getURelativeFolder() const {
return etk::to_u32string(getRelativeFolder()); return etk::toUString(getRelativeFolder());
} }
#endif #endif
@ -1390,8 +1390,8 @@ bool etk::FSNode::move(const etk::String& _path) {
} }
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::FSNode::move(const std::u32string& _path) { bool etk::FSNode::move(const etk::UString& _path) {
return move(etk::to_string(_path)); return move(etk::toString(_path));
} }
#endif #endif
@ -1427,8 +1427,8 @@ etk::String etk::FSNode::timeCreatedString() const {
return tmpTime; return tmpTime;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNode::timeUCreatedString() const { etk::UString etk::FSNode::timeUCreatedString() const {
return etk::to_u32string(timeCreatedString()); return etk::toUString(timeCreatedString());
} }
#endif #endif
@ -1445,8 +1445,8 @@ etk::String etk::FSNode::timeModifiedString() const {
return tmpTime; return tmpTime;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNode::timeUModifiedString() const { etk::UString etk::FSNode::timeUModifiedString() const {
return etk::to_u32string(timeModifiedString()); return etk::toUString(timeModifiedString());
} }
#endif #endif
@ -1463,8 +1463,8 @@ etk::String etk::FSNode::timeAccessedString() const {
return tmpTime; return tmpTime;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNode::timeUAccessedString() const { etk::UString etk::FSNode::timeUAccessedString() const {
return etk::to_u32string(timeAccessedString()); return etk::toUString(timeAccessedString());
} }
#endif #endif
/* /*
@ -1622,7 +1622,7 @@ int64_t etk::FSNode::folderCount() {
return counter; return counter;
} }
std::vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bool _getFolderAndOther, bool _getFile, bool _temporaryFile) { etk::Vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bool _getFolderAndOther, bool _getFile, bool _temporaryFile) {
etk::String filter=".*"; etk::String filter=".*";
if (_temporaryFile == true) { if (_temporaryFile == true) {
filter = ".*(~|\\.bck|\\.tmp)"; filter = ".*(~|\\.bck|\\.tmp)";
@ -1630,15 +1630,15 @@ std::vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bo
return etk::FSNode::folderGetSubList(_showHidenFile, _getFolderAndOther, _getFile, filter); return etk::FSNode::folderGetSubList(_showHidenFile, _getFolderAndOther, _getFile, filter);
} }
std::vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bool _getFolderAndOther, bool _getFile, const etk::String& _filter) { etk::Vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bool _getFolderAndOther, bool _getFile, const etk::String& _filter) {
TK_TODO("implement filter ... "); TK_TODO("implement filter ... ");
std::vector<etk::FSNode*> tmpp; etk::Vector<etk::FSNode*> tmpp;
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
/* /*
if (m_systemFileName.size() == 0) { if (m_systemFileName.size() == 0) {
std::vector<etk::String> listDrive = getListDrive(); etk::Vector<etk::String> listDrive = getListDrive();
for (auto &it : listDrive) { for (auto &it : listDrive) {
tmpp.push_back(new etk::FSNode(it)); tmpp.pushBack(new etk::FSNode(it));
} }
return tmpp; return tmpp;
} }
@ -1652,7 +1652,7 @@ std::vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bo
#ifdef HAVE_ZIP_DATA #ifdef HAVE_ZIP_DATA
if( m_type == etk::FSNType_data if( m_type == etk::FSNType_data
|| m_type == etk::FSNType_themeData) { || m_type == etk::FSNType_themeData) {
std::vector<etk::String> listAdded; etk::Vector<etk::String> listAdded;
etk::String assetsName = baseFolderData; etk::String assetsName = baseFolderData;
etk::String FolderName = getNameFolder(); etk::String FolderName = getNameFolder();
if (s_APKArchive==nullptr) { if (s_APKArchive==nullptr) {
@ -1682,14 +1682,14 @@ std::vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bo
} }
} }
if (findIt == false) { if (findIt == false) {
listAdded.push_back(tmpString); listAdded.pushBack(tmpString);
tmpEmement = new etk::FSNode(tmpString); tmpEmement = new etk::FSNode(tmpString);
if (nullptr == tmpEmement) { if (nullptr == tmpEmement) {
TK_ERROR("allocation error ... of ewol::FSNode"); TK_ERROR("allocation error ... of ewol::FSNode");
continue; continue;
} }
TK_VERBOSE("find element : '" << tmpString << "' --> " << *tmpEmement); TK_VERBOSE("find element : '" << tmpString << "' --> " << *tmpEmement);
tmpp.push_back(tmpEmement); tmpp.pushBack(tmpEmement);
tmpEmement = nullptr; tmpEmement = nullptr;
} }
} }
@ -1719,13 +1719,13 @@ std::vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bo
} }
if(tmpEmement->getNodeType() == etk::typeNode_file) { if(tmpEmement->getNodeType() == etk::typeNode_file) {
if (true == _getFile) { if (true == _getFile) {
tmpp.push_back(tmpEmement); tmpp.pushBack(tmpEmement);
} else { } else {
delete(tmpEmement); delete(tmpEmement);
tmpEmement = nullptr; tmpEmement = nullptr;
} }
} else if (_getFolderAndOther) { } else if (_getFolderAndOther) {
tmpp.push_back(tmpEmement); tmpp.pushBack(tmpEmement);
} else { } else {
delete(tmpEmement); delete(tmpEmement);
tmpEmement = nullptr; tmpEmement = nullptr;
@ -1743,7 +1743,7 @@ std::vector<etk::FSNode *> etk::FSNode::folderGetSubList(bool _showHidenFile, bo
return tmpp; return tmpp;
} }
std::vector<etk::String> etk::FSNode::folderGetSub(bool _getFolder, bool _getFile, const etk::String& _filter) { etk::Vector<etk::String> etk::FSNode::folderGetSub(bool _getFolder, bool _getFile, const etk::String& _filter) {
TK_TODO("implement filter ... "); TK_TODO("implement filter ... ");
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
/* /*
@ -1752,7 +1752,7 @@ std::vector<etk::String> etk::FSNode::folderGetSub(bool _getFolder, bool _getFil
} }
*/ */
#endif #endif
std::vector<etk::String> out; etk::Vector<etk::String> out;
// regenerate the next list : // regenerate the next list :
etk::FSNode * tmpEmement = nullptr; etk::FSNode * tmpEmement = nullptr;
if (m_typeNode != etk::typeNode_folder ) { if (m_typeNode != etk::typeNode_folder ) {
@ -1761,7 +1761,7 @@ std::vector<etk::String> etk::FSNode::folderGetSub(bool _getFolder, bool _getFil
#ifdef HAVE_ZIP_DATA #ifdef HAVE_ZIP_DATA
if( m_type == etk::FSNType_data if( m_type == etk::FSNType_data
|| m_type == etk::FSNType_themeData) { || m_type == etk::FSNType_themeData) {
std::vector<etk::String> listAdded; etk::Vector<etk::String> listAdded;
etk::String assetsName = baseFolderData; etk::String assetsName = baseFolderData;
etk::String FolderName = getNameFolder(); etk::String FolderName = getNameFolder();
if (s_APKArchive == nullptr) { if (s_APKArchive == nullptr) {
@ -1788,10 +1788,10 @@ std::vector<etk::String> etk::FSNode::folderGetSub(bool _getFolder, bool _getFil
} }
} }
if (findIt == false) { if (findIt == false) {
listAdded.push_back(tmpString); listAdded.pushBack(tmpString);
etk::FSNode tmpEmement(tmpString); etk::FSNode tmpEmement(tmpString);
TK_VERBOSE("find element : '" << tmpString << "' --> " << tmpEmement); TK_VERBOSE("find element : '" << tmpString << "' --> " << tmpEmement);
out.push_back(tmpEmement.getName()); out.pushBack(tmpEmement.getName());
} }
} }
} }
@ -1815,10 +1815,10 @@ std::vector<etk::String> etk::FSNode::folderGetSub(bool _getFolder, bool _getFil
etk::FSNode tmpEmement(getRelativeFolder()+tmpName); etk::FSNode tmpEmement(getRelativeFolder()+tmpName);
if(tmpEmement.getNodeType() == etk::typeNode_file) { if(tmpEmement.getNodeType() == etk::typeNode_file) {
if (_getFile == true) { if (_getFile == true) {
out.push_back(tmpEmement.getName()); out.pushBack(tmpEmement.getName());
} }
} else if (_getFolder) { } else if (_getFolder) {
out.push_back(tmpEmement.getName()); out.pushBack(tmpEmement.getName());
} }
} }
closedir(dir); closedir(dir);
@ -1826,7 +1826,7 @@ std::vector<etk::String> etk::FSNode::folderGetSub(bool _getFolder, bool _getFil
TK_ERROR("could not open directory : \"" << *this << "\""); TK_ERROR("could not open directory : \"" << *this << "\"");
} }
// reorder the files // reorder the files
std::sort(out.begin(), out.end()); etk::sort(out);
return out; return out;
} }
@ -1835,7 +1835,7 @@ etk::FSNode etk::FSNode::folderGetParent() {
return tmpp; return tmpp;
} }
void etk::FSNode::folderGetRecursiveFiles(std::vector<etk::String>& _output, bool _recursiveEnable) { void etk::FSNode::folderGetRecursiveFiles(etk::Vector<etk::String>& _output, bool _recursiveEnable) {
#ifdef HAVE_ZIP_DATA #ifdef HAVE_ZIP_DATA
if( m_type == etk::FSNType_data if( m_type == etk::FSNType_data
|| m_type == etk::FSNType_themeData) { || m_type == etk::FSNType_themeData) {
@ -1857,7 +1857,7 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector<etk::String>& _output, boo
filename.erase(0,assetsName.size()); filename.erase(0,assetsName.size());
} }
tmpString += filename; tmpString += filename;
_output.push_back(tmpString); _output.pushBack(tmpString);
} }
} }
return; return;
@ -1883,7 +1883,7 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector<etk::String>& _output, boo
if (nullptr != tmpEmement) { if (nullptr != tmpEmement) {
if(tmpEmement->getNodeType() == etk::typeNode_file) { if(tmpEmement->getNodeType() == etk::typeNode_file) {
etk::String tmpVal = tmpEmement->getName(); etk::String tmpVal = tmpEmement->getName();
_output.push_back(tmpVal); _output.pushBack(tmpVal);
} }
if(tmpEmement->getNodeType() == etk::typeNode_folder) { if(tmpEmement->getNodeType() == etk::typeNode_folder) {
if (true==_recursiveEnable) { if (true==_recursiveEnable) {
@ -1904,12 +1904,12 @@ void etk::FSNode::folderGetRecursiveFiles(std::vector<etk::String>& _output, boo
return; return;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void etk::FSNode::folderGetRecursiveFiles(std::vector<std::u32string>& _output, bool _recursiveEnable) { void etk::FSNode::folderGetRecursiveFiles(etk::Vector<etk::UString>& _output, bool _recursiveEnable) {
_output.clear(); _output.clear();
std::vector<etk::String> tmpVal; etk::Vector<etk::String> tmpVal;
folderGetRecursiveFiles(tmpVal, _recursiveEnable); folderGetRecursiveFiles(tmpVal, _recursiveEnable);
for (size_t iii=0; iii<tmpVal.size(); ++iii) { for (size_t iii=0; iii<tmpVal.size(); ++iii) {
_output.push_back(to_u32string(tmpVal[iii])); _output.pushBack(toUString(tmpVal[iii]));
} }
} }
#endif #endif
@ -1937,8 +1937,8 @@ etk::String etk::FSNode::fileGetExtention() {
return ""; return "";
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNode::fileUGetExtention() { etk::UString etk::FSNode::fileUGetExtention() {
return etk::to_u32string(fileGetExtention()); return etk::toUString(fileGetExtention());
} }
#endif #endif
@ -2336,8 +2336,8 @@ void etk::theme::setName(const etk::String& _refName, const etk::String& _folder
g_listTheme.insert(std::pair<etk::String,etk::String>(_refName, _folderName)); g_listTheme.insert(std::pair<etk::String,etk::String>(_refName, _folderName));
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void etk::theme::setName(const std::u32string& _refName, const std::u32string& _folderName) { void etk::theme::setName(const etk::UString& _refName, const etk::UString& _folderName) {
setName(etk::to_string(_refName), etk::to_string(_folderName)); setName(etk::toString(_refName), etk::toString(_folderName));
} }
#endif #endif
@ -2353,30 +2353,30 @@ etk::String etk::theme::getName(const etk::String& _refName) {
return _refName; return _refName;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::theme::getName(const std::u32string& _refName) { etk::UString etk::theme::getName(const etk::UString& _refName) {
return etk::to_u32string(getName(etk::to_string(_refName))); return etk::toUString(getName(etk::toString(_refName)));
} }
#endif #endif
// get the list of all the theme folder availlable in the user Home/appl // get the list of all the theme folder availlable in the user Home/appl
std::vector<etk::String> etk::theme::list() { etk::Vector<etk::String> etk::theme::list() {
std::vector<etk::String> keys; etk::Vector<etk::String> keys;
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
for (auto &it : g_listTheme) { for (auto &it : g_listTheme) {
keys.push_back(it.first); keys.pushBack(it.first);
} }
#else #else
for (std::map<etk::String, etk::String>::iterator it(g_listTheme.begin()); it != g_listTheme.end(); ++it) { for (std::map<etk::String, etk::String>::iterator it(g_listTheme.begin()); it != g_listTheme.end(); ++it) {
keys.push_back(it->first); keys.pushBack(it->first);
} }
#endif #endif
return keys; return keys;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::vector<std::u32string> etk::theme::listU() { etk::Vector<etk::UString> etk::theme::listU() {
std::vector<std::u32string> keys; etk::Vector<etk::UString> keys;
for (auto &it : g_listTheme) { for (auto &it : g_listTheme) {
keys.push_back(etk::to_u32string(it.first)); keys.pushBack(etk::toUString(it.first));
} }
return keys; return keys;
} }
@ -2396,8 +2396,8 @@ void etk::theme::setNameDefault(const etk::String& _refName, const etk::String&
g_listThemeDefault.insert(std::pair<etk::String,etk::String>(_refName, _folderName)); g_listThemeDefault.insert(std::pair<etk::String,etk::String>(_refName, _folderName));
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void etk::theme::setNameDefault(const std::u32string& _refName, const std::u32string& _folderName) { void etk::theme::setNameDefault(const etk::UString& _refName, const etk::UString& _folderName) {
setNameDefault(etk::to_string(_refName), etk::to_string(_folderName)); setNameDefault(etk::toString(_refName), etk::toString(_folderName));
} }
#endif #endif
@ -2413,8 +2413,8 @@ etk::String etk::theme::getNameDefault(const etk::String& _refName) {
return "default"; return "default";
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::theme::getNameDefault(const std::u32string& _refName) { etk::UString etk::theme::getNameDefault(const etk::UString& _refName) {
return etk::to_u32string(getNameDefault(etk::to_string(_refName))); return etk::toUString(getNameDefault(etk::toString(_refName)));
} }
#endif #endif
@ -2433,8 +2433,8 @@ uint64_t etk::FSNodeGetSize(const etk::String& _path) {
return tmpNode.fileSize(); return tmpNode.fileSize();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
uint64_t etk::FSNodeGetSize(const std::u32string& _path) { uint64_t etk::FSNodeGetSize(const etk::UString& _path) {
return FSNodeGetSize(etk::to_string(_path)); return FSNodeGetSize(etk::toString(_path));
} }
#endif #endif
@ -2446,8 +2446,8 @@ bool etk::FSNodeRemove(const etk::String& _path) {
return tmpNode.remove(); return tmpNode.remove();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::FSNodeRemove(const std::u32string& _path) { bool etk::FSNodeRemove(const etk::UString& _path) {
return FSNodeRemove(etk::to_string(_path)); return FSNodeRemove(etk::toString(_path));
} }
#endif #endif
@ -2459,8 +2459,8 @@ int64_t etk::FSNodeGetCount(const etk::String& _path) {
return tmpNode.folderCount(); return tmpNode.folderCount();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
int64_t etk::FSNodeGetCount(const std::u32string& _path) { int64_t etk::FSNodeGetCount(const etk::UString& _path) {
return FSNodeGetCount(etk::to_string(_path)); return FSNodeGetCount(etk::toString(_path));
} }
#endif #endif
@ -2469,8 +2469,8 @@ bool etk::FSNodeCreate(const etk::String& _path, etk::FSNodeRight _right, enum e
return false; return false;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type) { bool etk::FSNodeCreate(const etk::UString& _path, etk::FSNodeRight _right, enum etk::typeNode _type) {
return FSNodeCreate(etk::to_string(_path), _right, _type); return FSNodeCreate(etk::toString(_path), _right, _type);
} }
#endif #endif
@ -2479,8 +2479,8 @@ bool etk::FSNodeExist(const etk::String& _path) {
return tmpNode.exist(); return tmpNode.exist();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::FSNodeExist(const std::u32string& _path) { bool etk::FSNodeExist(const etk::UString& _path) {
return FSNodeExist(etk::to_string(_path)); return FSNodeExist(etk::toString(_path));
} }
#endif #endif
@ -2496,8 +2496,8 @@ bool etk::FSNodeMove(const etk::String& _path1, const etk::String& _path2) {
return tmpNode.move(_path2); return tmpNode.move(_path2);
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::FSNodeMove(const std::u32string& _path1, const std::u32string& _path2) { bool etk::FSNodeMove(const etk::UString& _path1, const etk::UString& _path2) {
return FSNodeMove(etk::to_string(_path1), etk::to_string(_path2)); return FSNodeMove(etk::toString(_path1), etk::toString(_path2));
} }
#endif #endif
@ -2506,8 +2506,8 @@ etk::FSNodeRight etk::FSNodeGetRight(const etk::String& _path) {
return tmpNode.getRight(); return tmpNode.getRight();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
etk::FSNodeRight etk::FSNodeGetRight(const std::u32string& _path) { etk::FSNodeRight etk::FSNodeGetRight(const etk::UString& _path) {
return FSNodeGetRight(etk::to_string(_path)); return FSNodeGetRight(etk::toString(_path));
} }
#endif #endif
@ -2516,8 +2516,8 @@ enum etk::typeNode etk::FSNodeGetType(const etk::String& _path) {
return tmpNode.getNodeType(); return tmpNode.getNodeType();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
enum etk::typeNode etk::FSNodeGetType(const std::u32string& _path) { enum etk::typeNode etk::FSNodeGetType(const etk::UString& _path) {
return FSNodeGetType(etk::to_string(_path)); return FSNodeGetType(etk::toString(_path));
} }
#endif #endif
@ -2526,8 +2526,8 @@ uint64_t etk::FSNodeGetTimeCreated(const etk::String& _path) {
return tmpNode.timeCreated(); return tmpNode.timeCreated();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
uint64_t etk::FSNodeGetTimeCreated(const std::u32string& _path) { uint64_t etk::FSNodeGetTimeCreated(const etk::UString& _path) {
return FSNodeGetTimeCreated(etk::to_string(_path)); return FSNodeGetTimeCreated(etk::toString(_path));
} }
#endif #endif
@ -2536,8 +2536,8 @@ uint64_t etk::FSNodeGetTimeModified(const etk::String& _path) {
return tmpNode.timeModified(); return tmpNode.timeModified();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
uint64_t etk::FSNodeGetTimeModified(const std::u32string& _path) { uint64_t etk::FSNodeGetTimeModified(const etk::UString& _path) {
return FSNodeGetTimeModified(etk::to_string(_path)); return FSNodeGetTimeModified(etk::toString(_path));
} }
#endif #endif
@ -2546,8 +2546,8 @@ uint64_t etk::FSNodeGetTimeAccessed(const etk::String& _path) {
return tmpNode.timeAccessed(); return tmpNode.timeAccessed();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
uint64_t etk::FSNodeGetTimeAccessed(const std::u32string& _path) { uint64_t etk::FSNodeGetTimeAccessed(const etk::UString& _path) {
return FSNodeGetTimeAccessed(etk::to_string(_path)); return FSNodeGetTimeAccessed(etk::toString(_path));
} }
#endif #endif
@ -2556,8 +2556,8 @@ bool etk::FSNodeTouch(const etk::String& _path) {
return tmpNode.touch(); return tmpNode.touch();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::FSNodeTouch(const std::u32string& _path) { bool etk::FSNodeTouch(const etk::UString& _path) {
return FSNodeTouch(etk::to_string(_path)); return FSNodeTouch(etk::toString(_path));
} }
#endif #endif
@ -2580,8 +2580,8 @@ bool etk::FSNodeEcho(const etk::String& _path, const etk::String& _dataTowrite)
return tmpNode.fileClose(); return tmpNode.fileClose();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite) { bool etk::FSNodeEcho(const etk::UString& _path, const etk::UString& _dataTowrite) {
return FSNodeEcho(etk::to_string(_path), etk::to_string(_dataTowrite)); return FSNodeEcho(etk::toString(_path), etk::toString(_dataTowrite));
} }
#endif #endif
@ -2604,8 +2604,8 @@ bool etk::FSNodeEchoAdd(const etk::String& _path, const etk::String& _dataTowrit
return tmpNode.fileClose(); return tmpNode.fileClose();
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite) { bool etk::FSNodeEchoAdd(const etk::UString& _path, const etk::UString& _dataTowrite) {
return FSNodeEchoAdd(etk::to_string(_path), etk::to_string(_dataTowrite)); return FSNodeEchoAdd(etk::toString(_path), etk::toString(_dataTowrite));
} }
#endif #endif
@ -2613,8 +2613,8 @@ void etk::FSNodeHistory(const etk::String& _path, int32_t _historyCount) {
// step 1 : Move the file to prevent writing error // step 1 : Move the file to prevent writing error
//Get the first oldest save : //Get the first oldest save :
for (int32_t iii=_historyCount-1; iii>0 ; iii--) { for (int32_t iii=_historyCount-1; iii>0 ; iii--) {
if (etk::FSNodeExist(_path + "-" + etk::to_string(iii)) == true) { if (etk::FSNodeExist(_path + "-" + etk::toString(iii)) == true) {
etk::FSNodeMove(_path + "-" + etk::to_string(iii), _path + "-" + etk::to_string(iii+1)); etk::FSNodeMove(_path + "-" + etk::toString(iii), _path + "-" + etk::toString(iii+1));
} }
} }
if (etk::FSNodeExist(_path) == true) { if (etk::FSNodeExist(_path) == true) {
@ -2622,8 +2622,8 @@ void etk::FSNodeHistory(const etk::String& _path, int32_t _historyCount) {
} }
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void etk::FSNodeHistory(const std::u32string& _path, int32_t _historyCount) { void etk::FSNodeHistory(const etk::UString& _path, int32_t _historyCount) {
return FSNodeHistory(etk::to_string(_path), _historyCount); return FSNodeHistory(etk::toString(_path), _historyCount);
} }
#endif #endif
@ -2659,8 +2659,8 @@ etk::String etk::FSNodeGetRealName(const etk::String& _path) {
return node.getFileSystemName(); return node.getFileSystemName();
} }
std::vector<etk::String> etk::FSNodeExplodeMultiplePath(const etk::String& _path) { etk::Vector<etk::String> etk::FSNodeExplodeMultiplePath(const etk::String& _path) {
std::vector<etk::String> out; etk::Vector<etk::String> out;
etk::String libSearch = ""; etk::String libSearch = "";
etk::String newName = _path; etk::String newName = _path;
@ -2680,14 +2680,14 @@ std::vector<etk::String> etk::FSNodeExplodeMultiplePath(const etk::String& _path
} }
if (libSearch.size() != 0) { if (libSearch.size() != 0) {
if (libSearch[0] != '@') { if (libSearch[0] != '@') {
out.push_back(newName); out.pushBack(newName);
out.push_back(etk::String("{@") + libSearch + "}" + newName); out.pushBack(etk::String("{@") + libSearch + "}" + newName);
return out; return out;
} }
out.push_back(etk::String("{") + libSearch + "}" + newName); out.pushBack(etk::String("{") + libSearch + "}" + newName);
return out; return out;
} }
out.push_back(newName); out.pushBack(newName);
return out; return out;
} }

View File

@ -197,7 +197,7 @@ namespace etk {
*/ */
FSNode(const etk::String& _path = "~"); FSNode(const etk::String& _path = "~");
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
FSNode(const std::u32string& _path); FSNode(const etk::UString& _path);
#endif #endif
/** /**
* @brief Destructor * @brief Destructor
@ -219,7 +219,7 @@ namespace etk {
*/ */
void privateSetName(etk::String _newName); void privateSetName(etk::String _newName);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void privateSetName(const std::u32string& _newName); void privateSetName(const etk::UString& _newName);
#endif #endif
private: private:
#ifdef HAVE_ZIP_DATA #ifdef HAVE_ZIP_DATA
@ -270,7 +270,7 @@ namespace etk {
*/ */
void setName(const etk::String& _newName); void setName(const etk::String& _newName);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void setName(const std::u32string& _newName); void setName(const etk::UString& _newName);
#endif #endif
/** /**
* @brief Get the Generate FileSystem name * @brief Get the Generate FileSystem name
@ -278,7 +278,7 @@ namespace etk {
*/ */
etk::String getFileSystemName() const; etk::String getFileSystemName() const;
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string getUFileSystemName() const; etk::UString getUFileSystemName() const;
#endif #endif
/** /**
* @brief Get the current folder of the Node. (file system name) * @brief Get the current folder of the Node. (file system name)
@ -287,7 +287,7 @@ namespace etk {
*/ */
etk::String getNameFolder() const; etk::String getNameFolder() const;
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string getUNameFolder() const; etk::UString getUNameFolder() const;
#endif #endif
/** /**
* @brief Get the current compleate node name (file system name) * @brief Get the current compleate node name (file system name)
@ -296,7 +296,7 @@ namespace etk {
*/ */
etk::String getName() const; etk::String getName() const;
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string getUName() const; etk::UString getUName() const;
#endif #endif
/** /**
* @brief Get the file or current file name (if it was a file) * @brief Get the file or current file name (if it was a file)
@ -304,7 +304,7 @@ namespace etk {
*/ */
etk::String getNameFile() const; etk::String getNameFile() const;
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string getUNameFile() const; etk::UString getUNameFile() const;
#endif #endif
/** /**
* @brief Get the current folder of the Node. * @brief Get the current folder of the Node.
@ -313,7 +313,7 @@ namespace etk {
*/ */
etk::String getRelativeFolder() const; etk::String getRelativeFolder() const;
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string getURelativeFolder() const; etk::UString getURelativeFolder() const;
#endif #endif
/** /**
* @brief update the Time of the file with the current time * @brief update the Time of the file with the current time
@ -329,7 +329,7 @@ namespace etk {
*/ */
bool move(const etk::String& _path); bool move(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool move(const std::u32string& _path); bool move(const etk::UString& _path);
#endif #endif
/** /**
* @brief Get the node type (DATA/DIRECT...) * @brief Get the node type (DATA/DIRECT...)
@ -355,7 +355,7 @@ namespace etk {
*/ */
etk::String timeCreatedString() const; etk::String timeCreatedString() const;
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string timeUCreatedString() const; etk::UString timeUCreatedString() const;
#endif #endif
/** /**
* @brief Get the modifying time of the File * @brief Get the modifying time of the File
@ -368,7 +368,7 @@ namespace etk {
*/ */
etk::String timeModifiedString() const; etk::String timeModifiedString() const;
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string timeUModifiedString() const; etk::UString timeUModifiedString() const;
#endif #endif
/** /**
* @brief Get the Accessed time of the File * @brief Get the Accessed time of the File
@ -381,7 +381,7 @@ namespace etk {
*/ */
etk::String timeAccessedString() const; etk::String timeAccessedString() const;
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string timeUAccessedString() const; etk::UString timeUAccessedString() const;
#endif #endif
/** /**
* @brief copy the other FSnode ==> for vector * @brief copy the other FSnode ==> for vector
@ -423,7 +423,7 @@ namespace etk {
* @param[in] _temporaryFile add Tmp file like .bck or ~ * @param[in] _temporaryFile add Tmp file like .bck or ~
* @return The requested list * @return The requested list
*/ */
std::vector<etk::FSNode*> folderGetSubList(bool _showHidenFile = true, etk::Vector<etk::FSNode*> folderGetSubList(bool _showHidenFile = true,
bool _getFolderAndOther = true, bool _getFolderAndOther = true,
bool _getFile = true, bool _getFile = true,
bool _temporaryFile = true); bool _temporaryFile = true);
@ -435,7 +435,7 @@ namespace etk {
* @param[in] _filter Generic regex string to filter file names * @param[in] _filter Generic regex string to filter file names
* @return The requested list * @return The requested list
*/ */
std::vector<etk::FSNode*> folderGetSubList(bool _showHidenFile = true, etk::Vector<etk::FSNode*> folderGetSubList(bool _showHidenFile = true,
bool _getFolderAndOther = true, bool _getFolderAndOther = true,
bool _getFile = true, bool _getFile = true,
const etk::String& _filter = ".*"); const etk::String& _filter = ".*");
@ -446,7 +446,7 @@ namespace etk {
* @param[in] _filter Generic regex string to filter file names * @param[in] _filter Generic regex string to filter file names
* @return The requested list * @return The requested list
*/ */
std::vector<etk::String> folderGetSub(bool _getFolder, bool _getFile, const etk::String& _filter); etk::Vector<etk::String> folderGetSub(bool _getFolder, bool _getFile, const etk::String& _filter);
/** /**
* @brief Get the father node of this node * @brief Get the father node of this node
* @return The requested node * @return The requested node
@ -457,9 +457,9 @@ namespace etk {
* @param[out] _output List of all the File names (You must clear it before set it in) * @param[out] _output List of all the File names (You must clear it before set it in)
* @param[in] _recursiveEnable Activate the recursive mode (enable by default) * @param[in] _recursiveEnable Activate the recursive mode (enable by default)
*/ */
void folderGetRecursiveFiles(std::vector<etk::String>& _output, bool _recursiveEnable=true); void folderGetRecursiveFiles(etk::Vector<etk::String>& _output, bool _recursiveEnable=true);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void folderGetRecursiveFiles(std::vector<std::u32string>& _output, bool _recursiveEnable=true); void folderGetRecursiveFiles(etk::Vector<etk::UString>& _output, bool _recursiveEnable=true);
#endif #endif
/** /**
* @brief Check if the file have an extention ( ***.ccc) * @brief Check if the file have an extention ( ***.ccc)
@ -473,7 +473,7 @@ namespace etk {
*/ */
etk::String fileGetExtention(); etk::String fileGetExtention();
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string fileUGetExtention(); etk::UString fileUGetExtention();
#endif #endif
/** /**
* @brief Get the File size * @brief Get the File size
@ -600,8 +600,8 @@ namespace etk {
* @brief Read all element in a file and set it in a generic vector * @brief Read all element in a file and set it in a generic vector
* @return the read vector * @return the read vector
*/ */
template<typename T> std::vector<T> fileReadAll() { template<typename T> etk::Vector<T> fileReadAll() {
std::vector<T> value; etk::Vector<T> value;
value.resize(fileSize()); value.resize(fileSize());
fileRead(&value[0], sizeof(T), fileSize()/sizeof(T)); fileRead(&value[0], sizeof(T), fileSize()/sizeof(T));
return value; return value;
@ -617,7 +617,7 @@ namespace etk {
return value; return value;
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string fileReadAllU32String() { etk::UString fileReadAllU32String() {
return utf8::convertUnicode(fileReadAllString()); return utf8::convertUnicode(fileReadAllString());
} }
#endif #endif
@ -626,7 +626,7 @@ namespace etk {
* @param[in] _value Data to write in the File * @param[in] _value Data to write in the File
*/ */
template<typename T> template<typename T>
void fileWriteAll(const std::vector<T>& _value) { void fileWriteAll(const etk::Vector<T>& _value) {
fileWrite(static_cast<const void*>(&(_value[0])), sizeof(T), _value.size()/sizeof(T)); fileWrite(static_cast<const void*>(&(_value[0])), sizeof(T), _value.size()/sizeof(T));
} }
/** /**
@ -637,7 +637,7 @@ namespace etk {
fileWrite(static_cast<const void*>(&(_value[0])), sizeof(char), _value.size()/sizeof(char)); fileWrite(static_cast<const void*>(&(_value[0])), sizeof(char), _value.size()/sizeof(char));
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void fileWriteAll(const std::u32string& _value) { void fileWriteAll(const etk::UString& _value) {
fileWriteAll(u32char::convertToUtf8(_value)); fileWriteAll(u32char::convertToUtf8(_value));
} }
#endif #endif
@ -646,7 +646,7 @@ namespace etk {
* @brief Order the list of subnode the folder first and the alphabetical order * @brief Order the list of subnode the folder first and the alphabetical order
* @param[in,out] _list The list to order * @param[in,out] _list The list to order
*/ */
void sortElementList(std::vector<etk::FSNode *>& _list); void sortElementList(etk::Vector<etk::FSNode *>& _list);
}; };
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream &_os, const etk::FSNode &_obj); std::ostream& operator <<(std::ostream &_os, const etk::FSNode &_obj);
@ -678,7 +678,7 @@ namespace etk {
*/ */
etk::String getUserHomeFolder(); etk::String getUserHomeFolder();
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string getUUserHomeFolder(); etk::UString getUUserHomeFolder();
#endif #endif
/** /**
* @brief Get the folder of the Program is running * @brief Get the folder of the Program is running
@ -686,7 +686,7 @@ namespace etk {
*/ */
etk::String getUserRunFolder(); etk::String getUserRunFolder();
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string getUUserRunFolder(); etk::UString getUUserRunFolder();
#endif #endif
namespace theme { namespace theme {
@ -699,7 +699,7 @@ namespace etk {
void setName(const etk::String& _refName, const etk::String& _folderName); void setName(const etk::String& _refName, const etk::String& _folderName);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
//! @previous //! @previous
void setName(const std::u32string& _refName, const std::u32string& _folderName); void setName(const etk::UString& _refName, const etk::UString& _folderName);
#endif #endif
/** /**
* @brief get the folder from a Reference theme * @brief get the folder from a Reference theme
@ -709,7 +709,7 @@ namespace etk {
etk::String getName(const etk::String& _refName); etk::String getName(const etk::String& _refName);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
//! @previous //! @previous
std::u32string getName(const std::u32string& _refName); etk::UString getName(const etk::UString& _refName);
#endif #endif
/** /**
* @brief Set the default folder of a subset of a theme ... * @brief Set the default folder of a subset of a theme ...
@ -719,7 +719,7 @@ namespace etk {
void setNameDefault(const etk::String& _refName, const etk::String& _folderName); void setNameDefault(const etk::String& _refName, const etk::String& _folderName);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
//! @previous //! @previous
void setNameDefault(const std::u32string& _refName, const std::u32string& _folderName); void setNameDefault(const etk::UString& _refName, const etk::UString& _folderName);
#endif #endif
/** /**
* @brief get the default folder from a Reference theme * @brief get the default folder from a Reference theme
@ -729,16 +729,16 @@ namespace etk {
etk::String getNameDefault(const etk::String& _refName); etk::String getNameDefault(const etk::String& _refName);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
//! @previous //! @previous
std::u32string getNameDefault(const std::u32string& _refName); etk::UString getNameDefault(const etk::UString& _refName);
#endif #endif
/** /**
* @brief Get the list of all the theme folder availlable in the user Home/appl * @brief Get the list of all the theme folder availlable in the user Home/appl
* @return The list of elements * @return The list of elements
*/ */
std::vector<etk::String> list(); etk::Vector<etk::String> list();
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
//! @previous //! @previous
std::vector<std::u32string> listU(); etk::Vector<etk::UString> listU();
#endif #endif
}; };
/** /**
@ -748,7 +748,7 @@ namespace etk {
*/ */
uint64_t FSNodeGetSize(const etk::String& _path); uint64_t FSNodeGetSize(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
uint64_t FSNodeGetSize(const std::u32string& _path); uint64_t FSNodeGetSize(const etk::UString& _path);
#endif #endif
/** /**
@ -759,7 +759,7 @@ namespace etk {
*/ */
bool FSNodeRemove(const etk::String& _path); bool FSNodeRemove(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool FSNodeRemove(const std::u32string& _path); bool FSNodeRemove(const etk::UString& _path);
#endif #endif
/** /**
* @brief Simple access for : count the number of element in a path (if it is not a path ==> return -1) * @brief Simple access for : count the number of element in a path (if it is not a path ==> return -1)
@ -769,7 +769,7 @@ namespace etk {
*/ */
int64_t FSNodeGetCount(const etk::String& _path); int64_t FSNodeGetCount(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
int64_t FSNodeGetCount(const std::u32string& _path); int64_t FSNodeGetCount(const etk::UString& _path);
#endif #endif
/** /**
* @brief Simple access for : Create a file or a folder depending of the request * @brief Simple access for : Create a file or a folder depending of the request
@ -781,7 +781,7 @@ namespace etk {
*/ */
bool FSNodeCreate(const etk::String& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::typeNode_folder); bool FSNodeCreate(const etk::String& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::typeNode_folder);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool FSNodeCreate(const std::u32string& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::typeNode_folder); bool FSNodeCreate(const etk::UString& _path, etk::FSNodeRight _right, enum etk::typeNode _type=etk::typeNode_folder);
#endif #endif
/** /**
* @brief Simple access for : chexk the exestance of an element * @brief Simple access for : chexk the exestance of an element
@ -791,7 +791,7 @@ namespace etk {
*/ */
bool FSNodeExist(const etk::String& _path); bool FSNodeExist(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool FSNodeExist(const std::u32string& _path); bool FSNodeExist(const etk::UString& _path);
#endif #endif
/** /**
* @brief Simple access for : chexk the exestance of an element * @brief Simple access for : chexk the exestance of an element
@ -802,7 +802,7 @@ namespace etk {
*/ */
bool FSNodeMove(const etk::String& _path1, const etk::String& _path2); bool FSNodeMove(const etk::String& _path1, const etk::String& _path2);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool FSNodeMove(const std::u32string& _path1, const std::u32string& _path2); bool FSNodeMove(const etk::UString& _path1, const etk::UString& _path2);
#endif #endif
/** /**
* @brief Simple access for : Get right of the current Node * @brief Simple access for : Get right of the current Node
@ -812,7 +812,7 @@ namespace etk {
*/ */
etk::FSNodeRight FSNodeGetRight(const etk::String& _path); etk::FSNodeRight FSNodeGetRight(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
etk::FSNodeRight FSNodeGetRight(const std::u32string& _path); etk::FSNodeRight FSNodeGetRight(const etk::UString& _path);
#endif #endif
/** /**
* @brief Simple access for : Get type of the current node * @brief Simple access for : Get type of the current node
@ -822,7 +822,7 @@ namespace etk {
*/ */
enum etk::typeNode FSNodeGetType(const etk::String& _path); enum etk::typeNode FSNodeGetType(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
enum etk::typeNode FSNodeGetType(const std::u32string& _path); enum etk::typeNode FSNodeGetType(const etk::UString& _path);
#endif #endif
/** /**
* @brief Simple access for : Getting creation time of the current node * @brief Simple access for : Getting creation time of the current node
@ -832,7 +832,7 @@ namespace etk {
*/ */
uint64_t FSNodeGetTimeCreated(const etk::String& _path); uint64_t FSNodeGetTimeCreated(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
uint64_t FSNodeGetTimeCreated(const std::u32string& _path); uint64_t FSNodeGetTimeCreated(const etk::UString& _path);
#endif #endif
/** /**
* @brief Simple access for : Getting Modification time of the current node * @brief Simple access for : Getting Modification time of the current node
@ -842,7 +842,7 @@ namespace etk {
*/ */
uint64_t FSNodeGetTimeModified(const etk::String& _path); uint64_t FSNodeGetTimeModified(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
uint64_t FSNodeGetTimeModified(const std::u32string& _path); uint64_t FSNodeGetTimeModified(const etk::UString& _path);
#endif #endif
/** /**
* @brief Simple access for : Getting Accessing time of the current node * @brief Simple access for : Getting Accessing time of the current node
@ -852,7 +852,7 @@ namespace etk {
*/ */
uint64_t FSNodeGetTimeAccessed(const etk::String& _path); uint64_t FSNodeGetTimeAccessed(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
uint64_t FSNodeGetTimeAccessed(const std::u32string& _path); uint64_t FSNodeGetTimeAccessed(const etk::UString& _path);
#endif #endif
/** /**
* @brief Simple access for : Update Modification time with the current time of the node (>) * @brief Simple access for : Update Modification time with the current time of the node (>)
@ -862,7 +862,7 @@ namespace etk {
*/ */
bool FSNodeTouch(const etk::String& _path); bool FSNodeTouch(const etk::String& _path);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool FSNodeTouch(const std::u32string& _path); bool FSNodeTouch(const etk::UString& _path);
#endif #endif
/** /**
* @brief Simple access for : Basic write on the node (like console echo) * @brief Simple access for : Basic write on the node (like console echo)
@ -873,7 +873,7 @@ namespace etk {
*/ */
bool FSNodeEcho(const etk::String& _path, const etk::String& _dataTowrite); bool FSNodeEcho(const etk::String& _path, const etk::String& _dataTowrite);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool FSNodeEcho(const std::u32string& _path, const std::u32string& _dataTowrite); bool FSNodeEcho(const etk::UString& _path, const etk::UString& _dataTowrite);
#endif #endif
/** /**
* @brief Simple access for : Basic write on the node (like console echo) in adding mode (>>) * @brief Simple access for : Basic write on the node (like console echo) in adding mode (>>)
@ -884,7 +884,7 @@ namespace etk {
*/ */
bool FSNodeEchoAdd(const etk::String& _path, const etk::String& _dataTowrite); bool FSNodeEchoAdd(const etk::String& _path, const etk::String& _dataTowrite);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool FSNodeEchoAdd(const std::u32string& _path, const std::u32string& _dataTowrite); bool FSNodeEchoAdd(const etk::UString& _path, const etk::UString& _dataTowrite);
#endif #endif
/** /**
* @brief move file to generate an history of the current file * @brief move file to generate an history of the current file
@ -893,7 +893,7 @@ namespace etk {
*/ */
void FSNodeHistory(const etk::String& _path, int32_t _historyCount); void FSNodeHistory(const etk::String& _path, int32_t _historyCount);
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void FSNodeHistory(const std::u32string& _path, int32_t _historyCount); void FSNodeHistory(const etk::UString& _path, int32_t _historyCount);
#endif #endif
/** /**
* @brief Read all the data from a file * @brief Read all the data from a file
@ -912,8 +912,8 @@ namespace etk {
* @param[in] _path Folder/File/Pipe path of the node * @param[in] _path Folder/File/Pipe path of the node
* @return all the data of the file in a typed vector * @return all the data of the file in a typed vector
*/ */
template<typename TTT> std::vector<TTT> FSNodeReadAllDataType(const etk::String& _path) { template<typename TTT> etk::Vector<TTT> FSNodeReadAllDataType(const etk::String& _path) {
std::vector<TTT> out; etk::Vector<TTT> out;
etk::FSNode node(_path); etk::FSNode node(_path);
if (node.fileOpenRead() == false) { if (node.fileOpenRead() == false) {
//TK_ERROR("can not open file : '" << node << "'"); //TK_ERROR("can not open file : '" << node << "'");
@ -933,7 +933,7 @@ namespace etk {
* @param[in] _path Folder/File/Pipe path of the node * @param[in] _path Folder/File/Pipe path of the node
* @param[in] _data All the data of the file in a vector Typed bits ... * @param[in] _data All the data of the file in a vector Typed bits ...
*/ */
template<typename TTT> void FSNodeWriteAllDataType(const etk::String& _path, const std::vector<TTT>& _data) { template<typename TTT> void FSNodeWriteAllDataType(const etk::String& _path, const etk::Vector<TTT>& _data) {
etk::FSNode node(_path); etk::FSNode node(_path);
if (node.fileOpenWrite() == false) { if (node.fileOpenWrite() == false) {
//TK_ERROR("can not open file : '" << node << "'"); //TK_ERROR("can not open file : '" << node << "'");
@ -962,7 +962,7 @@ namespace etk {
* // out contain: {"{@ewol}DATA:font"} * // out contain: {"{@ewol}DATA:font"}
* @endcode * @endcode
*/ */
std::vector<etk::String> FSNodeExplodeMultiplePath(const etk::String& _path); etk::Vector<etk::String> FSNodeExplodeMultiplePath(const etk::String& _path);
}; };

View File

@ -6,6 +6,7 @@
#include <etk/os/FSNodeRight.hpp> #include <etk/os/FSNodeRight.hpp>
#include <etk/stdTools.hpp>
// Right Flags : // Right Flags :
enum { enum {
@ -147,8 +148,8 @@ void etk::FSNodeRight::setOtherRunable(bool _newStatus) {
} }
} }
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::FSNodeRight::getURight() const { etk::UString etk::FSNodeRight::getURight() const {
return etk::to_u32string(getRight()); return etk::toUString(getRight());
} }
#endif #endif

View File

@ -8,6 +8,8 @@
#pragma once #pragma once
#include <etk/String.hpp>
namespace etk { namespace etk {
/** /**
* @brief File System Right management * @brief File System Right management
@ -141,7 +143,7 @@ namespace etk {
* @brief Get the write written in a string mode (like in linux rw-r-----) * @brief Get the write written in a string mode (like in linux rw-r-----)
* @return String with the right in string * @return String with the right in string
*/ */
std::u32string getURight() const; etk::UString getURight() const;
#endif #endif
/** /**
* @brief Get the write written in a string mode (like in linux rw-r-----) * @brief Get the write written in a string mode (like in linux rw-r-----)

View File

@ -1,240 +1,9 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/stdTools.hpp>
#include <etk/debug.hpp>
const char32_t u32char::Null('\0');
const char32_t u32char::Return('\n');
const char32_t u32char::CarrierReturn('\r');
const char32_t u32char::Tabulation('\t');
const char32_t u32char::Suppress((const char)127);
const char32_t u32char::Delete((const char)8);
const char32_t u32char::Space(' ');
const char32_t u32char::Escape((const char)27);
bool u32char::isWhiteChar(char32_t _val) {
if( _val == ' '
|| _val == '\t'
|| _val == '\n'
|| _val == '\r') {
return true;
}
return false;
}
bool u32char::isSpecialChar(char32_t _val) {
if( _val < '0'
|| (_val > '9' && _val < 'A')
|| (_val > 'Z' && _val < 'a')
|| (_val > 'z' && _val < 0xFF) ) {
return true;
}
return false;
}
bool u32char::isInteger(char32_t _val) {
if( _val >= (uint32_t)'0'
&& _val <= (uint32_t)'9') {
return true;
}
return false;
}
int32_t u32char::toInt(char32_t _val) {
return _val - (uint32_t)'0';
}
char32_t u32char::changeOrder(char32_t _val) {
if (_val >= 'A' && _val <= 'Z') {
return (_val - (uint32_t)'A')*2 + 'A';
}
if (_val >= 'a' && _val <= 'z') {
return (_val - (uint32_t)'a')*2 + 'A' + 1;
}
if (_val >= ':' && _val <= '@') {
return _val + 52;
}
if (_val >= '[' && _val <= '`') {
return _val +26;
}
return _val;
}
static uint32_t getUtf8Val(char32_t _val) {
uint32_t output = 0;
if (_val <= 127) {
output = _val;
} else if (_val <= 2047) {
// output ==> 00000000 00000000 110xxxxx 10xxxxxx
// input ==> -------- -------- -----222 22111111
output = 0x0000C080;
output+= (_val & 0x000007C0)<<2;
output+= _val & 0x0000003F;
} else if (_val <= 65535) {
// output ==> 00000000 1110xxxx 10xxxxxx 10xxxxxx
// input ==> -------- -------- 33332222 22111111
output = 0x00E08080;
output+= (_val & 0x0000F000)<<4;
output+= (_val & 0x00000FC0)<<2;
output+= _val & 0x0000003F;
} else if (_val <= 1114111) {
// output ==> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
// input ==> -------- ---44433 33332222 22111111
output = 0xF0808080;
output+= (_val & 0x001C0000)<<6;
output+= (_val & 0x0003F000)<<4;
output+= (_val & 0x00000FC0)<<2;
output+= _val & 0x0000003F;
} else {
//TK_ERROR("NOT UTF8 character input...");
printf("not an utf8 char : %#08x\n", _val);
return 0;
}
//printf("utf-8 conversion : %d=%08x ==> %08x\n",value, value, output);
return output;
}
int8_t u32char::convertUtf8(char32_t _val, char _output[5]) {
uint32_t value = getUtf8Val(_val);
if (0xFF >= value) {
_output[0] = (char)value;
_output[1] = '\0';
return 1;
} else if (0xFFFF >= value) {
_output[0] = (char)((value>>8) & 0x000000FF);
_output[1] = (char)value;
_output[2] = '\0';
return 2;
} else if (0xFFFFFF >= value) {
_output[0] = (char)((value>>16) & 0x000000FF);
_output[1] = (char)((value>>8) & 0x000000FF);
_output[2] = (char)value;
_output[3] = '\0';
return 3;
} else {
_output[0] = (char)((value>>24) & 0x000000FF);
_output[1] = (char)((value>>16) & 0x000000FF);
_output[2] = (char)((value>>8) & 0x000000FF);
_output[3] = (char)value;
_output[4] = '\0';
return 4;
}
}
#if __CPP_VERSION__ >= 2011
std::string u32char::convertToUtf8(const std::u32string& _input) {
TK_TODO("implement this function ...");
return "TODO ... std::string u32char::convertToUtf8(const std::u32string& _input)";
}
#endif
static uint8_t sizeElement(const char* _data, int32_t _lenMax) {
uint8_t size = 0;
TK_ASSERT(0 <= _lenMax, "size can not be < 0 ...");
if (0 > _lenMax) {
return 0;
}
//4 case
if( _lenMax >= 1
&& (_data[0] & 0x80) == 0x00 ) {
// One Char Element
size = 1;
} else if( _lenMax >= 2
&& (_data[0] & 0xE0) == 0xC0
&& (_data[1] & 0xC0) == 0x80) {
size = 2;
} else if( _lenMax >= 3
&& (_data[0] & 0xF0) == 0xE0
&& (_data[1] & 0xC0) == 0x80
&& (_data[2] & 0xC0) == 0x80) {
size = 3;
} else if( _lenMax >= 4
&& (_data[0] & 0xF8) == 0xF0
&& (_data[1] & 0xC0) == 0x80
&& (_data[2] & 0xC0) == 0x80
&& (_data[3] & 0xC0) == 0x80) {
size = 4;
}
return size;
}
char32_t utf8::convertChar32(const char* _input) {
char32_t value = 0;
if (nullptr == _input) {
return value;
}
int32_t len = strlen(_input);
len = sizeElement(_input, len);
switch (len) {
default:
// case 0 : An error occurred...
value = _input[0];
return value;
case 1:
value = (uint8_t)(_input[0]) & 0x7F;
return value;
case 2:
value = (((uint8_t)_input[0]) & 0x1F)<< 6;
value += ((uint8_t)_input[1]) & 0x3F;
return value;
case 3:
value = (((uint8_t)_input[0]) & 0x0F)<< 12;
value += (((uint8_t)_input[1]) & 0x3F)<< 6;
value += ((uint8_t)_input[2]) & 0x3F;
return value;
case 4:
value = (((uint8_t)_input[0]) & 0x07)<< 18;
value += (((uint8_t)_input[1]) & 0x3F)<< 12;
value += (((uint8_t)_input[2]) & 0x3F)<< 6;
value += ((uint8_t)_input[3]) & 0x3F;
return value;
}
}
int8_t utf8::length(const char _input) {
if((_input&0x80) == 0x00 ) {
return 1;
}
if((_input&0xE0) == 0xC0) {
return 2;
}
if((_input&0xF0) == 0xE0) {
return 3;
}
if((_input&0xF8) == 0xF0) {
return 4;
}
return 1;
}
bool utf8::first(const char _input) {
// When started with the bit 0 then the size is single element.
if((_input&0x80) == 0x00 ) {
return true;
}
// for multiple element size, we just need to check the second element (might be != 1)
if((_input&0x40) == 0x40 ) {
return true;
}
return false;
}
#if __CPP_VERSION__ >= 2011
std::u32string utf8::convertUnicode(const etk::String& _input) {
TK_TODO("implement this function ...");
return U"TODO ... std::u32string utf8::convertUnicode(const etk::String& _input)";
}
#endif
namespace etk { namespace etk {
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> std::string to_string<std::u32string>(const std::u32string& _input) { template<> etk::String toString<etk::UString>(const etk::UString& _input) {
std::string out; etk::String out;
for (size_t iii=0; iii<_input.size(); ++iii) { for (size_t iii=0; iii<_input.size(); ++iii) {
char output[10]; char output[10];
u32char::convertUtf8(_input[iii], output); u32char::convertUtf8(_input[iii], output);
@ -242,108 +11,22 @@ namespace etk {
} }
return out; return out;
} }
template<> std::string to_string<char32_t>(const char32_t& _input) { template<> etk::String toString<char32_t>(const char32_t& _input) {
std::string out; etk::String out;
char output[10]; char output[10];
u32char::convertUtf8(_input, output); u32char::convertUtf8(_input, output);
out += output; out += output;
return out; return out;
} }
#endif #endif
template<> std::string to_string<std::string>(const std::string& _val) {
return _val;
}
template<> std::string to_string<bool>(const bool& _val) {
if (_val == true) {
return "true";
}
return "false";
}
template<> std::string to_string<int8_t>(const int8_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%d", _val);
return tmpVal;
}
template<> std::string to_string<int16_t>(const int16_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%d", _val);
return tmpVal;
}
template<> std::string to_string<int32_t>(const int32_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%d", _val);
return tmpVal;
}
template<> std::string to_string<int64_t>(const int64_t& _val) {
char tmpVal[256];
#if ( defined(__TARGET_OS__Android) \
|| defined(__TARGET_OS__Windows) \
|| defined(__TARGET_OS__MacOs) \
|| defined(__TARGET_OS__IOs))
sprintf(tmpVal, "%lld", _val);
#else
sprintf(tmpVal, "%ld", _val);
#endif
return tmpVal;
}
template<> std::string to_string<uint8_t>(const uint8_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%u", _val);
return tmpVal;
}
template<> std::string to_string<uint16_t>(const uint16_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%u", _val);
return tmpVal;
}
template<> std::string to_string<uint32_t>(const uint32_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%u", _val);
return tmpVal;
}
template<> std::string to_string<uint64_t>(const uint64_t& _val) {
char tmpVal[256];
#if ( defined(__TARGET_OS__Android) \
|| defined(__TARGET_OS__Windows) \
|| defined(__TARGET_OS__MacOs) \
|| defined(__TARGET_OS__IOs))
sprintf(tmpVal, "%llu", _val);
#else
sprintf(tmpVal, "%lu", _val);
#endif
return tmpVal;
}
#if (defined(__TARGET_OS__IOs) || defined(__TARGET_OS__MacOs))
template<> std::string to_string<size_t>(const size_t& _val) {
char tmpVal[256];
sprintf(tmpVal, "%lu", _val);
return tmpVal;
}
#endif
template<> std::string to_string<float>(const float& _val) {
char tmpVal[256];
sprintf(tmpVal, "%f", _val);
return tmpVal;
}
template<> std::string to_string<double>(const double& _val) {
char tmpVal[256];
sprintf(tmpVal, "%f", _val);
return tmpVal;
}
template<> std::string to_string<long double>(const long double& _val) {
char tmpVal[256];
sprintf(tmpVal, "%Lf", _val);
return tmpVal;
}
}; };
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
static std::u32string transform_to_u32string(const char* _input) { static etk::UString transform_toUString(const char* _input) {
if (_input == NULL) { if (_input == nullptr) {
return U""; return U"";
} }
std::u32string out; etk::UString out;
char tmpData[20]; char tmpData[20];
int64_t pos = 0; int64_t pos = 0;
int64_t inputLen = strlen(_input); int64_t inputLen = strlen(_input);
@ -393,46 +76,46 @@ namespace etk {
#endif #endif
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
namespace etk { namespace etk {
template<> std::u32string to_u32string<char*>(char* const & _input) { template<> etk::UString toUString<char*>(char* const & _input) {
return transform_to_u32string(_input); return transform_toUString(_input);
} }
template<> std::u32string to_u32string<std::string>(const std::string& _input) { template<> etk::UString toUString<etk::String>(const etk::String& _input) {
return transform_to_u32string(_input.c_str()); return transform_toUString(_input.c_str());
} }
template<> std::u32string to_u32string<int8_t>(const int8_t& _val) { template<> etk::UString toUString<int8_t>(const int8_t& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<int16_t>(const int16_t& _val) { template<> etk::UString toUString<int16_t>(const int16_t& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<int32_t>(const int32_t& _val) { template<> etk::UString toUString<int32_t>(const int32_t& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<int64_t>(const int64_t& _val) { template<> etk::UString toUString<int64_t>(const int64_t& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<uint8_t>(const uint8_t& _val) { template<> etk::UString toUString<uint8_t>(const uint8_t& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<uint16_t>(const uint16_t& _val) { template<> etk::UString toUString<uint16_t>(const uint16_t& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<uint32_t>(const uint32_t& _val) { template<> etk::UString toUString<uint32_t>(const uint32_t& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<uint64_t>(const uint64_t& _val) { template<> etk::UString toUString<uint64_t>(const uint64_t& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<float>(const float& _val) { template<> etk::UString toUString<float>(const float& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<double>(const double& _val) { template<> etk::UString toUString<double>(const double& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<long double>(const long double& _val) { template<> etk::UString toUString<long double>(const long double& _val) {
return etk::to_u32string(etk::to_string(_val)); return etk::toUString(etk::toString(_val));
}; };
template<> std::u32string to_u32string<bool>(const bool& _val) { template<> etk::UString toUString<bool>(const bool& _val) {
if (_val == true) { if (_val == true) {
return U"true"; return U"true";
} }
@ -440,7 +123,7 @@ namespace etk {
} }
}; };
bool etk::string_to_bool(const std::u32string& _str) { bool etk::string_to_bool(const etk::UString& _str) {
if( true == compare_no_case(_str, U"true") if( true == compare_no_case(_str, U"true")
|| true == compare_no_case(_str, U"enable") || true == compare_no_case(_str, U"enable")
|| true == compare_no_case(_str, U"yes") || true == compare_no_case(_str, U"yes")
@ -450,57 +133,43 @@ namespace etk {
return false; return false;
} }
double etk::string_to_double(const std::u32string& _str) { double etk::string_to_double(const etk::UString& _str) {
return std::stod(etk::to_string(_str)); return etk::string_to_double(etk::toString(_str));
} }
long double etk::string_to_long_double(const std::u32string& _str) { long double etk::string_to_long_double(const etk::UString& _str) {
return std::stold(etk::to_string(_str)); return etk::string_to_long_double(etk::toString(_str));
} }
float etk::string_to_float(const std::u32string& _str) { float etk::string_to_float(const etk::UString& _str) {
return std::stof(etk::to_string(_str)); return etk::string_to_float(etk::toString(_str));
} }
int8_t etk::string_to_int8_t(const std::u32string& _str, int _base) { int8_t etk::string_to_int8_t(const etk::UString& _str) {
return std::stoi(etk::to_string(_str), 0, _base); return etk::string_to_int8_t(etk::toString(_str));
} }
int16_t etk::string_to_int16_t(const std::u32string& _str, int _base) { int16_t etk::string_to_int16_t(const etk::UString& _str) {
return std::stoi(etk::to_string(_str), 0, _base); return etk::string_to_int16_t(etk::toString(_str));
} }
int32_t etk::string_to_int32_t(const std::u32string& _str, int _base) { int32_t etk::string_to_int32_t(const etk::UString& _str) {
return std::stoi(etk::to_string(_str), 0, _base); return etk::string_to_int32_t(etk::toString(_str));
} }
int64_t etk::string_to_int64_t(const std::u32string& _str, int _base) { int64_t etk::string_to_int64_t(const etk::UString& _str) {
return std::stoll(etk::to_string(_str), 0, _base); return etk::string_to_int64_t(etk::toString(_str));
} }
uint8_t etk::string_to_uint8_t(const std::u32string& _str, int _base) { uint8_t etk::string_to_uint8_t(const etk::UString& _str) {
return std::stoul(etk::to_string(_str), 0, _base); return etk::string_to_uint8_t(etk::toString(_str));
} }
uint16_t etk::string_to_uint16_t(const std::u32string& _str, int _base) { uint16_t etk::string_to_uint16_t(const etk::UString& _str) {
return std::stoul(etk::to_string(_str), 0, _base); return etk::string_to_uint16_t(etk::toString(_str));
} }
uint32_t etk::string_to_uint32_t(const std::u32string& _str, int _base) { uint32_t etk::string_to_uint32_t(const etk::UString& _str) {
return std::stoul(etk::to_string(_str), 0, _base); return etk::string_to_uint32_t(etk::toString(_str));
} }
uint64_t etk::string_to_uint64_t(const std::u32string& _str, int _base) { uint64_t etk::string_to_uint64_t(const etk::UString& _str) {
return std::stoull(etk::to_string(_str), 0, _base); return etk::string_to_uint64_t(etk::toString(_str));
} }
#endif #endif
bool etk::string_to_bool(const std::string& _str) {
if( true == compare_no_case(_str, "true")
|| true == compare_no_case(_str, "enable")
|| true == compare_no_case(_str, "yes")
#if __CPP_VERSION__ >= 2011
|| _str == u8"1"
#else
|| _str == "1"
#endif
) {
return true;
}
return false;
}
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::compare_no_case(const std::u32string& _obj, const std::u32string& _val) { bool etk::compare_no_case(const etk::UString& _obj, const etk::UString& _val) {
if (_val.size() != _obj.size()) { if (_val.size() != _obj.size()) {
return false; return false;
} }
@ -513,17 +182,6 @@ bool etk::string_to_bool(const std::string& _str) {
} }
#endif #endif
bool etk::compare_no_case(const std::string& _obj, const std::string& _val) {
if (_val.size() != _obj.size()) {
return false;
}
for(size_t iii=0; iii<_val.size(); ++iii) {
if (std::tolower(_val[iii]) != std::tolower(_obj[iii])) {
return false;
}
}
return true;
}
class DoubleChar { class DoubleChar {
public: public:
@ -581,14 +239,8 @@ static char32_t localToLower(char32_t _input) {
} }
std::string etk::tolower(std::string _obj) {
for(size_t iii=0 ; iii<_obj.size() ; iii++) {
_obj[iii] = std::tolower(_obj[iii]);
}
return _obj;
}
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::tolower(std::u32string _obj) { etk::UString etk::tolower(etk::UString _obj) {
for(size_t iii=0 ; iii<_obj.size() ; iii++) { for(size_t iii=0 ; iii<_obj.size() ; iii++) {
_obj[iii] = localToLower(_obj[iii]); _obj[iii] = localToLower(_obj[iii]);
} }
@ -596,14 +248,8 @@ std::string etk::tolower(std::string _obj) {
} }
#endif #endif
std::string etk::toupper(std::string _obj) {
for(size_t iii=0 ; iii<_obj.size() ; iii++) {
_obj[iii] = std::toupper(_obj[iii]);
}
return _obj;
}
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::toupper(std::u32string _obj) { etk::UString etk::toupper(etk::UString _obj) {
for(size_t iii=0 ; iii<_obj.size() ; iii++) { for(size_t iii=0 ; iii<_obj.size() ; iii++) {
_obj[iii] = localToUpper(_obj[iii]); _obj[iii] = localToUpper(_obj[iii]);
} }
@ -611,34 +257,9 @@ std::string etk::toupper(std::string _obj) {
} }
#endif #endif
bool etk::end_with(const std::string& _obj, const std::string& _val, bool _caseSensitive) {
if (_val.size() == 0) {
return false;
}
if (_val.size() > _obj.size()) {
return false;
}
if (true == _caseSensitive) {
for( int64_t iii=_val.size()-1, jjj=_obj.size()-1;
iii>=0 && jjj>=0;
iii--, jjj--) {
if (_obj[jjj] != _val[iii]) {
return false;
}
}
return true;
}
for( int64_t iii=_val.size()-1, jjj=_obj.size()-1;
iii>=0 && jjj>=0;
iii--, jjj--) {
if (std::tolower(_val[iii]) != std::tolower(_obj[jjj])) {
return false;
}
}
return true;
}
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { bool etk::end_with(const etk::UString& _obj, const etk::UString& _val, bool _caseSensitive) {
if (_val.size() == 0) { if (_val.size() == 0) {
return false; return false;
} }
@ -666,34 +287,8 @@ bool etk::end_with(const std::string& _obj, const std::string& _val, bool _caseS
} }
#endif #endif
bool etk::start_with(const std::string& _obj, const std::string& _val, bool _caseSensitive) {
if (_val.size() == 0) {
return false;
}
if (_val.size() > _obj.size()) {
return false;
}
if (_caseSensitive == true) {
for( size_t iii = 0;
iii < _val.size();
iii++) {
if (_obj[iii] != _val[iii]) {
return false;
}
}
return true;
}
for( size_t iii = 0;
iii < _val.size();
iii++) {
if (std::tolower(_val[iii]) != std::tolower(_obj[iii])) {
return false;
}
}
return true;
}
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
bool etk::start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive) { bool etk::start_with(const etk::UString& _obj, const etk::UString& _val, bool _caseSensitive) {
if (_val.size() == 0) { if (_val.size() == 0) {
return false; return false;
} }
@ -720,8 +315,8 @@ bool etk::start_with(const std::string& _obj, const std::string& _val, bool _cas
return true; return true;
} }
std::u32string etk::replace(const std::u32string& _obj, char32_t _val, char32_t _replace) { etk::UString etk::replace(const etk::UString& _obj, char32_t _val, char32_t _replace) {
std::u32string copy(_obj); etk::UString copy(_obj);
for( size_t iii = 0; for( size_t iii = 0;
iii < copy.size(); iii < copy.size();
iii++) { iii++) {
@ -734,7 +329,7 @@ bool etk::start_with(const std::string& _obj, const std::string& _val, bool _cas
#endif #endif
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::u32string etk::extract_line(const std::u32string& _obj, int32_t _pos) { etk::UString etk::extract_line(const etk::UString& _obj, int32_t _pos) {
// search back : '\n' // search back : '\n'
size_t startPos = _obj.rfind('\n', _pos); size_t startPos = _obj.rfind('\n', _pos);
if ((int64_t)startPos == _pos) { if ((int64_t)startPos == _pos) {
@ -750,32 +345,32 @@ bool etk::start_with(const std::string& _obj, const std::string& _val, bool _cas
stopPos = _obj.size(); stopPos = _obj.size();
} }
} }
if (startPos == std::string::npos) { if (startPos == etk::String::npos) {
startPos = 0; startPos = 0;
} else if (startPos >= _obj.size() ) { } else if (startPos >= _obj.size() ) {
return U""; return U"";
} }
if (stopPos == std::string::npos) { if (stopPos == etk::String::npos) {
return U""; return U"";
} else if (stopPos >= _obj.size() ) { } else if (stopPos >= _obj.size() ) {
stopPos = _obj.size(); stopPos = _obj.size();
} }
return std::u32string(_obj, startPos, stopPos - startPos); return etk::UString(_obj, startPos, stopPos - startPos);
} }
#endif #endif
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::vector<std::u32string> etk::split(const std::u32string& _input, char32_t _val) { etk::Vector<etk::UString> etk::split(const etk::UString& _input, char32_t _val) {
std::vector<std::u32string> list; etk::Vector<etk::UString> list;
size_t lastStartPos = 0; size_t lastStartPos = 0;
for(size_t iii=0; iii<_input.size(); iii++) { for(size_t iii=0; iii<_input.size(); iii++) {
if (_input[iii]==_val) { if (_input[iii]==_val) {
list.push_back(std::u32string(_input, lastStartPos, iii - lastStartPos)); list.pushBack(etk::UString(_input, lastStartPos, iii - lastStartPos));
lastStartPos = iii+1; lastStartPos = iii+1;
} }
} }
if (lastStartPos<_input.size()) { if (lastStartPos<_input.size()) {
list.push_back(std::u32string(_input, lastStartPos)); list.pushBack(etk::UString(_input, lastStartPos));
} }
return list; return list;
} }
@ -784,8 +379,8 @@ bool etk::start_with(const std::string& _obj, const std::string& _val, bool _cas
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
void etk::sort(std::vector<std::u32string *> &_list) { void etk::sort(etk::Vector<etk::UString *> &_list) {
std::vector<std::u32string *> tmpList(_list); etk::Vector<etk::UString *> tmpList(_list);
_list.clear(); _list.clear();
for(size_t iii=0; iii<tmpList.size(); iii++) { for(size_t iii=0; iii<tmpList.size(); iii++) {
size_t findPos = 0; size_t findPos = 0;
@ -803,55 +398,55 @@ bool etk::start_with(const std::string& _obj, const std::string& _val, bool _cas
namespace etk { namespace etk {
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
template<> bool from_string<std::u32string>(std::u32string& _variableRet, const std::string& _value) { template<> bool from_string<etk::UString>(etk::UString& _variableRet, const etk::String& _value) {
_variableRet = etk::to_u32string(_value); _variableRet = etk::toUString(_value);
return true; return true;
} }
template<> bool from_string<int8_t>(int8_t& _variableRet, const std::u32string& _value) { template<> bool from_string<int8_t>(int8_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_int8_t(_value); _variableRet = string_to_int8_t(_value);
return true; return true;
} }
template<> bool from_string<int16_t>(int16_t& _variableRet, const std::u32string& _value) { template<> bool from_string<int16_t>(int16_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_int16_t(_value); _variableRet = string_to_int16_t(_value);
return true; return true;
} }
template<> bool from_string<int32_t>(int32_t& _variableRet, const std::u32string& _value) { template<> bool from_string<int32_t>(int32_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_int32_t(_value); _variableRet = string_to_int32_t(_value);
return true; return true;
} }
template<> bool from_string<int64_t>(int64_t& _variableRet, const std::u32string& _value) { template<> bool from_string<int64_t>(int64_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_int64_t(_value); _variableRet = string_to_int64_t(_value);
return true; return true;
} }
template<> bool from_string<uint8_t>(uint8_t& _variableRet, const std::u32string& _value) { template<> bool from_string<uint8_t>(uint8_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_uint8_t(_value); _variableRet = string_to_uint8_t(_value);
return true; return true;
} }
template<> bool from_string<uint16_t>(uint16_t& _variableRet, const std::u32string& _value) { template<> bool from_string<uint16_t>(uint16_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_uint16_t(_value); _variableRet = string_to_uint16_t(_value);
return true; return true;
} }
template<> bool from_string<uint32_t>(uint32_t& _variableRet, const std::u32string& _value) { template<> bool from_string<uint32_t>(uint32_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_uint32_t(_value); _variableRet = string_to_uint32_t(_value);
return true; return true;
} }
template<> bool from_string<uint64_t>(uint64_t& _variableRet, const std::u32string& _value) { template<> bool from_string<uint64_t>(uint64_t& _variableRet, const etk::UString& _value) {
_variableRet = string_to_uint64_t(_value); _variableRet = string_to_uint64_t(_value);
return true; return true;
} }
template<> bool from_string<float>(float& _variableRet, const std::u32string& _value) { template<> bool from_string<float>(float& _variableRet, const etk::UString& _value) {
_variableRet = string_to_float(_value); _variableRet = string_to_float(_value);
return true; return true;
} }
template<> bool from_string<double>(double& _variableRet, const std::u32string& _value) { template<> bool from_string<double>(double& _variableRet, const etk::UString& _value) {
_variableRet = string_to_double(_value); _variableRet = string_to_double(_value);
return true; return true;
} }
template<> bool from_string<long double>(long double& _variableRet, const std::u32string& _value) { template<> bool from_string<long double>(long double& _variableRet, const etk::UString& _value) {
_variableRet = string_to_long_double(_value); _variableRet = string_to_long_double(_value);
return true; return true;
} }
template<> bool from_string<bool>(bool& _variableRet, const std::u32string& _value) { template<> bool from_string<bool>(bool& _variableRet, const etk::UString& _value) {
_variableRet = string_to_bool(_value); _variableRet = string_to_bool(_value);
return true; return true;
} }
@ -860,12 +455,12 @@ namespace etk {
#if __CPP_VERSION__ >= 2011 #if __CPP_VERSION__ >= 2011
std::ostream& std::operator <<(std::ostream& _os, const std::u32string& _obj) { std::ostream& std::operator <<(std::ostream& _os, const etk::UString& _obj) {
_os << etk::to_string(_obj).c_str(); _os << etk::toString(_obj).c_str();
return _os; return _os;
} }
std::ostream& std::operator <<(std::ostream& _os, const std::vector<std::u32string>& _obj) { std::ostream& std::operator <<(std::ostream& _os, const etk::Vector<etk::UString>& _obj) {
_os << "{"; _os << "{";
for (size_t iii=0; iii< _obj.size(); iii++) { for (size_t iii=0; iii< _obj.size(); iii++) {
if (iii>0) { if (iii>0) {
@ -878,52 +473,6 @@ namespace etk {
} }
#endif #endif
#if (defined(__TARGET_OS__Android))
double std::stod(const std::string& _str, size_t* _id) {
double ret = 0;
sscanf(_str.c_str(), "%lf", &ret);
return ret;
}
float std::stof(const std::string& _str, size_t* _id) {
float ret = 0;
sscanf(_str.c_str(), "%f", &ret);
return ret;
}
int std::stoi(const std::string& _str, size_t* _id, int _base) {
int ret = 0;
sscanf(_str.c_str(), "%d", &ret);
return ret;
}
long std::stol(const std::string& _str, size_t* _id, int _base) {
long ret = 0;
sscanf(_str.c_str(), "%ld", &ret);
return ret;
}
long double std::stold(const std::string& _str, size_t* _id) {
long double ret = 0;
sscanf(_str.c_str(), "%Lf", &ret);
return ret;
}
long long std::stoll(const std::string& _str, size_t* _id, int _base) {
long long ret = 0;
sscanf(_str.c_str(), "%lld", &ret);
return ret;
}
unsigned long std::stoul(const std::string& _str, size_t* _id, int _base) {
unsigned long ret = 0;
sscanf(_str.c_str(), "%lu", &ret);
return ret;
}
unsigned long long std::stoull(const std::string& _str, size_t* _id, int _base) {
unsigned long long ret = 0;
sscanf(_str.c_str(), "%llu", &ret);
return ret;
}
#endif
namespace std { namespace std {
std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj) { std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj) {
std::chrono::nanoseconds ns = std::chrono::duration_cast<std::chrono::nanoseconds>(_obj.time_since_epoch()); std::chrono::nanoseconds ns = std::chrono::duration_cast<std::chrono::nanoseconds>(_obj.time_since_epoch());

View File

@ -1,526 +1,47 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once #pragma once
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/String.hpp>
#include <etk/Vector.hpp> #include <etk/Vector.hpp>
#include <vector>
#include <sstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <chrono>
/**
* @brief Unicode simple wrapper interface
*/
namespace u32char {
extern const char32_t Null; //!< Value '\\0'
extern const char32_t Return; //!< Value '\\n'
extern const char32_t CarrierReturn; //!< Value '\\r' CR
extern const char32_t Tabulation; //!< Value '\\t' TAB
extern const char32_t Suppress; //!< Value BS (SUPPRESS)
extern const char32_t Delete; //!< Value DEL
extern const char32_t Space; //!< Value ' ' SPACE
extern const char32_t Escape; //!< Value ESC Escape
/**
* @brief check if the current element is white or not : '\\t' '\\n' '\\r' ' '
* @param[in] _val Value to interpret
* @return true if it is white char
* @return false otherwise
*/
bool isWhiteChar(char32_t _val);
/**
* @brief check if the current element is NOT [a-zA-Z0-9]
* @param[in] _val Value to interpret
* @return true Not in the previous list
* @return false otherwise
*/
bool isSpecialChar(char32_t _val);
/**
* @brief check if the current element is number or not [0-9]
* @param[in] _val Value to interpret
* @return true if it is a number char
* @return false otherwise
*/
bool isInteger(char32_t _val);
/**
* @brief Convert char32_t in an integer
* @param[in] _val Value to interpret
* @return The parsed Value or ...
*/
int32_t toInt(char32_t _val);
/**
* @brief Change order of the value to have an order of display with A->Z and after a->z and after 0->9 and after all the rest ....
* @param[in] _val Value in unicode
* @return A value usable in integer only ... to check order...
*/
char32_t changeOrder(char32_t _val);
/**
* @brief Convert unicode in UTF8 value
* @param[in] _val Value to convert
* @param[out] _output Char data converted
* @return Number of char in utf8
*/
int8_t convertUtf8(char32_t _val, char _output[5]);
#if __CPP_VERSION__ >= 2011
std::string convertToUtf8(const std::u32string& _input);
#endif
};
/**
* @brief UTF-8 simple wrapper interface
*/
namespace utf8 {
/**
* @brief Get the size of an utf8 char with his first char.
* @param[in] _input Char to parse
* @return number of char needed
*/
int8_t length(const char _input);
/**
* @brief When parsing a string in a reverse mode, we need to know if we get the first char
* @param[in] _input Char to parse.
* @return true if it was the first char.
*/
bool first(const char _input);
/**
* @brief Convert a char* in a unicode value
* @param[in] _input pointer on a string C (utf-8) to convert
* @return Converted Value
*/
char32_t convertChar32(const char* _input);
#if __CPP_VERSION__ >= 2011
std::u32string convertUnicode(const etk::String& _input);
#endif
/**
* @brief Iterator on a simple std::string that contain utf8 value
*/
class iterator {
private:
char32_t m_value; //!< store value to prevent multiple calculation of getting the data
std::string* m_data; //!< Pointer on the current Buffer
int64_t m_current; //!< current Id in the Buffer
public:
/**
* @brief Basic constructor that is not link on a string
*/
iterator():
m_value(u32char::Null),
m_data(nullptr),
m_current(0) {
// nothing to do ...
};
/**
* @brief Basic begin constructor link at the start of the string
* @param[in] _str reference on the string to inspect.
*/
iterator(std::string& _str) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
// nothing to do ...
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str reference on the string to inspect.
* @param[in] _pos Iterator position on the string.
*/
iterator(std::string& _str, const std::string::iterator& _pos) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
if (m_data != nullptr) {
m_current = std::distance(m_data->begin(), _pos);
}
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str reference on the string to inspect.
* @param[in] _pos Position on the string (in AINSI value).
*/
iterator(std::string& _str, size_t _pos) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
if (m_data != nullptr) {
if (_pos > m_data->size()) {
m_current = m_data->size();
} else {
m_current = _pos;
}
}
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str Pointer on the string to inspect.
* @param[in] _pos Iterator position on the string.
*/
iterator(std::string* _str, const std::string::iterator& _pos) :
m_value(u32char::Null),
m_data(_str),
m_current(0) {
if (m_data != nullptr) {
m_current = std::distance(m_data->begin(), _pos);
}
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str Pointer on the string to inspect.
* @param[in] _pos Position on the string (in AINSI value).
*/
iterator(std::string* _str, size_t _pos) :
m_value(u32char::Null),
m_data(_str),
m_current(0) {
if (m_data != nullptr) {
if (_pos > m_data->size()) {
m_current = m_data->size();
} else {
m_current = _pos;
}
}
};
/**
* @brief Recopy constructor.
* @param[in] _obj The Iterator that might be copy
*/
iterator(const iterator& _obj):
m_value(u32char::Null),
m_data(_obj.m_data),
m_current(_obj.m_current) {
// nothing to do ...
};
/**
* @brief Assignation operator.
* @param[in] _obj The Iterator that might be copy
* @return reference on the current Iterator
*/
iterator& operator=(const iterator & _obj) {
m_current = _obj.m_current;
m_data = _obj.m_data;
m_value = u32char::Null;
return *this;
};
/**
* @brief Basic destructor
*/
virtual ~iterator() {
m_current = 0;
m_data = nullptr;
m_value = u32char::Null;
};
/**
* @brief basic boolean cast
* @return true if the element is present in buffer
*/
operator size_t () const {
if (m_data == nullptr) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current > (int64_t)m_data->size()) {
return m_data->size();
}
return (size_t)m_current;
};
/**
* @brief Incremental operator
* @return Reference on the current iterator increment
*/
iterator& operator++ ();
/**
* @brief Decremental operator
* @return Reference on the current iterator decrement
*/
iterator& operator-- ();
/**
* @brief Incremental operator
* @return Reference on a new iterator and increment the other one
*/
iterator operator++ (int32_t) {
iterator it(*this);
++(*this);
return it;
};
/**
* @brief Decremental operator
* @return Reference on a new iterator and decrement the other one
*/
iterator operator-- (int32_t) {
iterator it(*this);
--(*this);
return it;
};
/**
* @brief equality iterator
* @param[in] _obj Iterator to compare
* @return true if the iterator is identical pos
*/
bool operator== (const iterator& _obj) const {
if ( m_current == _obj.m_current
&& m_data == _obj.m_data) {
return true;
}
return false;
};
/**
* @brief equality iterator
* @param[in] _obj Iterator to compare
* @return true if the iterator is identical pos
*/
bool operator!= (const iterator& _obj) const {
if ( m_current != _obj.m_current
|| m_data != _obj.m_data) {
return true;
}
return false;
};
/**
* @brief <= iterator
* @param[in] _obj Iterator to compare
* @return true if the iterator is identical pos
*/
bool operator<= (const iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current <= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief >= iterator
* @param[in] _obj Iterator to compare
* @return true if the iterator is identical pos
*/
bool operator>= (const iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current >= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief < iterator
* @param[in] _obj Iterator to compare
* @return true if the iterator is identical pos
*/
bool operator< (const iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current < _obj.m_current) {
return true;
}
return false;
};
/**
* @brief > iterator
* @param[in] _obj Iterator to compare
* @return true if the iterator is identical pos
*/
bool operator> (const iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current > _obj.m_current) {
return true;
}
return false;
};
/**
* @brief Get the value on the current element
* @return The request element value
*/
char32_t operator* ();
/**
* @brief Get the position in the buffer
* @return The requested position.
*/
size_t getPos() const {
if (m_data == nullptr) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current >= (int64_t)m_data->size()) {
return m_data->size()-1;
}
return (size_t)m_current;
};
/**
* @brief move the element position
* @param[in] _val Value to add on the Iterator
* @return a new iterator.
*/
iterator operator+ (const int64_t _val) const {
iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmp;
}
return tmp;
};
/**
* @copydoc utf8::iterator::operator+ (const int64_t)
*/
iterator operator+ (const int32_t _val) const {
iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmp;
}
return tmp;
}
/**
* @copydoc utf8::iterator::operator+ (const int64_t)
*/
iterator operator+ (const size_t _val) const {
iterator tmp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
++tmp;
}
return tmp;
}
/**
* @brief move the element position
* @param[in] _val Value to remove on the Iterator
* @return a new iterator.
*/
iterator operator- (const int64_t _val) const {
iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmp;
}
return tmp;
}
/**
* @copydoc utf8::iterator::operator- (const int64_t)
*/
iterator operator- (const int32_t _val) const {
iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmp;
}
return tmp;
}
/**
* @copydoc utf8::iterator::operator- (const int64_t)
*/
iterator operator- (const size_t _val) const {
iterator tmp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
--tmp;
}
return tmp;
}
/*
iterator begin() const {
return iterator(m_data);
}
iterator end() const {
return --iterator(m_data, m_data.end());
}
*/
};
};
namespace etk { namespace etk {
// these declaration is to prevent some under template declaration of unknown type template<class ETK_ITERATOR_TYPE>
size_t distance(const ETK_ITERATOR_TYPE& _start, const ETK_ITERATOR_TYPE& _stop) {
#if __CPP_VERSION__ >= 2011 size_t out = 0;
template <class TYPE> ETK_ITERATOR_TYPE tmp = _start;
std::u32string to_u32string(const TYPE& _variable); while (tmp != _stop) {
template <class TYPE> out++;
bool from_string(TYPE& _variableRet, const std::u32string& _value); ++tmp;
long double string_to_long_double(const std::u32string& _str);
double string_to_double(const std::u32string& _str);
float string_to_float(const std::u32string& _str);
int8_t string_to_int8_t(const std::u32string& _str, int _base = 10);
int16_t string_to_int16_t(const std::u32string& _str, int _base = 10);
int32_t string_to_int32_t(const std::u32string& _str, int _base = 10);
int64_t string_to_int64_t(const std::u32string& _str, int _base = 10);
uint8_t string_to_uint8_t(const std::u32string& _str, int _base = 10);
uint16_t string_to_uint16_t(const std::u32string& _str, int _base = 10);
uint32_t string_to_uint32_t(const std::u32string& _str, int _base = 10);
uint64_t string_to_uint64_t(const std::u32string& _str, int _base = 10);
bool string_to_bool(const std::u32string& _str);
std::u32string tolower(std::u32string _obj);
std::u32string toupper(std::u32string _obj);
bool compare_no_case(const std::u32string& _obj, const std::u32string& _val);
bool end_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true);
bool start_with(const std::u32string& _obj, const std::u32string& _val, bool _caseSensitive = true);
std::u32string replace(const std::u32string& _obj, char32_t _val, char32_t _replace);
std::u32string extract_line(const std::u32string& _obj, int32_t _pos);
std::vector<std::u32string> split(const std::u32string& _input, char32_t _val);
void sort(std::vector<std::u32string *>& _list);
#endif
//! @not_in_doc
template<typename T, typename T2>
bool isIn(const T& _val, const std::vector<T2>& _list) {
for (size_t iii=0; iii<_list.size(); ++iii) {
if (_list[iii] == _val) {
return true;
}
} }
return false; return out;
} }
}; }
namespace std { namespace std {
#if __CPP_VERSION__ >= 2011
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::u32string& _obj);
//! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<std::u32string>& _obj);
#endif
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<float>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<float>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<double>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<double>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<int64_t>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<int64_t>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<uint64_t>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<uint64_t>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<int32_t>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<int32_t>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<uint32_t>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<uint32_t>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<int16_t>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<int16_t>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<uint16_t>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<uint16_t>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<int8_t>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<int8_t>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::vector<uint8_t>& _obj); std::ostream& operator <<(std::ostream& _os, const etk::Vector<uint8_t>& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj); std::ostream& operator <<(std::ostream& _os, const std::chrono::system_clock::time_point& _obj);
//! @not_in_doc //! @not_in_doc
std::ostream& operator <<(std::ostream& _os, const std::chrono::steady_clock::time_point& _obj); std::ostream& operator <<(std::ostream& _os, const std::chrono::steady_clock::time_point& _obj);
} }
/**
* @brief Calculate the size of a string (unicode)
* @param[in] _data Data to parse to find the end of string
* @return The Number of char32_t before the '\\0' value
*/
int32_t strlen(const char32_t* _data);
#if (defined(__TARGET_OS__Windows))
#define M_PI 3.14159265358979323846
#endif

View File

@ -65,6 +65,10 @@
#define ETK_EXPORT_VISIBILITY __attribute__ ((visibility ("default"))) #define ETK_EXPORT_VISIBILITY __attribute__ ((visibility ("default")))
#endif #endif
#if (defined(__TARGET_OS__Windows))
#define M_PI 3.14159265358979323846
#endif
namespace etk { namespace etk {
template <class TYPE> const TYPE& min(const TYPE& _val1, const TYPE& _val2) { template <class TYPE> const TYPE& min(const TYPE& _val1, const TYPE& _val2) {
return (_val1 > _val2) ? _val2 : _val1; return (_val1 > _val2) ? _val2 : _val1;

233
etk/utf8.cpp Normal file
View File

@ -0,0 +1,233 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/stdTools.hpp>
#include <etk/debug.hpp>
#include <etk/String.hpp>
const char32_t u32char::Null('\0');
const char32_t u32char::Return('\n');
const char32_t u32char::CarrierReturn('\r');
const char32_t u32char::Tabulation('\t');
const char32_t u32char::Suppress((const char)127);
const char32_t u32char::Delete((const char)8);
const char32_t u32char::Space(' ');
const char32_t u32char::Escape((const char)27);
bool u32char::isWhiteChar(char32_t _val) {
if( _val == ' '
|| _val == '\t'
|| _val == '\n'
|| _val == '\r') {
return true;
}
return false;
}
bool u32char::isSpecialChar(char32_t _val) {
if( _val < '0'
|| (_val > '9' && _val < 'A')
|| (_val > 'Z' && _val < 'a')
|| (_val > 'z' && _val < 0xFF) ) {
return true;
}
return false;
}
bool u32char::isInteger(char32_t _val) {
if( _val >= (uint32_t)'0'
&& _val <= (uint32_t)'9') {
return true;
}
return false;
}
int32_t u32char::toInt(char32_t _val) {
return _val - (uint32_t)'0';
}
char32_t u32char::changeOrder(char32_t _val) {
if (_val >= 'A' && _val <= 'Z') {
return (_val - (uint32_t)'A')*2 + 'A';
}
if (_val >= 'a' && _val <= 'z') {
return (_val - (uint32_t)'a')*2 + 'A' + 1;
}
if (_val >= ':' && _val <= '@') {
return _val + 52;
}
if (_val >= '[' && _val <= '`') {
return _val +26;
}
return _val;
}
static uint32_t getUtf8Val(char32_t _val) {
uint32_t output = 0;
if (_val <= 127) {
output = _val;
} else if (_val <= 2047) {
// output ==> 00000000 00000000 110xxxxx 10xxxxxx
// input ==> -------- -------- -----222 22111111
output = 0x0000C080;
output+= (_val & 0x000007C0)<<2;
output+= _val & 0x0000003F;
} else if (_val <= 65535) {
// output ==> 00000000 1110xxxx 10xxxxxx 10xxxxxx
// input ==> -------- -------- 33332222 22111111
output = 0x00E08080;
output+= (_val & 0x0000F000)<<4;
output+= (_val & 0x00000FC0)<<2;
output+= _val & 0x0000003F;
} else if (_val <= 1114111) {
// output ==> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
// input ==> -------- ---44433 33332222 22111111
output = 0xF0808080;
output+= (_val & 0x001C0000)<<6;
output+= (_val & 0x0003F000)<<4;
output+= (_val & 0x00000FC0)<<2;
output+= _val & 0x0000003F;
} else {
//TK_ERROR("NOT UTF8 character input...");
printf("not an utf8 char : %#08x\n", _val);
return 0;
}
//printf("utf-8 conversion : %d=%08x ==> %08x\n",value, value, output);
return output;
}
int8_t u32char::convertUtf8(char32_t _val, char _output[5]) {
uint32_t value = getUtf8Val(_val);
if (0xFF >= value) {
_output[0] = (char)value;
_output[1] = '\0';
return 1;
} else if (0xFFFF >= value) {
_output[0] = (char)((value>>8) & 0x000000FF);
_output[1] = (char)value;
_output[2] = '\0';
return 2;
} else if (0xFFFFFF >= value) {
_output[0] = (char)((value>>16) & 0x000000FF);
_output[1] = (char)((value>>8) & 0x000000FF);
_output[2] = (char)value;
_output[3] = '\0';
return 3;
} else {
_output[0] = (char)((value>>24) & 0x000000FF);
_output[1] = (char)((value>>16) & 0x000000FF);
_output[2] = (char)((value>>8) & 0x000000FF);
_output[3] = (char)value;
_output[4] = '\0';
return 4;
}
}
#if __CPP_VERSION__ >= 2011
etk::String u32char::convertToUtf8(const etk::UString& _input) {
TK_TODO("implement this function ...");
return "TODO ... etk::String u32char::convertToUtf8(const etk::UString& _input)";
}
#endif
static uint8_t sizeElement(const char* _data, int32_t _lenMax) {
uint8_t size = 0;
TK_ASSERT(0 <= _lenMax, "size can not be < 0 ...");
if (0 > _lenMax) {
return 0;
}
//4 case
if( _lenMax >= 1
&& (_data[0] & 0x80) == 0x00 ) {
// One Char Element
size = 1;
} else if( _lenMax >= 2
&& (_data[0] & 0xE0) == 0xC0
&& (_data[1] & 0xC0) == 0x80) {
size = 2;
} else if( _lenMax >= 3
&& (_data[0] & 0xF0) == 0xE0
&& (_data[1] & 0xC0) == 0x80
&& (_data[2] & 0xC0) == 0x80) {
size = 3;
} else if( _lenMax >= 4
&& (_data[0] & 0xF8) == 0xF0
&& (_data[1] & 0xC0) == 0x80
&& (_data[2] & 0xC0) == 0x80
&& (_data[3] & 0xC0) == 0x80) {
size = 4;
}
return size;
}
char32_t utf8::convertChar32(const char* _input) {
char32_t value = 0;
if (nullptr == _input) {
return value;
}
int32_t len = strlen(_input);
len = sizeElement(_input, len);
switch (len) {
default:
// case 0 : An error occurred...
value = _input[0];
return value;
case 1:
value = (uint8_t)(_input[0]) & 0x7F;
return value;
case 2:
value = (((uint8_t)_input[0]) & 0x1F)<< 6;
value += ((uint8_t)_input[1]) & 0x3F;
return value;
case 3:
value = (((uint8_t)_input[0]) & 0x0F)<< 12;
value += (((uint8_t)_input[1]) & 0x3F)<< 6;
value += ((uint8_t)_input[2]) & 0x3F;
return value;
case 4:
value = (((uint8_t)_input[0]) & 0x07)<< 18;
value += (((uint8_t)_input[1]) & 0x3F)<< 12;
value += (((uint8_t)_input[2]) & 0x3F)<< 6;
value += ((uint8_t)_input[3]) & 0x3F;
return value;
}
}
int8_t utf8::length(const char _input) {
if((_input&0x80) == 0x00 ) {
return 1;
}
if((_input&0xE0) == 0xC0) {
return 2;
}
if((_input&0xF0) == 0xE0) {
return 3;
}
if((_input&0xF8) == 0xF0) {
return 4;
}
return 1;
}
bool utf8::first(const char _input) {
// When started with the bit 0 then the size is single element.
if((_input&0x80) == 0x00 ) {
return true;
}
// for multiple element size, we just need to check the second element (might be != 1)
if((_input&0x40) == 0x40 ) {
return true;
}
return false;
}
#if __CPP_VERSION__ >= 2011
etk::UString utf8::convertUnicode(const etk::String& _input) {
TK_TODO("implement this function ...");
return U"TODO ... etk::UString utf8::convertUnicode(const etk::String& _input)";
}
#endif

448
etk/utf8.hpp Normal file
View File

@ -0,0 +1,448 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/String.hpp>
#include <etk/Vector.hpp>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <chrono>
#include <etk/stdTools.hpp>
namespace etk {
class UString;
}
/**
* @brief Unicode simple wrapper interface
*/
namespace u32char {
extern const char32_t Null; //!< Value '\\0'
extern const char32_t Return; //!< Value '\\n'
extern const char32_t CarrierReturn; //!< Value '\\r' CR
extern const char32_t Tabulation; //!< Value '\\t' TAB
extern const char32_t Suppress; //!< Value BS (SUPPRESS)
extern const char32_t Delete; //!< Value DEL
extern const char32_t Space; //!< Value ' ' SPACE
extern const char32_t Escape; //!< Value ESC Escape
/**
* @brief check if the current element is white or not : '\\t' '\\n' '\\r' ' '
* @param[in] _val Value to interpret
* @return true if it is white char
* @return false otherwise
*/
bool isWhiteChar(char32_t _val);
/**
* @brief check if the current element is NOT [a-zA-Z0-9]
* @param[in] _val Value to interpret
* @return true Not in the previous list
* @return false otherwise
*/
bool isSpecialChar(char32_t _val);
/**
* @brief check if the current element is number or not [0-9]
* @param[in] _val Value to interpret
* @return true if it is a number char
* @return false otherwise
*/
bool isInteger(char32_t _val);
/**
* @brief Convert char32_t in an integer
* @param[in] _val Value to interpret
* @return The parsed Value or ...
*/
int32_t toInt(char32_t _val);
/**
* @brief Change order of the value to have an order of display with A->Z and after a->z and after 0->9 and after all the rest ....
* @param[in] _val Value in unicode
* @return A value usable in integer only ... to check order...
*/
char32_t changeOrder(char32_t _val);
/**
* @brief Convert unicode in UTF8 value
* @param[in] _val Value to convert
* @param[out] _output Char data converted
* @return Number of char in utf8
*/
int8_t convertUtf8(char32_t _val, char _output[5]);
#if __CPP_VERSION__ >= 2011
etk::String convertToUtf8(const etk::UString& _input);
#endif
};
/**
* @brief UTF-8 simple wrapper interface
*/
namespace utf8 {
/**
* @brief Get the size of an utf8 char with his first char.
* @param[in] _input Char to parse
* @return number of char needed
*/
int8_t length(const char _input);
/**
* @brief When parsing a string in a reverse mode, we need to know if we get the first char
* @param[in] _input Char to parse.
* @return true if it was the first char.
*/
bool first(const char _input);
/**
* @brief Convert a char* in a unicode value
* @param[in] _input pointer on a string C (utf-8) to convert
* @return Converted Value
*/
char32_t convertChar32(const char* _input);
#if __CPP_VERSION__ >= 2011
etk::UString convertUnicode(const etk::String& _input);
#endif
/**
* @brief Iterator on a simple etk::String that contain utf8 value
*/
class Iterator {
private:
char32_t m_value; //!< store value to prevent multiple calculation of getting the data
etk::String* m_data; //!< Pointer on the current Buffer
int64_t m_current; //!< current Id in the Buffer
public:
/**
* @brief Basic constructor that is not link on a string
*/
Iterator():
m_value(u32char::Null),
m_data(nullptr),
m_current(0) {
// nothing to do ...
};
/**
* @brief Basic begin constructor link at the start of the string
* @param[in] _str reference on the string to inspect.
*/
Iterator(etk::String& _str) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
// nothing to do ...
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str reference on the string to inspect.
* @param[in] _pos Iterator position on the string.
*/
Iterator(etk::String& _str, const etk::String::Iterator& _pos) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
if (m_data != nullptr) {
m_current = etk::distance(m_data->begin(), _pos);
}
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str reference on the string to inspect.
* @param[in] _pos Position on the string (in AINSI value).
*/
Iterator(etk::String& _str, size_t _pos) :
m_value(u32char::Null),
m_data(&_str),
m_current(0) {
if (m_data != nullptr) {
if (_pos > m_data->size()) {
m_current = m_data->size();
} else {
m_current = _pos;
}
}
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str Pointer on the string to inspect.
* @param[in] _pos Iterator position on the string.
*/
Iterator(etk::String* _str, const etk::String::Iterator& _pos) :
m_value(u32char::Null),
m_data(_str),
m_current(0) {
if (m_data != nullptr) {
m_current = etk::distance(m_data->begin(), _pos);
}
};
/**
* @brief Basic position constructor link at the _pos position of the string
* @param[in] _str Pointer on the string to inspect.
* @param[in] _pos Position on the string (in AINSI value).
*/
Iterator(etk::String* _str, size_t _pos) :
m_value(u32char::Null),
m_data(_str),
m_current(0) {
if (m_data != nullptr) {
if (_pos > m_data->size()) {
m_current = m_data->size();
} else {
m_current = _pos;
}
}
};
/**
* @brief Recopy constructor.
* @param[in] _obj The Iterator that might be copy
*/
Iterator(const Iterator& _obj):
m_value(u32char::Null),
m_data(_obj.m_data),
m_current(_obj.m_current) {
// nothing to do ...
};
/**
* @brief Assignation operator.
* @param[in] _obj The Iterator that might be copy
* @return reference on the current Iterator
*/
Iterator& operator=(const Iterator & _obj) {
m_current = _obj.m_current;
m_data = _obj.m_data;
m_value = u32char::Null;
return *this;
};
/**
* @brief Basic destructor
*/
virtual ~Iterator() {
m_current = 0;
m_data = nullptr;
m_value = u32char::Null;
};
/**
* @brief basic boolean cast
* @return true if the element is present in buffer
*/
operator size_t () const {
if (m_data == nullptr) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current > (int64_t)m_data->size()) {
return m_data->size();
}
return (size_t)m_current;
};
/**
* @brief Incremental operator
* @return Reference on the current Iterator increment
*/
Iterator& operator++ ();
/**
* @brief Decremental operator
* @return Reference on the current Iterator decrement
*/
Iterator& operator-- ();
/**
* @brief Incremental operator
* @return Reference on a new Iterator and increment the other one
*/
Iterator operator++ (int32_t) {
Iterator it(*this);
++(*this);
return it;
};
/**
* @brief Decremental operator
* @return Reference on a new Iterator and decrement the other one
*/
Iterator operator-- (int32_t) {
Iterator it(*this);
--(*this);
return it;
};
/**
* @brief equality Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator== (const Iterator& _obj) const {
if ( m_current == _obj.m_current
&& m_data == _obj.m_data) {
return true;
}
return false;
};
/**
* @brief equality Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator!= (const Iterator& _obj) const {
if ( m_current != _obj.m_current
|| m_data != _obj.m_data) {
return true;
}
return false;
};
/**
* @brief <= Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator<= (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current <= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief >= Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator>= (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current >= _obj.m_current) {
return true;
}
return false;
};
/**
* @brief < Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator< (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current < _obj.m_current) {
return true;
}
return false;
};
/**
* @brief > Iterator
* @param[in] _obj Iterator to compare
* @return true if the Iterator is identical pos
*/
bool operator> (const Iterator& _obj) const {
if (m_data != _obj.m_data) {
return false;
}
if (m_current > _obj.m_current) {
return true;
}
return false;
};
/**
* @brief Get the value on the current element
* @return The request element value
*/
char32_t operator* ();
/**
* @brief Get the position in the buffer
* @return The requested position.
*/
size_t getPos() const {
if (m_data == nullptr) {
return 0;
}
if (m_current < 0) {
return 0;
}
if (m_current >= (int64_t)m_data->size()) {
return m_data->size()-1;
}
return (size_t)m_current;
};
/**
* @brief move the element position
* @param[in] _val Value to add on the Iterator
* @return a new Iterator.
*/
Iterator operator+ (const int64_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmp;
}
return tmp;
};
/**
* @copydoc utf8::Iterator::operator+ (const int64_t)
*/
Iterator operator+ (const int32_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
++tmp;
}
return tmp;
}
/**
* @copydoc utf8::Iterator::operator+ (const int64_t)
*/
Iterator operator+ (const size_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
++tmp;
}
return tmp;
}
/**
* @brief move the element position
* @param[in] _val Value to remove on the Iterator
* @return a new Iterator.
*/
Iterator operator- (const int64_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmp;
}
return tmp;
}
/**
* @copydoc utf8::Iterator::operator- (const int64_t)
*/
Iterator operator- (const int32_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<_val; ++iii) {
--tmp;
}
return tmp;
}
/**
* @copydoc utf8::Iterator::operator- (const int64_t)
*/
Iterator operator- (const size_t _val) const {
Iterator tmp(*this);
for (int64_t iii=0; iii<(int64_t)_val; ++iii) {
--tmp;
}
return tmp;
}
/*
Iterator begin() const {
return Iterator(m_data);
}
Iterator end() const {
return --Iterator(m_data, m_data.end());
}
*/
};
}
/**
* @brief Calculate the size of a string (unicode)
* @param[in] _data Data to parse to find the end of string
* @return The Number of char32_t before the '\\0' value
*/
int32_t strlen(const char32_t* _data);

View File

@ -30,6 +30,8 @@ def configure(target, my_module):
my_module.add_src_file([ my_module.add_src_file([
'etk/debug.cpp', 'etk/debug.cpp',
'etk/String.cpp', 'etk/String.cpp',
'etk/UString.cpp',
'etk/utf8.cpp',
'etk/etk.cpp', 'etk/etk.cpp',
'etk/stdTools.cpp', 'etk/stdTools.cpp',
'etk/tool.cpp', 'etk/tool.cpp',
@ -62,6 +64,8 @@ def configure(target, my_module):
'etk/Buffer.hpp', 'etk/Buffer.hpp',
'etk/Hash.hpp', 'etk/Hash.hpp',
'etk/String.hpp', 'etk/String.hpp',
'etk/UString.hpp',
'etk/utf8.hpp',
'etk/Vector.hpp', 'etk/Vector.hpp',
'etk/math/Matrix2x2.hpp', 'etk/math/Matrix2x2.hpp',
'etk/math/Matrix2x3.hpp', 'etk/math/Matrix2x3.hpp',

View File

@ -13,12 +13,12 @@
#define NAME "Hash" #define NAME "Hash"
TEST(TestEtkHash, Creation) { TEST(TestEtkHash, Creation) {
etk::Hash<std::string> testData; etk::Hash<etk::String> testData;
EXPECT_EQ(testData.size(), 0); EXPECT_EQ(testData.size(), 0);
} }
TEST(TestEtkHash, AddElement) { TEST(TestEtkHash, AddElement) {
etk::Hash<std::string> testData; etk::Hash<etk::String> testData;
testData.add("TEST", "testData"); testData.add("TEST", "testData");
testData.add("TEST2", "22222222222222222"); testData.add("TEST2", "22222222222222222");
testData.add("TEST4", "4444444444444444444"); testData.add("TEST4", "4444444444444444444");
@ -31,7 +31,7 @@ TEST(TestEtkHash, AddElement) {
} }
TEST(TestEtkHash, OverWriteElement) { TEST(TestEtkHash, OverWriteElement) {
etk::Hash<std::string> testData; etk::Hash<etk::String> testData;
testData.add("TEST", "testData"); testData.add("TEST", "testData");
testData.add("TEST2", "22222222222222222"); testData.add("TEST2", "22222222222222222");
testData.add("TEST4", "4444444444444444444"); testData.add("TEST4", "4444444444444444444");
@ -45,7 +45,7 @@ TEST(TestEtkHash, OverWriteElement) {
} }
TEST(TestEtkHash, RemoveElement) { TEST(TestEtkHash, RemoveElement) {
etk::Hash<std::string> testData; etk::Hash<etk::String> testData;
testData.add("TEST", "testData"); testData.add("TEST", "testData");
testData.add("TEST2", "22222222222222222"); testData.add("TEST2", "22222222222222222");
testData.add("TEST4", "4444444444444444444"); testData.add("TEST4", "4444444444444444444");
@ -58,7 +58,7 @@ TEST(TestEtkHash, RemoveElement) {
} }
TEST(TestEtkHash, ExistElement) { TEST(TestEtkHash, ExistElement) {
etk::Hash<std::string> testData; etk::Hash<etk::String> testData;
testData.add("TEST", "testData"); testData.add("TEST", "testData");
testData.add("TEST2", "22222222222222222"); testData.add("TEST2", "22222222222222222");
EXPECT_EQ(testData.exist("TEST"), true); EXPECT_EQ(testData.exist("TEST"), true);
@ -66,7 +66,7 @@ TEST(TestEtkHash, ExistElement) {
} }
TEST(TestEtkHash, clear) { TEST(TestEtkHash, clear) {
etk::Hash<std::string> testData; etk::Hash<etk::String> testData;
testData.add("TEST", "1"); testData.add("TEST", "1");
testData.add("TEST2", "2"); testData.add("TEST2", "2");
EXPECT_EQ(testData.size(), 2); EXPECT_EQ(testData.size(), 2);
@ -75,7 +75,7 @@ TEST(TestEtkHash, clear) {
} }
TEST(TestEtkHash, getKey) { TEST(TestEtkHash, getKey) {
etk::Hash<std::string> testData; etk::Hash<etk::String> testData;
testData.add("TEST", "1"); testData.add("TEST", "1");
testData.add("TEST2", "2"); testData.add("TEST2", "2");
testData.add("TEST3", "3"); testData.add("TEST3", "3");
@ -83,11 +83,11 @@ TEST(TestEtkHash, getKey) {
} }
TEST(TestEtkHash, getKeys) { TEST(TestEtkHash, getKeys) {
etk::Hash<std::string> testData; etk::Hash<etk::String> testData;
testData.add("TEST", "1"); testData.add("TEST", "1");
testData.add("TEST2", "2"); testData.add("TEST2", "2");
testData.add("TEST3", "3"); testData.add("TEST3", "3");
std::vector<std::string> list = testData.getKeys(); etk::Vector<etk::String> list = testData.getKeys();
EXPECT_EQ(list.size(), 3); EXPECT_EQ(list.size(), 3);
EXPECT_EQ(list[0], "TEST"); EXPECT_EQ(list[0], "TEST");
EXPECT_EQ(list[1], "TEST2"); EXPECT_EQ(list[1], "TEST2");