This commit is contained in:
SergeySlice 2020-03-28 21:34:37 +03:00
commit fab5d07b37
4 changed files with 100 additions and 71 deletions

View File

@ -102,7 +102,7 @@ typedef struct PrintfParams {
#if PRINTF_UTF8_OUTPUT_SUPPORT == 1 #if PRINTF_UTF8_OUTPUT_SUPPORT == 1
// Print a char as is. Not analyse is made to check if it's a utf8 partial char // Print a char as is. No analyse is made to check if it's a utf8 partial char
// c is an int for prototype compatibility, but must be < 255 // c is an int for prototype compatibility, but must be < 255
static void print_char(int c, PrintfParams* printfParams) static void print_char(int c, PrintfParams* printfParams)
{ {
@ -167,6 +167,9 @@ static void print_wchar(int c, PrintfParams* printfParams)
*printfParams->newlinePtr = 0; // to do BEFORE call to printTimeStamp *printfParams->newlinePtr = 0; // to do BEFORE call to printTimeStamp
if ( printfParams->timestamp ) print_timestamp(printfParams); if ( printfParams->timestamp ) print_timestamp(printfParams);
} }
#if PRINTF_EMIT_CR == 1
if ( c == '\n' ) print_wchar('\r', printfParams);
#endif
#if PRINTF_LITE_BUF_SIZE > 1 #if PRINTF_LITE_BUF_SIZE > 1
printfParams->buf.wbuf[(printfParams->bufIdx)++] = (wchar_t)c; printfParams->buf.wbuf[(printfParams->bufIdx)++] = (wchar_t)c;
#else #else
@ -176,6 +179,9 @@ static void print_wchar(int c, PrintfParams* printfParams)
*printfParams->newlinePtr = 1; *printfParams->newlinePtr = 1;
} }
}else{ }else{
#if PRINTF_EMIT_CR == 1
if ( c == '\n' ) print_wchar('\r', printfParams);
#endif
#if PRINTF_LITE_BUF_SIZE > 1 #if PRINTF_LITE_BUF_SIZE > 1
printfParams->buf.wbuf[(printfParams->bufIdx)++] = (wchar_t)c; printfParams->buf.wbuf[(printfParams->bufIdx)++] = (wchar_t)c;
#else #else
@ -184,6 +190,9 @@ static void print_wchar(int c, PrintfParams* printfParams)
} }
#else #else
{ {
#if PRINTF_EMIT_CR == 1
if ( c == '\n' ) print_wchar('\r', printfParams);
#endif
#if PRINTF_LITE_BUF_SIZE > 1 #if PRINTF_LITE_BUF_SIZE > 1
printfParams->buf.wbuf[(printfParams->bufIdx)++] = (wchar_t)c; // cast suposed to be safe, as this function must be called printfParams->buf.wbuf[(printfParams->bufIdx)++] = (wchar_t)c; // cast suposed to be safe, as this function must be called
#else #else

View File

@ -33,7 +33,7 @@ const XString NullXString;
void XString::Init(xsize aSize) void XString::Init(xsize aSize)
{ {
m_data = (char*)malloc( (aSize+1)*sizeof(char) ); /* le 0 terminal n'est pas compté dans mSize */ m_data = (char*)malloc( (aSize+1)*sizeof(char) ); /* le 0 terminal n'est pas compté dans m_allocatedSize */
if ( !m_data ) { if ( !m_data ) {
DebugLog(2, "XString::Init(%llu) : Xalloc returned NULL. Cpu halted\n", (aSize+1)*sizeof(char)); DebugLog(2, "XString::Init(%llu) : Xalloc returned NULL. Cpu halted\n", (aSize+1)*sizeof(char));
panic(); panic();
@ -51,7 +51,7 @@ XString::XString()
XString::~XString() XString::~XString()
{ {
//Debugf("Destructeur :%s\n", c); //Debugf("Destructeur :%s\n", c);
delete m_data; delete m_data; // delete nullptr do nothing
} }
void XString::setLength(xsize len) void XString::setLength(xsize len)
@ -67,7 +67,7 @@ char *XString::CheckSize(xsize nNewSize, xsize nGrowBy)
{ {
nNewSize += nGrowBy; nNewSize += nGrowBy;
m_data = (char*)realloc(m_data, (nNewSize+1)*sizeof(char), m_allocatedSize*sizeof(wchar_t)); m_data = (char*)realloc(m_data, (nNewSize+1)*sizeof(char), m_allocatedSize*sizeof(wchar_t)); // realloc is identical to malloc if m_data is NULL
if ( !m_data ) { if ( !m_data ) {
DBG("XString::CheckSize(%d, %d) : Xrealloc(%d, %d, %d) returned NULL. System halted\n", nNewSize, nGrowBy, m_size, (nNewSize+1)*sizeof(char), c); DBG("XString::CheckSize(%d, %d) : Xrealloc(%d, %d, %d) returned NULL. System halted\n", nNewSize, nGrowBy, m_size, (nNewSize+1)*sizeof(char), c);
panic(); panic();
@ -349,6 +349,14 @@ XString::XString(const XString &aString)
StrnCpy(aString.data(), aString.length()); StrnCpy(aString.data(), aString.length());
} }
XString::XString(XString&& aString) // Move constructor
{
m_data = aString.m_data;
m_allocatedSize = aString.m_allocatedSize;
aString.m_data = 0;
aString.m_allocatedSize = 0;
}
//// Deactivate assignment during refactoring to avoid confusion //// Deactivate assignment during refactoring to avoid confusion
//XString::XString(const wchar_t *S) //XString::XString(const wchar_t *S)
//{ //{
@ -828,23 +836,16 @@ const XString &XString::operator =(const XString &aString)
return *this; return *this;
} }
#ifdef __AFXWIN_H__ XString& XString::operator =(XString&& aString)
const XString &XString::operator =(const CString &aCString)
{ {
//TRACE("Operator =const CString&\n"); delete m_data; // delete does nothing if m_data is NULL
StrnCpy(aCString, aCString.GetLength()); m_data = aString.m_data;
m_allocatedSize = aString.m_allocatedSize;
aString.m_data = 0;
aString.m_allocatedSize = 0;
return *this; return *this;
} }
#endif
#ifdef _WX_WXSTRINGH__
const XString &XString::operator =(const wxString &awxString)
{
//TRACE("Operator =const wxString&\n");
StrnCpy(awxString.mb_str(), awxString.length());
return *this;
}
#endif
// //
//const XString &XString::operator =(const XConstString &aConstString) //const XString &XString::operator =(const XConstString &aConstString)
//{ //{
@ -1082,7 +1083,7 @@ XString ToUpper(const char *S)
} }
#endif #endif
// Deactivate assignment during refactoring to avoid confusion // Deactivate during refactoring to avoid confusion
//XString CleanCtrl(const XString &S) //XString CleanCtrl(const XString &S)
//{ //{
// XString ReturnValue; // XString ReturnValue;

View File

@ -43,6 +43,8 @@ class XString
void Init(xsize aSize=0); void Init(xsize aSize=0);
XString(); XString();
XString(const XString &aString); XString(const XString &aString);
XString(XString&& aString); // Move constructor
// XString(const XConstString &aConstString); // XString(const XConstString &aConstString);
// XString(const char *S); // XString(const char *S);
@ -125,6 +127,7 @@ class XString
const XString& takeValueFrom(const wchar_t* S) { SPrintf("%ls", S); return *this; } const XString& takeValueFrom(const wchar_t* S) { SPrintf("%ls", S); return *this; }
const XString& operator =(const XString& aString); const XString& operator =(const XString& aString);
XString& operator =(XString&& aString);
// const XString &operator =(const XConstString &aConstString); // const XString &operator =(const XConstString &aConstString);
// Deactivate assignment during refactoring to avoid confusion // Deactivate assignment during refactoring to avoid confusion
@ -226,7 +229,9 @@ class XString
// OpÈrateur + // OpÈrateur +
// Chaines // Chaines
friend XString operator + (const XString& p1, const XString& p2) { XString s; s=p1; s+=p2; return s; } friend XString operator + (const XString& p1, const XString& p2) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (const XString& p1, const char *p2 ) { XString s; s=p1; s+=p2; return s; } // friend XString operator + (const XString& p1, const char *p2 ) { XString s; s=p1; s+=p2; return s; }
XString operator + (const char *p2 ) { XString s(*this); s+=p2; return s; }
friend XString operator + (const char *p1, const XString& p2) { XString s; s.takeValueFrom(p1); s+=p2; return s; } friend XString operator + (const char *p1, const XString& p2) { XString s; s.takeValueFrom(p1); s+=p2; return s; }
// friend XString operator + (const XConstString& p1, const XString& p2) { XString s; s=p1; s+=p2; return s; } // friend XString operator + (const XConstString& p1, const XString& p2) { XString s; s=p1; s+=p2; return s; }
// friend XString operator + (const XString& p1, const XConstString& p2) { XString s; s=p1; s+=p2; return s; } // friend XString operator + (const XString& p1, const XConstString& p2) { XString s; s=p1; s+=p2; return s; }

View File

@ -4,12 +4,13 @@
#include "global_test.h" #include "global_test.h"
//#include <wchar.h>
int XString_tests() int XString_tests()
{ {
#ifdef JIEF_DEBUG
#endif
#ifdef JIEF_DEBUG #ifdef JIEF_DEBUG
// DebugLog(2, "XStringW_tests -> Enter\n"); // DebugLog(2, "XStringW_tests -> Enter\n");
#endif #endif
@ -48,6 +49,19 @@ int XString_tests()
} }
#endif #endif
// Move assignment.
{
XString str1;
str1.takeValueFrom("str1");
XString str2(str1 + "b");
str2 += "a"; // this is more efficient than str2 = str2 + "a", of course
if ( str2 != "str1ba" ) return 120;
str2 = str2 + "a";
if ( str2 != "str1baa" ) return 121;
str2 = str1 + "a"; // this must call the move assignment operator
if ( str2 != "str1a" ) return 122;
}
// check [] operator // check [] operator
{ {
XString str; XString str;