[DEV] add a tmporary class to convert UString to char* string

This commit is contained in:
Edouard DUPIN 2013-03-22 12:51:37 +01:00
parent 3d4b4123b7
commit 3b6cd4880c
6 changed files with 87 additions and 11 deletions

41
etk/Char.cpp Normal file
View File

@ -0,0 +1,41 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <etk/Char.h>
#include <etk/os/Memory.h>
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<char>& 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');
}

32
etk/Char.h Normal file
View File

@ -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 <etk/DebugInternal.h>
#include <etk/Stream.h>
#include <etk/Vector.h>
namespace etk
{
class Char
{
private:
etk::Vector<char> m_data;
public:
Char(void);
~Char(void);
operator const char *();
void SetValue(const etk::Vector<char>& data);
};
};
#endif

View File

@ -1628,7 +1628,8 @@ template<class CLASS_TYPE> 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;

View File

@ -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<char> 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;
}

View File

@ -12,6 +12,7 @@
#include <etk/DebugInternal.h>
#include <etk/Stream.h>
#include <etk/Vector.h>
#include <etk/Char.h>
namespace etk
{
@ -118,15 +119,14 @@ namespace etk
etk::Vector<uniChar_t> 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<uniChar_t> m_data; //!< internal data is stored in the Unicode properties ...
etk::Vector<char> m_dataUtf8; //!< Tmp data for the Utf8Data() function
};
etk::CCout& operator <<(etk::CCout &os, const etk::UString &obj);

View File

@ -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 \