2020-02-23 12:21:28 +01:00
|
|
|
//*************************************************************************************************
|
|
|
|
//*************************************************************************************************
|
|
|
|
//
|
2020-02-15 15:51:18 +01:00
|
|
|
// STRING
|
2020-02-23 12:21:28 +01:00
|
|
|
//
|
|
|
|
// Developed by jief666, from 1997.
|
|
|
|
//
|
|
|
|
//*************************************************************************************************
|
|
|
|
//*************************************************************************************************
|
|
|
|
|
2020-02-15 15:51:18 +01:00
|
|
|
|
|
|
|
#if !defined(__XStringW_CPP__)
|
|
|
|
#define __XStringW_CPP__
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define DBG(...) DebugLog(2, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DBG(...)
|
|
|
|
#endif
|
|
|
|
|
2020-02-23 12:21:28 +01:00
|
|
|
#include "XToolsCommon.h"
|
2020-02-15 15:51:18 +01:00
|
|
|
#include "XStringW.h"
|
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
#include "../../Include/Library/printf_lite.h"
|
2020-02-15 15:51:18 +01:00
|
|
|
|
|
|
|
UINTN XStringWGrowByDefault = 1024;
|
2020-02-23 12:21:28 +01:00
|
|
|
const XStringW NullXStringW;
|
2020-02-15 15:51:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
void XStringW::Init(UINTN aSize)
|
|
|
|
{
|
|
|
|
//DBG("Init aSize=%d\n", aSize);
|
2020-03-21 14:12:26 +01:00
|
|
|
m_data = (wchar_t*)malloc( (aSize+1)*sizeof(wchar_t) ); /* le 0 terminal n'est pas compté dans mSize */
|
2020-02-15 15:51:18 +01:00
|
|
|
if ( !m_data ) {
|
2020-03-12 15:40:38 +01:00
|
|
|
DebugLog(2, "XStringW::Init(%d) : Xalloc returned NULL. Cpu halted\n", (aSize+1)*sizeof(wchar_t));
|
2020-03-09 02:12:24 +01:00
|
|
|
panic();
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
2020-03-09 02:12:24 +01:00
|
|
|
m_allocatedSize = aSize;
|
2020-02-15 15:51:18 +01:00
|
|
|
m_len = 0;
|
|
|
|
m_data[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
// Constructor
|
|
|
|
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
|
|
|
|
XStringW::XStringW()
|
|
|
|
{
|
|
|
|
DBG("Construteur\n");
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
XStringW::XStringW(const XStringW &aString)
|
|
|
|
{
|
|
|
|
DBG("Constructor(const XStringW &aString) : %s\n", aString.data());
|
|
|
|
Init(aString.length());
|
2020-02-21 10:44:15 +01:00
|
|
|
StrnCpy(aString.data(), aString.length());
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
2020-03-10 17:50:55 +01:00
|
|
|
//
|
|
|
|
//XStringW::XStringW(const wchar_t *S)
|
|
|
|
//{
|
|
|
|
// if ( !S ) {
|
|
|
|
// DebugLog(2, "XStringW(const wchar_t *S) called with NULL. Use setEmpty()\n");
|
|
|
|
// panic();
|
|
|
|
// }
|
|
|
|
//DBG("Constructor(const wchar_t *S) : %s, StrLen(S)=%d\n", S, StrLen(S));
|
|
|
|
// Init(StrLen(S));
|
|
|
|
// StrCpy(S);
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//XStringW::XStringW(const wchar_t *S, UINTN count)
|
|
|
|
//{
|
|
|
|
//DBG("Constructor(const wchar_t *S, UINTN count) : %s, %d\n", S, count);
|
|
|
|
// Init(count);
|
|
|
|
// StrnCpy(S, count);
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//XStringW::XStringW(const wchar_t aChar)
|
|
|
|
//{
|
|
|
|
//DBG("Constructor(const wchar_t aChar)\n");
|
|
|
|
// Init(1);
|
|
|
|
// StrnCpy(&aChar, 1);
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//XStringW::XStringW(const char* S)
|
|
|
|
//{
|
|
|
|
//DBG("Constructor(const char* S)\n");
|
|
|
|
// xsize newLen = StrLenInWChar(S, AsciiStrLen(S));
|
|
|
|
// Init(newLen);
|
|
|
|
// utf8ToWChar(m_data, m_allocatedSize+1, S, AsciiStrLen(S)); // m_size doesn't count the NULL terminator
|
|
|
|
// SetLength(newLen);
|
|
|
|
//}
|
2020-03-21 14:12:26 +01:00
|
|
|
wchar_t * XStringW::forgetDataWithoutFreeing()
|
|
|
|
{
|
|
|
|
wchar_t* ret = m_data;
|
|
|
|
Init();
|
|
|
|
return ret;
|
|
|
|
}
|
2020-02-15 15:51:18 +01:00
|
|
|
|
2020-03-10 17:50:55 +01:00
|
|
|
const XStringW& XStringW::takeValueFrom(const wchar_t* S)
|
2020-02-15 15:51:18 +01:00
|
|
|
{
|
2020-03-10 17:50:55 +01:00
|
|
|
if ( !S ) {
|
|
|
|
DebugLog(2, "takeValueFrom(const wchar_t* S) called with NULL. Use setEmpty()\n");
|
|
|
|
panic();
|
|
|
|
}
|
2020-03-21 14:12:26 +01:00
|
|
|
Init(wcslen(S));
|
2020-03-10 17:50:55 +01:00
|
|
|
StrCpy(S);
|
|
|
|
return *this;
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
2020-03-10 17:50:55 +01:00
|
|
|
const XStringW& XStringW::takeValueFrom(const char* S)
|
2020-02-24 14:07:24 +01:00
|
|
|
{
|
2020-03-11 15:23:58 +01:00
|
|
|
xsize newLen = StrLenInWChar(S);
|
2020-02-24 14:07:24 +01:00
|
|
|
Init(newLen);
|
2020-03-11 15:23:58 +01:00
|
|
|
utf8ToWChar(m_data, m_allocatedSize+1, S); // m_size doesn't count the NULL terminator
|
2020-03-10 17:50:55 +01:00
|
|
|
SetLength(newLen);
|
|
|
|
return *this;
|
2020-02-24 14:07:24 +01:00
|
|
|
}
|
|
|
|
|
2020-02-15 15:51:18 +01:00
|
|
|
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
// Destructor
|
|
|
|
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
|
|
|
|
|
|
|
|
XStringW::~XStringW()
|
|
|
|
{
|
|
|
|
DBG("Destructor :%s\n", data());
|
2020-03-21 14:12:26 +01:00
|
|
|
free((void*)m_data);
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
//
|
|
|
|
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
|
|
|
|
void XStringW::SetLength(UINTN len)
|
|
|
|
{
|
|
|
|
//DBG("SetLength(%d)\n", len);
|
2020-03-12 15:40:38 +01:00
|
|
|
CheckSize(len);
|
|
|
|
|
2020-02-15 15:51:18 +01:00
|
|
|
m_len = len;
|
|
|
|
m_data[len] = 0;
|
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
if ( wcslen(data()) != len ) {
|
2020-02-15 15:51:18 +01:00
|
|
|
DBG("XStringW::SetLength(UINTN len) : StrLen(data()) != len (%d != %d). System halted\n", StrLen(data()), len);
|
2020-03-09 02:12:24 +01:00
|
|
|
panic();
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CheckSize() */
|
|
|
|
wchar_t *XStringW::CheckSize(UINTN nNewSize, UINTN nGrowBy)
|
|
|
|
{
|
|
|
|
//DBG("CheckSize: m_size=%d, nNewSize=%d\n", m_size, nNewSize);
|
|
|
|
|
2020-03-09 02:12:24 +01:00
|
|
|
if ( m_allocatedSize < nNewSize )
|
2020-02-15 15:51:18 +01:00
|
|
|
{
|
|
|
|
nNewSize += nGrowBy;
|
2020-03-21 14:12:26 +01:00
|
|
|
m_data = (wchar_t*)realloc(m_data, (nNewSize+1)*sizeof(wchar_t), m_allocatedSize*sizeof(wchar_t));
|
2020-02-15 15:51:18 +01:00
|
|
|
if ( !m_data ) {
|
2020-02-23 12:21:28 +01:00
|
|
|
DBG("XStringW::CheckSize(%d, %d) : Xrealloc(%d, %d, %d) returned NULL. System halted\n", nNewSize, nGrowBy, m_size, (nNewSize+1)*sizeof(wchar_t), m_data);
|
2020-03-09 02:12:24 +01:00
|
|
|
panic();
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
2020-03-09 02:12:24 +01:00
|
|
|
m_allocatedSize = nNewSize;
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void XStringW::StrnCpy(const wchar_t *buf, UINTN len)
|
|
|
|
{
|
2020-03-10 17:50:55 +01:00
|
|
|
UINTN newLen = 0;
|
2020-02-15 15:51:18 +01:00
|
|
|
if ( buf && *buf && len > 0 ) {
|
|
|
|
CheckSize(len, 0);
|
2020-03-10 17:50:55 +01:00
|
|
|
while ( *buf && newLen < len ) {
|
|
|
|
m_data[newLen++] = *buf++;
|
|
|
|
}
|
2020-03-21 14:12:26 +01:00
|
|
|
// memmove(data(), buf, len*sizeof(wchar_t));
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
2020-03-10 17:50:55 +01:00
|
|
|
SetLength(newLen); /* data()[len]=0 done in SetLength */
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void XStringW::StrCpy(const wchar_t *buf)
|
|
|
|
{
|
|
|
|
if ( buf && *buf ) {
|
2020-03-21 14:12:26 +01:00
|
|
|
StrnCpy(buf, wcslen(buf));
|
2020-02-15 15:51:18 +01:00
|
|
|
}else{
|
|
|
|
SetLength(0); /* data()[0]=0 done in SetLength */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void XStringW::StrnCat(const wchar_t *buf, UINTN len)
|
|
|
|
{
|
|
|
|
UINTN NewLen;
|
|
|
|
|
|
|
|
if ( buf && *buf && len > 0 ) {
|
|
|
|
NewLen = length()+len;
|
|
|
|
CheckSize(NewLen, 0);
|
2020-03-21 14:12:26 +01:00
|
|
|
memmove(data(length()), buf, len*sizeof(wchar_t));
|
2020-02-15 15:51:18 +01:00
|
|
|
SetLength(NewLen); /* data()[NewLen]=0 done in SetLength */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 20:02:32 +01:00
|
|
|
void XStringW::StrCat(const wchar_t *buf)
|
2020-02-15 15:51:18 +01:00
|
|
|
{
|
|
|
|
if ( buf && *buf ) {
|
2020-03-21 14:12:26 +01:00
|
|
|
StrnCat(buf, wcslen(buf));
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void XStringW::StrCat(const XStringW &uneXStringWW)
|
|
|
|
{
|
2020-02-21 22:22:30 +01:00
|
|
|
StrnCat(uneXStringWW.data(), uneXStringWW.length());
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void XStringW::Delete(UINTN pos, UINTN count)
|
|
|
|
{
|
|
|
|
if ( pos < length() ) {
|
2020-02-23 21:23:31 +01:00
|
|
|
if ( count != MAX_XSIZE && pos + count < length() ) {
|
2020-03-21 14:12:26 +01:00
|
|
|
memmove( data(pos), data(pos+count), (length()-pos-count)*sizeof(wchar_t)); // memmove handles overlapping memory move
|
2020-02-15 15:51:18 +01:00
|
|
|
SetLength(length()-count);/* data()[length()-count]=0 done in SetLength */
|
|
|
|
}else{
|
|
|
|
SetLength(pos);/* data()[pos]=0 done in SetLength */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void XStringW::Insert(UINTN pos, const XStringW& Str)
|
|
|
|
{
|
|
|
|
if ( pos < length() ) {
|
|
|
|
CheckSize(length()+Str.length());
|
2020-03-21 14:12:26 +01:00
|
|
|
memmove(data(pos + Str.length()), data(pos), (length()-pos)*sizeof(wchar_t));
|
|
|
|
memmove(data(pos), Str.data(), Str.length()*sizeof(wchar_t));
|
2020-02-15 15:51:18 +01:00
|
|
|
SetLength(length()+Str.length());
|
|
|
|
}else{
|
2020-02-21 22:22:30 +01:00
|
|
|
StrCat(Str);
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void XStringW::Replace(wchar_t c1, wchar_t c2)
|
|
|
|
{
|
|
|
|
wchar_t* p;
|
|
|
|
|
|
|
|
p = data();
|
|
|
|
while ( *p ) {
|
|
|
|
if ( *p == c1 ) *p = c2;
|
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XStringW XStringW::SubStringReplace(wchar_t c1, wchar_t c2)
|
|
|
|
{
|
|
|
|
wchar_t* p;
|
|
|
|
XStringW Result;
|
|
|
|
|
|
|
|
p = data();
|
|
|
|
while ( *p ) {
|
|
|
|
if ( *p == c1 ) Result += c2;
|
|
|
|
else Result += *p;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
//static XStringW* XStringW_sprintfBuf;
|
2020-02-24 14:07:24 +01:00
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
static void XStringW_transmitSPrintf(const wchar_t* buf, unsigned int nbchar, void* context)
|
2020-02-24 14:07:24 +01:00
|
|
|
{
|
2020-03-21 14:12:26 +01:00
|
|
|
// (*XStringW_sprintfBuf).StrnCat(buf, nbchar);
|
|
|
|
((XStringW*)(context))->StrnCat(buf, nbchar);
|
2020-02-24 14:07:24 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
void XStringW::vSPrintf(const char* format, va_list va)
|
2020-02-15 15:51:18 +01:00
|
|
|
{
|
2020-02-24 14:07:24 +01:00
|
|
|
SetLength(0);
|
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
// XStringW_sprintfBuf = this;
|
|
|
|
|
|
|
|
vwprintf_with_callback(format, va, XStringW_transmitSPrintf, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is an attempt to use _PPrint from IO.c. Problem is : you have to allocate the memory BEFORE calling it.
|
|
|
|
//void XStringW::vSPrintf(const char* format, va_list va)
|
|
|
|
//{
|
2020-02-23 21:23:31 +01:00
|
|
|
// POOL_PRINT spc;
|
|
|
|
// PRINT_STATE ps;
|
|
|
|
//
|
|
|
|
// ZeroMem(&spc, sizeof (spc));
|
|
|
|
// spc.Str = data();
|
|
|
|
// SetLength(0);
|
|
|
|
// spc.Len = 0;
|
|
|
|
// spc.Maxlen = m_size;
|
|
|
|
// ZeroMem(&ps, sizeof (ps));
|
|
|
|
// ps.Output = (IN EFI_STATUS (EFIAPI *)(VOID *context, CONST CHAR16 *str))_PoolPrint;
|
|
|
|
// ps.Context = (void*)&spc;
|
|
|
|
// ps.fmt.u.pw = format;
|
|
|
|
//
|
|
|
|
// VA_COPY(ps.args, va);
|
|
|
|
// _PPrint (&ps);
|
2020-03-21 14:12:26 +01:00
|
|
|
// va_end(ps.args);
|
|
|
|
//}
|
2020-02-15 15:51:18 +01:00
|
|
|
|
2020-02-24 14:07:24 +01:00
|
|
|
void XStringW::SPrintf(const char* format, ...)
|
2020-02-15 15:51:18 +01:00
|
|
|
{
|
2020-03-21 14:12:26 +01:00
|
|
|
va_list va;
|
2020-02-15 15:51:18 +01:00
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
va_start (va, format);
|
2020-02-15 15:51:18 +01:00
|
|
|
vSPrintf(format, va);
|
2020-03-21 14:12:26 +01:00
|
|
|
va_end(va);
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
XStringW XStringW::basename() const
|
|
|
|
{
|
|
|
|
UINTN idx = RIdxOf(LPATH_SEPARATOR);
|
2020-02-23 21:23:31 +01:00
|
|
|
if ( idx == MAX_XSIZE ) return NullXStringW;
|
2020-02-21 22:22:30 +01:00
|
|
|
return SubString(idx+1, length()-idx-1);
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
XStringW XStringW::dirname() const
|
|
|
|
{
|
|
|
|
UINTN idx = RIdxOf(LPATH_SEPARATOR);
|
2020-02-23 21:23:31 +01:00
|
|
|
if ( idx == MAX_XSIZE ) return NullXStringW;
|
2020-02-21 22:22:30 +01:00
|
|
|
return SubString(0, idx);
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
XStringW XStringW::SubString(UINTN pos, UINTN count) const
|
|
|
|
{
|
|
|
|
if ( count > length()-pos ) count = length()-pos;
|
2020-03-10 17:50:55 +01:00
|
|
|
XStringW ret;
|
|
|
|
ret.StrnCat(&(data()[pos]), count);
|
|
|
|
return ret;
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
UINTN XStringW::IdxOf(wchar_t aChar, UINTN Pos) const
|
|
|
|
{
|
|
|
|
UINTN Idx;
|
|
|
|
|
|
|
|
for ( Idx=Pos ; Idx<length() ; Idx+=1 ) {
|
|
|
|
if ( data()[Idx] == aChar ) return Idx;
|
|
|
|
}
|
2020-02-23 21:23:31 +01:00
|
|
|
return MAX_XSIZE;
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
UINTN XStringW::IdxOf(const XStringW &S, UINTN Pos) const
|
|
|
|
{
|
|
|
|
UINTN i;
|
|
|
|
UINTN Idx;
|
|
|
|
|
2020-02-23 21:23:31 +01:00
|
|
|
if ( length() < S.length() ) return MAX_XSIZE;
|
2020-02-15 15:51:18 +01:00
|
|
|
for ( Idx=Pos ; Idx<=length()-S.length() ; Idx+=1 ) {
|
|
|
|
i = 0;
|
|
|
|
while( i<S.length() && ( data()[Idx+i] - S[i] ) == 0 ) i += 1;
|
|
|
|
if ( i == S.length() ) return Idx;
|
|
|
|
}
|
2020-02-23 21:23:31 +01:00
|
|
|
return MAX_XSIZE;
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
UINTN XStringW::RIdxOf(const wchar_t charToSearch, UINTN Pos) const
|
|
|
|
{
|
|
|
|
UINTN Idx;
|
|
|
|
|
|
|
|
if ( Pos > length() ) Pos = length();
|
2020-02-23 21:23:31 +01:00
|
|
|
if ( Pos < 1 ) return MAX_XSIZE;
|
2020-02-15 15:51:18 +01:00
|
|
|
for ( Idx=Pos ; Idx-- > 0 ; ) {
|
|
|
|
if ( m_data[Idx] == charToSearch ) return Idx;
|
|
|
|
}
|
2020-02-23 21:23:31 +01:00
|
|
|
return MAX_XSIZE;
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
UINTN XStringW::RIdxOf(const XStringW &S, UINTN Pos) const
|
|
|
|
{
|
|
|
|
UINTN i;
|
|
|
|
UINTN Idx;
|
|
|
|
|
2020-02-23 21:23:31 +01:00
|
|
|
if ( S.length() == 0 ) return MAX_XSIZE;
|
2020-02-15 15:51:18 +01:00
|
|
|
if ( Pos > length() ) Pos = length();
|
2020-02-23 21:23:31 +01:00
|
|
|
if ( Pos < S.length() ) return MAX_XSIZE;
|
2020-02-15 15:51:18 +01:00
|
|
|
Pos -= S.length();
|
|
|
|
for ( Idx=Pos+1 ; Idx-- > 0 ; ) {
|
|
|
|
i = 0;
|
|
|
|
while( i<S.length() && data()[Idx+i] == S[i] ) i += 1;
|
|
|
|
if ( i == S.length() ) return Idx;
|
|
|
|
}
|
2020-02-23 21:23:31 +01:00
|
|
|
return MAX_XSIZE;
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool XStringW::IsDigits() const
|
|
|
|
{
|
|
|
|
const wchar_t *p;
|
|
|
|
|
|
|
|
p = data();
|
|
|
|
if ( !*p ) return false;
|
|
|
|
for ( ; *p ; p+=1 ) {
|
|
|
|
if ( *p < '0' ) return false;
|
|
|
|
if ( *p > '9' ) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XStringW::IsDigits(UINTN pos, UINTN count) const
|
|
|
|
{
|
|
|
|
const wchar_t *p;
|
|
|
|
const wchar_t *q;
|
|
|
|
|
|
|
|
if ( pos >= length() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( pos+count > length() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
p = data() + pos;
|
|
|
|
q = p + count;
|
|
|
|
for ( ; p < q ; p+=1 ) {
|
|
|
|
if ( *p < '0' ) return false;
|
|
|
|
if ( *p > '9' ) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XStringW::RemoveLastEspCtrl()
|
|
|
|
{
|
|
|
|
wchar_t *p;
|
|
|
|
|
|
|
|
if ( length() > 0 ) {
|
|
|
|
p = data() + length() - 1;
|
|
|
|
if ( *p >= 0 && *p <= ' ' ) {
|
|
|
|
p -= 1;
|
|
|
|
while ( p>data() && *p >= 0 && *p <= ' ' ) p -= 1;
|
|
|
|
if ( p>data() ) {
|
|
|
|
SetLength( (UINTN)(p-data())+1);
|
|
|
|
}else{
|
|
|
|
if ( *p >= 0 && *p <= ' ' ) SetLength(0);
|
|
|
|
else SetLength(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
|
|
//bool XStringW::ReadFromFILE(FILE *fp)
|
|
|
|
//{
|
|
|
|
// UINTN longueur;
|
|
|
|
//
|
|
|
|
// if ( fread(&longueur, sizeof(longueur), 1, fp) != 1 ) goto fin;
|
|
|
|
// if ( longueur > 0 && fread(dataWithSizeMin(0, longueur), sizeof(wchar_t), longueur, fp) != 1 ) goto fin;
|
|
|
|
// SetLength(longueur);
|
|
|
|
// return true;
|
|
|
|
// fin:
|
|
|
|
// SetNull();
|
|
|
|
// return false;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//bool XStringW::WriteToFILE(FILE *fp) const
|
|
|
|
//{
|
|
|
|
// UINTN longueur;
|
|
|
|
//
|
|
|
|
// longueur = length();
|
|
|
|
// if ( fwrite(&longueur, sizeof(longueur), 1, fp) != 1 ) return false;
|
|
|
|
// if ( longueur > 0 && fwrite(data(), sizeof(wchar_t), longueur, fp) != 1 ) return false;
|
|
|
|
// return true;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//*************************************************************************************************
|
|
|
|
//
|
|
|
|
// Operators =
|
|
|
|
//
|
|
|
|
//*************************************************************************************************
|
|
|
|
|
|
|
|
const XStringW &XStringW::operator =(const XStringW &aString)
|
|
|
|
{
|
|
|
|
//TRACE("Operator =const XStringW&\n");
|
|
|
|
StrnCpy(aString.data(), aString.length());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-03-10 17:50:55 +01:00
|
|
|
//
|
|
|
|
//const XStringW &XStringW::operator =(wchar_t aChar)
|
|
|
|
//{
|
|
|
|
////TRACE("Operator =wchar_t \n");
|
|
|
|
// StrnCpy(&aChar, 1);
|
|
|
|
// return *this;
|
|
|
|
//}
|
|
|
|
|
|
|
|
//const XStringW &XStringW::operator =(const wchar_t *S)
|
|
|
|
//{
|
|
|
|
////TRACE("Operator =const wchar_t *\n");
|
|
|
|
// if ( S == NULL ) {
|
|
|
|
// DBG("operator =(const wchar_t *S) called with NULL\n");
|
|
|
|
// panic();
|
|
|
|
// }
|
|
|
|
// StrCpy(S);
|
|
|
|
// return *this;
|
|
|
|
//}
|
2020-02-15 15:51:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*************************************************************************************************
|
|
|
|
//
|
|
|
|
// Operators +=
|
|
|
|
//
|
|
|
|
//*************************************************************************************************
|
|
|
|
|
|
|
|
const XStringW &XStringW::operator +=(wchar_t aChar)
|
|
|
|
{
|
|
|
|
//TRACE("Operator +=wchar_t \n");
|
|
|
|
StrnCat(&aChar, 1);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const XStringW &XStringW::operator +=(const XStringW &aString)
|
|
|
|
{
|
|
|
|
//TRACE("Operator +=const XStringW&\n");
|
|
|
|
StrnCat(aString.data(), aString.length());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const XStringW &XStringW::operator +=(const wchar_t *S)
|
|
|
|
{
|
|
|
|
//TRACE("operator +=const wchar_t *\n");
|
|
|
|
StrCat(S);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Functions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2020-03-12 15:40:38 +01:00
|
|
|
XStringW WPrintf(const char* format, ...)
|
2020-02-15 15:51:18 +01:00
|
|
|
{
|
2020-03-21 14:12:26 +01:00
|
|
|
va_list va;
|
2020-02-15 15:51:18 +01:00
|
|
|
XStringW str;
|
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
va_start (va, format);
|
2020-02-15 15:51:18 +01:00
|
|
|
str.vSPrintf(format, va);
|
2020-03-21 14:12:26 +01:00
|
|
|
va_end(va);
|
2020-02-15 15:51:18 +01:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
XStringW SubString(const wchar_t *S, UINTN pos, UINTN count)
|
|
|
|
{
|
2020-03-21 14:12:26 +01:00
|
|
|
if ( wcslen(S)-pos < count ) count = wcslen(S)-pos;
|
2020-03-10 17:50:55 +01:00
|
|
|
XStringW ret;
|
|
|
|
ret.StrnCpy(S+pos, count);
|
|
|
|
// return ( XStringW(S+pos, count) );
|
|
|
|
return ret;
|
2020-02-15 15:51:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
XStringW CleanCtrl(const XStringW &S)
|
|
|
|
{
|
|
|
|
XStringW ReturnValue;
|
|
|
|
UINTN i;
|
|
|
|
|
|
|
|
for ( i=0 ; i<S.length() ; i+=1 ) {
|
|
|
|
if ( S[i] >=0 && S[i] < ' ' ) ReturnValue += 'x'; /* wchar_t are signed !!! */
|
|
|
|
else ReturnValue += S[i];
|
|
|
|
}
|
|
|
|
return ReturnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|