Rename XString to XString8.

This commit is contained in:
Jief L 2020-04-30 09:03:56 +03:00
parent 82b679bcbd
commit e170b16516
17 changed files with 62 additions and 57 deletions

View File

@ -1384,7 +1384,7 @@ EFI_STATUS SetStartupDiskVolume (
// Status = SetNvramVariable (L"efi-boot-device", &gEfiAppleBootGuid, Attributes, Size, EfiBootDevice);
// FreePool(EfiBootDevice);
XString EfiBootDevice;
XString8 EfiBootDevice;
EfiBootDevice.SPrintf(
"<array><dict>"
"<key>IOMatch</key>"

View File

@ -21,7 +21,7 @@ extern "C" {
#include "../../cpp_foundation/XString.h"
static XString stdio_static_buf;
static XString8 stdio_static_buf;
static XStringW stdio_static_wbuf;
int vprintf(const char* format, VA_LIST va)

View File

@ -57,7 +57,7 @@
// return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization.
//}
const XString NullXString;
const XString8 NullXString;
const XString16 NullXString16;
const XString32 NullXString32;
const XStringW NullXStringW;
@ -70,10 +70,10 @@ const XStringW NullXStringW;
//XStringW LStringW::operator + (const wchar_t* p2) { XStringW s; s.strcat(this->s()); s.strcat(p2); return s; }
XString SPrintf(const char* format, ...)
XString8 SPrintf(const char* format, ...)
{
va_list va;
XString str;
XString8 str;
va_start (va, format);
str.vSPrintf(format, va);

View File

@ -22,36 +22,36 @@
#endif
//------------------------------------------------------------------------------------------------------------------
class XString;
class LString8 : public LString<char, XString>
class XString8;
class LString8 : public LString<char, XString8>
{
public:
constexpr LString8() = delete;
constexpr LString8(const char* s) : LString<char, XString>(s) {};
constexpr LString8(const char* s) : LString<char, XString8>(s) {};
// no assignement, no destructor
friend constexpr LString8 operator "" _XS ( const char* s, size_t) { return LString8(s); }
};
class XString : public XStringAbstract<char, XString>
class XString8 : public XStringAbstract<char, XString8>
{
public:
XString() : XStringAbstract<char, XString>() {};
XString(const XString& S) : XStringAbstract<char, XString>(S) {}
XString(const LString8& S) : XStringAbstract<char, XString>(S) { }
XString8() : XStringAbstract<char, XString8>() {};
XString8(const XString8& S) : XStringAbstract<char, XString8>(S) {}
XString8(const LString8& S) : XStringAbstract<char, XString8>(S) { }
template<class OtherXStringClass, enable_if( is___String(OtherXStringClass) && !is___LString(OtherXStringClass))> // enable_if is to avoid constructing with a non-corresponding LString. To avoid memory allocation.
XString(const OtherXStringClass& S) : XStringAbstract<char, XString>(S) {}
XString8(const OtherXStringClass& S) : XStringAbstract<char, XString8>(S) {}
XString& operator=(const XString &S) { this->XStringAbstract<char, XString>::operator=(S); return *this; }
XString8& operator=(const XString8 &S) { this->XStringAbstract<char, XString8>::operator=(S); return *this; }
using XStringAbstract<char, XString>::operator =;
using XStringAbstract<char, XString8>::operator =;
protected:
static void transmitSPrintf(const char* buf, unsigned int nbchar, void* context)
{
((XString*)(context))->strncat(buf, nbchar);
((XString8*)(context))->strncat(buf, nbchar);
}
public:
void vSPrintf(const char* format, va_list va)
@ -176,14 +176,14 @@ constexpr LString16 operator"" _XS16 ( const char16_t* s, size_t len);
constexpr LString32 operator"" _XS32 ( const char32_t* s, size_t len);
constexpr LStringW operator"" _XSW ( const wchar_t* s, size_t len);
extern const XString NullXString;
extern const XString8 NullXString;
extern const XStringW NullXStringW;
#ifdef _MSC_VER
# define __attribute__(x)
#endif
XString SPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2)));
XString8 SPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2)));
XStringW SWPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2)));

View File

@ -240,7 +240,7 @@ class XStringArray_/* : public XStringArraySuper*/
};
class XStringArray : public XStringArray_<XString>
class XStringArray : public XStringArray_<XString8>
{
};
extern const XStringArray NullXStringArray;

View File

