diff --git a/etk/Char.cpp b/etk/Char.cpp new file mode 100644 index 0000000..0e408a2 --- /dev/null +++ b/etk/Char.cpp @@ -0,0 +1,41 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#include +#include + + +etk::Char::Char(void) { + m_data.PushBack('\0'); +} + +etk::Char::~Char(void) +{ + +} + +etk::Char::operator const char *() +{ + return &m_data[0]; +}; + + +void etk::Char::SetValue(const etk::Vector& data) +{ + m_data = data; + // check presence of '\0' (note : start by the end might be faster ... + for (int32_t iii=m_data.Size()-1; iii>=0; iii--) { + if (m_data[iii] == '\0') { + return; + } + } + m_data.PushBack('\0'); +} + + + diff --git a/etk/Char.h b/etk/Char.h new file mode 100644 index 0000000..9d87330 --- /dev/null +++ b/etk/Char.h @@ -0,0 +1,32 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __ETK_CHAR_H__ +#define __ETK_CHAR_H__ + +#include +#include +#include + +namespace etk +{ + class Char + { + private: + etk::Vector m_data; + public: + Char(void); + ~Char(void); + operator const char *(); + void SetValue(const etk::Vector& data); + }; +}; + + +#endif + diff --git a/etk/RegExp.h b/etk/RegExp.h index 2f8b543..b181125 100644 --- a/etk/RegExp.h +++ b/etk/RegExp.h @@ -1628,7 +1628,8 @@ template class RegExp { m_notEndWithChar = false; // TODO : Check this ... ==> could create some errors ... - char * exp = expressionRequested.c_str(); + etk::Char tmppChar = expressionRequested.c_str(); + const char * exp = tmppChar; int32_t regExpLen = strlen(exp); // change in the regular Opcode ==> replace \x with the corect element ... x if needed int32_t iii; diff --git a/etk/UString.cpp b/etk/UString.cpp index eb417a8..2940868 100644 --- a/etk/UString.cpp +++ b/etk/UString.cpp @@ -599,14 +599,15 @@ bool etk::UString::EndWith(const etk::UString& data, bool caseSensitive) const } -char * etk::UString::c_str(void) +etk::Char etk::UString::c_str(void) const { + etk::Char tmpVar; + etk::Vector tmpData; // UTF8 generation : - m_dataUtf8.Clear(); - unicode::convertUnicodeToUtf8(m_data, m_dataUtf8); - m_dataUtf8.PushBack('\0'); - - return &m_dataUtf8[0]; + tmpData.Clear(); + unicode::convertUnicodeToUtf8(m_data, tmpData); + tmpVar.SetValue(tmpData); + return tmpVar; } diff --git a/etk/UString.h b/etk/UString.h index 6b019bd..d5552f4 100644 --- a/etk/UString.h +++ b/etk/UString.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace etk { @@ -118,15 +119,14 @@ namespace etk etk::Vector GetVector(void); uniChar_t * pointer(void) { return &m_data[0]; }; - // generate temporary allocation (auto unallocated...) - char * c_str(void); + + etk::Char c_str(void) const; // Sting operation : - etk::UString Extract(int32_t posStart=0, int32_t posEnd=0x7FFFFFFF) const; + etk::UString Extract(int32_t posStart=0, int32_t posEnd=0x7FFFFFFF) const; private : etk::Vector m_data; //!< internal data is stored in the Unicode properties ... - etk::Vector m_dataUtf8; //!< Tmp data for the Utf8Data() function }; etk::CCout& operator <<(etk::CCout &os, const etk::UString &obj); diff --git a/file.mk b/file.mk index 718290c..e77f874 100644 --- a/file.mk +++ b/file.mk @@ -5,6 +5,7 @@ FILE_LIST = \ etk/DebugInternal.cpp \ etk/unicode.cpp \ etk/unicodeTable.cpp \ + etk/Char.cpp \ etk/UString.cpp \ etk/Stream.cpp \ etk/RegExp.cpp \