Introducing a UTF8 XString

This commit is contained in:
jief 2020-03-12 17:40:38 +03:00
parent 59dd1913b8
commit b920b9f8fb
15 changed files with 1563 additions and 18 deletions

View File

@ -53,6 +53,12 @@
9A57C2272418B9A00029A39F /* XArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08532402FE9B00E2B470 /* XArray_tests.cpp */; };
9A57C2282418B9A00029A39F /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B085D240300E000E2B470 /* Platform.cpp */; };
9A57C2292418B9A00029A39F /* XStringW_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08552402FE9B00E2B470 /* XStringW_test.cpp */; };
9A57C263241A752E0029A39F /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C261241A752E0029A39F /* XString_test.cpp */; };
9A57C264241A752E0029A39F /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C261241A752E0029A39F /* XString_test.cpp */; };
9A57C265241A752E0029A39F /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C261241A752E0029A39F /* XString_test.cpp */; };
9A57C268241A799B0029A39F /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C267241A799B0029A39F /* XString.cpp */; };
9A57C269241A799B0029A39F /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C267241A799B0029A39F /* XString.cpp */; };
9A57C26A241A799B0029A39F /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C267241A799B0029A39F /* XString.cpp */; };
9A9223312402FD1000483CBA /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9223302402FD1000483CBA /* main.cpp */; };
9AA05BB7240FC78D008EA4F8 /* utf8Conversion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA05BB6240FC78D008EA4F8 /* utf8Conversion.cpp */; };
9AA05BB8240FC78D008EA4F8 /* utf8Conversion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA05BB6240FC78D008EA4F8 /* utf8Conversion.cpp */; };
@ -122,6 +128,10 @@
9A57C2132418A6E90029A39F /* XStringWP.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XStringWP.cpp; sourceTree = "<group>"; };
9A57C2142418A6EA0029A39F /* XStringWP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringWP.h; sourceTree = "<group>"; };
9A57C22F2418B9A00029A39F /* cpp_tests UTF16 unsigned char */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp_tests UTF16 unsigned char"; sourceTree = BUILT_PRODUCTS_DIR; };
9A57C261241A752E0029A39F /* XString_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XString_test.cpp; sourceTree = "<group>"; };
9A57C262241A752E0029A39F /* XString_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XString_test.h; sourceTree = "<group>"; };
9A57C266241A799B0029A39F /* XString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XString.h; sourceTree = "<group>"; };
9A57C267241A799B0029A39F /* XString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XString.cpp; sourceTree = "<group>"; };
9A92232D2402FD1000483CBA /* cpp_tests UTF16 signed char */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp_tests UTF16 signed char"; sourceTree = BUILT_PRODUCTS_DIR; };
9A9223302402FD1000483CBA /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
9A92234D2402FD9500483CBA /* Platform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = "<group>"; };
@ -165,6 +175,8 @@
9AA05BB9240FC796008EA4F8 /* utf8Conversion.h */,
9A0B084A2402FE9300E2B470 /* XArray.h */,
9A0B084B2402FE9300E2B470 /* XObjArray.h */,
9A57C267241A799B0029A39F /* XString.cpp */,
9A57C266241A799B0029A39F /* XString.h */,
9A0B08482402FE9300E2B470 /* XStringW.cpp */,
9A0B08462402FE9300E2B470 /* XStringW.h */,
9A0B08472402FE9300E2B470 /* XStringWArray.cpp */,
@ -193,6 +205,8 @@
9A0B08502402FE9B00E2B470 /* XObjArray_tests.h */,
9A0B08552402FE9B00E2B470 /* XStringW_test.cpp */,
9A0B08632403132300E2B470 /* XStringW_test.h */,
9A57C261241A752E0029A39F /* XString_test.cpp */,
9A57C262241A752E0029A39F /* XString_test.h */,
9A0B084F2402FE9B00E2B470 /* XStringWArray_test.cpp */,
9A0B084D2402FE9B00E2B470 /* XStringWArray_test.h */,
9A57C20F2418A3550029A39F /* XUINTN_test.cpp */,
@ -339,6 +353,7 @@
9A57C20E2418A27B0029A39F /* XUINTN.cpp in Sources */,
9A0B08732403B08400E2B470 /* XObjArray_tests.cpp in Sources */,
9A0B08742403B08400E2B470 /* main.cpp in Sources */,
9A57C264241A752E0029A39F /* XString_test.cpp in Sources */,
9A0B08752403B08400E2B470 /* printf_lite.cpp in Sources */,
9A0B08772403B08400E2B470 /* XStringWArray.cpp in Sources */,
9A57C2122418A3560029A39F /* XUINTN_test.cpp in Sources */,
@ -353,6 +368,7 @@
9A0B087E2403B08400E2B470 /* XArray_tests.cpp in Sources */,
9A0B087F2403B08400E2B470 /* Platform.cpp in Sources */,
9A0B08802403B08400E2B470 /* XStringW_test.cpp in Sources */,
9A57C269241A799B0029A39F /* XString.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -363,6 +379,7 @@
9A57C2192418B9A00029A39F /* XUINTN.cpp in Sources */,
9A57C21A2418B9A00029A39F /* XObjArray_tests.cpp in Sources */,
9A57C21B2418B9A00029A39F /* main.cpp in Sources */,
9A57C265241A752E0029A39F /* XString_test.cpp in Sources */,
9A57C21C2418B9A00029A39F /* printf_lite.cpp in Sources */,
9A57C21D2418B9A00029A39F /* XStringWArray.cpp in Sources */,
9A57C21E2418B9A00029A39F /* XUINTN_test.cpp in Sources */,
@ -377,6 +394,7 @@
9A57C2272418B9A00029A39F /* XArray_tests.cpp in Sources */,
9A57C2282418B9A00029A39F /* Platform.cpp in Sources */,
9A57C2292418B9A00029A39F /* XStringW_test.cpp in Sources */,
9A57C26A241A799B0029A39F /* XString.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -387,6 +405,7 @@
9A57C20D2418A27B0029A39F /* XUINTN.cpp in Sources */,
9A0B085A2402FF8400E2B470 /* XObjArray_tests.cpp in Sources */,
9A9223312402FD1000483CBA /* main.cpp in Sources */,
9A57C263241A752E0029A39F /* XString_test.cpp in Sources */,
9A0B086D24039FE700E2B470 /* printf_lite.cpp in Sources */,
9A0B08562402FF7700E2B470 /* XStringWArray.cpp in Sources */,
9A57C2112418A3560029A39F /* XUINTN_test.cpp in Sources */,
@ -401,6 +420,7 @@
9A0B085B2402FF8700E2B470 /* XArray_tests.cpp in Sources */,
9A0B085E240300E000E2B470 /* Platform.cpp in Sources */,
9A0B085C2402FF8B00E2B470 /* XStringW_test.cpp in Sources */,
9A57C268241A799B0029A39F /* XString.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -69,6 +69,11 @@ UINTN AsciiStrLen(const char* String)
return (UINTN)strlen(String);
}
INTN AsciiStrCmp (const char *FirstString,const char *SecondString)
{
return (INTN)strcmp(FirstString, SecondString);
}
#if __WCHAR_MAX__ <= 0xFFFFu
#ifndef _MSC_VER

View File

@ -61,7 +61,7 @@ int StrCmp(const wchar_t* FirstString, const wchar_t* SecondString);
int StrnCmp(const wchar_t* FirstString, const wchar_t* SecondString, UINTN Length);
UINTN StrLen(const wchar_t* String);
UINTN AsciiStrLen(const char* String);
INTN AsciiStrCmp (const char *FirstString,const char *SecondString);

View File

@ -37,8 +37,8 @@ class XArray
virtual ~XArray();
public:
const TYPE *Data() const { return m_data; }
TYPE *Data() { return m_data; }
const TYPE *data() const { return m_data; }
TYPE *data() { return m_data; }
public:
xsize AllocatedSize() const { return m_allocatedSize; }
@ -137,7 +137,7 @@ template<class TYPE>
XArray<TYPE>::XArray(const XArray<TYPE> &anArray)
{
Init();
AddArray(anArray.Data(), anArray.size());
AddArray(anArray.data(), anArray.size());
}
/* operator = */
@ -147,7 +147,7 @@ const XArray<TYPE> &XArray<TYPE>::operator =(const XArray<TYPE> &anArray)
xsize ui;
setEmpty();
for ( ui=0 ; ui<anArray.Length() ; ui+=1 ) Add(anArray[ui] );
for ( ui=0 ; ui<anArray.length() ; ui+=1 ) Add(anArray[ui] );
return *this;
}