@ -183,14 +183,14 @@ int BootOptions_tests()
LoadOptions = Old1_AddLoadOption(LoadOptions, L"opt2");
LoadOptions = Old1_AddLoadOption(LoadOptions, L"opt3");
if ( XString().takeValueFrom(LoadOptions) != "opt1 opt2 opt3"_XS ) return 1;
if ( XString8().takeValueFrom(LoadOptions) != "opt1 opt2 opt3"_XS ) return 1;
CHAR16* LoadOptions1 = Old1_RemoveLoadOption(LoadOptions, L"opt1");
if ( XString().takeValueFrom(LoadOptions1) != "opt2 opt3"_XS ) return 2;
if ( XString8().takeValueFrom(LoadOptions1) != "opt2 opt3"_XS ) return 2;
CHAR16* LoadOptions2 = Old1_RemoveLoadOption(LoadOptions, L"opt2");
if ( XString().takeValueFrom(LoadOptions2) != "opt1 opt3"_XS ) return 3;
if ( XString8().takeValueFrom(LoadOptions2) != "opt1 opt3"_XS ) return 3;
CHAR16* LoadOptions3 = Old1_RemoveLoadOption(LoadOptions, L"opt3");
if ( XString().takeValueFrom(LoadOptions3) != "opt1 opt2"_XS ) return 4;
if ( XString8().takeValueFrom(LoadOptions3) != "opt1 opt2"_XS ) return 4;
}
// {
// XString LoadOptions;

View File

@ -267,10 +267,10 @@ struct XStringClassInfo
};
template<>
struct XStringClassInfo<XString>
struct XStringClassInfo<XString8>
{
typedef char ch_t;
typedef XString xs_t;
typedef XString8 xs_t;
static constexpr const char* prefix = "";
static constexpr const char* xStringClassName = "XString";
};
@ -306,7 +306,7 @@ template<>
struct XStringClassInfo<char>
{
typedef char ch_t;
typedef XString xs_t;
typedef XString8 xs_t;
static constexpr const char* prefix = "";
static constexpr const char* xStringClassName = "XString";
};
@ -342,7 +342,7 @@ template<>
struct XStringClassInfo<TestString<char>>
{
typedef char ch_t;
typedef XString xs_t;
typedef XString8 xs_t;
static constexpr const char* prefix = "";
static constexpr const char* xStringClassName = "XString";
};
@ -470,7 +470,7 @@ bool displayOnlyIfFailed_tmp;
__TEST_ALL_UTF2(test, XStringClass, classEncoding, wchar); \
#define TEST_ALL_CLASSES(test, macro) \
macro(test, XString, utf8); \
macro(test, XString8, utf8); \
macro(test, XString16, utf16); \
macro(test, XString32, utf32); \
macro(test, XStringW, wchar); \
@ -1518,9 +1518,14 @@ int XString_tests()
// printf("XString16_tests -> Enter\n");
#endif
//LString8 a = "dfsf"_XS;
//XStringW b = "ssdfsdf"_XS;
//XString c = a + b;
XString8 xs1 = "Test:"_XS;
XStringW xsw1 = L"world"_XSW;
XString8 xs2 = xs1 + "hel" + 'l' + L'o' + U" the " + xsw1;
XString8 xs3 = xs1;
LString8 a = "Hello"_XS;
XStringW b = L"world"_XSW;
XString8 c = a + "foo"; // + 'o' + L'o' + b + L"bar";
//char c = 1;
//int ii = sizeof(size_t);

View File

