Correction of the Unicode transcription and simplify the UString class

This commit is contained in:
Edouard Dupin 2012-02-16 14:02:36 +01:00
parent 23ca4b1821
commit 199d24a3a4
6 changed files with 37 additions and 279 deletions

View File

@ -171,7 +171,7 @@ static struct zip * s_APKArchive = NULL;
static int32_t s_APKnbFiles = 0;
static void loadAPK (const etk::UString& apkPath)
static void loadAPK(etk::UString& apkPath)
{
TK_DEBUG("Loading APK \"" << apkPath << "\"");
s_APKArchive = zip_open(apkPath.Utf8Data(), 0, NULL);
@ -235,8 +235,8 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
} else {
destFilename = newFilename;
}
TK_DEBUG("2 : Get file Name : " << destFilename );
if (false == destFilename.StartWith('/')) {
TK_DEBUG("2 : Get file Name : " << destFilename << "start with '/'=" << destFilename.StartWith('/'));
if (true == destFilename.StartWith('/')) {
m_type = etk::FILE_TYPE_DIRECT;
if (type != etk::FILE_TYPE_DIRECT) {
TK_DEBUG("Incompatible type with a file=\"" << newFilename << "\" ==> force it in direct mode ...");
@ -257,8 +257,6 @@ void etk::File::SetCompleateName(etk::UString &newFilename, etk::FileType_te typ
destFilename = cCurrentPath;
destFilename += "/";
destFilename += tmpFilename;
} else {
m_type = type;
}

View File

@ -116,6 +116,14 @@ namespace etk{
strncat(m_tmpChar, tmp, MAX_LOG_SIZE);
return *this;
}
CCout& operator << (bool t) {
if (t) {
strncat(m_tmpChar, "true", MAX_LOG_SIZE);
} else {
strncat(m_tmpChar, "false", MAX_LOG_SIZE);
}
return *this;
}
CCout& operator << (CStart ccc) {
pthread_mutex_lock(&m_mutex);
return *this;

View File

@ -170,6 +170,18 @@ void etk::UString::Set(const uniChar_t * inputData, int32_t len)
* @return
*
*/
etk::UString::UString(char inputData)
{
char tmpVal[2];
// generate the UString :
sprintf(tmpVal, "%c", inputData);
// set the internal data :
m_data.Clear();
m_data.PushBack('\0');
Set(tmpVal);
}
etk::UString::UString(int inputData)
{
char tmpVal[256];
@ -227,57 +239,6 @@ const etk::UString& etk::UString::operator= (const etk::UString &etkS )
}
/**
* @brief
*
* @param[in,out]
*
* @return
*
*/
const etk::UString& etk::UString::operator= (const char * inputData)
{
m_data.Clear();
m_data.PushBack('\0');
if (NULL == inputData) {
return *this;
}
// calculate the size :
uint32_t len = strlen(inputData);
// check the new size ...
if (len > 0 ) {
// copy all data :
Set(inputData, len);
}
return *this;
}
/**
* @brief
*
* @param[in,out]
*
* @return
*
*/
const etk::UString& etk::UString::operator= (const uniChar_t * inputData)
{
m_data.Clear();
m_data.PushBack('\0');
if (NULL == inputData) {
return *this;
}
// calculate the size :
int32_t len = strlen(inputData);
// check the new size ...
if (len > 0 ) {
// copy all data :
Set(inputData, len);
}
return *this;
}
/**
* @brief
*
@ -442,43 +403,6 @@ bool etk::UString::operator== (const etk::UString& etkS) const
}
/**
* @brief
*
* @param[in,out]
*
* @return
*
*/
bool etk::UString::operator== (const char * inputData) const
{
etk::UString tmpString(inputData);
return *this == tmpString;
}
/**
* @brief
*
* @param[in,out]
*
* @return
*
*/
bool etk::UString::operator== (const uniChar_t * inputData) const
{
// calculate the size :
int32_t len = strlen(inputData);
if (len+1 != m_data.Size()) {
return false;
}
for (int32_t iii= 0; iii<m_data.Size(); iii++) {
if (inputData[iii]!= m_data[iii]){
return false;
}
}
return true;
}
/**
* @brief
@ -494,20 +418,6 @@ bool etk::UString::operator!= (const etk::UString& etkS) const
}
/**
* @brief
*
* @param[in,out]
*
* @return
*
*/
bool etk::UString::operator!= (const char * inputData) const
{
return !(*this == inputData);
}
/**
* @brief
*
@ -533,65 +443,6 @@ const etk::UString& etk::UString::operator+= (const etk::UString &etkS)
}
/**
* @brief
*
* @param[in,out]
*
* @return
*
*/
const etk::UString& etk::UString::operator+= (const uniChar_t * inputData)
{
//TK_INFO(" UString(arg) : \"" << inputData << "\"");
//TK_INFO(" UString(direct) : \"" << m_data << "\"");
int32_t len = strlen(inputData);
if (len != 0) {
// remove the last '\0'
m_data.PopBack();
// copy the data ...
m_data.PushBack(inputData, len+1 );
}
return *this;
}
/**
* @brief
*
* @param[in,out]
*
* @return
*
*/
const etk::UString& etk::UString::operator+= (const char * inputData)
{
etk::UString tmpString(inputData);
*this += tmpString;
return *this;
}
const etk::UString& etk::UString::operator+= (const char data)
{
etk::UString tmpString(data);
*this += tmpString;
return *this;
}
const etk::UString& etk::UString::operator+= (const int data)
{
etk::UString tmpString(data);
*this += tmpString;
return *this;
}
const etk::UString& etk::UString::operator+= (const unsigned int data)
{
etk::UString tmpString(data);
*this += tmpString;
return *this;
}
/**
* @brief
*
@ -611,41 +462,6 @@ etk::UString etk::UString::operator+ (const etk::UString &etkS)
}
/**
* @brief
*
* @param[in,out]
*
* @return
*
*/
etk::UString etk::UString::operator+ (const char * inputData)
{
etk::UString temp;
//TK_INFO(" UString(arg) : \"" << inputData << "\"");
//TK_INFO(" UString(direct) : \"" << m_data << "\"");
temp += *this;
temp += inputData;
return temp;
}
/**
* @brief
*
* @param[in,out]
*
* @return
*
*/
etk::UString etk::UString::operator+ (const uniChar_t * inputData)
{
etk::UString temp;
//TK_INFO(" UString(arg) : \"" << inputData << "\"");
//TK_INFO(" UString(direct) : \"" << m_data << "\"");
temp += *this;
temp += inputData;
return temp;
}
@ -865,31 +681,6 @@ etk::VectorType<uniChar_t> etk::UString::GetVector(void)
// Start With ...
bool etk::UString::StartWith(const char* data)
{
etk::UString tmpString(data);
return StartWith(tmpString);
}
bool etk::UString::StartWith(const uniChar_t* data)
{
if (NULL == data) {
return false;
}
int32_t len = strlen(data);
if (len == 0) {
return false;
}
if (len > Size()) {
return false;
}
for (int32_t iii=0; iii<len; iii++) {
if (data[iii] != m_data[iii]) {
return false;
}
}
return true;
}
bool etk::UString::StartWith(const etk::UString& data)
{
@ -908,35 +699,6 @@ bool etk::UString::StartWith(const etk::UString& data)
}
bool etk::UString::EndWith(const char* data)
{
etk::UString tmpString(data);
return EndWith(tmpString);
}
bool etk::UString::EndWith(const uniChar_t* data)
{
if (NULL == data) {
return false;
}
int32_t len = strlen(data);
if (len == 0) {
return false;
}
if (len > Size()) {
return false;
}
for( int32_t iii=Size()-1, jjj=len-1;
iii>=0 && jjj>=0;
iii--, jjj--) {
if (data[jjj] != m_data[iii]) {
return false;
}
}
return true;
}
bool etk::UString::EndWith(const etk::UString& data)
{
if (data.Size() == 0) {

View File

@ -40,6 +40,7 @@ namespace etk
void Set(const uniChar_t* inputData, int32_t len=-1);
void Set(const char* inputData, int32_t len=-1);
// basic convertion integer en string
UString(char inputData);
UString(int inputData);
UString(unsigned int inputData);
UString(const etk::UString &etkS);
@ -50,22 +51,16 @@ namespace etk
* = assigment
*****************************************************/
const etk::UString& operator= (const etk::UString &etkS );
const etk::UString& operator= (const char * inputData);
const etk::UString& operator= (const uniChar_t * inputData);
const etk::UString& operator= (etk::VectorType<char> inputData);
const etk::UString& operator= (etk::VectorType<uniChar_t> inputData);
/*****************************************************
* == operator
*****************************************************/
bool operator== (const etk::UString& etkS) const;
bool operator== (const uniChar_t * inputData) const;
bool operator== (const char * inputData) const;
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const etk::UString& etkS) const;
bool operator!= (const uniChar_t * inputData) const;
bool operator!= (const char * inputData) const;
/*****************************************************
* > < >= <= operator
*****************************************************/
@ -77,17 +72,10 @@ namespace etk
* += operator
*****************************************************/
const etk::UString& operator+= (const etk::UString &etkS);
const etk::UString& operator+= (const char data);
const etk::UString& operator+= (const int data);
const etk::UString& operator+= (const unsigned int data);
const etk::UString& operator+= (const char * inputData);
const etk::UString& operator+= (const uniChar_t * inputData);
/*****************************************************
* + operator
*****************************************************/
etk::UString operator+ (const etk::UString &etkS);
etk::UString operator+ (const char * inputData);
etk::UString operator+ (const uniChar_t * inputData);
/*****************************************************
* << operator
*****************************************************/
@ -118,12 +106,8 @@ namespace etk
* toolbox
*****************************************************/
// Start With ...
bool StartWith(const char* data);
bool StartWith(const uniChar_t* data);
bool StartWith(const etk::UString& data);
// End With ...
bool EndWith(const char* data);
bool EndWith(const uniChar_t* data);
bool EndWith(const etk::UString& data);
// Find element
int32_t FindForward(const char data, int32_t startPos=0);

View File

@ -238,7 +238,7 @@ int32_t unicode::convertUtf8ToUnicode(etk::VectorType<char>& input_UTF8, etk::Ve
tmpData[0] = input_UTF8[pos+0];
tmpData[1] = input_UTF8[pos+1];
tmpData[2] = '\0';
pos += 1;
pos += 2;
} else if( 3<=lenMax
&& 0xE0 == (input_UTF8[pos+0] & 0xF0)
&& 0x80 == (input_UTF8[pos+1] & 0xC0)
@ -247,7 +247,7 @@ int32_t unicode::convertUtf8ToUnicode(etk::VectorType<char>& input_UTF8, etk::Ve
tmpData[1] = input_UTF8[pos+1];
tmpData[2] = input_UTF8[pos+2];
tmpData[3] = '\0';
pos += 1;
pos += 3;
} else if( 4<=lenMax
&& 0xF0 == (input_UTF8[pos+0] & 0xF8)
&& 0x80 == (input_UTF8[pos+1] & 0xC0)
@ -258,7 +258,7 @@ int32_t unicode::convertUtf8ToUnicode(etk::VectorType<char>& input_UTF8, etk::Ve
tmpData[2] = input_UTF8[pos+2];
tmpData[3] = input_UTF8[pos+3];
tmpData[4] = '\0';
pos += 1;
pos += 4;
} else {
tmpData[0] = '\0';
pos += 1;
@ -293,7 +293,7 @@ int32_t unicode::convertUtf8ToUnicode(char * input_UTF8, etk::VectorType<uniChar
tmpData[0] = input_UTF8[pos+0];
tmpData[1] = input_UTF8[pos+1];
tmpData[2] = '\0';
pos += 1;
pos += 2;
} else if( 3<=lenMax
&& 0xE0 == (input_UTF8[pos+0] & 0xF0)
&& 0x80 == (input_UTF8[pos+1] & 0xC0)
@ -302,7 +302,7 @@ int32_t unicode::convertUtf8ToUnicode(char * input_UTF8, etk::VectorType<uniChar
tmpData[1] = input_UTF8[pos+1];
tmpData[2] = input_UTF8[pos+2];
tmpData[3] = '\0';
pos += 1;
pos += 3;
} else if( 4<=lenMax
&& 0xF0 == (input_UTF8[pos+0] & 0xF8)
&& 0x80 == (input_UTF8[pos+1] & 0xC0)
@ -313,7 +313,7 @@ int32_t unicode::convertUtf8ToUnicode(char * input_UTF8, etk::VectorType<uniChar
tmpData[2] = input_UTF8[pos+2];
tmpData[3] = input_UTF8[pos+3];
tmpData[4] = '\0';
pos += 1;
pos += 4;
} else {
tmpData[0] = '\0';
pos += 1;

View File

@ -532,10 +532,13 @@ bool ewol::FileChooser::OnEventAreaExternal(int32_t widgetID, const char * gener
//==> this is an internal event ...
FileChooserFolderList * myListFolder = (FileChooserFolderList *)ewol::widgetManager::Get(m_widgetListFolderId);
etk::UString tmpString = myListFolder->GetSelectedLine();
EWOL_DEBUG(" old PATH : \"" << m_folder << "\" + \"" << tmpString << "\"");
m_folder = m_folder + tmpString;
char buf[MAX_FILE_NAME];
memset(buf, 0, MAX_FILE_NAME);
char * ok;
EWOL_DEBUG("new PATH : \"" << m_folder << "\"");
ok = realpath(m_folder.Utf8Data(), buf);
if (!ok) {
EWOL_ERROR("Error to get the real path");
@ -585,7 +588,9 @@ void ewol::FileChooser::UpdateCurrentFolder(void)
myEntry->SetValue(m_folder);
myListFolder->AddElement(etk::UString("."));
myListFolder->AddElement(etk::UString(".."));
if (m_folder != "/" ) {
myListFolder->AddElement(etk::UString(".."));
}
DIR *dir;
struct dirent *ent;
dir = opendir(m_folder.Utf8Data());
@ -598,6 +603,7 @@ void ewol::FileChooser::UpdateCurrentFolder(void)
myListFile->AddElement(tmpString);
}
} else if (DT_DIR == ent->d_type) {
//EWOL_DEBUG(" find Folder : \"" << tmpString << "\"(" << tmpString.Size() << ") ?= \"" << ent->d_name << "\"(" << strlen(ent->d_name) );
if (tmpString != "." && tmpString != "..") {
if (false == tmpString.StartWith(".") || true==ShowHidenFile) {
myListFolder->AddElement(tmpString);