View File

@ -161,7 +161,7 @@ const XObjArray<TYPE> &XObjArray<TYPE>::operator =(const XObjArray<TYPE> &anObjA
xsize ui;
XObjArrayNC<TYPE>::Empty();
CheckSize(anObjArray.Length(), 0);
CheckSize(anObjArray.length(), 0);
for ( ui=0 ; ui<anObjArray.size() ; ui+=1 ) AddCopy(anObjArray.ElementAt(ui));
return *this;
}
@ -426,7 +426,7 @@ void XObjArrayNC<TYPE>::RemoveAtIndex(xsize nIndex)
if ( nIndex < XObjArrayNC<TYPE>::_Len )
{
if ( nIndex >= XObjArrayNC<TYPE>::_Len ) {
DebugLog(2, "void XObjArrayNC<TYPE>::RemoveAtIndex(xsize nIndex) : BUG nIndex (%d) is > Length(). System halted\n", nIndex);
DebugLog(2, "void XObjArrayNC<TYPE>::RemoveAtIndex(xsize nIndex) : BUG nIndex (%d) is > length(). System halted\n", nIndex);
panic();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,285 @@
//*************************************************************************************************
//*************************************************************************************************
//
// STRING
//
//*************************************************************************************************
//*************************************************************************************************
#if !defined(__XSTRING_H__)
#define __XSTRING_H__
#if 0
#define DBG(...) DebugLog(2, __VA_ARGS__)
#else
#define DBG(...)
#endif
#include "XToolsCommon.h"
#include "utf8Conversion.h"
#define PATH_SEPARATOR '\\'
extern UINTN XStringGrowByDefault;
//class XConstString;
class XStringW;
class XString
{
protected:
// char *_Data;
public:
char *c;
xsize m_allocatedSize;
void Init(xsize aSize=0);
XString();
XString(const XString &aString);
// XString(const XConstString &aConstString);
XString(const char *S);
XString(const char* S, xsize count);
XString(const wchar_t *S);
// XString(uchar);
XString(char);
XString(int);
XString(unsigned long long);
~XString();
public:
char *CheckSize(xsize nNewSize, xsize nGrowBy = XStringGrowByDefault);
public:
const char *data(xsize ui=0) const { return c+ui; }
char *data(xsize ui=0) { return (char*)(c+ui); }
char *data(int i) { if ( i<0 ) panic("const wchar_t *data(INTN i=0) const -> i < 0"); return c+i; }
char *DataWithSizeMin(xsize ui, xsize size, xsize nGrowBy=XStringGrowByDefault) { CheckSize(size, nGrowBy); return data(ui); }
xsize length() const { return (xsize)AsciiStrLen(c); }
xsize Size() const { return m_allocatedSize; }
void SetLength(xsize len);
/* IsNull ? */
void setEmpty() { c[0] = 0; }
bool isEmpty() const { return length() == 0; }
/* Cast */
operator const char *() const { return data(); }
// operator char *() { return data(); }
int ToInt() const;
UINTN ToUINTN() const;
XStringW wcs();
/* char [] */
char operator [](int i) const {
#if defined __XTOOLS_INT_CHECK__
if ( i < 0 ) DebugLog(2, "XString index cannot < 0");
panic();
#endif
return *data((unsigned int)i);
}
char operator [](xsize i) const { return *data(i); }
/* char& [] */
char& operator [](int i) {
#if defined __XTOOLS_INT_CHECK__
if ( i < 0 ) DebugLog(2, "XString index cannot < 0");
panic();
#endif
return *data(i);
}
char& operator [](xsize i) { return *data(i); }
char LastChar() const { if ( length() > 0 ) return data()[length()-1]; else return 0; }
void RemoveLastEspCtrl();
void SetNull() { SetLength(0); };
void StrCpy(const char *buf);
void StrnCpy(const char *buf, xsize len);
void StrnCat(const char *buf, xsize len);
void StrnCat(const char *buf);
void Delete(xsize pos, xsize count=1);
void Insert(xsize pos, const XString& Str);
void Cat(const XString &uneXString);
void vSPrintf(const char *Format, VA_LIST va);
void SPrintf(const char *format, ...) __attribute__((format (printf, 2, 3))); // 3 and 4 because of hidden parameter.
const XString& takeValueFrom(const char* S) { StrCpy(S); return *this; }
const XString &operator =(const XString &aString);
// const XString &operator =(const XConstString &aConstString);
const XString &operator =(const char* S);
const XString &operator =(char);
const XString &operator =(int);
const XString &operator =(unsigned int);
const XString &operator =(long);
const XString &operator =(unsigned long long);
const XString &operator += (const XString &);
// const XString &operator += (const XConstString &aConstString);
const XString &operator += (const char* S);
const XString &operator += (char);
const XString &operator += (int);
const XString &operator += (unsigned int);
const XString &operator += (long);
const XString &operator += (unsigned long long);
XString SubString(xsize pos, xsize count) const;
xsize IdxOf(char c, xsize Pos = 0) const;
xsize IdxOf(const XString &S, xsize Pos = 0) const;
#ifdef TODO_skqdjfhksqjhfksjqdf
xsize IdxOfIC(const XString &S, xsize Pos = 0) const;
xsize IdxOfIAC(const XString &S, xsize Pos = 0) const;
#endif
xsize RIdxOf(const XString &S, xsize Pos = MAX_XSIZE) const;
void ToLower(bool FirstCharIsCap = false);
bool IsLetters() const;
bool IsLettersNoAccent() const;
bool IsDigits() const;
bool IsDigits(xsize pos, xsize count) const;
bool ExistIn(const XString &S) const { return IdxOf(S) != MAX_XSIZE; }
#ifdef TODO_skqdjfhksqjhfksjqdf
bool ExistInIC(const XString &S) const { return IdxOfIC(S) != MAX_XSIZE; }
bool ExistInIAC(const XString &S) const { return IdxOfIC(S) != MAX_XSIZE; }
bool DeleteIC(const XString &S);
#endif
void Replace(char c1, char c2);
XString SubStringReplace(char c1, char c2);
// int Compare(const char* S) const { return (int)AsciiStrCmp(data(), (S ? S : "")); }// AsciiStrCmp return 0 or !0, not usual strcmp
#ifdef TODO_skqdjfhksqjhfksjqdf
//IC
int CompareIC(const char* S) const { return StringCompareIC(data(), (S ? S : "")); }
// IA
int CompareIA(const char* S) const { return StringCompareIA(data(), (S ? S : "")); }
// IAC
int CompareIAC(const char* S) const { return StringCompareIAC(data(), (S ? S : "")); }
/*
int CompareIACSubString(const char* S, size_t LenS) const { return SubStringCompareIAC(data(), length(), S, LenS); } //SubStringCompareIC renvoi 0 (ÈgalitÈ) si Len1 ou Len2 == 0
int CompareIACSubString(xsize Pos, const char* S, size_t LenS) const { return SubStringCompareIAC(data(Pos), length()-Pos, S, LenS); } //SubStringCompareIC renvoi 0 (ÈgalitÈ) si Len1 ou Len2 == 0
int CompareIACSubString(xsize Pos, xsize Len, const char* S, size_t LenS) const { return SubStringCompareIAC(data(Pos), Len, S, LenS); }
*/
#endif
bool Equal(const char* S) const { return AsciiStrCmp(data(), (S ? S : "")) == 0; };
// bool BeginEqual(const char* S) const { return StringBeginEqual(data(), S); }
// bool SubStringEqual(xsize Pos, const char* S) const { return StringBeginEqual(data(Pos), S); }
#ifdef TODO_skqdjfhksqjhfksjqdf
// IC
bool EqualIC(const char* S) const { return StringEqualIC(data(), S); }
bool BeginEqualIC(const char* S) const { return StringBeginEqualIC(data(), S); }
bool SubStringEqualIC(xsize Pos, const char* S) const { return StringBeginEqualIC(data(Pos), S); }
bool EqualSubStringIC(const char* S) const { return StringBeginEqualIC(S, data()); }
// IA
bool EqualIA(const char* S) const { return CompareIA(S) == 0; };
// IAC
bool EqualIAC(const char* S) const { return CompareIAC(S) == 0; };
bool BeginEqualIAC(const char* S) const { return StringBeginEqualIAC(data(), S); }
bool SubStringEqualIAC(xsize Pos, const char* S) const { return StringBeginEqualIAC(data(Pos), S); }
bool EqualSubStringIAC(const char* S) const { return StringBeginEqualIAC(S, data()); }
/* bool EqualIACSubString(const char* S, size_t LenS) const { return CompareIACSubString(S, LenS) == 0; }
bool EqualIACSubString(xsize Pos, const char* S, size_t LenS) const { return CompareIACSubString(Pos, S, LenS) == 0; }
bool EqualIACSubString(xsize Pos, xsize Len, const char* S, size_t LenS) const { return CompareIACSubString(Pos, Len, S, LenS) == 0; }
*/
#endif
XString basename() const;
XString dirname() const;
// size_t Sizeof() const { return size_t(sizeof(xsize)+length()); } // overflow ? underflow ?
// bool ReadFromBuf(const char *buf, size_t *idx, size_t count);
// bool WriteToBuf(char *buf, size_t *idx, size_t count) const;
// bool ReadFromFILE(FILE *fp);
// bool WriteToFILE(FILE *fp) const;
// //
// bool ReadFromXBuffer(XRBuffer &unXBuffer); // Impossible de mettre le XBuffer en const car il y a une variable d'instance de XBuffer incrÈmentÈe par ReadFromXBuffer
// void CatToXBuffer(XBuffer *unXBuffer) const;
//// void WriteToXBuffer(XBuffer *unXBuffer, xsize *idx) const;
public:
// OpÈrateur +
// 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 char *p2 ) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (const char *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 XConstString& p1, const XConstString& p2) { XString s; s=p1; s+=p2; return s; }
// friend XString operator + (const XConstString &p1, const char *p2 ) { XString s; s=p1; s+=p2; return s; }
// friend XString operator + (const char *p1, const XConstString &p2) { XString s; s=p1; s+=p2; return s; }
// Char
friend XString operator + (const XString& p1, char p2 ) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (char p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; }
// NumÈrique
friend XString operator + (const XString& p1, int p2 ) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (int p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (const XString& p1, unsigned int p2 ) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (unsigned int p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (const XString& p1, long p2 ) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (long p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (const XString& p1, unsigned long long p2 ) { XString s; s=p1; s+=p2; return s; }
friend XString operator + (unsigned long long p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; }
// OpÈrateur ==
// Chaines
friend bool operator == (const XString& s1, const XString& s2) { return s1.Equal(s2); }
friend bool operator == (const XString& s1, const char* s2 ) { return s1.Equal(s2); }
friend bool operator == (const char* s1, const XString& s2) { return s2.Equal(s1); }
// friend bool operator == (const XConstString &s1, const XString& s2) { return s1.Compare(s2) == 0; }
// friend bool operator == (const XString &s1, const XConstString& s2) { return s1.Compare(s2) == 0; }
// friend bool operator == (const XConstString &s1, const XConstString& s2) { return s1.Compare(s2) == 0; }
friend bool operator != (const XString& s1, const XString& s2) { return !s1.Equal(s2); }
friend bool operator != (const XString& s1, const char* s2 ) { return !s1.Equal(s2); }
friend bool operator != (const char* s1, const XString& s2) { return !s2.Equal(s1); }
// friend bool operator != (const XConstString &s1, const XString& s2) { return s1.Compare(s2) != 0; }
// friend bool operator != (const XString &s1, const XConstString& s2) { return s1.Compare(s2) != 0; }
// friend bool operator != (const XConstString &s1, const XConstString& s2) { return s1.Compare(s2) != 0; }
// friend bool operator < (const XString& s1, const XString& s2) { return s1.Compare(s2) < 0; }
// friend bool operator < (const XString& s1, const char* s2 ) { return s1.Compare(s2) < 0; }
// friend bool operator < (const char* s1, const XString& s2) { return s2.Compare(s1) > 0; }
//
// friend bool operator > (const XString& s1, const XString& s2) { return s1.Compare(s2) > 0; }
// friend bool operator > (const XString& s1, const char* s2 ) { return s1.Compare(s2) > 0; }
// friend bool operator > (const char* s1, const XString& s2) { return s2.Compare(s1) < 0; }
//
// friend bool operator <= (const XString& s1, const XString& s2) { return s1.Compare(s2) <= 0; }
// friend bool operator <= (const XString& s1, const char* s2 ) { return s1.Compare(s2) <= 0; }
// friend bool operator <= (const char* s1, const XString& s2) { return s2.Compare(s1) >= 0; }
//
// friend bool operator >= (const XString& s1, const XString& s2) { return s1.Compare(s2) >= 0; }
// friend bool operator >= (const XString& s1, const char* s2 ) { return s1.Compare(s2) >= 0; }
// friend bool operator >= (const char* s1, const XString& s2) { return s2.Compare(s1) <= 0; }
};
extern const XString NullXString;
XString SPrintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));;
XString SubString(const char *S, xsize pos, xsize count);
#ifdef TODO_skqdjfhksqjhfksjqdf
XString ToAlpha(const char *S);
XString ToAlpha(const XString &S);
XString ToLower(const char *S, bool FirstCharIsCap = false);
XString ToUpper(const char *S);
#endif
XString CleanCtrl(const XString &S);
#endif

View File

@ -32,7 +32,7 @@ void XStringW::Init(UINTN aSize)
//DBG("Init aSize=%d\n", aSize);
m_data = (wchar_t*)Xalloc( (aSize+1)*sizeof(wchar_t) ); /* le 0 terminal n'est pas compté dans mSize */
if ( !m_data ) {
DBG("XStringW::Init(%d) : Xalloc returned NULL. Cpu halted\n", (aSize+1)*sizeof(wchar_t));
DebugLog(2, "XStringW::Init(%d) : Xalloc returned NULL. Cpu halted\n", (aSize+1)*sizeof(wchar_t));
panic();
}
m_allocatedSize = aSize;
@ -129,6 +129,8 @@ DBG("Destructor :%s\n", data());
void XStringW::SetLength(UINTN len)
{
//DBG("SetLength(%d)\n", len);
CheckSize(len);
m_len = len;
m_data[len] = 0;
@ -251,19 +253,19 @@ XStringW XStringW::SubStringReplace(wchar_t c1, wchar_t c2)
return Result;
}
static XStringW* sprintfBuf;
static XStringW* XStringW_sprintfBuf;
void transmitSprintf(const wchar_t* buf, size_t nbyte)
static void XStringW_transmitSprintf(const wchar_t* buf, size_t nbyte)
{
(*sprintfBuf).StrnCat(buf, nbyte);
(*XStringW_sprintfBuf).StrnCat(buf, nbyte);
}
void XStringW::vSPrintf(const char* format, VA_LIST va)
{
SetLength(0);
sprintfBuf = this;
vprintf_with_callback(format, va, transmitSprintf);
XStringW_sprintfBuf = this;
vprintf_with_callback(format, va, XStringW_transmitSprintf);
// This is an attempt to use _PPrint from IO.c. Problem is : you have to allocate the memory BEFORE calling it.
// POOL_PRINT spc;
@ -515,7 +517,7 @@ const XStringW &XStringW::operator +=(const wchar_t *S)
// Functions
//-----------------------------------------------------------------------------
XStringW SPrintf(const char* format, ...)
XStringW WPrintf(const char* format, ...)
{
VA_LIST va;
XStringW str;

View File

@ -15,7 +15,7 @@
#define LPATH_SEPARATOR L'\\'
extern UINTN XStringWGrowByDefault;
extern void __GLOBAL__sub_I_XStringW();
//extern void __GLOBAL__sub_I_XStringW();
class XStringW
{
@ -187,9 +187,9 @@ public:
//extern const XStringW NullXStringW;
#ifndef _MSC_VER
XStringW SPrintf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2)));
XStringW WPrintf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2)));
#else
XStringW SPrintf(const char* format, ...);
XStringW WPrintf(const char* format, ...);
#endif // !__MSC_VER