@ -9,10 +9,10 @@ public:
}
};
class XStringTest : public XString
class XStringTest : public XString8
{
public:
XStringTest(const char *S) : XString()
XStringTest(const char *S) : XString8()
{
strcpy(S);
}

View File

@ -64,7 +64,7 @@ const XStringW MACOSX_LOADER_PATH = L"\\System\\Library\\CoreServices\\boot.efi"
const XStringW LINUX_ISSUE_PATH = L"\\etc\\issue"_XSW;
#define LINUX_BOOT_PATH L"\\boot"
#define LINUX_BOOT_ALT_PATH L"\\boot"
const XString LINUX_LOADER_PATH = "vmlinuz"_XS;
const XString8 LINUX_LOADER_PATH = "vmlinuz"_XS;
const XStringW LINUX_FULL_LOADER_PATH = SWPrintf("%ls\\%s", LINUX_BOOT_PATH, LINUX_LOADER_PATH.c_str());
#define LINUX_LOADER_SEARCH_PATH L"vmlinuz*"
const XStringArray LINUX_DEFAULT_OPTIONS = Split<XStringArray>("ro add_efi_memmap quiet splash vt.handoff=7", " ");
@ -84,7 +84,7 @@ typedef struct LINUX_PATH_DATA
CONST XStringW Path;
CONST XStringW Title;
CONST XStringW Icon;
CONST XString Issue;
CONST XString8 Issue;
} LINUX_PATH_DATA;
typedef struct LINUX_ICON_DATA
@ -339,7 +339,7 @@ STATIC CONST XStringW& LinuxIconNameFromPath(IN CONST XStringW& Path,
return linux;
}
STATIC CONST XString LinuxInitImagePath[] = {
STATIC CONST XString8 LinuxInitImagePath[] = {
"initrd%s"_XS,
"initrd.img%s"_XS,
"initrd%s.img"_XS,

View File

@ -44,7 +44,7 @@
//#include "menu_items/menu_items.h"
//#include "../entry_scan/common.h"
CONST XString ArgOptional[NUM_OPT] = {
CONST XString8 ArgOptional[NUM_OPT] = {
"arch=i386"_XS, //0
"arch=x86_64"_XS, //1
"-v"_XS, //2

View File

@ -53,7 +53,7 @@ extern UINTN FrameTime;
textFaces textFace[4]; //0-help 1-message 2-menu 3-test, far future it will be infinite list with id
EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString& IconNameX, XImage* Image)
EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString8& IconNameX, XImage* Image)
{
EFI_STATUS Status = EFI_NOT_FOUND;
NSVGimage *SVGimage;
@ -95,7 +95,7 @@ EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString& IconNameX, XImage* Imag
shape->opacity = 0.f;
}
// if (strstr(shape->id, "BoundingRect") != NULL) {
if (XString().takeValueFrom(shape->id).contains("BoundingRect")) {
if (XString8().takeValueFrom(shape->id).contains("BoundingRect")) {
//there is bounds after nsvgParse()
IconImage->width = shape->bounds[2] - shape->bounds[0];
IconImage->height = shape->bounds[3] - shape->bounds[1];
@ -161,7 +161,7 @@ EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString& IconNameX, XImage* Imag
// if (strcmp(group->id, IconNameX.c_str()) == 0) {
// break;
// }
if (IconNameX == XString().takeValueFrom(group->id)) {
if (IconNameX == XString8().takeValueFrom(group->id)) {
break;
}
group = group->parent;
@ -434,7 +434,7 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer)
EFI_STATUS XTheme::LoadSvgFrame(INTN i, OUT XImage* XFrame)
{
EFI_STATUS Status = EFI_NOT_FOUND;
XString XFrameName = SPrintf("frame_%04lld", i+1);
XString8 XFrameName = SPrintf("frame_%04lld", i+1);
Status = ParseSVGXIcon(BUILTIN_ICON_ANIME, XFrameName, XFrame);
if (EFI_ERROR(Status)) {
DBG("frame '%s' not loaded, status=%s\n", XFrameName.c_str(), strerror(Status));

View File

@ -299,7 +299,7 @@ void XTheme::Init()
static XImage NullIcon;
static XImage DummyIcon;
const XImage& XTheme::GetIcon(const XString& Name)
const XImage& XTheme::GetIcon(const XString8& Name)
{
for (size_t i = 0; i < Icons.size(); i++)
{
@ -385,15 +385,15 @@ const XImage& XTheme::GetIconAlt(INTN Id, INTN Alt) //if not found then take emb
const XImage& XTheme::LoadOSIcon(const CHAR16* OSIconName)
{
return LoadOSIcon(XString().takeValueFrom(OSIconName));
return LoadOSIcon(XString8().takeValueFrom(OSIconName));
}
const XImage& XTheme::LoadOSIcon(const XString& Full)
const XImage& XTheme::LoadOSIcon(const XString8& Full)
{
// input value can be L"win", L"ubuntu,linux", L"moja,mac" set by GetOSIconName (OSVersion)
XString First;
XString Second;
XString Third;
XString8 First;
XString8 Second;
XString8 Third;
const XImage *ReturnImage;
UINTN Comma = Full.indexOf(',');
UINTN Size = Full.length();

View File

@ -15,7 +15,7 @@ class Icon
{
public:
INTN Id; //for example BUILTIN_ICON_POINTER
XString Name; //for example "os_moja", "vol_internal"
XString8 Name; //for example "os_moja", "vol_internal"
XImage Image;
XImage ImageNight;
bool Native;
@ -126,11 +126,11 @@ public:
//fill the theme
// const XImage& GetIcon(const char* Name);
// const XImage& GetIcon(const CHAR16* Name);
const XImage& GetIcon(const XString& Name); //get by name
const XImage& GetIcon(const XString8& Name); //get by name
const XImage& GetIcon(INTN Id); //get by id
const XImage& GetIconAlt(INTN Id, INTN Alt); //if id not found
const XImage& LoadOSIcon(const CHAR16* OSIconName); //TODO make XString provider
const XImage& LoadOSIcon(const XString& Full);
const XImage& LoadOSIcon(const XString8& Full);
bool CheckNative(INTN Id);
//fonts
@ -140,7 +140,7 @@ public:
INTN RenderText(IN const XStringW& Text, OUT XImage* CompImage_ptr,
IN INTN PosX, IN INTN PosY, IN UINTN Cursor, INTN textType, float textScale = 0.f);
//overload for UTF8 text
INTN RenderText(IN const XString& Text, OUT XImage* CompImage_ptr,
INTN RenderText(IN const XString8& Text, OUT XImage* CompImage_ptr,
IN INTN PosX, IN INTN PosY, IN UINTN Cursor, INTN textType, float textScale = 0.f);
VOID MeasureText(IN const XStringW& Text, OUT INTN *Width, OUT INTN *Height);
@ -151,7 +151,7 @@ public:
EFI_STATUS GetThemeTagSettings(void* DictPointer);
void parseTheme(void* p, const char** dict); //in nano project
EFI_STATUS ParseSVGXTheme(const CHAR8* buffer); // in VectorTheme
EFI_STATUS ParseSVGXIcon(INTN Id, const XString& IconNameX, XImage* Image);
EFI_STATUS ParseSVGXIcon(INTN Id, const XString8& IconNameX, XImage* Image);
void* LoadTheme(const CHAR16 *TestTheme); //return TagPtr why?
EFI_STATUS LoadSvgFrame(INTN i, OUT XImage* XFrame); // for animation

View File

@ -438,7 +438,7 @@ VOID egDumpGOPVideoModes(VOID);
EFI_STATUS egSetMode(INT32 Next);
VOID egGetScreenSize(OUT INTN *ScreenWidth, OUT INTN *ScreenHeight);
XString egScreenDescription(VOID);
XString8 egScreenDescription(VOID);
BOOLEAN egHasGraphicsMode(VOID);
BOOLEAN egIsGraphicsModeEnabled(VOID);
VOID egSetGraphicsModeEnabled(IN BOOLEAN Enable);

View File

@ -439,7 +439,7 @@ VOID egGetScreenSize(OUT INTN *ScreenWidth, OUT INTN *ScreenHeight)
*ScreenHeight = egScreenHeight;
}
XString egScreenDescription(VOID)
XString8 egScreenDescription(VOID)
{
if (egHasGraphics) {
if (GraphicsOutput != NULL) {

View File

@ -248,7 +248,7 @@ INTN XTheme::GetEmpty(const XImage& Buffer, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL&
return m;
}
INTN XTheme::RenderText(IN const XString& Text, OUT XImage* CompImage_ptr,
INTN XTheme::RenderText(IN const XString8& Text, OUT XImage* CompImage_ptr,
IN INTN PosX, IN INTN PosY, IN UINTN Cursor, INTN textType, float textScale)
{
const XStringW& UTF16Text = XStringW().takeValueFrom(Text.c_str());

View File

@ -751,7 +751,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry)
// Set boot argument for kernel if no caches, this should force kernel loading
if ( OSFLAG_ISSET(Entry->Flags, OSFLAG_NOCACHES) && !Entry->LoadOptions.containsStartWithIC("Kernel=") ) {
XString KernelLocation;
XString8 KernelLocation;
if (Entry->OSVersion && AsciiOSVersionToUint64(Entry->OSVersion) <= AsciiOSVersionToUint64("10.9")) {
KernelLocation.SPrintf("\"Kernel=/mach_kernel\"");
@ -2137,7 +2137,7 @@ RefitMain (IN EFI_HANDLE ImageHandle,
DBG(" string %ls, size=%lld, len=%lld sizeof=%ld iStrLen=%lld\n", aaa, StrSize(aaa), StrLen(aaa), sizeof(aaa), iStrLen(bbb, 10));
const CHAR8* ccc = "Выход ";
DBG(" string %s, size=%lld, len=%lld sizeof=%ld iStrLen=%lld\n", ccc, AsciiStrSize(ccc), AsciiStrLen(ccc), sizeof(ccc), iStrLen(ccc, 10));
XString ddd = "Выход "_XS;
XString8 ddd = "Выход "_XS;
// size_t sizex = ddd.allocatedSize();
DBG(" xstring %s, asize=%ld, sizeinbyte=%ld sizeof=%ld lastcharat=%ld\n", ddd.c_str(), ddd.allocatedSize(), ddd.sizeInBytes(), sizeof(ddd),
ddd.indexOf(ddd.lastChar()));