2020-04-23 15:20:48 +02:00
|
|
|
//*************************************************************************************************
|
|
|
|
//*************************************************************************************************
|
|
|
|
//
|
2020-03-12 15:40:38 +01:00
|
|
|
// STRING
|
2020-04-23 15:20:48 +02:00
|
|
|
//
|
|
|
|
// Developed by jief666, from 1997.
|
|
|
|
//
|
|
|
|
//*************************************************************************************************
|
|
|
|
//*************************************************************************************************
|
2020-03-12 15:40:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
2020-04-24 11:30:09 +02:00
|
|
|
#define DBG(...) printf__VA_ARGS__)
|
2020-03-12 15:40:38 +01:00
|
|
|
#else
|
|
|
|
#define DBG(...)
|
|
|
|
#endif
|
|
|
|
|
2020-04-24 11:30:09 +02:00
|
|
|
#include <Platform.h>
|
2020-03-12 15:40:38 +01:00
|
|
|
#include "XString.h"
|
|
|
|
|
2020-03-21 14:12:26 +01:00
|
|
|
#include "../../Include/Library/printf_lite.h"
|
2020-03-12 15:40:38 +01:00
|
|
|
|
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Functions
|
|
|
|
//-----------------------------------------------------------------------------
|
2020-03-12 15:40:38 +01:00
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
XString operator"" _XS ( const char* s, size_t len)
|
2020-03-12 15:40:38 +01:00
|
|
|
{
|
2020-04-23 15:20:48 +02:00
|
|
|
XString returnValue;
|
|
|
|
returnValue.takeValueFrom(s, len);
|
|
|
|
return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization.
|
2020-03-12 15:40:38 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
XString16 operator"" _XS16 ( const char16_t* s, size_t len)
|
2020-03-12 15:40:38 +01:00
|
|
|
{
|
2020-04-23 15:20:48 +02:00
|
|
|
XString16 returnValue;
|
|
|
|
returnValue.takeValueFrom(s, len);
|
|
|
|
return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization.
|
2020-03-12 15:40:38 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
XString32 operator"" _XS32 ( const char32_t* s, size_t len)
|
2020-03-12 15:40:38 +01:00
|
|
|
{
|
2020-04-23 15:20:48 +02:00
|
|
|
XString32 returnValue;
|
|
|
|
returnValue.takeValueFrom(s, len);
|
|
|
|
return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization.
|
2020-03-12 15:40:38 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
XStringW operator"" _XSW ( const wchar_t* s, size_t len)
|
2020-03-12 15:40:38 +01:00
|
|
|
{
|
2020-04-23 15:20:48 +02:00
|
|
|
XStringW returnValue;
|
|
|
|
returnValue.takeValueFrom(s, len);
|
|
|
|
return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization.
|
2020-03-12 15:40:38 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
const XString NullXString;
|
|
|
|
const XStringW NullXStringW;
|
2020-03-12 15:40:38 +01:00
|
|
|
|
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
XString SPrintf(const char* format, ...)
|
2020-03-12 15:40:38 +01:00
|
|
|
{
|
2020-04-23 15:20:48 +02:00
|
|
|
va_list va;
|
|
|
|
XString str;
|
2020-03-12 15:40:38 +01:00
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
va_start (va, format);
|
|
|
|
str.vSPrintf(format, va);
|
2020-03-12 15:40:38 +01:00
|
|
|
va_end(va);
|
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
return str;
|
2020-03-12 15:40:38 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
XStringW SWPrintf(const char* format, ...)
|
2020-03-12 15:40:38 +01:00
|
|
|
{
|
2020-04-23 15:20:48 +02:00
|
|
|
va_list va;
|
|
|
|
XStringW str;
|
2020-03-12 15:40:38 +01:00
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
va_start (va, format);
|
|
|
|
str.vSWPrintf(format, va);
|
|
|
|
va_end(va);
|
2020-03-12 15:40:38 +01:00
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
return str;
|
2020-03-12 15:40:38 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
//XStringW SubString(const wchar_t *S, UINTN pos, UINTN count)
|
2020-03-12 15:40:38 +01:00
|
|
|
//{
|
2020-04-23 15:20:48 +02:00
|
|
|
// if ( wcslen(S)-pos < count ) count = wcslen(S)-pos;
|
|
|
|
// XStringW ret;
|
|
|
|
// ret.StrnCpy(S+pos, count);
|
|
|
|
//// return ( XStringW(S+pos, count) );
|
|
|
|
// return ret;
|
2020-03-12 15:40:38 +01:00
|
|
|
//}
|
|
|
|
//
|
|
|
|
//
|
2020-04-23 15:20:48 +02:00
|
|
|
//XStringW CleanCtrl(const XStringW &S)
|
2020-03-12 15:40:38 +01:00
|
|
|
//{
|
2020-04-23 15:20:48 +02:00
|
|
|
// XStringW ReturnValue;
|
|
|
|
// UINTN i;
|
2020-03-12 15:40:38 +01:00
|
|
|
//
|
2020-04-23 15:20:48 +02:00
|
|
|
// for ( i=0 ; i<S.size() ; i+=1 ) {
|
|
|
|
//#if __WCHAR_MIN__ < 0
|
|
|
|
// if ( S.wc_str()[i] >=0 && S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* wchar_t are signed */
|
|
|
|
//#else
|
|
|
|
// if ( S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* wchar_t are unsigned */
|
2020-03-12 15:40:38 +01:00
|
|
|
//#endif
|
2020-04-23 15:20:48 +02:00
|
|
|
// else ReturnValue += S.wc_str()[i];
|
2020-03-21 14:12:26 +01:00
|
|
|
// }
|
|
|
|
// return ReturnValue;
|
|
|
|
//}
|
2020-03-12 15:40:38 +01:00
|
|
|
|
2020-04-23 15:20:48 +02:00
|
|
|
|