[DEV] add a tmporary class to convert UString to char* string
This commit is contained in:
parent
3d4b4123b7
commit
3b6cd4880c
41
etk/Char.cpp
Normal file
41
etk/Char.cpp
Normal 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
32
etk/Char.h
Normal 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
|
||||||
|
|
@ -1628,7 +1628,8 @@ template<class CLASS_TYPE> class RegExp {
|
|||||||
m_notEndWithChar = false;
|
m_notEndWithChar = false;
|
||||||
|
|
||||||
// TODO : Check this ... ==> could create some errors ...
|
// 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);
|
int32_t regExpLen = strlen(exp);
|
||||||
// change in the regular Opcode ==> replace \x with the corect element ... x if needed
|
// change in the regular Opcode ==> replace \x with the corect element ... x if needed
|
||||||
int32_t iii;
|
int32_t iii;
|
||||||
|
@ -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 :
|
// UTF8 generation :
|
||||||
m_dataUtf8.Clear();
|
tmpData.Clear();
|
||||||
unicode::convertUnicodeToUtf8(m_data, m_dataUtf8);
|
unicode::convertUnicodeToUtf8(m_data, tmpData);
|
||||||
m_dataUtf8.PushBack('\0');
|
tmpVar.SetValue(tmpData);
|
||||||
|
return tmpVar;
|
||||||
return &m_dataUtf8[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <etk/DebugInternal.h>
|
#include <etk/DebugInternal.h>
|
||||||
#include <etk/Stream.h>
|
#include <etk/Stream.h>
|
||||||
#include <etk/Vector.h>
|
#include <etk/Vector.h>
|
||||||
|
#include <etk/Char.h>
|
||||||
|
|
||||||
namespace etk
|
namespace etk
|
||||||
{
|
{
|
||||||
@ -118,15 +119,14 @@ namespace etk
|
|||||||
|
|
||||||
etk::Vector<uniChar_t> GetVector(void);
|
etk::Vector<uniChar_t> GetVector(void);
|
||||||
uniChar_t * pointer(void) { return &m_data[0]; };
|
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 :
|
// 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 :
|
private :
|
||||||
etk::Vector<uniChar_t> m_data; //!< internal data is stored in the Unicode properties ...
|
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);
|
etk::CCout& operator <<(etk::CCout &os, const etk::UString &obj);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user