View File

@ -0,0 +1,123 @@
#include <Platform.h>
#include "../cpp_foundation/XString.h"
#include "../cpp_foundation/utf8Conversion.h"
#include "global_test.h"
//#include <wchar.h>
int XString_tests()
{
#ifdef JIEF_DEBUG
// DebugLog(2, "XStringW_tests -> Enter\n");
#endif
if ( global_str1 != "global_str1" ) return 1;
if ( global_str2 != "global_str2" ) return 2;
#ifdef XSTRINGW_HAS_CTOR_LITTERAL
XStringW str("1");
if ( str != "1" ) return 3;
str.StrCat("2");
if ( str != "12" ) return 4;
#endif
XString str;
str.takeValueFrom("12");
XString str2;
if ( !str2.isEmpty() ) return 10;
str2.StrnCpy(str.data(), 2);
if ( str2 != "12" ) return 11;
str2.StrnCat("345", 2);
if ( str2 != "1234" ) return 12;
str2.Insert(1, str);
if ( str2 != "112234" ) return 13;
str2 += "6";
if ( str2 != "1122346" ) return 14;
str2 = "123";
str2.Insert(0, "x");
if ( str2 != "x123" ) return 15;
str2.Insert(4, "y");
if ( str2 != "x123y" ) return 16;
//wchar_t c2 = L'Ň';
//printf("1=%lc\n", c2);
//const char* s1 = "𐌾";
str2.SPrintf("%c", 'a'); // signle UTF8 ascii char
if ( str2 != "a" ) return 20;
str2.takeValueFrom("ab"); // UTF16(32) string containing ascii char
if ( str2 != "ab" ) return 21;
#ifdef _MSC_VER
// IMPORTANT : you can't pass a litteral char in a vararg function with Visual Studio (Microsoft strikes again :-).
// At least, you got a warning C4066
// IMPORTANT2 : Litteral string containing UTF16 char are WRONG. And you don't get a warning !!! If litteral is only ascii, it's ok.
// Maybe it's compilation option butI didn't find them.
wchar_t c = 'Ň'; // using an imtermediary var for Microsoft.
wchar_t s[2]; // wchar_t s2[] = "Ň";
s[0] = 'Ň';
s[1] = 0;
str2.SPrintf("%lc", c); // UTF16(32) char. (2 bytes in total if UTF16)
if (str2 != s) return 22;
str2.takeValueFrom("");
if (str2.length() != 0) return 221;
str2.takeValueFrom(s); // this is a UTF8 string 2 bytes long
if (str2 != s) return 23;
#else
str2.SPrintf("%lc", L'Ň'); // signe UTF16(32) char. (2 bytes in total if UTF16)
if ( str2 != "Ň" ) return 22;
str2.takeValueFrom("");
if (str2.length() != 0) return 221;
#ifdef XSTRING_HAS_CTOR_LITTERAL
str2.takeValueFrom("Ň"); // this is a UTF8 string 2 bytes long
if (str2 != "Ň") return 23; // utf8 litteral are converted to an XStringW if ctor is available.
#endif
str2.takeValueFrom("");
if (str2.length() != 0) return 231;
#ifdef XSTRING_HAS_CTOR_LITTERAL
str2.takeValueFrom("Ň"); // this is a UTF8 string 2 bytes long
if (str2 != "Ň") return 24;
#endif
#endif
#if __WCHAR_MAX__ > 0xFFFFu
str2.SPrintf("%lc", L'𐌾'); // L'𐌾' // this char cannot convert to an UTF16 char. So it doesn't compile with -fshort-wchar
if ( str2 != L'𐌾' ) return 30;
#endif
#ifndef _MSC_VER
// "𐌾" in UTF16 is 2 char : 0xd800, 0xdf3e
str2.takeValueFrom("𐌾"); // this is a UTF8 string 4 bytes long
if ( str2 != "𐌾" ) return 31;
str2.takeValueFrom("𐌾"); // this is a UTF16 or UTF32 string (depending of -fshort-wchar)
if ( str2 != "𐌾" ) return 32;
#ifdef XSTRINGW_HAS_CTOR_LITTERAL
{
XStringW str3("a");
if ( str3 != "a" ) return 40;
XStringW str4("aŇ𐌾");
if ( str4 != "aŇ𐌾" ) return 41;
}
#endif
#endif
XString str3(L"Выход");
if ( str3 != "Выход" ) return 50;
// XStringW CommonName("EFI\\CLOVER\\misc\\screenshot");
// for (UINTN Index = 0; Index < 20; Index++) {
// XStringW Name = CommonName + SPrintf("%lld", Index) + ".png";
// DebugLog(2, "XStringW_test shot: %s\n", Name.data());
// }
return 0;
}

