mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-12-17 15:18:06 +01:00
71e952401a
Added unit tests
141 lines
3.1 KiB
C++
Executable File
141 lines
3.1 KiB
C++
Executable File
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
//
|
|
// STRINGS
|
|
//
|
|
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
#if !defined(__XSTRINGWS_CPP__)
|
|
#define __XSTRINGWS_CPP__
|
|
|
|
#include "XToolsCommon.h"
|
|
#include "XStringWArray.h"
|
|
#include <Platform.h>
|
|
|
|
|
|
const XStringWArray NullXStrings;
|
|
|
|
|
|
XStringWArray::XStringWArray() : XStringWArraySuper()
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
//
|
|
//-------------------------------------------------------------------------------------------------
|
|
void XStringWArray::AddStrings(const wchar_t *Val1, ...)
|
|
{
|
|
VA_LIST va;
|
|
const wchar_t *p;
|
|
|
|
AddCopy(Val1);
|
|
VA_START(va, Val1);
|
|
p = VA_ARG(va, const wchar_t *);
|
|
while ( p != nullptr ) {
|
|
AddCopy(p);
|
|
p = VA_ARG(va, const wchar_t *);
|
|
}
|
|
VA_END(va);
|
|
}
|
|
|
|
XStringW XStringWArray::ConcatAll(XStringW Separator, XStringW Prefix, XStringW Suffix) const
|
|
{
|
|
xsize i;
|
|
XStringW s;
|
|
|
|
if ( Length() > 0 ) {
|
|
s = Prefix;
|
|
s += ElementAt(0);
|
|
for ( i=1 ; i<Length() ; i+=1 ) {
|
|
s += Separator;
|
|
s += ElementAt(i);
|
|
}
|
|
s += Suffix;
|
|
}
|
|
return s;
|
|
}
|
|
|
|
bool XStringWArray::Equal(const XStringWArray &aStrings) const
|
|
{
|
|
xsize ui;
|
|
|
|
if ( Length() != aStrings.Length() ) return false;
|
|
for ( ui=0 ; ui<Length() ; ui+=1 ) {
|
|
if ( ElementAt(ui) != aStrings[ui] ) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool XStringWArray::Same(const XStringWArray &aStrings) const
|
|
{
|
|
xsize i;
|
|
|
|
for ( i=0 ; i<Length() ; i+=1 ) {
|
|
if ( !aStrings.Contains(ElementAt(i)) ) return false;
|
|
}
|
|
for ( i=0 ; i<aStrings.Length() ; i+=1 ) {
|
|
if ( !Contains(aStrings.ElementAt(i)) ) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool XStringWArray::Contains(const XStringW &S) const
|
|
{
|
|
xsize i;
|
|
|
|
for ( i=0 ; i<Length() ; i+=1 ) {
|
|
if ( ElementAt(i) == S ) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
// Add
|
|
//-------------------------------------------------------------------------------------------------
|
|
void XStringWArray::Add(const XStringWArray &aStrings)
|
|
{
|
|
xsize i;
|
|
|
|
for ( i=0 ; i<aStrings.Length() ; i+=1 ) {
|
|
AddCopy(aStrings[i]);
|
|
}
|
|
}
|
|
|
|
void XStringWArray::AddID(const XStringW &aString)
|
|
{
|
|
if ( !Contains(aString) ) AddCopy(aString);
|
|
}
|
|
|
|
void XStringWArray::AddID(const XStringWArray &aStrings)
|
|
{
|
|
xsize i;
|
|
|
|
for ( i=0 ; i<aStrings.Length() ; i+=1 ) {
|
|
if ( !Contains(aStrings[i]) ) AddCopy(aStrings[i]);
|
|
}
|
|
}
|
|
|
|
|
|
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
// Divers
|
|
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
|
|
XStringWArray Split(const XStringW &S, const XStringW &Separator)
|
|
{
|
|
XStringWArray Ss;
|
|
xsize idxB, idxE;
|
|
|
|
idxB = 0;
|
|
idxE = S.IdxOf(Separator, idxB);
|
|
while ( idxE != MAX_XSIZE ) {
|
|
Ss.AddCopy(SubString(S, idxB, idxE-idxB));
|
|
idxB = idxE + Separator.length();
|
|
idxE = S.IdxOf(Separator, idxB);
|
|
}
|
|
if ( idxB < S.length() ) Ss.AddCopy(SubString(S, idxB, S.length()-idxB));
|
|
return Ss;
|
|
}
|
|
|
|
|
|
|
|
#endif
|