From 067bed60a56c918befc41ef58482ff8f84f650a7 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 23 Aug 2017 21:10:33 +0200 Subject: [PATCH] [DEV] continue integration of etk::String --- etk/Color.cpp | 14 +-- etk/Color.hpp | 72 ++++++------- etk/Color_16_bits.cxx | 16 +-- etk/Color_32_bits.cxx | 16 +-- etk/Color_8_bits.cxx | 16 +-- etk/Color_double.cxx | 16 +-- etk/Color_float.cxx | 16 +-- etk/Hash.hpp | 26 ++--- etk/RegEx.cpp | 82 +++++++-------- etk/RegEx.hpp | 28 ++--- etk/String.cpp | 235 +++++++++++++++++++++++++++++++++++------- etk/String.hpp | 39 ++++--- etk/etk.cpp | 4 +- etk/etk.hpp | 2 +- etk/stdTools.cpp | 76 -------------- 15 files changed, 379 insertions(+), 279 deletions(-) diff --git a/etk/Color.cpp b/etk/Color.cpp index 1d16446..553970f 100644 --- a/etk/Color.cpp +++ b/etk/Color.cpp @@ -22,7 +22,7 @@ class ColorList { static int32_t getColorSize(); static const ColorList* getColorList(); -etk::Color etk::parseStringStartWithSharp(const std::string& _input) { +etk::Color etk::parseStringStartWithSharp(const etk::String& _input) { TK_VERBOSE("parseStringStartWithSharp('" << _input << "'"); size_t len = _input.size(); etk::Color outputValue(0,0,0,0); @@ -73,7 +73,7 @@ etk::Color etk::parseStringStartWithSharp(const std::string& _input) return outputValue; } -etk::Color etk::parseStringStartWithRGBGen(const std::string& _input) { +etk::Color etk::parseStringStartWithRGBGen(const etk::String& _input) { TK_VERBOSE("parseStringStartWithRGB('" << _input << "'"); etk::Color outputValue(0,0,0,0); int32_t red=0, green=0, blue=0, alpha=0; @@ -118,7 +118,7 @@ etk::Color etk::parseStringStartWithRGBGen(const std::string& _input return outputValue; } -etk::Color etk::parseStringStartWithRGB(const std::string& _input) { +etk::Color etk::parseStringStartWithRGB(const etk::String& _input) { TK_VERBOSE("parseStringStartWithRGB('" << _input << "')"); etk::Color outputValue(0,0,0,0); double float_red=0, float_green=0, float_blue=0, float_alpha=0; @@ -155,7 +155,7 @@ etk::Color etk::parseStringStartWithRGB(const std::string& _input) { } return outputValue; } -etk::Color etk::parseStringStartWithRGBUnsigned32(const std::string& _input) { +etk::Color etk::parseStringStartWithRGBUnsigned32(const etk::String& _input) { etk::Color outputValue(0,0,0,0); int32_t red=0, green=0, blue=0, alpha=0; double float_red=0, float_green=0, float_blue=0, float_alpha=0; @@ -192,7 +192,7 @@ etk::Color etk::parseStringStartWithRGBUnsigned32(const std::string return outputValue; } -etk::Color etk::parseStringStartWithRGBUnsigned16(const std::string& _input) { +etk::Color etk::parseStringStartWithRGBUnsigned16(const etk::String& _input) { etk::Color outputValue(0,0,0,0); int32_t red=0, green=0, blue=0, alpha=0; double float_red=0, float_green=0, float_blue=0, float_alpha=0; @@ -229,7 +229,7 @@ etk::Color etk::parseStringStartWithRGBUnsigned16(const std::string return outputValue; } -etk::Color etk::parseStringStartWithRGBUnsigned8(const std::string& _input) { +etk::Color etk::parseStringStartWithRGBUnsigned8(const etk::String& _input) { etk::Color outputValue(0,0,0,0); int32_t red=0, green=0, blue=0, alpha=0; double float_red=0, float_green=0, float_blue=0, float_alpha=0; @@ -266,7 +266,7 @@ etk::Color etk::parseStringStartWithRGBUnsigned8(const std::string& return outputValue; } -etk::Color etk::parseStringColorNamed(const std::string& _input) { +etk::Color etk::parseStringColorNamed(const etk::String& _input) { // direct named color ... for (int32_t iii=0; iii parseStringStartWithSharp(const std::string& _input); + etk::Color parseStringStartWithSharp(const etk::String& _input); /** * @brief Get a color value started with a "rgb()" converted in unsigned 8 bits integer * @param[in] _input String to parse * @return Value parsed */ - etk::Color parseStringStartWithRGBGen(const std::string& _input); + etk::Color parseStringStartWithRGBGen(const etk::String& _input); /** * @brief Get a color value started with a "rgb()" keep in double * @param[in] _input String to parse * @return Value parsed */ - etk::Color parseStringStartWithRGB(const std::string& _input); + etk::Color parseStringStartWithRGB(const etk::String& _input); /** * @brief Get a color value started with a "rgb()" converted in unsigned 32 bits integer * @param[in] _input String to parse * @return Value parsed */ - etk::Color parseStringStartWithRGBUnsigned32(const std::string& _input); + etk::Color parseStringStartWithRGBUnsigned32(const etk::String& _input); /** * @brief Get a color value started with a "rgb()" converted in unsigned 16 bits integer * @param[in] _input String to parse * @return Value parsed */ - etk::Color parseStringStartWithRGBUnsigned16(const std::string& _input); + etk::Color parseStringStartWithRGBUnsigned16(const etk::String& _input); /** * @brief Get a color value started with a "rgb()" converted in unsigned 8 bits integer * @param[in] _input String to parse * @return Value parsed */ - etk::Color parseStringStartWithRGBUnsigned8(const std::string& _input); + etk::Color parseStringStartWithRGBUnsigned8(const etk::String& _input); /** * @brief Get a color value started with a "named" converted in unsigned 8 bits integer like red, green ... * @param[in] _input String to parse * @return Value parsed */ - etk::Color parseStringColorNamed(const std::string& _input); + etk::Color parseStringColorNamed(const etk::String& _input); /** * @brief Specify that the Get instance is specialized for unsigned 8 bits integer on RGBA template @@ -452,49 +452,49 @@ namespace etk { return tmp.get(); } - template Color::Color(const std::string& _input) { + template Color::Color(const etk::String& _input) { //TK_VERBOSE("convert color string : '" << _input << "'"); const char* inputData = _input.c_str(); size_t len = _input.size(); if( len >=1 && inputData[0] == '#') { - Color value = etk::parseStringStartWithSharp(std::string(_input, 1)); + Color value = etk::parseStringStartWithSharp(etk::String(_input, 1)); *this = value; - } else if(etk::start_with(_input, "rgb(", false) == true) { - Color value = etk::parseStringStartWithRGBGen(std::string(_input, 4, _input.size()-5)); + } else if(_input.startWith("rgb(", false) == true) { + Color value = etk::parseStringStartWithRGBGen(etk::String(_input, 4, _input.size()-5)); *this = value; - } else if(etk::start_with(_input, "rgba(", false) == true) { - Color value = etk::parseStringStartWithRGBGen(std::string(_input, 5, _input.size()-6)); + } else if(_input.startWith("rgba(", false) == true) { + Color value = etk::parseStringStartWithRGBGen(etk::String(_input, 5, _input.size()-6)); *this = value; - } else if(etk::start_with(_input, "rgb[FLOAT](", false) == true) { - Color value = etk::parseStringStartWithRGB(std::string(_input, 11, _input.size()-12)); + } else if(_input.startWith("rgb[FLOAT](", false) == true) { + Color value = etk::parseStringStartWithRGB(etk::String(_input, 11, _input.size()-12)); *this = value; - } else if(etk::start_with(_input, "rgba[FLOAT](", false) == true) { - Color value = etk::parseStringStartWithRGB(std::string(_input, 12, _input.size()-13)); + } else if(_input.startWith("rgba[FLOAT](", false) == true) { + Color value = etk::parseStringStartWithRGB(etk::String(_input, 12, _input.size()-13)); *this = value; - } else if(etk::start_with(_input, "rgb[DOUBLE](", false) == true) { - Color value = etk::parseStringStartWithRGB(std::string(_input, 12, _input.size()-13)); + } else if(_input.startWith("rgb[DOUBLE](", false) == true) { + Color value = etk::parseStringStartWithRGB(etk::String(_input, 12, _input.size()-13)); *this = value; - } else if(etk::start_with(_input, "rgba[DOUBLE](", false) == true) { - Color value = etk::parseStringStartWithRGB(std::string(_input, 13, _input.size()-14)); + } else if(_input.startWith("rgba[DOUBLE](", false) == true) { + Color value = etk::parseStringStartWithRGB(etk::String(_input, 13, _input.size()-14)); *this = value; - } else if(etk::start_with(_input, "rgb[U32](", false) == true) { - Color value = etk::parseStringStartWithRGBUnsigned32(std::string(_input, 9, _input.size()-10)); + } else if(_input.startWith("rgb[U32](", false) == true) { + Color value = etk::parseStringStartWithRGBUnsigned32(etk::String(_input, 9, _input.size()-10)); *this = value; - } else if(etk::start_with(_input, "rgba[U32](", false) == true) { - Color value = etk::parseStringStartWithRGBUnsigned32(std::string(_input, 10, _input.size()-11)); + } else if(_input.startWith("rgba[U32](", false) == true) { + Color value = etk::parseStringStartWithRGBUnsigned32(etk::String(_input, 10, _input.size()-11)); *this = value; - } else if(etk::start_with(_input, "rgb[U16](", false) == true) { - Color value = etk::parseStringStartWithRGBUnsigned16(std::string(_input, 9, _input.size()-10)); + } else if(_input.startWith("rgb[U16](", false) == true) { + Color value = etk::parseStringStartWithRGBUnsigned16(etk::String(_input, 9, _input.size()-10)); *this = value; - } else if(etk::start_with(_input, "rgba[U16](", false) == true) { - Color value = etk::parseStringStartWithRGBUnsigned16(std::string(_input, 10, _input.size()-11)); + } else if(_input.startWith("rgba[U16](", false) == true) { + Color value = etk::parseStringStartWithRGBUnsigned16(etk::String(_input, 10, _input.size()-11)); *this = value; - } else if(etk::start_with(_input, "rgb[U8](", false) == true) { - Color value = etk::parseStringStartWithRGBUnsigned8(std::string(_input, 8, _input.size()-9)); + } else if(_input.startWith("rgb[U8](", false) == true) { + Color value = etk::parseStringStartWithRGBUnsigned8(etk::String(_input, 8, _input.size()-9)); *this = value; - } else if(etk::start_with(_input, "rgba[U8](", false) == true) { - Color value = etk::parseStringStartWithRGBUnsigned8(std::string(_input, 9, _input.size()-10)); + } else if(_input.startWith("rgba[U8](", false) == true) { + Color value = etk::parseStringStartWithRGBUnsigned8(etk::String(_input, 9, _input.size()-10)); *this = value; } else { Color value = etk::parseStringColorNamed(_input); diff --git a/etk/Color_16_bits.cxx b/etk/Color_16_bits.cxx index 3379f2a..b267c76 100644 --- a/etk/Color_16_bits.cxx +++ b/etk/Color_16_bits.cxx @@ -385,7 +385,7 @@ template<> template<> Color::Color(const Color& _obj) { // =========================================================================================================== -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -398,14 +398,14 @@ template<> std::string to_string >(const Color& return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -418,14 +418,14 @@ template<> std::string to_string >(const Color& return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -438,14 +438,14 @@ template<> std::string to_string >(const Color& return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -458,7 +458,7 @@ template<> std::string to_string >(const Color& return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/Color_32_bits.cxx b/etk/Color_32_bits.cxx index e84a63b..37f029e 100644 --- a/etk/Color_32_bits.cxx +++ b/etk/Color_32_bits.cxx @@ -385,7 +385,7 @@ template<> template<> Color::Color(const Color& _obj) { // =========================================================================================================== -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -397,12 +397,12 @@ template<> std::string to_string >(const Color& return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -414,14 +414,14 @@ template<> std::string to_string >(const Color& return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -433,14 +433,14 @@ template<> std::string to_string >(const Color& return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -452,7 +452,7 @@ template<> std::string to_string >(const Color& return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/Color_8_bits.cxx b/etk/Color_8_bits.cxx index 3674e91..f33e1f9 100644 --- a/etk/Color_8_bits.cxx +++ b/etk/Color_8_bits.cxx @@ -384,7 +384,7 @@ template<> template<> Color::Color(const Color& _obj) { // =========================================================================================================== -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -396,7 +396,7 @@ template<> std::string to_string >(const Color& _v return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } @@ -404,7 +404,7 @@ template<> bool from_string >(Color& _variableRet, -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -416,14 +416,14 @@ template<> std::string to_string >(const Color& _v return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -435,13 +435,13 @@ template<> std::string to_string >(const Color& _v return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -453,7 +453,7 @@ template<> std::string to_string >(const Color& _v return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/Color_double.cxx b/etk/Color_double.cxx index ff02d17..a33b6ac 100644 --- a/etk/Color_double.cxx +++ b/etk/Color_double.cxx @@ -385,7 +385,7 @@ template<> template<> Color::Color(const Color& _obj) { // =========================================================================================================== -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -397,7 +397,7 @@ template<> std::string to_string >(const Color& _val return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } @@ -405,7 +405,7 @@ template<> bool from_string >(Color& _variableRet, c -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -417,7 +417,7 @@ template<> std::string to_string >(const Color& _val return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } @@ -425,7 +425,7 @@ template<> bool from_string >(Color& _variableRet, c -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -437,14 +437,14 @@ template<> std::string to_string >(const Color& _val return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -456,7 +456,7 @@ template<> std::string to_string >(const Color& _val return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/Color_float.cxx b/etk/Color_float.cxx index 3a46231..27eefe7 100644 --- a/etk/Color_float.cxx +++ b/etk/Color_float.cxx @@ -383,7 +383,7 @@ template<> template<> Color::Color(const Color& _obj) { } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -395,13 +395,13 @@ template<> std::string to_string >(const Color& _val) return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -413,13 +413,13 @@ template<> std::string to_string >(const Color& _val) return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -431,13 +431,13 @@ template<> std::string to_string >(const Color& _val) return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } -template<> std::string to_string >(const Color& _val) { +template<> etk::String to_string >(const Color& _val) { return _val.getString(); } #if __cplusplus >= 201103L @@ -449,7 +449,7 @@ template<> std::string to_string >(const Color& _val) return true; } #endif -template<> bool from_string >(Color& _variableRet, const std::string& _value) { +template<> bool from_string >(Color& _variableRet, const etk::String& _value) { _variableRet = Color(_value); return true; } diff --git a/etk/Hash.hpp b/etk/Hash.hpp index ddc364e..493edb2 100644 --- a/etk/Hash.hpp +++ b/etk/Hash.hpp @@ -16,14 +16,14 @@ namespace etk { */ template class HashData { public: - std::string m_key; //!< name of the current hash + etk::String m_key; //!< name of the current hash MY_TYPE m_value; //!< data of the current Hash /** * @brief Constructor of the data for hash table. * @param[in] _key name of the hash table. * @param[in] _val Value of the hash element. */ - HashData(const std::string& _key, const MY_TYPE& _val) : + HashData(const etk::String& _key, const MY_TYPE& _val) : m_key(_key), m_value(_val) { // nothing to do ... @@ -95,7 +95,7 @@ namespace etk { * @param[in] _key Name of the hash requested * @return Id of the element in the table or -1 of it does not existed */ - int64_t getId(const std::string& _key) const { + int64_t getId(const etk::String& _key) const { for (size_t iii=0; iiim_key << "' with '" << _key << "'" ); @@ -112,7 +112,7 @@ namespace etk { * @param[in] _name Name of the hash requested * @return true if the element exist */ - bool exist(const std::string& _name) const { + bool exist(const etk::String& _name) const { int64_t elementId = getId(_name); //TK_INFO(" Exist ? '" << _name << "' id=" << elementId ); if (elementId<0) { @@ -127,7 +127,7 @@ namespace etk { * @param[in] _key Name of the hash requested * @return Reference on the Element */ - MY_TYPE& get(const std::string& _key) const { + MY_TYPE& get(const etk::String& _key) const { static MY_TYPE g_error; int64_t elementId = getId(_key); if (elementId<0) { @@ -141,7 +141,7 @@ namespace etk { * @param[in] _key Name of the hash requested * @return An reference on the copy of selected element */ - MY_TYPE& operator[] (const std::string& _key) { + MY_TYPE& operator[] (const etk::String& _key) { return get(_key); } /** @@ -149,7 +149,7 @@ namespace etk { * @param[in] _key Name of the hash requested * @return An reference on the copy of selected element */ - const MY_TYPE& operator[] (const std::string& _key) const { + const MY_TYPE& operator[] (const etk::String& _key) const { return get(_key); } /** @@ -158,7 +158,7 @@ namespace etk { * @param[in] _key Name of the value to set in the hash table. * @param[in] _value Value to set in the hash table. */ - void add(const std::string& _key, const MY_TYPE& _value) { + void add(const etk::String& _key, const MY_TYPE& _value) { int64_t elementId = getId(_key); if (elementId <0) { HashData* tmp = new HashData(_key, _value); @@ -177,14 +177,14 @@ namespace etk { * @param[in] _key Name of the value to set in the hash table. * @param[in] _value Value to set in the hash table. */ - void set(const std::string& _key, const MY_TYPE& _value) { + void set(const etk::String& _key, const MY_TYPE& _value) { add(_key, _value); } /** * @brief Remove an element in the hash table. * @param[in] _key Name of the element to remove. */ - void remove(const std::string& _key) { + void remove(const etk::String& _key) { int64_t elementId = getId(_key); if (elementId <0) { //nothing to do ==> not existed @@ -224,7 +224,7 @@ namespace etk { * @param[in] _pos Position of the element in the hash table. * @return name of the element (key). */ - const std::string& getKey(size_t _pos) const { + const etk::String& getKey(size_t _pos) const { // NOTE :Do not change log level, this generate error only in debug mode #if DEBUG_LEVEL > 2 if(_pos>m_data.size()){ @@ -237,8 +237,8 @@ namespace etk { * @brief Get all the element name (keys). * @return a vector of all name (key). */ - std::vector getKeys() const { - std::vector keys; + std::vector getKeys() const { + std::vector keys; for (auto &it : m_data) { if (it != nullptr) { keys.push_back(it->m_key); diff --git a/etk/RegEx.cpp b/etk/RegEx.cpp index fa95dd1..62ebf4d 100644 --- a/etk/RegEx.cpp +++ b/etk/RegEx.cpp @@ -79,36 +79,36 @@ std::ostream& etk::regex::operator <<(std::ostream& _os, const etk::regex::FindP return _os; } -std::string etk::regex::createString(const std::vector& _data, int64_t _start, int64_t _stop) { - std::string output(ETK_BASH_COLOR_NORMAL); +etk::String etk::regex::createString(const std::vector& _data, int64_t _start, int64_t _stop) { + etk::String output(ETK_BASH_COLOR_NORMAL); for (int64_t iii=_start; iii<(int64_t)_data.size() && iii<_stop ; iii++) { switch(_data[iii]) { - case regexOpcodePTheseIn: output += std::string(ETK_BASH_COLOR_RED) + (char*)"(" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodePTheseOut: output += std::string(ETK_BASH_COLOR_RED) + (char*)")" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeBracketIn: output += std::string(ETK_BASH_COLOR_YELLOW) + (char*)"[" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeBracketOut: output += std::string(ETK_BASH_COLOR_YELLOW) + (char*)"]" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeTo: output += std::string(ETK_BASH_COLOR_YELLOW) + (char*)"-" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeBraceIn: output += std::string(ETK_BASH_COLOR_GREEN) + (char*)"{" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeBraceOut: output += std::string(ETK_BASH_COLOR_GREEN) + (char*)"}" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeStar: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"*" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeDot: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"." + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeQuestion: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"?" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodePlus: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"+" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodePipe: output += std::string(ETK_BASH_COLOR_BLUE) + (char*)"|" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeNoChar: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"@" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeStartOfLine: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"^" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeEndOfLine: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"$" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeDigit: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\d" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeDigitNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\D" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeLetter: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\l" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeLetterNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\L" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeSpace: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\s" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeSpaceNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\S" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeWord: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\w" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeWordNot: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\W" + ETK_BASH_COLOR_NORMAL; break; - case regexOpcodeEOF: output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\e" + ETK_BASH_COLOR_NORMAL; break; - case '\n': output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\n" + ETK_BASH_COLOR_NORMAL; break; - case '\t': output += std::string(ETK_BASH_COLOR_MAGENTA) + (char*)"\\t" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodePTheseIn: output += etk::String(ETK_BASH_COLOR_RED) + (char*)"(" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodePTheseOut: output += etk::String(ETK_BASH_COLOR_RED) + (char*)")" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeBracketIn: output += etk::String(ETK_BASH_COLOR_YELLOW) + (char*)"[" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeBracketOut: output += etk::String(ETK_BASH_COLOR_YELLOW) + (char*)"]" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeTo: output += etk::String(ETK_BASH_COLOR_YELLOW) + (char*)"-" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeBraceIn: output += etk::String(ETK_BASH_COLOR_GREEN) + (char*)"{" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeBraceOut: output += etk::String(ETK_BASH_COLOR_GREEN) + (char*)"}" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeStar: output += etk::String(ETK_BASH_COLOR_BLUE) + (char*)"*" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeDot: output += etk::String(ETK_BASH_COLOR_BLUE) + (char*)"." + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeQuestion: output += etk::String(ETK_BASH_COLOR_BLUE) + (char*)"?" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodePlus: output += etk::String(ETK_BASH_COLOR_BLUE) + (char*)"+" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodePipe: output += etk::String(ETK_BASH_COLOR_BLUE) + (char*)"|" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeNoChar: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"@" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeStartOfLine: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"^" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeEndOfLine: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"$" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeDigit: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\d" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeDigitNot: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\D" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeLetter: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\l" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeLetterNot: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\L" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeSpace: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\s" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeSpaceNot: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\S" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeWord: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\w" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeWordNot: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\W" + ETK_BASH_COLOR_NORMAL; break; + case regexOpcodeEOF: output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\e" + ETK_BASH_COLOR_NORMAL; break; + case '\n': output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\n" + ETK_BASH_COLOR_NORMAL; break; + case '\t': output += etk::String(ETK_BASH_COLOR_MAGENTA) + (char*)"\\t" + ETK_BASH_COLOR_NORMAL; break; default: char plop[10]; int8_t nb = u32char::convertUtf8(_data[iii], plop); @@ -240,7 +240,7 @@ int64_t etk::regex::getLenOfBracket(const std::vector& _data, int64_t || _data[pos] == regexOpcodeTo) { // nothing to do ... it is permitted } else if(_data[pos] > 0xFF ) { - std::string displayElement; + etk::String displayElement; if (_data[pos] == regexOpcodeStartOfLine) { displayElement = "^"; } else if (_data[pos] == regexOpcodeDigitNot) { @@ -400,8 +400,8 @@ allIsSet: return true; } -std::string etk::regex::autoStr(const std::string& _data) { - std::string out; +etk::String etk::regex::autoStr(const etk::String& _data) { + etk::String out; for (auto &it : _data) { if (it == '\n') { out += "\\n"; @@ -423,8 +423,8 @@ std::string etk::regex::autoStr(const std::string& _data) { } -std::string etk::regex::autoStr(char _data) { - std::string out; +etk::String etk::regex::autoStr(char _data) { + etk::String out; if (_data == '\n') { out += "\\n"; } else if (_data == '\t') { @@ -443,8 +443,8 @@ std::string etk::regex::autoStr(char _data) { return out; } -std::string etk::regex::strTick(int32_t _pos) { - std::string out; +etk::String etk::regex::strTick(int32_t _pos) { + etk::String out; for (int32_t iii=0; iii<_pos; ++iii) { out += " "; } @@ -455,20 +455,20 @@ std::string etk::regex::strTick(int32_t _pos) { namespace etk { - template<> std::string to_string>(const etk::RegEx& _val) { + template<> etk::String to_string>(const etk::RegEx& _val) { return _val.getRegEx(); } - template<> std::string to_string>(const etk::RegEx& _val) { + template<> etk::String to_string>(const etk::RegEx& _val) { return _val.getRegEx(); } - template<> std::u32string to_u32string>(const etk::RegEx& _val) { + template<> std::u32string to_u32string>(const etk::RegEx& _val) { return _val.getURegEx(); } template<> std::u32string to_u32string>(const etk::RegEx& _val) { return _val.getURegEx(); } - template<> bool from_string>(etk::RegEx& _variableRet, const std::u32string& _value) { + template<> bool from_string>(etk::RegEx& _variableRet, const std::u32string& _value) { _variableRet.compile(_value); return true; } @@ -476,11 +476,11 @@ namespace etk { _variableRet.compile(_value); return true; } - template<> bool from_string>(etk::RegEx& _variableRet, const std::string& _value) { + template<> bool from_string>(etk::RegEx& _variableRet, const etk::String& _value) { _variableRet.compile(_value); return true; } - template<> bool from_string>(etk::RegEx& _variableRet, const std::string& _value) { + template<> bool from_string>(etk::RegEx& _variableRet, const etk::String& _value) { _variableRet.compile(_value); return true; } diff --git a/etk/RegEx.hpp b/etk/RegEx.hpp index 4719ab7..a26a114 100644 --- a/etk/RegEx.hpp +++ b/etk/RegEx.hpp @@ -152,7 +152,7 @@ extern const struct conversionTable constConversionTable[]; //! @not-in-doc extern const int64_t constConversionTableSize; //! @not-in-doc -std::string createString(const std::vector& _data, int64_t _start=0, int64_t _stop=0x7FFFFFFF); +etk::String createString(const std::vector& _data, int64_t _start=0, int64_t _stop=0x7FFFFFFF); //! @not-in-doc char * levelSpace(uint32_t _level); //! @not-in-doc @@ -168,9 +168,9 @@ int64_t getLenOfNormal(const std::vector& _data, int64_t _startPos); //! @not-in-doc bool parseBrace(const std::vector& _data, uint32_t& _min, uint32_t& _max); //! @not-in-doc -std::string autoStr(const std::string& _data); -std::string autoStr(char _data); -std::string strTick(int32_t _pos); +etk::String autoStr(const etk::String& _data); +etk::String autoStr(char _data); +etk::String strTick(int32_t _pos); /** * @brief Node Elements for every-one @@ -251,7 +251,7 @@ class FindProperty { } template static void display(const FindProperty& _element, const CLASS_TYPE& _data, int32_t _level = 0) { - std::string tmp; + etk::String tmp; for (int32_t iii=_element.m_positionStart; iii<_element.m_positionStop; ++iii) { tmp += _data[iii]; } @@ -996,7 +996,7 @@ template class NodePTheseElement : public Node { return _data.size(); }; virtual void parse(const CLASS_TYPE& _data, int64_t _currentPos, int64_t _lenMax, FindProperty& _property) { - //TK_REG_DEBUG_2("Parse " << levelSpace(Node::m_nodeLevel) << " (element) data to parse : '" << autoStr(std::string(_data, _currentPos, _lenMax-_currentPos)) << "'"); + //TK_REG_DEBUG_2("Parse " << levelSpace(Node::m_nodeLevel) << " (element) data to parse : '" << autoStr(etk::String(_data, _currentPos, _lenMax-_currentPos)) << "'"); //TK_REG_DEBUG_2("Parse " << levelSpace(Node::m_nodeLevel) << " (element) m_data='" << autoStr(Node::m_data) << "'"); TK_REG_DEBUG("Parse " << levelSpace(Node::m_nodeLevel) << " (element) " << _property); TK_REG_DEBUG(" " << levelSpace(Node::m_nodeLevel) << " work on: " << createString(Node::m_regExData)); @@ -1033,7 +1033,7 @@ template class NodePTheseElement : public Node { prop.setPositionStart(tmpCurrentPos); } while (iii < m_subNode.size()) { - //TK_REG_DEBUG_2(" " << levelSpace(Node::m_nodeLevel) << " (element=" << iii << "/" << m_subNode.size() << ") data='" << autoStr(std::string(_data, tmpCurrentPos, _lenMax-tmpCurrentPos)) << "'"); + //TK_REG_DEBUG_2(" " << levelSpace(Node::m_nodeLevel) << " (element=" << iii << "/" << m_subNode.size() << ") data='" << autoStr(etk::String(_data, tmpCurrentPos, _lenMax-tmpCurrentPos)) << "'"); m_subNode[iii]->parse(_data, tmpCurrentPos, _lenMax, prop); if (prop.getStatus() == parseStatusNone) { TK_REG_DEBUG(" " << levelSpace(Node::m_nodeLevel) << " (element=" << iii << "/" << m_subNode.size() << ") ===None=== : " << prop); @@ -1177,7 +1177,7 @@ template class NodePThese : public Node { TK_REG_DEBUG("Parse " << levelSpace(Node::m_nodeLevel) << " (...) {" << Node::m_multipleMin << "," << Node::m_multipleMax << "}"); TK_REG_DEBUG(" " << levelSpace(Node::m_nodeLevel) << " work on: " << createString(Node::m_regExData)); TK_REG_DEBUG(" " << levelSpace(Node::m_nodeLevel) << " pos=" << _currentPos << " ==> " << _lenMax); - TK_REG_DEBUG_2(" " << levelSpace(Node::m_nodeLevel) << " (...) data='" << autoStr(std::string(_data, _currentPos, _lenMax-_currentPos)) << "'"); + TK_REG_DEBUG_2(" " << levelSpace(Node::m_nodeLevel) << " (...) data='" << autoStr(etk::String(_data, _currentPos, _lenMax-_currentPos)) << "'"); TK_REG_DEBUG_3(" " << levelSpace(Node::m_nodeLevel) << " (...) input property=" << _property); if (m_subNode.size() == 0) { _property.setStatus(parseStatusNone); @@ -1335,7 +1335,7 @@ template class NodePThese : public Node { * @brief get the string represented the regex (colored) * @return Regex string */ - std::string getColoredRegEx() { + etk::String getColoredRegEx() { return createString(Node::m_regExData); } }; @@ -1405,7 +1405,7 @@ template class RegEx { /** * @previous */ - RegEx(const std::string &_expression) : + RegEx(const etk::String &_expression) : m_expressionRequested(U""), m_isOk(false), m_notBeginWithChar(false), @@ -1436,7 +1436,7 @@ template class RegEx { * @param[in] _expression the new expression to search */ // TODO : Add an error ... - void compile(const std::string &_expression) { + void compile(const etk::String &_expression) { if (_expression.size() != 0) { TK_REG_DEBUG("normal string parse : '" << _expression << "'"); compile(etk::to_u32string(_expression)); @@ -1580,7 +1580,7 @@ template class RegEx { * @brief Get the regular expression string * @return the string representing the RegEx */ - std::string getRegEx() const { + etk::String getRegEx() const { return etk::to_string(m_expressionRequested); }; /** @@ -1659,7 +1659,7 @@ template class RegEx { if ( prop.getStatus() == regex::parseStatusFull || prop.getStatus() == regex::parseStatusPartial ) { findLen = prop.getFindLen(); - TK_REG_DEBUG_3("main search find : " << findLen << " elements data=" << std::string(_SearchIn, prop.getPositionStart(), prop.getFindLen())); + TK_REG_DEBUG_3("main search find : " << findLen << " elements data=" << etk::String(_SearchIn, prop.getPositionStart(), prop.getFindLen())); // Check end : if (m_notEndWithChar == true) { TK_REG_DEBUG("Check end is not a char: '" << (char)_SearchIn[iii+findLen] << "'"); @@ -1805,7 +1805,7 @@ template class RegEx { * @brief Get decorated regular expression. This generate a [class[ewol::compositing::Text]] decoration text. Note that can be use in [class[ewol::widget::Label]]. * @return The decorated string */ - std::string getRegExDecorated() { + etk::String getRegExDecorated() { return m_expressionRootNode.getColoredRegEx(); } private: diff --git a/etk/String.cpp b/etk/String.cpp index 4a75ad4..918073b 100644 --- a/etk/String.cpp +++ b/etk/String.cpp @@ -187,48 +187,209 @@ namespace etk { } - etk::String etk::toString(int _val) { - char tmpVal[256]; - sprintf(tmpVal, "%d", _val); - return tmpVal; +etk::String etk::toString(bool _val) { + if (_val == true) { + return "true"; } - etk::String etk::toString(long _val) { - char tmpVal[256]; - sprintf(tmpVal, "%ld", _val); - return tmpVal; + return "false"; +} +etk::String etk::toString(int _val) { + char tmpVal[256]; + sprintf(tmpVal, "%d", _val); + return tmpVal; +} +etk::String etk::toString(long _val) { + char tmpVal[256]; + sprintf(tmpVal, "%ld", _val); + return tmpVal; +} +etk::String etk::toString(long long _val) { + char tmpVal[256]; + sprintf(tmpVal, "%lld", _val); + return tmpVal; +} +etk::String etk::toString(unsigned _val) { + char tmpVal[256]; + sprintf(tmpVal, "%u", _val); + return tmpVal; +} +etk::String etk::toString(unsigned long _val) { + char tmpVal[256]; + sprintf(tmpVal, "%lu", _val); + return tmpVal; +} +etk::String etk::toString(unsigned long long _val) { + char tmpVal[256]; + sprintf(tmpVal, "%llu", _val); + return tmpVal; +} +etk::String etk::toString(float _val) { + char tmpVal[256]; + sprintf(tmpVal, "%f", _val); + return tmpVal; +} +etk::String etk::toString(double _val) { + char tmpVal[256]; + sprintf(tmpVal, "%f", _val); + return tmpVal; +} +etk::String etk::toString(long double _val) { + char tmpVal[256]; + sprintf(tmpVal, "%Lf", _val); + return tmpVal; +} + +size_t etk::String::find(char _value, size_t _pos) const { + for (size_t iii=_pos; iii= m_data.size()) { + return etk::String::npos; + } + if (_value[jjj] != m_data[iii+jjj]) { + check = false; + break; + } + } + if (check == true) { + return iii; + } } - etk::String etk::toString(unsigned _val) { - char tmpVal[256]; - sprintf(tmpVal, "%u", _val); - return tmpVal; + return etk::String::npos; +} + +size_t etk::String::rfind(char _value, size_t _pos) const { + if (_pos >= m_data.size()) { + _pos = m_data.size()-1; } - etk::String etk::toString(unsigned long _val) { - char tmpVal[256]; - sprintf(tmpVal, "%lu", _val); - return tmpVal; + for (int64_t iii=_pos; iii>=0; --iii) { + if (_value == m_data[iii]) { + return iii; + } } - etk::String etk::toString(unsigned long long _val) { - char tmpVal[256]; - sprintf(tmpVal, "%llu", _val); - return tmpVal; + return etk::String::npos; +} + +size_t etk::String::rfind(const etk::String& _value, size_t _pos) const { + if (_pos >= m_data.size()) { + _pos = m_data.size()-1; } - etk::String etk::toString(float _val) { - char tmpVal[256]; - sprintf(tmpVal, "%f", _val); - return tmpVal; + for (int64_t iii=_pos; iii>=0; --iii) { + bool check = true; + for (size_t jjj=0; jjj<_value.size(); ++jjj) { + if (iii+jjj >= m_data.size()) { + check = false; + break; + } + if (_value[jjj] != m_data[iii+jjj]) { + check = false; + break; + } + } + if (check == true) { + return iii; + } } - etk::String etk::toString(double _val) { - char tmpVal[256]; - sprintf(tmpVal, "%f", _val); - return tmpVal; + return etk::String::npos; +} + +etk::String& etk::replace(size_t _pos, size_t _len, char _replace) { + erase(_pos, _len); + insert(_pos, _replace); + return *this; +} + +etk::String& etk::replace(size_t _pos, size_t _len, const etk::String& _replace) { + erase(_pos, _len); + insert(_pos, _replace); + return *this; +} + +etk::String& etk::replace(char _val, char _replace) { + size_t pos = 0; + while ((pos = find(_val, pos)) != etk::String::npos) { + replace(pos, _val.size(), _replace); + pos += _replace.size(); } - etk::String etk::toString(long double _val) { - char tmpVal[256]; - sprintf(tmpVal, "%Lf", _val); - return tmpVal; - } \ No newline at end of file + return *this; +} + +etk::String& etk::String::replace(const etk::String& _val, const etk::String& _replace) { + size_t pos = 0; + while ((pos = find(_val, pos)) != etk::String::npos) { + replace(pos, _val.size(), _replace); + pos += _replace.size(); + } + return *this; +} + +etk::String etk::String::getLine(int32_t _pos) const { + // search back : '\n' + size_t startPos = rfind('\n', _pos); + if ((int64_t)startPos == (int64_t)_pos) { + startPos = 0; + } else { + startPos++; + } + // search forward : '\n' + size_t stopPos = _pos; + if (m_data[_pos] != '\n') { + stopPos = find('\n', _pos); + if ((int64_t)stopPos == _pos) { + stopPos = size(); + } + } + if (startPos == etk::String::npos) { + startPos = 0; + } else if (startPos >= size() ) { + return ""; + } + if (stopPos == etk::String::npos) { + return ""; + } else if (stopPos >= size() ) { + stopPos = size(); + } + return etk::String(*this, startPos, stopPos - startPos); +} + + +etk::Vector etk::String::split(char _val) const { + etk::Vector list; + size_t lastStartPos = 0; + for(size_t iii=0; iii etk::String::split(etk::String _val) const { + etk::Vector list; + size_t lastStartPos = 0; + for(size_t iii=0; iii split(char _val) const; + etk::Vector split(etk::String _val) const; /** * @brief Template that permit to convert string in everythings you want * @param[in] ETK_STRING_TYPE Template type of the convertion output @@ -718,8 +744,7 @@ namespace etk { //! @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 @@ -728,15 +753,5 @@ namespace etk { template bool from_string(TYPE& _variableRet, const etk::String& _value); - 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 replace(const etk::String& _obj, const etk::String& _val, const etk::String& _replace); - etk::String extract_line(const etk::String& _obj, int32_t _pos); - etk::Vector split(const etk::String& _input, char _val); - etk::Vector split(const etk::String& _input, etk::String _val); void sort(etk::Vector& _list); } diff --git a/etk/etk.cpp b/etk/etk.cpp index 13af5cd..e134a0b 100644 --- a/etk/etk.cpp +++ b/etk/etk.cpp @@ -50,7 +50,7 @@ void etk::init(int _argc, const char** _argv) { #endif for (int32_t iii=0; iii<_argc ; ++iii) { - std::string data = _argv[iii]; + etk::String data = _argv[iii]; if ( data == "-h" || data == "--help") { TK_PRINT("etk - help : "); @@ -70,6 +70,6 @@ void etk::init(int _argc, const char** _argv) { TK_INFO("ETK system init (END)"); } -std::string etk::getApplicationName() { +etk::String etk::getApplicationName() { return etk::FSNodeGetApplicationName(); } diff --git a/etk/etk.hpp b/etk/etk.hpp index 2d2b274..16a0942 100644 --- a/etk/etk.hpp +++ b/etk/etk.hpp @@ -25,6 +25,6 @@ namespace etk { * @brief Get application name. * @return The application name */ - std::string getApplicationName(); + etk::String getApplicationName(); } diff --git a/etk/stdTools.cpp b/etk/stdTools.cpp index 7f18bbd..266335e 100644 --- a/etk/stdTools.cpp +++ b/etk/stdTools.cpp @@ -733,52 +733,6 @@ bool etk::start_with(const std::string& _obj, const std::string& _val, bool _cas } #endif -std::string etk::replace(const std::string& _obj, char _val, char _replace) { - std::string copy(_obj); - std::replace(copy.begin(), copy.end(), _val, _replace); - return copy; - -} - -//! @not_in_doc -std::string etk::replace(const std::string& _obj, const std::string& _val, const std::string& _replace) { - std::string copy(_obj); - size_t pos = 0; - while ((pos = copy.find(_val, pos)) != std::string::npos) { - copy.replace(pos, _val.length(), _replace); - pos += _replace.length(); - } - return copy; -} - -std::string etk::extract_line(const std::string& _obj, int32_t _pos) { - // search back : '\n' - size_t startPos = _obj.rfind('\n', _pos); - if ((int64_t)startPos == (int64_t)_pos) { - startPos = 0; - } else { - startPos++; - } - // search forward : '\n' - size_t stopPos = _pos; - if (_obj[_pos] != '\n') { - stopPos = _obj.find('\n', _pos); - if ((int64_t)stopPos == _pos) { - stopPos = _obj.size(); - } - } - if (startPos == std::string::npos) { - startPos = 0; - } else if (startPos >= _obj.size() ) { - return ""; - } - if (stopPos == std::string::npos) { - return ""; - } else if (stopPos >= _obj.size() ) { - stopPos = _obj.size(); - } - return std::string(_obj, startPos, stopPos - startPos); -} #if __CPP_VERSION__ >= 2011 std::u32string etk::extract_line(const std::u32string& _obj, int32_t _pos) { // search back : '\n' @@ -810,21 +764,6 @@ std::string etk::extract_line(const std::string& _obj, int32_t _pos) { } #endif -std::vector etk::split(const std::string& _input, char _val) { - std::vector list; - size_t lastStartPos = 0; - for(size_t iii=0; iii<_input.size(); iii++) { - if (_input[iii]==_val) { - list.push_back(std::string(_input, lastStartPos, iii - lastStartPos)); - lastStartPos = iii+1; - } - } - if (lastStartPos<_input.size()) { - list.push_back(std::string(_input, lastStartPos)); - } - return list; -} - #if __CPP_VERSION__ >= 2011 std::vector etk::split(const std::u32string& _input, char32_t _val) { std::vector list; @@ -842,21 +781,6 @@ std::vector etk::split(const std::string& _input, char _val) { } #endif -std::vector etk::split(const std::string& _input, std::string _val) { - std::vector list; - size_t lastStartPos = 0; - for(size_t iii=0; iii<_input.size()-_val.size(); iii++) { - if (std::string(_input.begin()+iii, _input.begin()+iii+_val.size()) ==_val) { - list.push_back(std::string(_input, lastStartPos, iii - lastStartPos)); - lastStartPos = iii+_val.size(); - iii += _val.size()-1; - } - } - if (lastStartPos<_input.size()) { - list.push_back(std::string(_input, lastStartPos)); - } - return list; -} #if __CPP_VERSION__ >= 2011