View File

@ -0,0 +1 @@
int XString_tests();

View File

@ -6,6 +6,7 @@
#include "XArray_tests.h"
#include "XObjArray_tests.h"
#include "XStringWArray_test.h"
#include "XString_test.h"
#include "XStringW_test.h"
#include "XUINTN_test.h"
@ -26,6 +27,11 @@ bool all_tests()
DebugLog(2, "XObjArray_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = XString_tests();
if ( ret != 0 ) {
DebugLog(2, "XString_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = XStringW_tests();
if ( ret != 0 ) {
DebugLog(2, "XStringW_tests() failed at test %d\n", ret);

View File

@ -1,8 +1,12 @@
#include <Platform.h>
#include "global_test.h"
#include "../cpp_foundation/XString.h"
#include "../cpp_foundation/XStringW.h"
XStringTest global_str1("global_str1");
XStringTest global_str2("global_str2");
XStringWTest global_str3(L"global_str3");
XStringWTest global_str4(L"global_str4");

View File

@ -1,3 +1,4 @@
#include "../cpp_foundation/XString.h"
#include "../cpp_foundation/XStringW.h"
class XStringWTest : public XStringW
@ -9,5 +10,17 @@ public:
}
};
class XStringTest : public XString
{
public:
XStringTest(const char *S) : XString()
{
StrCpy(S);
}
};
extern XStringTest global_str1;
extern XStringTest global_str2;
extern XStringWTest global_str3;
extern XStringWTest global_str4;

View File

@ -641,7 +641,7 @@ EFI_STATUS egScreenShot(VOID)
XStringWP CommonName(L"EFI\\CLOVER\\misc\\screenshot");
for (UINTN Index = 0; Index < 60; Index++) {
// ScreenshotName = PoolPrint(L"%a%d.png", ScreenShotName, Index);
XStringW Name = CommonName + SPrintf("%lld", Index) + L".png";
XStringW Name = CommonName + WPrintf("%lld", Index) + L".png";
if (!FileExists(SelfRootDir, Name.data())) {
Status = egSaveFile(SelfRootDir, Name.data(), FileData, FileDataLength);
if (!EFI_ERROR(Status)) {