|
|
|
|
@ -51,7 +51,7 @@ namespace KviTQString
|
|
|
|
|
// The global empty (and null) string
|
|
|
|
|
const TQString empty;
|
|
|
|
|
|
|
|
|
|
bool equalCSN(const TQString &sz1,const TQString &sz2,unsigned int len)
|
|
|
|
|
KVILIB_API bool equalCSN(const TQString &sz1,const TQString &sz2,unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
if(len == 0)return true; // assume equal
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
@ -71,7 +71,7 @@ namespace KviTQString
|
|
|
|
|
return (c1 == c1e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool equalCIN(const TQString &sz1,const TQString &sz2,unsigned int len)
|
|
|
|
|
KVILIB_API bool equalCIN(const TQString &sz1,const TQString &sz2,unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
if(len == 0)return true; // assume equal
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
@ -91,7 +91,7 @@ namespace KviTQString
|
|
|
|
|
return (c1 == c1e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool equalCSN(const TQString &sz1,const char * sz2,unsigned int len)
|
|
|
|
|
KVILIB_API bool equalCSN(const TQString &sz1,const char * sz2,unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
if(len == 0)return true; // assume equal
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
@ -110,7 +110,7 @@ namespace KviTQString
|
|
|
|
|
return (c1 == c1e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool equalCIN(const TQString &sz1,const char * sz2,unsigned int len)
|
|
|
|
|
KVILIB_API bool equalCIN(const TQString &sz1,const char * sz2,unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
if(len == 0)return true; // assume equal
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
@ -130,7 +130,7 @@ namespace KviTQString
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sz2 is assumed to be null terminated, sz1 is not!
|
|
|
|
|
bool equalCIN(const TQString &sz1,const TQChar *sz2,unsigned int len)
|
|
|
|
|
KVILIB_API bool equalCIN(const TQString &sz1,const TQChar *sz2,unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
if(len == 0)return true; // assume equal
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
@ -149,7 +149,7 @@ namespace KviTQString
|
|
|
|
|
return (c1 == c1e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TQString makeSizeReadable(size_t bytes)
|
|
|
|
|
KVILIB_API TQString makeSizeReadable(size_t bytes)
|
|
|
|
|
{
|
|
|
|
|
double size = bytes;
|
|
|
|
|
if(size<900)
|
|
|
|
|
@ -173,7 +173,7 @@ namespace KviTQString
|
|
|
|
|
return TQString(__tr2qs("%1 TB")).arg(size,0,'f',3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool equalCS(const TQString &sz1,const TQString &sz2)
|
|
|
|
|
KVILIB_API bool equalCS(const TQString &sz1,const TQString &sz2)
|
|
|
|
|
{
|
|
|
|
|
if(sz1.length() != sz2.length())return false;
|
|
|
|
|
|
|
|
|
|
@ -192,7 +192,7 @@ namespace KviTQString
|
|
|
|
|
return (c1 == c1e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool equalCI(const TQString &sz1,const TQString &sz2)
|
|
|
|
|
KVILIB_API bool equalCI(const TQString &sz1,const TQString &sz2)
|
|
|
|
|
{
|
|
|
|
|
if(sz1.length() != sz2.length())return false;
|
|
|
|
|
|
|
|
|
|
@ -212,7 +212,7 @@ namespace KviTQString
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sz2 is assumed to be null terminated, sz1 is not!
|
|
|
|
|
bool equalCI(const TQString &sz1,const TQChar *sz2)
|
|
|
|
|
KVILIB_API bool equalCI(const TQString &sz1,const TQChar *sz2)
|
|
|
|
|
{
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
const TQChar * c1e = c1 + sz1.length();
|
|
|
|
|
@ -229,7 +229,7 @@ namespace KviTQString
|
|
|
|
|
return (c1 == c1e) && (!sz2->unicode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool equalCS(const TQString &sz1,const char * sz2)
|
|
|
|
|
KVILIB_API bool equalCS(const TQString &sz1,const char * sz2)
|
|
|
|
|
{
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
const TQChar * c1e = c1 + sz1.length();
|
|
|
|
|
@ -245,7 +245,7 @@ namespace KviTQString
|
|
|
|
|
return ((c1 == c1e) && (*sz2 == '\0'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool equalCI(const TQString &sz1,const char * sz2)
|
|
|
|
|
KVILIB_API bool equalCI(const TQString &sz1,const char * sz2)
|
|
|
|
|
{
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
const TQChar * c1e = c1 + sz1.length();
|
|
|
|
|
@ -261,7 +261,7 @@ namespace KviTQString
|
|
|
|
|
return ((c1 == c1e) && (*sz2 == '\0'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cmpCS(const TQString &sz1,const TQString &sz2)
|
|
|
|
|
KVILIB_API int cmpCS(const TQString &sz1,const TQString &sz2)
|
|
|
|
|
{
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
const TQChar * c2 = sz2.unicode();
|
|
|
|
|
@ -295,7 +295,7 @@ namespace KviTQString
|
|
|
|
|
return 0; // never here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cmpCI(const TQString &sz1,const TQString &sz2)
|
|
|
|
|
KVILIB_API int cmpCI(const TQString &sz1,const TQString &sz2)
|
|
|
|
|
{
|
|
|
|
|
const TQChar * c1 = sz1.unicode();
|
|
|
|
|
const TQChar * c2 = sz2.unicode();
|
|
|
|
|
@ -328,7 +328,7 @@ namespace KviTQString
|
|
|
|
|
return 0; // never here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cmpCIN(const TQString &sz1,const TQString &sz2,unsigned int len)
|
|
|
|
|
KVILIB_API int cmpCIN(const TQString &sz1,const TQString &sz2,unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
if(len == 0)return 0; // assume equal
|
|
|
|
|
unsigned int l1 = MY_MIN(len,sz1.length());
|
|
|
|
|
@ -356,12 +356,12 @@ namespace KviTQString
|
|
|
|
|
return diff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ensureLastCharIs(TQString &szString,const TQChar &c)
|
|
|
|
|
KVILIB_API void ensureLastCharIs(TQString &szString,const TQChar &c)
|
|
|
|
|
{
|
|
|
|
|
if(!lastCharIs(szString,c))szString.append(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TQString getToken(TQString &szString,const TQChar &sep)
|
|
|
|
|
KVILIB_API TQString getToken(TQString &szString,const TQChar &sep)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i=0;
|
|
|
|
|
while(i < szString.length())
|
|
|
|
|
@ -387,7 +387,7 @@ namespace KviTQString
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stripRightWhiteSpace(TQString &s)
|
|
|
|
|
KVILIB_API void stripRightWhiteSpace(TQString &s)
|
|
|
|
|
{
|
|
|
|
|
unsigned int iRemove = 0;
|
|
|
|
|
while(iRemove < s.length())
|
|
|
|
|
@ -398,7 +398,7 @@ namespace KviTQString
|
|
|
|
|
if(iRemove > 0)s.remove(s.length() - iRemove,iRemove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stripRight(TQString &s,const TQChar &c)
|
|
|
|
|
KVILIB_API void stripRight(TQString &s,const TQChar &c)
|
|
|
|
|
{
|
|
|
|
|
unsigned int iRemove = 0;
|
|
|
|
|
while(iRemove < s.length())
|
|
|
|
|
@ -409,7 +409,7 @@ namespace KviTQString
|
|
|
|
|
if(iRemove > 0)s.remove(s.length() - iRemove,iRemove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stripLeft(TQString &s,const TQChar &c)
|
|
|
|
|
KVILIB_API void stripLeft(TQString &s,const TQChar &c)
|
|
|
|
|
{
|
|
|
|
|
unsigned int iRemove = 0;
|
|
|
|
|
while(iRemove < s.length())
|
|
|
|
|
@ -422,53 +422,53 @@ namespace KviTQString
|
|
|
|
|
if(iRemove > 0)s.remove(0,iRemove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void detach(TQString &sz)
|
|
|
|
|
KVILIB_API void detach(TQString &sz)
|
|
|
|
|
{
|
|
|
|
|
sz.setLength(sz.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TQChar * nullTerminatedArray(const TQString &sz)
|
|
|
|
|
KVILIB_API const TQChar * nullTerminatedArray(const TQString &sz)
|
|
|
|
|
{
|
|
|
|
|
//sz.setLength(sz.length()); // detach!
|
|
|
|
|
return (const TQChar *)sz.ucs2(); // MAY BE NULL!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void appendNumber(TQString &s,double dReal)
|
|
|
|
|
KVILIB_API void appendNumber(TQString &s,double dReal)
|
|
|
|
|
{
|
|
|
|
|
char buffer[512];
|
|
|
|
|
::sprintf(buffer,"%f",dReal);
|
|
|
|
|
s.append(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void appendNumber(TQString &s,int iInteger)
|
|
|
|
|
KVILIB_API void appendNumber(TQString &s,int iInteger)
|
|
|
|
|
{
|
|
|
|
|
char buffer[64];
|
|
|
|
|
::sprintf(buffer,"%d",iInteger);
|
|
|
|
|
s.append(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void appendNumber(TQString &s,kvi_i64_t iInteger)
|
|
|
|
|
KVILIB_API void appendNumber(TQString &s,kvi_i64_t iInteger)
|
|
|
|
|
{
|
|
|
|
|
char buffer[64];
|
|
|
|
|
::sprintf(buffer,"%ld",iInteger);
|
|
|
|
|
s.append(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void appendNumber(TQString &s,kvi_u64_t uInteger)
|
|
|
|
|
KVILIB_API void appendNumber(TQString &s,kvi_u64_t uInteger)
|
|
|
|
|
{
|
|
|
|
|
char buffer[64];
|
|
|
|
|
::sprintf(buffer,"%lu",uInteger);
|
|
|
|
|
s.append(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void appendNumber(TQString &s,unsigned int uInteger)
|
|
|
|
|
KVILIB_API void appendNumber(TQString &s,unsigned int uInteger)
|
|
|
|
|
{
|
|
|
|
|
char buffer[64];
|
|
|
|
|
::sprintf(buffer,"%u",uInteger);
|
|
|
|
|
s.append(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vsprintf(TQString &s,const TQString &szFmt,kvi_va_list list)
|
|
|
|
|
KVILIB_API void vsprintf(TQString &s,const TQString &szFmt,kvi_va_list list)
|
|
|
|
|
{
|
|
|
|
|
#define MEMINCREMENT 32
|
|
|
|
|
|
|
|
|
|
@ -690,7 +690,7 @@ namespace KviTQString
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TQString & sprintf(TQString &s,const TQString &szFmt,...)
|
|
|
|
|
KVILIB_API TQString & sprintf(TQString &s,const TQString &szFmt,...)
|
|
|
|
|
{
|
|
|
|
|
kvi_va_list list;
|
|
|
|
|
kvi_va_start_by_reference(list,szFmt);
|
|
|
|
|
@ -700,7 +700,7 @@ namespace KviTQString
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void appendFormatted(TQString &s,const TQString &szFmt,...)
|
|
|
|
|
KVILIB_API void appendFormatted(TQString &s,const TQString &szFmt,...)
|
|
|
|
|
{
|
|
|
|
|
TQString tmp;
|
|
|
|
|
kvi_va_list list;
|
|
|
|
|
@ -711,7 +711,7 @@ namespace KviTQString
|
|
|
|
|
s.append(tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool matchWildExpressionsCI(const TQString &szM1,const TQString &szM2)
|
|
|
|
|
KVILIB_API bool matchWildExpressionsCI(const TQString &szM1,const TQString &szM2)
|
|
|
|
|
{
|
|
|
|
|
//Matches two regular expressions containging wildcards (* and ?)
|
|
|
|
|
|
|
|
|
|
@ -804,7 +804,7 @@ namespace KviTQString
|
|
|
|
|
return (!(m2->unicode())); //m1 surely finished , so for the match , m2 must be finished too
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool matchStringCI(const TQString &szExp,const TQString &szStr,bool bIsRegExp,bool bExact)
|
|
|
|
|
KVILIB_API bool matchStringCI(const TQString &szExp,const TQString &szStr,bool bIsRegExp,bool bExact)
|
|
|
|
|
{
|
|
|
|
|
TQString szWildcard;
|
|
|
|
|
TQChar* ptr=(TQChar*)szExp.ucs2();
|
|
|
|
|
@ -826,7 +826,7 @@ namespace KviTQString
|
|
|
|
|
return re.search(szStr) != -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool matchStringCS(const TQString &szExp,const TQString &szStr,bool bIsRegExp,bool bExact)
|
|
|
|
|
KVILIB_API bool matchStringCS(const TQString &szExp,const TQString &szStr,bool bIsRegExp,bool bExact)
|
|
|
|
|
{
|
|
|
|
|
TQString szWildcard;
|
|
|
|
|
TQChar* ptr=(TQChar*)szExp.ucs2();
|
|
|
|
|
@ -848,21 +848,21 @@ namespace KviTQString
|
|
|
|
|
return re.search(szStr) != -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cutFromFirst(TQString &s,const TQChar &c,bool bIncluded)
|
|
|
|
|
KVILIB_API void cutFromFirst(TQString &s,const TQChar &c,bool bIncluded)
|
|
|
|
|
{
|
|
|
|
|
int idx = s.find(c);
|
|
|
|
|
if(idx == -1)return;
|
|
|
|
|
s.truncate(bIncluded ? idx : idx + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cutFromLast(TQString &s,const TQChar &c,bool bIncluded)
|
|
|
|
|
KVILIB_API void cutFromLast(TQString &s,const TQChar &c,bool bIncluded)
|
|
|
|
|
{
|
|
|
|
|
int idx = s.findRev(c);
|
|
|
|
|
if(idx == -1)return;
|
|
|
|
|
s.truncate(bIncluded ? idx : idx + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cutToFirst(TQString &s,const TQChar &c,bool bIncluded,bool bClearIfNotFound)
|
|
|
|
|
KVILIB_API void cutToFirst(TQString &s,const TQChar &c,bool bIncluded,bool bClearIfNotFound)
|
|
|
|
|
{
|
|
|
|
|
int idx = s.find(c);
|
|
|
|
|
if(idx == -1)
|
|
|
|
|
@ -873,7 +873,7 @@ namespace KviTQString
|
|
|
|
|
s.remove(0,bIncluded ? idx + 1 : idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cutToLast(TQString &s,const TQChar &c,bool bIncluded,bool bClearIfNotFound)
|
|
|
|
|
KVILIB_API void cutToLast(TQString &s,const TQChar &c,bool bIncluded,bool bClearIfNotFound)
|
|
|
|
|
{
|
|
|
|
|
int idx = s.findRev(c);
|
|
|
|
|
if(idx == -1)
|
|
|
|
|
@ -884,21 +884,21 @@ namespace KviTQString
|
|
|
|
|
s.remove(0,bIncluded ? idx + 1 : idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cutFromFirst(TQString &s,const TQString &c,bool bIncluded)
|
|
|
|
|
KVILIB_API void cutFromFirst(TQString &s,const TQString &c,bool bIncluded)
|
|
|
|
|
{
|
|
|
|
|
int idx = s.find(c);
|
|
|
|
|
if(idx == -1)return;
|
|
|
|
|
s.truncate(bIncluded ? idx : idx + c.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cutFromLast(TQString &s,const TQString &c,bool bIncluded)
|
|
|
|
|
KVILIB_API void cutFromLast(TQString &s,const TQString &c,bool bIncluded)
|
|
|
|
|
{
|
|
|
|
|
int idx = s.findRev(c);
|
|
|
|
|
if(idx == -1)return;
|
|
|
|
|
s.truncate(bIncluded ? idx : idx + c.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cutToFirst(TQString &s,const TQString &c,bool bIncluded,bool bClearIfNotFound)
|
|
|
|
|
KVILIB_API void cutToFirst(TQString &s,const TQString &c,bool bIncluded,bool bClearIfNotFound)
|
|
|
|
|
{
|
|
|
|
|
int idx = s.find(c);
|
|
|
|
|
if(idx == -1)
|
|
|
|
|
@ -909,7 +909,7 @@ namespace KviTQString
|
|
|
|
|
s.remove(0,bIncluded ? idx + c.length() : idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cutToLast(TQString &s,const TQString &c,bool bIncluded,bool bClearIfNotFound)
|
|
|
|
|
KVILIB_API void cutToLast(TQString &s,const TQString &c,bool bIncluded,bool bClearIfNotFound)
|
|
|
|
|
{
|
|
|
|
|
int idx = s.findRev(c);
|
|
|
|
|
if(idx == -1)
|
|
|
|
|
@ -920,7 +920,7 @@ namespace KviTQString
|
|
|
|
|
s.remove(0,bIncluded ? idx + c.length() : idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TQString upperISO88591(const TQString &szSrc)
|
|
|
|
|
KVILIB_API TQString upperISO88591(const TQString &szSrc)
|
|
|
|
|
{
|
|
|
|
|
const TQChar * c = nullTerminatedArray(szSrc);
|
|
|
|
|
if(!c)
|
|
|
|
|
@ -946,7 +946,7 @@ namespace KviTQString
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TQString lowerISO88591(const TQString &szSrc)
|
|
|
|
|
KVILIB_API TQString lowerISO88591(const TQString &szSrc)
|
|
|
|
|
{
|
|
|
|
|
const TQChar * c = nullTerminatedArray(szSrc);
|
|
|
|
|
if(!c)
|
|
|
|
|
@ -973,7 +973,7 @@ namespace KviTQString
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void transliterate(TQString &s,const TQString &szToFind,const TQString &szReplacement)
|
|
|
|
|
KVILIB_API void transliterate(TQString &s,const TQString &szToFind,const TQString &szReplacement)
|
|
|
|
|
{
|
|
|
|
|
int i=0;
|
|
|
|
|
int il = MY_MIN(szToFind.length(),szReplacement.length());
|
|
|
|
|
@ -992,7 +992,7 @@ namespace KviTQString
|
|
|
|
|
|
|
|
|
|
static char hexdigits[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
|
|
|
|
|
|
|
|
|
|
void bufferToHex(TQString &szRetBuffer,const unsigned char * buffer,unsigned int len)
|
|
|
|
|
KVILIB_API void bufferToHex(TQString &szRetBuffer,const unsigned char * buffer,unsigned int len)
|
|
|
|
|
{
|
|
|
|
|
szRetBuffer.setLength(len * 2);
|
|
|
|
|
unsigned int i=0;
|
|
|
|
|
|