CloverBootloader/rEFIt_UEFI/cpp_foundation/XString.h

144 lines
4.2 KiB
C
Raw Normal View History

2020-03-12 15:40:38 +01:00
//*************************************************************************************************
//*************************************************************************************************
//
2020-04-23 15:20:48 +02:00
// STRING
//
// Developed by jief666, from 1997.
2020-03-12 15:40:38 +01:00
//
//*************************************************************************************************
//*************************************************************************************************
2020-04-23 15:20:48 +02:00
#if !defined(__XString_H__)
#define __XString_H__
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
#include "XToolsCommon.h"
#include "XStringAbstract.h"
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
#include "../../Include/Library/printf_lite.h"
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
#ifndef XString16GrowByDefault
#define XString16GrowByDefault 16
#endif
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
//typedef XStringAbstract<char> XString;
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
class XString : public XStringAbstract<char, XString>
2020-03-12 15:40:38 +01:00
{
public:
2020-04-23 15:20:48 +02:00
XString() : XStringAbstract<char, XString>() {};
XString(const XString& S) : XStringAbstract<char, XString>(S) {}
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
template<typename O, class OtherXStringClass>
XString(const XStringAbstract<O, OtherXStringClass> &S) : XStringAbstract<char, XString>(S) {}
2020-03-28 17:17:02 +01:00
2020-04-23 15:20:48 +02:00
XString& operator=(const XString &S) { this->XStringAbstract<char, XString>::operator=(S); return *this; }
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
using XStringAbstract<char, XString>::operator =;
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
protected:
static void transmitSPrintf(const char* buf, unsigned int nbchar, void* context)
{
((XString*)(context))->strncat(buf, nbchar);
}
public:
void vSPrintf(const char* format, va_list va)
{
setEmpty();
vprintf_with_callback(format, va, transmitSPrintf, this);
}
void SPrintf(const char* format, ...) __attribute__((__format__(__printf__, 2, 3)))
{
va_list va;
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
va_start (va, format);
vSPrintf(format, va);
va_end(va);
}
};
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
class XString16 : public XStringAbstract<char16_t, XString16>
{
2020-03-12 15:40:38 +01:00
public:
2020-04-23 15:20:48 +02:00
XString16() : XStringAbstract<char16_t, XString16>() {};
XString16(const XString16& S) : XStringAbstract<char16_t, XString16>(S) {}
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
template<typename O, class OtherXStringClass>
XString16(const XStringAbstract<O, OtherXStringClass> &S) : XStringAbstract<char16_t, XString16>(S) {}
2020-03-26 13:59:20 +01:00
2020-04-23 15:20:48 +02:00
XString16& operator=(const XString16 &S) { this->XStringAbstract<char16_t, XString16>::operator=(S); return *this; }
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
using XStringAbstract<char16_t, XString16>::operator =;
};
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
class XString32 : public XStringAbstract<char32_t, XString32>
{
public:
XString32() : XStringAbstract<char32_t, XString32>() {};
XString32(const XString32& S) : XStringAbstract<char32_t, XString32>(S) {}
2020-04-05 14:25:39 +02:00
2020-04-23 15:20:48 +02:00
template<typename O, class OtherXStringClass>
XString32(const XStringAbstract<O, OtherXStringClass> &S) : XStringAbstract<char32_t, XString32>(S) {}
2020-04-05 14:25:39 +02:00
2020-04-23 15:20:48 +02:00
XString32& operator=(const XString32 &S) { this->XStringAbstract<char32_t, XString32>::operator=(S); return *this; }
using XStringAbstract<char32_t, XString32>::operator =;
};
2020-04-05 14:25:39 +02:00
2020-04-23 15:20:48 +02:00
class XStringW : public XStringAbstract<wchar_t, XStringW>
{
public:
XStringW() : XStringAbstract<wchar_t, XStringW>() {};
XStringW(const XStringW& S) : XStringAbstract<wchar_t, XStringW>(S) {}
2020-04-05 14:25:39 +02:00
2020-04-23 15:20:48 +02:00
template<class OtherXStringClass>
XStringW(const OtherXStringClass& S) : XStringAbstract<wchar_t, XStringW>(S) {}
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
XStringW& operator=(const XStringW &S) { this->XStringAbstract<wchar_t, XStringW>::operator=(S); return *this; }
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
using XStringAbstract<wchar_t, XStringW>::operator =;
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
protected:
static void transmitSPrintf(const wchar_t* buf, unsigned int nbchar, void* context)
{
((XStringW*)(context))->strncat(buf, nbchar);
}
public:
void vSWPrintf(const char* format, va_list va)
{
setEmpty();
vwprintf_with_callback(format, va, transmitSPrintf, this);
}
void SWPrintf(const char* format, ...) __attribute__((__format__(__printf__, 2, 3)))
{
va_list va;
2020-03-12 15:40:38 +01:00
2020-04-23 15:20:48 +02:00
va_start (va, format);
vSWPrintf(format, va);
va_end(va);
}
2020-03-12 15:40:38 +01:00
};
XString operator"" _XS ( const char* s, size_t len);
2020-04-23 15:20:48 +02:00
XString16 operator"" _XS16 ( const char16_t* s, size_t len);
XString32 operator"" _XS32 ( const char32_t* s, size_t len);
XStringW operator"" _XSW ( const wchar_t* s, size_t len);
2020-04-23 15:20:48 +02:00
extern const XString NullXString;
extern const XStringW NullXStringW;
2020-04-05 14:25:39 +02:00
2020-04-23 15:20:48 +02:00
#ifdef _MSC_VER
# define __attribute__(x)
2020-03-12 15:40:38 +01:00
#endif
2020-04-23 15:20:48 +02:00
XString SPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2)));
XStringW SWPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2)));
2020-03-12 15:40:38 +01:00
#endif