diff --git a/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj b/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj index d262435cb..d2ce2155c 100644 --- a/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj +++ b/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj @@ -136,13 +136,11 @@ 9AC77FB924176C04005CDD5C /* XStringWArray_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ECC24176C04005CDD5C /* XStringWArray_test.h */; }; 9AC77FBA24176C04005CDD5C /* XArray_tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ECD24176C04005CDD5C /* XArray_tests.h */; }; 9AC77FBB24176C04005CDD5C /* XStringWArray_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ECE24176C04005CDD5C /* XStringWArray_test.cpp */; }; - 9AC77FBF24176C04005CDD5C /* XStringW_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ED224176C04005CDD5C /* XStringW_test.h */; }; 9AC77FC024176C04005CDD5C /* XObjArray_tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ED324176C04005CDD5C /* XObjArray_tests.h */; }; 9AC77FC124176C04005CDD5C /* all_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ED424176C04005CDD5C /* all_tests.cpp */; }; 9AC77FC224176C04005CDD5C /* XObjArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ED524176C04005CDD5C /* XObjArray_tests.cpp */; }; 9AC77FC324176C04005CDD5C /* XArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ED624176C04005CDD5C /* XArray_tests.cpp */; }; 9AC77FC424176C04005CDD5C /* all_tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ED724176C04005CDD5C /* all_tests.h */; }; - 9AC77FC524176C04005CDD5C /* XStringW_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ED824176C04005CDD5C /* XStringW_test.cpp */; }; 9AC77FFD24176C04005CDD5C /* Version.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F1224176C04005CDD5C /* Version.h */; }; 9AC77FFE24176C04005CDD5C /* syslinux_mbr.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F1424176C04005CDD5C /* syslinux_mbr.h */; }; 9AC77FFF24176C04005CDD5C /* Handle.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F1524176C04005CDD5C /* Handle.h */; }; @@ -285,9 +283,7 @@ 9AC7808C24176C04005CDD5C /* remove_ref.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAA24176C04005CDD5C /* remove_ref.h */; }; 9AC7808D24176C04005CDD5C /* XStringWArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAC24176C04005CDD5C /* XStringWArray.h */; }; 9AC7808E24176C04005CDD5C /* XToolsCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAD24176C04005CDD5C /* XToolsCommon.h */; }; - 9AC7808F24176C04005CDD5C /* XStringW.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAE24176C04005CDD5C /* XStringW.h */; }; 9AC7809024176C04005CDD5C /* XStringWArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77FAF24176C04005CDD5C /* XStringWArray.cpp */; }; - 9AC7809124176C04005CDD5C /* XStringW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77FB024176C04005CDD5C /* XStringW.cpp */; }; 9AC7809524176C04005CDD5C /* XToolsCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77FB424176C04005CDD5C /* XToolsCommon.cpp */; }; 9AC7809724176C04005CDD5C /* XArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FB624176C04005CDD5C /* XArray.h */; }; 9AC7809824176C04005CDD5C /* XObjArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FB724176C04005CDD5C /* XObjArray.h */; }; @@ -310,7 +306,6 @@ 9ACFE65E24309AF80071CC93 /* remove_ref.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAA24176C04005CDD5C /* remove_ref.h */; }; 9ACFE66024309AF80071CC93 /* loader.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F4824176C04005CDD5C /* loader.h */; }; 9ACFE66124309AF80071CC93 /* AmlGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F1E24176C04005CDD5C /* AmlGenerator.h */; }; - 9ACFE66224309AF80071CC93 /* XStringW.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAE24176C04005CDD5C /* XStringW.h */; }; 9ACFE66424309AF80071CC93 /* BootLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AF4173C242F15CB00D2644C /* BootLog.h */; }; 9ACFE66724309AF80071CC93 /* list.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F9824176C04005CDD5C /* list.h */; }; 9ACFE66924309AF80071CC93 /* XObjArray_tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ED324176C04005CDD5C /* XObjArray_tests.h */; }; @@ -349,7 +344,6 @@ 9ACFE68C24309AF80071CC93 /* XToolsCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAD24176C04005CDD5C /* XToolsCommon.h */; }; 9ACFE68E24309AF80071CC93 /* bootscreen.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F8724176C04005CDD5C /* bootscreen.h */; }; 9ACFE69024309AF80071CC93 /* Settings.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F2524176C04005CDD5C /* Settings.h */; }; - 9ACFE69124309AF80071CC93 /* XStringW_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ED224176C04005CDD5C /* XStringW_test.h */; }; 9ACFE69324309AF80071CC93 /* ati_reg.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F4F24176C04005CDD5C /* ati_reg.h */; }; 9ACFE69424309AF80071CC93 /* libegint.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F6124176C04005CDD5C /* libegint.h */; }; 9ACFE69524309AF80071CC93 /* memvendors.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F1D24176C04005CDD5C /* memvendors.h */; }; @@ -397,7 +391,6 @@ 9ACFE6C524309AF80071CC93 /* libscreen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F7424176C04005CDD5C /* libscreen.cpp */; }; 9ACFE6C624309AF80071CC93 /* strlen_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD2B241BC0DF00F3D247 /* strlen_test.cpp */; }; 9ACFE6C724309AF80071CC93 /* panic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77FA624176C04005CDD5C /* panic.cpp */; }; - 9ACFE6C924309AF80071CC93 /* XStringW_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ED824176C04005CDD5C /* XStringW_test.cpp */; }; 9ACFE6CA24309AF80071CC93 /* tool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F8924176C04005CDD5C /* tool.cpp */; }; 9ACFE6CB24309AF80071CC93 /* BasicIO.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AF4173D242F15CC00D2644C /* BasicIO.cpp */; }; 9ACFE6CC24309AF80071CC93 /* lib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F9624176C04005CDD5C /* lib.cpp */; }; @@ -433,7 +426,6 @@ 9ACFE6ED24309AF80071CC93 /* LegacyBoot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F1824176C04005CDD5C /* LegacyBoot.cpp */; }; 9ACFE6EE24309AF80071CC93 /* REFIT_MENU_SCREEN.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F9124176C04005CDD5C /* REFIT_MENU_SCREEN.cpp */; }; 9ACFE6EF24309AF80071CC93 /* LegacyBiosThunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F3624176C04005CDD5C /* LegacyBiosThunk.cpp */; }; - 9ACFE6F224309AF80071CC93 /* XStringW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77FB024176C04005CDD5C /* XStringW.cpp */; }; 9ACFE6F324309AF80071CC93 /* lockedgraphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F8324176C04005CDD5C /* lockedgraphics.cpp */; }; 9ACFE6F424309AF80071CC93 /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CC95241AB34800F3D247 /* XString_test.cpp */; }; 9ACFE6F524309AF80071CC93 /* device_inject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F4E24176C04005CDD5C /* device_inject.cpp */; }; @@ -498,7 +490,6 @@ 9AF41594242CD75C00D2644C /* remove_ref.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAA24176C04005CDD5C /* remove_ref.h */; }; 9AF41596242CD75C00D2644C /* loader.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F4824176C04005CDD5C /* loader.h */; }; 9AF41597242CD75C00D2644C /* AmlGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F1E24176C04005CDD5C /* AmlGenerator.h */; }; - 9AF41598242CD75C00D2644C /* XStringW.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAE24176C04005CDD5C /* XStringW.h */; }; 9AF4159C242CD75C00D2644C /* list.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F9824176C04005CDD5C /* list.h */; }; 9AF4159E242CD75C00D2644C /* XObjArray_tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ED324176C04005CDD5C /* XObjArray_tests.h */; }; 9AF4159F242CD75C00D2644C /* Events.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F3424176C04005CDD5C /* Events.h */; }; @@ -536,7 +527,6 @@ 9AF415C2242CD75C00D2644C /* XToolsCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAD24176C04005CDD5C /* XToolsCommon.h */; }; 9AF415C4242CD75C00D2644C /* bootscreen.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F8724176C04005CDD5C /* bootscreen.h */; }; 9AF415C6242CD75C00D2644C /* Settings.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F2524176C04005CDD5C /* Settings.h */; }; - 9AF415C7242CD75C00D2644C /* XStringW_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ED224176C04005CDD5C /* XStringW_test.h */; }; 9AF415C9242CD75C00D2644C /* ati_reg.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F4F24176C04005CDD5C /* ati_reg.h */; }; 9AF415CA242CD75C00D2644C /* libegint.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F6124176C04005CDD5C /* libegint.h */; }; 9AF415CB242CD75C00D2644C /* memvendors.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F1D24176C04005CDD5C /* memvendors.h */; }; @@ -584,7 +574,6 @@ 9AF415FB242CD75C00D2644C /* libscreen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F7424176C04005CDD5C /* libscreen.cpp */; }; 9AF415FC242CD75C00D2644C /* strlen_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD2B241BC0DF00F3D247 /* strlen_test.cpp */; }; 9AF415FD242CD75C00D2644C /* panic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77FA624176C04005CDD5C /* panic.cpp */; }; - 9AF415FF242CD75C00D2644C /* XStringW_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ED824176C04005CDD5C /* XStringW_test.cpp */; }; 9AF41600242CD75C00D2644C /* tool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F8924176C04005CDD5C /* tool.cpp */; }; 9AF41601242CD75C00D2644C /* lib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F9624176C04005CDD5C /* lib.cpp */; }; 9AF41602242CD75C00D2644C /* Injectors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F3524176C04005CDD5C /* Injectors.cpp */; }; @@ -618,7 +607,6 @@ 9AF41623242CD75C00D2644C /* LegacyBoot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F1824176C04005CDD5C /* LegacyBoot.cpp */; }; 9AF41624242CD75C00D2644C /* REFIT_MENU_SCREEN.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F9124176C04005CDD5C /* REFIT_MENU_SCREEN.cpp */; }; 9AF41625242CD75C00D2644C /* LegacyBiosThunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F3624176C04005CDD5C /* LegacyBiosThunk.cpp */; }; - 9AF41628242CD75C00D2644C /* XStringW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77FB024176C04005CDD5C /* XStringW.cpp */; }; 9AF41629242CD75C00D2644C /* lockedgraphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F8324176C04005CDD5C /* lockedgraphics.cpp */; }; 9AF4162A242CD75C00D2644C /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CC95241AB34800F3D247 /* XString_test.cpp */; }; 9AF4162B242CD75C00D2644C /* device_inject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F4E24176C04005CDD5C /* device_inject.cpp */; }; @@ -677,7 +665,6 @@ 9AF41671242CDA5800D2644C /* remove_ref.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAA24176C04005CDD5C /* remove_ref.h */; }; 9AF41673242CDA5800D2644C /* loader.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F4824176C04005CDD5C /* loader.h */; }; 9AF41674242CDA5800D2644C /* AmlGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F1E24176C04005CDD5C /* AmlGenerator.h */; }; - 9AF41675242CDA5800D2644C /* XStringW.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAE24176C04005CDD5C /* XStringW.h */; }; 9AF41679242CDA5800D2644C /* list.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F9824176C04005CDD5C /* list.h */; }; 9AF4167B242CDA5800D2644C /* XObjArray_tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ED324176C04005CDD5C /* XObjArray_tests.h */; }; 9AF4167C242CDA5800D2644C /* Events.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F3424176C04005CDD5C /* Events.h */; }; @@ -715,7 +702,6 @@ 9AF4169F242CDA5800D2644C /* XToolsCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77FAD24176C04005CDD5C /* XToolsCommon.h */; }; 9AF416A1242CDA5800D2644C /* bootscreen.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F8724176C04005CDD5C /* bootscreen.h */; }; 9AF416A3242CDA5800D2644C /* Settings.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F2524176C04005CDD5C /* Settings.h */; }; - 9AF416A4242CDA5800D2644C /* XStringW_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ED224176C04005CDD5C /* XStringW_test.h */; }; 9AF416A6242CDA5800D2644C /* ati_reg.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F4F24176C04005CDD5C /* ati_reg.h */; }; 9AF416A7242CDA5800D2644C /* libegint.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F6124176C04005CDD5C /* libegint.h */; }; 9AF416A8242CDA5800D2644C /* memvendors.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77F1D24176C04005CDD5C /* memvendors.h */; }; @@ -763,7 +749,6 @@ 9AF416D8242CDA5800D2644C /* libscreen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F7424176C04005CDD5C /* libscreen.cpp */; }; 9AF416D9242CDA5800D2644C /* strlen_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD2B241BC0DF00F3D247 /* strlen_test.cpp */; }; 9AF416DA242CDA5800D2644C /* panic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77FA624176C04005CDD5C /* panic.cpp */; }; - 9AF416DC242CDA5800D2644C /* XStringW_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ED824176C04005CDD5C /* XStringW_test.cpp */; }; 9AF416DD242CDA5800D2644C /* tool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F8924176C04005CDD5C /* tool.cpp */; }; 9AF416DE242CDA5800D2644C /* lib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F9624176C04005CDD5C /* lib.cpp */; }; 9AF416DF242CDA5800D2644C /* Injectors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F3524176C04005CDD5C /* Injectors.cpp */; }; @@ -797,7 +782,6 @@ 9AF41700242CDA5800D2644C /* LegacyBoot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F1824176C04005CDD5C /* LegacyBoot.cpp */; }; 9AF41701242CDA5800D2644C /* REFIT_MENU_SCREEN.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F9124176C04005CDD5C /* REFIT_MENU_SCREEN.cpp */; }; 9AF41702242CDA5800D2644C /* LegacyBiosThunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F3624176C04005CDD5C /* LegacyBiosThunk.cpp */; }; - 9AF41705242CDA5800D2644C /* XStringW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77FB024176C04005CDD5C /* XStringW.cpp */; }; 9AF41706242CDA5800D2644C /* lockedgraphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F8324176C04005CDD5C /* lockedgraphics.cpp */; }; 9AF41707242CDA5800D2644C /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CC95241AB34800F3D247 /* XString_test.cpp */; }; 9AF41708242CDA5800D2644C /* device_inject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77F4E24176C04005CDD5C /* device_inject.cpp */; }; @@ -917,13 +901,11 @@ 9AC77ECC24176C04005CDD5C /* XStringWArray_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringWArray_test.h; sourceTree = ""; }; 9AC77ECD24176C04005CDD5C /* XArray_tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XArray_tests.h; sourceTree = ""; }; 9AC77ECE24176C04005CDD5C /* XStringWArray_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XStringWArray_test.cpp; sourceTree = ""; }; - 9AC77ED224176C04005CDD5C /* XStringW_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringW_test.h; sourceTree = ""; }; 9AC77ED324176C04005CDD5C /* XObjArray_tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XObjArray_tests.h; sourceTree = ""; }; 9AC77ED424176C04005CDD5C /* all_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = all_tests.cpp; sourceTree = ""; }; 9AC77ED524176C04005CDD5C /* XObjArray_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XObjArray_tests.cpp; sourceTree = ""; }; 9AC77ED624176C04005CDD5C /* XArray_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XArray_tests.cpp; sourceTree = ""; }; 9AC77ED724176C04005CDD5C /* all_tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = all_tests.h; sourceTree = ""; }; - 9AC77ED824176C04005CDD5C /* XStringW_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XStringW_test.cpp; sourceTree = ""; }; 9AC77F1224176C04005CDD5C /* Version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Version.h; sourceTree = ""; }; 9AC77F1424176C04005CDD5C /* syslinux_mbr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = syslinux_mbr.h; sourceTree = ""; }; 9AC77F1524176C04005CDD5C /* Handle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Handle.h; sourceTree = ""; }; @@ -1066,9 +1048,7 @@ 9AC77FAA24176C04005CDD5C /* remove_ref.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = remove_ref.h; sourceTree = ""; }; 9AC77FAC24176C04005CDD5C /* XStringWArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringWArray.h; sourceTree = ""; }; 9AC77FAD24176C04005CDD5C /* XToolsCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XToolsCommon.h; sourceTree = ""; }; - 9AC77FAE24176C04005CDD5C /* XStringW.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringW.h; sourceTree = ""; }; 9AC77FAF24176C04005CDD5C /* XStringWArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XStringWArray.cpp; sourceTree = ""; }; - 9AC77FB024176C04005CDD5C /* XStringW.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XStringW.cpp; sourceTree = ""; }; 9AC77FB424176C04005CDD5C /* XToolsCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XToolsCommon.cpp; sourceTree = ""; }; 9AC77FB624176C04005CDD5C /* XArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XArray.h; sourceTree = ""; }; 9AC77FB724176C04005CDD5C /* XObjArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XObjArray.h; sourceTree = ""; }; @@ -1220,8 +1200,6 @@ 9AC77ED324176C04005CDD5C /* XObjArray_tests.h */, 9A28CC95241AB34800F3D247 /* XString_test.cpp */, 9A28CC96241AB34800F3D247 /* XString_test.h */, - 9AC77ED824176C04005CDD5C /* XStringW_test.cpp */, - 9AC77ED224176C04005CDD5C /* XStringW_test.h */, 9AC77ECE24176C04005CDD5C /* XStringWArray_test.cpp */, 9AC77ECC24176C04005CDD5C /* XStringWArray_test.h */, ); @@ -1473,8 +1451,6 @@ 9AC77FB724176C04005CDD5C /* XObjArray.h */, 9A28CC91241AB33700F3D247 /* XString.cpp */, 9A28CC92241AB33700F3D247 /* XString.h */, - 9AC77FB024176C04005CDD5C /* XStringW.cpp */, - 9AC77FAE24176C04005CDD5C /* XStringW.h */, 9AC77FAF24176C04005CDD5C /* XStringWArray.cpp */, 9AC77FAC24176C04005CDD5C /* XStringWArray.h */, 9AC77FB424176C04005CDD5C /* XToolsCommon.cpp */, @@ -1508,7 +1484,6 @@ 9AC7808C24176C04005CDD5C /* remove_ref.h in Headers */, 9AC7803124176C04005CDD5C /* loader.h in Headers */, 9AC7800724176C04005CDD5C /* AmlGenerator.h in Headers */, - 9AC7808F24176C04005CDD5C /* XStringW.h in Headers */, 9A105B2D24464A830006DE06 /* BmLib.h in Headers */, 9AF4173F242F15CC00D2644C /* BootLog.h in Headers */, 9AC7807B24176C04005CDD5C /* list.h in Headers */, @@ -1566,7 +1541,6 @@ 9AC7800E24176C04005CDD5C /* Settings.h in Headers */, 9A105B3924483AD50006DE06 /* image.h in Headers */, 9A105B7A24483AE40006DE06 /* cpu.h in Headers */, - 9AC77FBF24176C04005CDD5C /* XStringW_test.h in Headers */, 9AC7803824176C04005CDD5C /* ati_reg.h in Headers */, 9A105B81244852D70006DE06 /* VersionString.h in Headers */, 9AC7804824176C04005CDD5C /* libegint.h in Headers */, @@ -1638,7 +1612,6 @@ 9ACFE65E24309AF80071CC93 /* remove_ref.h in Headers */, 9ACFE66024309AF80071CC93 /* loader.h in Headers */, 9ACFE66124309AF80071CC93 /* AmlGenerator.h in Headers */, - 9ACFE66224309AF80071CC93 /* XStringW.h in Headers */, 9ACFE66424309AF80071CC93 /* BootLog.h in Headers */, 9ACFE66724309AF80071CC93 /* list.h in Headers */, 9ACFE66924309AF80071CC93 /* XObjArray_tests.h in Headers */, @@ -1678,7 +1651,6 @@ 9ACFE68C24309AF80071CC93 /* XToolsCommon.h in Headers */, 9ACFE68E24309AF80071CC93 /* bootscreen.h in Headers */, 9ACFE69024309AF80071CC93 /* Settings.h in Headers */, - 9ACFE69124309AF80071CC93 /* XStringW_test.h in Headers */, 9ACFE69324309AF80071CC93 /* ati_reg.h in Headers */, 9ACFE69424309AF80071CC93 /* libegint.h in Headers */, 9ACFE69524309AF80071CC93 /* memvendors.h in Headers */, @@ -1736,7 +1708,6 @@ 9AF41594242CD75C00D2644C /* remove_ref.h in Headers */, 9AF41596242CD75C00D2644C /* loader.h in Headers */, 9AF41597242CD75C00D2644C /* AmlGenerator.h in Headers */, - 9AF41598242CD75C00D2644C /* XStringW.h in Headers */, 9AF4159C242CD75C00D2644C /* list.h in Headers */, 9AF4159E242CD75C00D2644C /* XObjArray_tests.h in Headers */, 9AF4159F242CD75C00D2644C /* Events.h in Headers */, @@ -1777,7 +1748,6 @@ 9AF415C2242CD75C00D2644C /* XToolsCommon.h in Headers */, 9AF415C4242CD75C00D2644C /* bootscreen.h in Headers */, 9AF415C6242CD75C00D2644C /* Settings.h in Headers */, - 9AF415C7242CD75C00D2644C /* XStringW_test.h in Headers */, 9AF415C9242CD75C00D2644C /* ati_reg.h in Headers */, 9AF415CA242CD75C00D2644C /* libegint.h in Headers */, 9AF415CB242CD75C00D2644C /* memvendors.h in Headers */, @@ -1833,7 +1803,6 @@ 9AF41671242CDA5800D2644C /* remove_ref.h in Headers */, 9AF41673242CDA5800D2644C /* loader.h in Headers */, 9AF41674242CDA5800D2644C /* AmlGenerator.h in Headers */, - 9AF41675242CDA5800D2644C /* XStringW.h in Headers */, 9AF41679242CDA5800D2644C /* list.h in Headers */, 9AF4167B242CDA5800D2644C /* XObjArray_tests.h in Headers */, 9AF4167C242CDA5800D2644C /* Events.h in Headers */, @@ -1874,7 +1843,6 @@ 9AF4169F242CDA5800D2644C /* XToolsCommon.h in Headers */, 9AF416A1242CDA5800D2644C /* bootscreen.h in Headers */, 9AF416A3242CDA5800D2644C /* Settings.h in Headers */, - 9AF416A4242CDA5800D2644C /* XStringW_test.h in Headers */, 9AF416A6242CDA5800D2644C /* ati_reg.h in Headers */, 9AF416A7242CDA5800D2644C /* libegint.h in Headers */, 9AF416A8242CDA5800D2644C /* memvendors.h in Headers */, @@ -2116,7 +2084,6 @@ 9AC7805B24176C04005CDD5C /* libscreen.cpp in Sources */, 9A28CD31241BC0DF00F3D247 /* strlen_test.cpp in Sources */, 9AC7808824176C04005CDD5C /* panic.cpp in Sources */, - 9AC77FC524176C04005CDD5C /* XStringW_test.cpp in Sources */, 9AC7806F24176C04005CDD5C /* tool.cpp in Sources */, 9AF41740242F15CC00D2644C /* BasicIO.cpp in Sources */, 9AC7807924176C04005CDD5C /* lib.cpp in Sources */, @@ -2155,7 +2122,6 @@ 9AC7807524176C04005CDD5C /* REFIT_MENU_SCREEN.cpp in Sources */, 9AC7801F24176C04005CDD5C /* LegacyBiosThunk.cpp in Sources */, 9A09863124389A6A00826276 /* menu.cpp in Sources */, - 9AC7809124176C04005CDD5C /* XStringW.cpp in Sources */, 9AC7806924176C04005CDD5C /* lockedgraphics.cpp in Sources */, 9A28CC97241AB34800F3D247 /* XString_test.cpp in Sources */, 9A4185BA2439F29D00BEAFB8 /* LoadOptions_test.cpp in Sources */, @@ -2231,7 +2197,6 @@ 9ACFE6C624309AF80071CC93 /* strlen_test.cpp in Sources */, 9A105B88244852D70006DE06 /* VersionString.cpp in Sources */, 9ACFE6C724309AF80071CC93 /* panic.cpp in Sources */, - 9ACFE6C924309AF80071CC93 /* XStringW_test.cpp in Sources */, 9ACFE6CA24309AF80071CC93 /* tool.cpp in Sources */, 9ACFE6CB24309AF80071CC93 /* BasicIO.cpp in Sources */, 9A4F68582449D4AE004B2F7E /* stdio.cpp in Sources */, @@ -2272,7 +2237,6 @@ 9ACFE6EE24309AF80071CC93 /* REFIT_MENU_SCREEN.cpp in Sources */, 9ACFE6EF24309AF80071CC93 /* LegacyBiosThunk.cpp in Sources */, 9A09863424389A6A00826276 /* menu.cpp in Sources */, - 9ACFE6F224309AF80071CC93 /* XStringW.cpp in Sources */, 9A9AEB9F243F7B9200FBD7D8 /* XStringArray.cpp in Sources */, 9ACFE6F324309AF80071CC93 /* lockedgraphics.cpp in Sources */, 9A4185BD2439F29D00BEAFB8 /* LoadOptions_test.cpp in Sources */, @@ -2349,7 +2313,6 @@ 9AF415FC242CD75C00D2644C /* strlen_test.cpp in Sources */, 9A105B86244852D70006DE06 /* VersionString.cpp in Sources */, 9AF415FD242CD75C00D2644C /* panic.cpp in Sources */, - 9AF415FF242CD75C00D2644C /* XStringW_test.cpp in Sources */, 9AF41600242CD75C00D2644C /* tool.cpp in Sources */, 9AF41742242F15D600D2644C /* BasicIO.cpp in Sources */, 9A4F68562449D4AE004B2F7E /* stdio.cpp in Sources */, @@ -2389,7 +2352,6 @@ 9AF41624242CD75C00D2644C /* REFIT_MENU_SCREEN.cpp in Sources */, 9AF41625242CD75C00D2644C /* LegacyBiosThunk.cpp in Sources */, 9A09863224389A6A00826276 /* menu.cpp in Sources */, - 9AF41628242CD75C00D2644C /* XStringW.cpp in Sources */, 9AF41629242CD75C00D2644C /* lockedgraphics.cpp in Sources */, 9A9AEB9D243F7B9000FBD7D8 /* XStringArray.cpp in Sources */, 9AF4162A242CD75C00D2644C /* XString_test.cpp in Sources */, @@ -2467,7 +2429,6 @@ 9AF416D9242CDA5800D2644C /* strlen_test.cpp in Sources */, 9A105B87244852D70006DE06 /* VersionString.cpp in Sources */, 9AF416DA242CDA5800D2644C /* panic.cpp in Sources */, - 9AF416DC242CDA5800D2644C /* XStringW_test.cpp in Sources */, 9AF416DD242CDA5800D2644C /* tool.cpp in Sources */, 9AF41743242F15D700D2644C /* BasicIO.cpp in Sources */, 9A4F68572449D4AE004B2F7E /* stdio.cpp in Sources */, @@ -2507,7 +2468,6 @@ 9AF41701242CDA5800D2644C /* REFIT_MENU_SCREEN.cpp in Sources */, 9AF41702242CDA5800D2644C /* LegacyBiosThunk.cpp in Sources */, 9A09863324389A6A00826276 /* menu.cpp in Sources */, - 9AF41705242CDA5800D2644C /* XStringW.cpp in Sources */, 9AF41706242CDA5800D2644C /* lockedgraphics.cpp in Sources */, 9A9AEB9E243F7B9100FBD7D8 /* XStringArray.cpp in Sources */, 9AF41707242CDA5800D2644C /* XString_test.cpp in Sources */, diff --git a/Xcode/cpp_tests/.cproject b/Xcode/cpp_tests/.cproject index c71fe880a..91ef2da54 100644 --- a/Xcode/cpp_tests/.cproject +++ b/Xcode/cpp_tests/.cproject @@ -215,7 +215,7 @@ - + @@ -439,9 +439,13 @@ + + - + + + diff --git a/Xcode/cpp_tests/.project b/Xcode/cpp_tests/.project index c810d0f72..1a6abbfc7 100644 --- a/Xcode/cpp_tests/.project +++ b/Xcode/cpp_tests/.project @@ -25,6 +25,11 @@ org.eclipse.cdt.core.ccnature + + MemLogLibDefault + 2 + PARENT-2-PROJECT_LOC/Library/MemLogLibDefault + cpp_foundation 2 @@ -35,5 +40,10 @@ 2 PARENT-2-PROJECT_LOC/rEFIt_UEFI/cpp_unit_test + + cpp_util + 2 + PARENT-2-PROJECT_LOC/rEFIt_UEFI/cpp_util + diff --git a/Xcode/cpp_tests/.settings/compilation_project_specific/all-all-all-includelist b/Xcode/cpp_tests/.settings/compilation_project_specific/all-all-all-includelist index f17011a15..20c7435c8 100755 --- a/Xcode/cpp_tests/.settings/compilation_project_specific/all-all-all-includelist +++ b/Xcode/cpp_tests/.settings/compilation_project_specific/all-all-all-includelist @@ -4,6 +4,8 @@ prefix=$1 echo " +../src + " | awk '$0!=""{ printf " -I'"${prefix}"'%s", $0; }' diff --git a/Xcode/cpp_tests/.settings/compilation_project_specific/gcc92-c-c++flags b/Xcode/cpp_tests/.settings/compilation_project_specific/gcc92-c-c++flags index 573960bdc..0cda450a9 100755 --- a/Xcode/cpp_tests/.settings/compilation_project_specific/gcc92-c-c++flags +++ b/Xcode/cpp_tests/.settings/compilation_project_specific/gcc92-c-c++flags @@ -2,6 +2,5 @@ SCRIPT_ABS_FILENAME=`LC_ALL=en_US.ISO8859-1 perl -e 'use Cwd "abs_path";print abs_path(shift)' "${BASH_SOURCE[0]}"` SCRIPT_DIR=`dirname "$SCRIPT_ABS_FILENAME"` -echo -g -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Wno-array-bounds -ffunction-sections -fdata-sections \ - -fno-common -m64 -fno-stack-protector -mabi=ms -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables \ - -Wno-address -flto -Wno-unused-but-set-variable -fno-omit-frame-pointer -Wno-unknown-pragmas -Wno-unused-label +echo -g -fshort-wchar -include ../src/Platform.h + diff --git a/Xcode/cpp_tests/.settings/language.settings.xml b/Xcode/cpp_tests/.settings/language.settings.xml index c0db618fb..283ea0745 100644 --- a/Xcode/cpp_tests/.settings/language.settings.xml +++ b/Xcode/cpp_tests/.settings/language.settings.xml @@ -11,7 +11,7 @@ - + @@ -33,7 +33,7 @@ - + diff --git a/Xcode/cpp_tests/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/Xcode/cpp_tests/.settings/org.eclipse.cdt.managedbuilder.core.prefs index 84688904a..5342e06d1 100644 --- a/Xcode/cpp_tests/.settings/org.eclipse.cdt.managedbuilder.core.prefs +++ b/Xcode/cpp_tests/.settings/org.eclipse.cdt.managedbuilder.core.prefs @@ -19,3 +19,7 @@ environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.macosx.exe.debug environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.macosx.exe.debug.1043399644.1294514338/LIBRARY_PATH/operation=remove environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.macosx.exe.debug.1043399644.1294514338/append=true environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.macosx.exe.debug.1043399644.1294514338/appendContributed=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.macosx.exe.debug.1043399644.573872575/LIBRARY_PATH/delimiter=\: +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.macosx.exe.debug.1043399644.573872575/LIBRARY_PATH/operation=remove +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.macosx.exe.debug.1043399644.573872575/append=true +environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.macosx.exe.debug.1043399644.573872575/appendContributed=true diff --git a/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj b/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj index 97d982119..da6385a66 100644 --- a/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj +++ b/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj @@ -13,21 +13,17 @@ 9A0B08592402FF8200E2B470 /* all_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08512402FE9B00E2B470 /* all_tests.cpp */; }; 9A0B085A2402FF8400E2B470 /* XObjArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08522402FE9B00E2B470 /* XObjArray_tests.cpp */; }; 9A0B085B2402FF8700E2B470 /* XArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08532402FE9B00E2B470 /* XArray_tests.cpp */; }; - 9A0B085C2402FF8B00E2B470 /* XStringW_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08552402FE9B00E2B470 /* XStringW_test.cpp */; }; 9A0B085E240300E000E2B470 /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B085D240300E000E2B470 /* Platform.cpp */; }; - 9A0B085F240308E400E2B470 /* XStringW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08482402FE9300E2B470 /* XStringW.cpp */; }; 9A0B08662403144C00E2B470 /* global_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08642403144C00E2B470 /* global_test.cpp */; }; 9A0B08732403B08400E2B470 /* XObjArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08522402FE9B00E2B470 /* XObjArray_tests.cpp */; }; 9A0B08742403B08400E2B470 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9223302402FD1000483CBA /* main.cpp */; }; 9A0B08772403B08400E2B470 /* XStringWArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08472402FE9300E2B470 /* XStringWArray.cpp */; }; - 9A0B08792403B08400E2B470 /* XStringW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08482402FE9300E2B470 /* XStringW.cpp */; }; 9A0B087A2403B08400E2B470 /* all_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08512402FE9B00E2B470 /* all_tests.cpp */; }; 9A0B087B2403B08400E2B470 /* global_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08642403144C00E2B470 /* global_test.cpp */; }; 9A0B087C2403B08400E2B470 /* XToolsCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08492402FE9300E2B470 /* XToolsCommon.cpp */; }; 9A0B087D2403B08400E2B470 /* XStringWArray_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B084F2402FE9B00E2B470 /* XStringWArray_test.cpp */; }; 9A0B087E2403B08400E2B470 /* XArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08532402FE9B00E2B470 /* XArray_tests.cpp */; }; 9A0B087F2403B08400E2B470 /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B085D240300E000E2B470 /* Platform.cpp */; }; - 9A0B08802403B08400E2B470 /* XStringW_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08552402FE9B00E2B470 /* XStringW_test.cpp */; }; 9A28CD09241B8DD400F3D247 /* strncmp_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD05241B8DD400F3D247 /* strncmp_test.cpp */; }; 9A28CD0A241B8DD400F3D247 /* strncmp_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD05241B8DD400F3D247 /* strncmp_test.cpp */; }; 9A28CD0B241B8DD400F3D247 /* strncmp_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD05241B8DD400F3D247 /* strncmp_test.cpp */; }; @@ -55,24 +51,22 @@ 9A4185C02439F73A00BEAFB8 /* XStringArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4185BE2439F73A00BEAFB8 /* XStringArray.cpp */; }; 9A4185C12439F73A00BEAFB8 /* XStringArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4185BE2439F73A00BEAFB8 /* XStringArray.cpp */; }; 9A4185C22439F73A00BEAFB8 /* XStringArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4185BE2439F73A00BEAFB8 /* XStringArray.cpp */; }; + 9A4FFA7E2451C8330050B38B /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4FFA7C2451C8330050B38B /* XString.cpp */; }; + 9A4FFA812451C88D0050B38B /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4FFA802451C88D0050B38B /* XString_test.cpp */; }; + 9A4FFA822451C88D0050B38B /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4FFA802451C88D0050B38B /* XString_test.cpp */; }; + 9A4FFA832451C88D0050B38B /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4FFA802451C88D0050B38B /* XString_test.cpp */; }; + 9A4FFA842451C9740050B38B /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4FFA7C2451C8330050B38B /* XString.cpp */; }; + 9A4FFA852451C9740050B38B /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4FFA7C2451C8330050B38B /* XString.cpp */; }; 9A57C21A2418B9A00029A39F /* XObjArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08522402FE9B00E2B470 /* XObjArray_tests.cpp */; }; 9A57C21B2418B9A00029A39F /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9223302402FD1000483CBA /* main.cpp */; }; 9A57C21D2418B9A00029A39F /* XStringWArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08472402FE9300E2B470 /* XStringWArray.cpp */; }; 9A57C2202418B9A00029A39F /* panic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC780A32417DD2F005CDD5C /* panic.cpp */; }; - 9A57C2212418B9A00029A39F /* XStringW.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08482402FE9300E2B470 /* XStringW.cpp */; }; 9A57C2222418B9A00029A39F /* all_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08512402FE9B00E2B470 /* all_tests.cpp */; }; 9A57C2232418B9A00029A39F /* global_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08642403144C00E2B470 /* global_test.cpp */; }; 9A57C2242418B9A00029A39F /* XToolsCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08492402FE9300E2B470 /* XToolsCommon.cpp */; }; 9A57C2252418B9A00029A39F /* XStringWArray_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B084F2402FE9B00E2B470 /* XStringWArray_test.cpp */; }; 9A57C2272418B9A00029A39F /* XArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08532402FE9B00E2B470 /* XArray_tests.cpp */; }; 9A57C2282418B9A00029A39F /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B085D240300E000E2B470 /* Platform.cpp */; }; - 9A57C2292418B9A00029A39F /* XStringW_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08552402FE9B00E2B470 /* XStringW_test.cpp */; }; - 9A57C263241A752E0029A39F /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C261241A752E0029A39F /* XString_test.cpp */; }; - 9A57C264241A752E0029A39F /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C261241A752E0029A39F /* XString_test.cpp */; }; - 9A57C265241A752E0029A39F /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C261241A752E0029A39F /* XString_test.cpp */; }; - 9A57C268241A799B0029A39F /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C267241A799B0029A39F /* XString.cpp */; }; - 9A57C269241A799B0029A39F /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C267241A799B0029A39F /* XString.cpp */; }; - 9A57C26A241A799B0029A39F /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A57C267241A799B0029A39F /* XString.cpp */; }; 9A9223312402FD1000483CBA /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9223302402FD1000483CBA /* main.cpp */; }; 9A9AEB8D243F73CE00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; }; 9A9AEB8E243F752C00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; }; @@ -120,9 +114,7 @@ /* Begin PBXFileReference section */ 9A0B08442402FE9300E2B470 /* XStringWArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XStringWArray.h; sourceTree = ""; }; 9A0B08452402FE9300E2B470 /* XToolsCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XToolsCommon.h; sourceTree = ""; }; - 9A0B08462402FE9300E2B470 /* XStringW.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XStringW.h; sourceTree = ""; }; 9A0B08472402FE9300E2B470 /* XStringWArray.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XStringWArray.cpp; sourceTree = ""; }; - 9A0B08482402FE9300E2B470 /* XStringW.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XStringW.cpp; sourceTree = ""; }; 9A0B08492402FE9300E2B470 /* XToolsCommon.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XToolsCommon.cpp; sourceTree = ""; }; 9A0B084A2402FE9300E2B470 /* XArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XArray.h; sourceTree = ""; }; 9A0B084B2402FE9300E2B470 /* XObjArray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XObjArray.h; sourceTree = ""; }; @@ -134,9 +126,7 @@ 9A0B08522402FE9B00E2B470 /* XObjArray_tests.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XObjArray_tests.cpp; sourceTree = ""; }; 9A0B08532402FE9B00E2B470 /* XArray_tests.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XArray_tests.cpp; sourceTree = ""; }; 9A0B08542402FE9B00E2B470 /* all_tests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = all_tests.h; sourceTree = ""; }; - 9A0B08552402FE9B00E2B470 /* XStringW_test.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = XStringW_test.cpp; sourceTree = ""; }; 9A0B085D240300E000E2B470 /* Platform.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Platform.cpp; sourceTree = ""; }; - 9A0B08632403132300E2B470 /* XStringW_test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XStringW_test.h; sourceTree = ""; }; 9A0B08642403144C00E2B470 /* global_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = global_test.cpp; sourceTree = ""; }; 9A0B08862403B08400E2B470 /* cpp_tests UTF32 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp_tests UTF32"; sourceTree = BUILT_PRODUCTS_DIR; }; 9A1A3FDC2424BC22008C89EB /* printf_lite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = printf_lite.h; sourceTree = ""; }; @@ -156,12 +146,14 @@ 9A4185B02439E4D600BEAFB8 /* LoadOptions_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadOptions_test.h; sourceTree = ""; }; 9A4185BE2439F73A00BEAFB8 /* XStringArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XStringArray.cpp; sourceTree = ""; }; 9A4185BF2439F73A00BEAFB8 /* XStringArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringArray.h; sourceTree = ""; }; + 9A4FFA7C2451C8330050B38B /* XString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XString.cpp; sourceTree = ""; }; + 9A4FFA7D2451C8330050B38B /* XStringAbstract copy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XStringAbstract copy.h"; sourceTree = ""; }; + 9A4FFA7F2451C88C0050B38B /* XString_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XString_test.h; sourceTree = ""; }; + 9A4FFA802451C88D0050B38B /* XString_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XString_test.cpp; sourceTree = ""; }; 9A57C20A2418A1FD0029A39F /* global_test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = global_test.h; sourceTree = ""; }; 9A57C22F2418B9A00029A39F /* cpp_tests UTF16 unsigned char */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp_tests UTF16 unsigned char"; sourceTree = BUILT_PRODUCTS_DIR; }; - 9A57C261241A752E0029A39F /* XString_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XString_test.cpp; sourceTree = ""; }; - 9A57C262241A752E0029A39F /* XString_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XString_test.h; sourceTree = ""; }; 9A57C266241A799B0029A39F /* XString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XString.h; sourceTree = ""; }; - 9A57C267241A799B0029A39F /* XString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XString.cpp; sourceTree = ""; }; + 9A6BA73C2449977300BDA52C /* XStringAbstract.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringAbstract.h; sourceTree = ""; }; 9A92232D2402FD1000483CBA /* cpp_tests UTF16 signed char */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp_tests UTF16 signed char"; sourceTree = BUILT_PRODUCTS_DIR; }; 9A9223302402FD1000483CBA /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 9A92234D2402FD9500483CBA /* Platform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = ""; }; @@ -217,16 +209,16 @@ 9A0B08432402FE9300E2B470 /* cpp_foundation */ = { isa = PBXGroup; children = ( + 9A4FFA7C2451C8330050B38B /* XString.cpp */, + 9A4FFA7D2451C8330050B38B /* XStringAbstract copy.h */, + 9A57C266241A799B0029A39F /* XString.h */, + 9A6BA73C2449977300BDA52C /* XStringAbstract.h */, 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */, 9A9AEB8B243F73CE00FBD7D8 /* unicode_conversions.h */, 9A0B084A2402FE9300E2B470 /* XArray.h */, 9A0B084B2402FE9300E2B470 /* XObjArray.h */, - 9A57C267241A799B0029A39F /* XString.cpp */, - 9A57C266241A799B0029A39F /* XString.h */, 9A4185BE2439F73A00BEAFB8 /* XStringArray.cpp */, 9A4185BF2439F73A00BEAFB8 /* XStringArray.h */, - 9A0B08482402FE9300E2B470 /* XStringW.cpp */, - 9A0B08462402FE9300E2B470 /* XStringW.h */, 9A0B08472402FE9300E2B470 /* XStringWArray.cpp */, 9A0B08442402FE9300E2B470 /* XStringWArray.h */, 9A0B08492402FE9300E2B470 /* XToolsCommon.cpp */, @@ -239,6 +231,8 @@ 9A0B084C2402FE9B00E2B470 /* cpp_unit_test */ = { isa = PBXGroup; children = ( + 9A4FFA802451C88D0050B38B /* XString_test.cpp */, + 9A4FFA7F2451C88C0050B38B /* XString_test.h */, 9A4185AF2439E4D500BEAFB8 /* LoadOptions_test.cpp */, 9A4185B02439E4D600BEAFB8 /* LoadOptions_test.h */, 9A0B08512402FE9B00E2B470 /* all_tests.cpp */, @@ -264,10 +258,6 @@ 9A0B084E2402FE9B00E2B470 /* XArray_tests.h */, 9A0B08522402FE9B00E2B470 /* XObjArray_tests.cpp */, 9A0B08502402FE9B00E2B470 /* XObjArray_tests.h */, - 9A57C261241A752E0029A39F /* XString_test.cpp */, - 9A57C262241A752E0029A39F /* XString_test.h */, - 9A0B08552402FE9B00E2B470 /* XStringW_test.cpp */, - 9A0B08632403132300E2B470 /* XStringW_test.h */, 9A0B084F2402FE9B00E2B470 /* XStringWArray_test.cpp */, 9A0B084D2402FE9B00E2B470 /* XStringWArray_test.h */, ); @@ -462,16 +452,16 @@ 9A4185B22439E4D600BEAFB8 /* LoadOptions_test.cpp in Sources */, 9A0B08732403B08400E2B470 /* XObjArray_tests.cpp in Sources */, 9A28CD20241BB61B00F3D247 /* abort.cpp in Sources */, + 9A4FFA842451C9740050B38B /* XString.cpp in Sources */, + 9A4FFA822451C88D0050B38B /* XString_test.cpp in Sources */, 9A28CD23241BB61B00F3D247 /* strlen.cpp in Sources */, 9A28CD4C241F4CCE00F3D247 /* xcode_utf16.cpp in Sources */, 9A0B08742403B08400E2B470 /* main.cpp in Sources */, - 9A57C264241A752E0029A39F /* XString_test.cpp in Sources */, 9A28CD17241BACBB00F3D247 /* strlen_test.cpp in Sources */, 9A0B08772403B08400E2B470 /* XStringWArray.cpp in Sources */, 9A28CD0D241B8DD400F3D247 /* strcmp_test.cpp in Sources */, 9A28CD0A241B8DD400F3D247 /* strncmp_test.cpp in Sources */, 9AC780AF2417DD2F005CDD5C /* panic.cpp in Sources */, - 9A0B08792403B08400E2B470 /* XStringW.cpp in Sources */, 9A0B087A2403B08400E2B470 /* all_tests.cpp in Sources */, 9A9AEB8E243F752C00FBD7D8 /* unicode_conversions.cpp in Sources */, 9A0B087B2403B08400E2B470 /* global_test.cpp in Sources */, @@ -483,8 +473,6 @@ 9A0B087E2403B08400E2B470 /* XArray_tests.cpp in Sources */, 9AA0458B2425F94D000D6970 /* printf_lite-test.cpp in Sources */, 9A0B087F2403B08400E2B470 /* Platform.cpp in Sources */, - 9A0B08802403B08400E2B470 /* XStringW_test.cpp in Sources */, - 9A57C269241A799B0029A39F /* XString.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -495,16 +483,16 @@ 9A4185B32439E4D600BEAFB8 /* LoadOptions_test.cpp in Sources */, 9A57C21A2418B9A00029A39F /* XObjArray_tests.cpp in Sources */, 9A28CD21241BB61B00F3D247 /* abort.cpp in Sources */, + 9A4FFA852451C9740050B38B /* XString.cpp in Sources */, + 9A4FFA832451C88D0050B38B /* XString_test.cpp in Sources */, 9A28CD24241BB61B00F3D247 /* strlen.cpp in Sources */, 9A28CD4D241F4CCE00F3D247 /* xcode_utf16.cpp in Sources */, 9A57C21B2418B9A00029A39F /* main.cpp in Sources */, - 9A57C265241A752E0029A39F /* XString_test.cpp in Sources */, 9A28CD18241BACBB00F3D247 /* strlen_test.cpp in Sources */, 9A57C21D2418B9A00029A39F /* XStringWArray.cpp in Sources */, 9A28CD0E241B8DD400F3D247 /* strcmp_test.cpp in Sources */, 9A28CD0B241B8DD400F3D247 /* strncmp_test.cpp in Sources */, 9A57C2202418B9A00029A39F /* panic.cpp in Sources */, - 9A57C2212418B9A00029A39F /* XStringW.cpp in Sources */, 9A57C2222418B9A00029A39F /* all_tests.cpp in Sources */, 9A9AEB8F243F752C00FBD7D8 /* unicode_conversions.cpp in Sources */, 9A57C2232418B9A00029A39F /* global_test.cpp in Sources */, @@ -516,8 +504,6 @@ 9A57C2272418B9A00029A39F /* XArray_tests.cpp in Sources */, 9AA0458C2425F94D000D6970 /* printf_lite-test.cpp in Sources */, 9A57C2282418B9A00029A39F /* Platform.cpp in Sources */, - 9A57C2292418B9A00029A39F /* XStringW_test.cpp in Sources */, - 9A57C26A241A799B0029A39F /* XString.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -527,16 +513,16 @@ files = ( 9A0B085A2402FF8400E2B470 /* XObjArray_tests.cpp in Sources */, 9A28CD1F241BB61B00F3D247 /* abort.cpp in Sources */, + 9A4FFA7E2451C8330050B38B /* XString.cpp in Sources */, + 9A4FFA812451C88D0050B38B /* XString_test.cpp in Sources */, 9A28CD22241BB61B00F3D247 /* strlen.cpp in Sources */, 9A28CD4B241F4CCE00F3D247 /* xcode_utf16.cpp in Sources */, 9A9223312402FD1000483CBA /* main.cpp in Sources */, - 9A57C263241A752E0029A39F /* XString_test.cpp in Sources */, 9A28CD16241BACBB00F3D247 /* strlen_test.cpp in Sources */, 9A0B08562402FF7700E2B470 /* XStringWArray.cpp in Sources */, 9A28CD0C241B8DD400F3D247 /* strcmp_test.cpp in Sources */, 9A28CD09241B8DD400F3D247 /* strncmp_test.cpp in Sources */, 9AC780AE2417DD2F005CDD5C /* panic.cpp in Sources */, - 9A0B085F240308E400E2B470 /* XStringW.cpp in Sources */, 9A0B08592402FF8200E2B470 /* all_tests.cpp in Sources */, 9A0B08662403144C00E2B470 /* global_test.cpp in Sources */, 9A4185B12439E4D600BEAFB8 /* LoadOptions_test.cpp in Sources */, @@ -549,8 +535,6 @@ 9A0B085B2402FF8700E2B470 /* XArray_tests.cpp in Sources */, 9AA0458A2425F94D000D6970 /* printf_lite-test.cpp in Sources */, 9A0B085E240300E000E2B470 /* Platform.cpp in Sources */, - 9A0B085C2402FF8B00E2B470 /* XStringW_test.cpp in Sources */, - 9A57C268241A799B0029A39F /* XString.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -659,7 +643,10 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREFIX_HEADER = src/Platform.h; - GCC_PREPROCESSOR_DEFINITIONS = JIEF_DEBUG; + GCC_PREPROCESSOR_DEFINITIONS = ( + JIEF_DEBUG, + XSTRING16_DEV, + ); GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; diff --git a/Xcode/cpp_tests/src/main.cpp b/Xcode/cpp_tests/src/main.cpp index 55018d69d..1fe95bba6 100755 --- a/Xcode/cpp_tests/src/main.cpp +++ b/Xcode/cpp_tests/src/main.cpp @@ -25,8 +25,8 @@ printf("sizeof(long)=%lu\n", sizeof(long)); printf("sizeof(long long)=%lu\n", sizeof(long long)); printf("sizeof(size_t)=%lu\n", sizeof(size_t)); #ifndef _MSC_VER -printf("%zu\n", (size_t)MAX_UINT64); -printf("%zd\n", (size_t)MAX_UINT64); +//printf("%zu\n", (size_t)MAX_UINT64); +//printf("%zd\n", (size_t)MAX_UINT64); #endif return all_tests(); diff --git a/Xcode/cpp_tests/src/poolprint-test-cpp_conf.h b/Xcode/cpp_tests/src/poolprint-test-cpp_conf.h index 8cf2b0001..c3cfd94b5 100644 --- a/Xcode/cpp_tests/src/poolprint-test-cpp_conf.h +++ b/Xcode/cpp_tests/src/poolprint-test-cpp_conf.h @@ -1,5 +1,5 @@ -#include "../../Include/Library/printf_lite.h" +#include "../../../Include/Library/printf_lite.h" #define F(x) x #define LF(x) L##x #define PRIF "%a" diff --git a/Xcode/cpp_tests/src/xcode_utf16.cpp b/Xcode/cpp_tests/src/xcode_utf16.cpp index cccd414dc..2c1775748 100644 --- a/Xcode/cpp_tests/src/xcode_utf16.cpp +++ b/Xcode/cpp_tests/src/xcode_utf16.cpp @@ -53,7 +53,7 @@ size_t utf16_wcslen(const wchar_t *s) // wcslen seems not to work if sizeof(wchar_t) == 2 const wchar_t* p; for ( p = s ; *p ; p++ ); - return (UINTN)(p-s); + return (size_t)(p-s); } int utf16_wcsncmp(const wchar_t *s1, const wchar_t * s2, size_t n) diff --git a/rEFIt_UEFI/Platform/Nvram.cpp b/rEFIt_UEFI/Platform/Nvram.cpp index 6f83f262d..d63c1709c 100644 --- a/rEFIt_UEFI/Platform/Nvram.cpp +++ b/rEFIt_UEFI/Platform/Nvram.cpp @@ -1395,7 +1395,7 @@ EFI_STATUS SetStartupDiskVolume ( "" "", strguid(Guid)); DBG (" * efi-boot-device: %s\n", EfiBootDevice.c_str()); - Status = SetNvramVariable (L"efi-boot-device", &gEfiAppleBootGuid, Attributes, EfiBootDevice.size(), EfiBootDevice.c_str()); + Status = SetNvramVariable (L"efi-boot-device", &gEfiAppleBootGuid, Attributes, EfiBootDevice.sizeInBytes(), EfiBootDevice.c_str()); } return Status; diff --git a/rEFIt_UEFI/Platform/Platform.h b/rEFIt_UEFI/Platform/Platform.h index 012250f06..5ab8b1390 100755 --- a/rEFIt_UEFI/Platform/Platform.h +++ b/rEFIt_UEFI/Platform/Platform.h @@ -16,7 +16,6 @@ Headers collection for procedures #ifdef __cplusplus #include #include "../cpp_foundation/XString.h" -#include "../cpp_foundation/XStringW.h" #include "../cpp_foundation/XArray.h" #include "../cpp_foundation/XObjArray.h" #include "../cpp_util/remove_ref.h" diff --git a/rEFIt_UEFI/Platform/Posix/posix.h b/rEFIt_UEFI/Platform/Posix/posix.h index 5655bb0bf..c327d4b6a 100755 --- a/rEFIt_UEFI/Platform/Posix/posix.h +++ b/rEFIt_UEFI/Platform/Posix/posix.h @@ -27,10 +27,10 @@ //#define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count)) //#define strcmp AsciiStrCmp //#define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count))) -#define strcpy(strDest,strSource) AsciiStrCpyS(strDest,AsciiStrLen(strDest)+1,strSource) -#define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,(UINTN)count+1,strSource,(UINTN)count) +//#define strcpy(strDest,strSource) AsciiStrCpyS(strDest,AsciiStrLen(strDest)+1,strSource) +//#define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,(UINTN)count+1,strSource,(UINTN)count) //#define strlen(str) (size_t)(AsciiStrLen(str)) -#define strcat(strDest,strSource) AsciiStrCatS(strDest,AsciiStrLen(strDest)+1,strSource) +//#define strcat(strDest,strSource) AsciiStrCatS(strDest,AsciiStrLen(strDest)+1,strSource) #define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch) #define strstr(a,b) AsciiStrStr(a,b) diff --git a/rEFIt_UEFI/Platform/Posix/stdio.cpp b/rEFIt_UEFI/Platform/Posix/stdio.cpp index 3f040b642..76e90f84b 100755 --- a/rEFIt_UEFI/Platform/Posix/stdio.cpp +++ b/rEFIt_UEFI/Platform/Posix/stdio.cpp @@ -20,7 +20,6 @@ extern "C" { } #include "../../cpp_foundation/XString.h" -#include "../../cpp_foundation/XStringW.h" static XString stdio_static_buf; static XStringW stdio_static_wbuf; @@ -46,7 +45,7 @@ const char* strerror(EFI_STATUS Status) n = AsciiSPrint(stdio_static_buf.dataSized(0, stdio_static_buf.allocatedSize()), stdio_static_buf.allocatedSize(), "%r", Status); } while ( n > stdio_static_buf.allocatedSize() - 2 ); - return stdio_static_buf.data(); + return stdio_static_buf.s(); } //this function print guid in LittleEndian format while we need BigEndian as Apple do @@ -58,6 +57,6 @@ const char* strguid(EFI_GUID* guid) n = AsciiSPrint(stdio_static_buf.dataSized(0, stdio_static_buf.allocatedSize()), stdio_static_buf.allocatedSize(), "%g", guid); } while ( n > stdio_static_buf.allocatedSize() - 2 ); - return stdio_static_buf.data(); + return stdio_static_buf.s(); } diff --git a/rEFIt_UEFI/Platform/Posix/string.h b/rEFIt_UEFI/Platform/Posix/string.h index 56e87ebc8..07415c218 100644 --- a/rEFIt_UEFI/Platform/Posix/string.h +++ b/rEFIt_UEFI/Platform/Posix/string.h @@ -5,6 +5,7 @@ extern "C" { #endif +#include #include #ifdef __GNUC__ @@ -26,9 +27,32 @@ inline void* memcpy(void *dst, const void *src, size_t len) return CopyMem(dst,src,len); } +inline char* strcat(char* s1, const char* s2) +{ + AsciiStrCatS(s1, AsciiStrLen(s1)+1, s2); + return s1; +} + +inline char* strcpy(char* dst, const char* src) +{ + AsciiStrCpyS(dst,AsciiStrLen(dst)+1,src); + return dst; +} + +inline char* strncpy(char * dst, const char * src, size_t len) +{ + AsciiStrnCpyS(dst,(UINTN)len+1,src,(UINTN)len); + return dst; +} + +//inline char* strncat(char *restrict s1, const char *restrict s2, size_t n) +//{ +// return AsciiStrCatS(s1, AsciiStrLen(strDest)+1,strSource) +//} +// #ifdef __cplusplus } #endif -#endif +#endif // __CLOVER_STRING_H__ diff --git a/rEFIt_UEFI/cpp_foundation/XArray.h b/rEFIt_UEFI/cpp_foundation/XArray.h index 96eabf388..fb87115b9 100755 --- a/rEFIt_UEFI/cpp_foundation/XArray.h +++ b/rEFIt_UEFI/cpp_foundation/XArray.h @@ -172,7 +172,7 @@ XArray::~XArray() if ( m_data ) free(m_data); } -/* CheckSize() */ +/* CheckSize() // nNewSize is number of TYPE, not in bytes */ template void XArray::CheckSize(xsize nNewSize, xsize nGrowBy) { diff --git a/rEFIt_UEFI/cpp_foundation/XString.cpp b/rEFIt_UEFI/cpp_foundation/XString.cpp index 2737ec7c8..e786c88f7 100755 --- a/rEFIt_UEFI/cpp_foundation/XString.cpp +++ b/rEFIt_UEFI/cpp_foundation/XString.cpp @@ -1,9 +1,13 @@ -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +//************************************************************************************************* +//************************************************************************************************* +// // STRING -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +// +// Developed by jief666, from 1997. +// +//************************************************************************************************* +//************************************************************************************************* -#if !defined(__XSTRING_CPP__) -#define __XSTRING_CPP__ #if 0 #define DBG(...) DebugLog(2, __VA_ARGS__) @@ -13,1088 +17,94 @@ #include "XToolsCommon.h" #include "XString.h" -#include "XStringW.h" #include "../../Include/Library/printf_lite.h" -xsize XStringGrowByDefault = 2; -const XString NullXString; - - -void XString::Init(xsize aSize) -{ - m_data = (char*)malloc( (aSize+1)*sizeof(char) ); /* le 0 terminal n'est pas compté dans m_allocatedSize */ - /* If want to change that the real allocated size is m_allocatedSize+1, _data method should be changed to limit access (ui > m_allocatedSize change to ui >= m_allocatedSize) */ - if ( !m_data ) { - DebugLog(2, "XString::Init(%llu) : Xalloc returned NULL. Cpu halted\n", (aSize+1)*sizeof(char)); - panic(); - } - m_allocatedSize = aSize; - m_data[0] = 0; -} - -XString::XString() -{ -//Debugf("Construteur\n"); - Init(); -} - -XString::~XString() -{ -//Debugf("Destructeur :%s\n", c); - delete m_data; // delete nullptr do nothing -} - -void XString::setLength(xsize len) -{ - CheckSize(len); - m_data[len] = 0; -} - -/* CheckSize() */ -char *XString::CheckSize(xsize nNewSize, xsize nGrowBy) -{ - if ( m_allocatedSize < nNewSize ) - { - - nNewSize += nGrowBy; - m_data = (char*)realloc(m_data, (nNewSize+1)*sizeof(char), m_allocatedSize*sizeof(wchar_t)); // realloc is identical to malloc if m_data is NULL - if ( !m_data ) { - DBG("XString::CheckSize(%d, %d) : Xrealloc(%d, %d, %d) returned NULL. System halted\n", nNewSize, nGrowBy, m_size, (nNewSize+1)*sizeof(char), c); - panic(); - } - m_allocatedSize = nNewSize; - } - return m_data; -} - -void XString::StrnCpy(const char *buf, xsize len) -{ - if ( buf && *buf && len > 0 ) { - CheckSize(len, 0); - xsize idx = 0; - char* p = _data(0); - while ( idx++ < len && (*p++ = *buf++) != 0 ); - setLength(idx-1); /* SetLength fait _Data[len]=0 */ - }else{ - setLength(0); /* SetLength fait _Data[len]=0 */ - } -} - -void XString::StrCpy(const char *buf) -{ - if ( buf && *buf ) { - StrnCpy(buf, (xsize)strlen(buf)); // overflow ? - }else{ - setLength(0); /* SetLength fait _Data[len]=0 */ - } -} - -//inline -void XString::StrnCat(const char *buf, xsize len) -{ - xsize NewLen; - - if ( buf && *buf && len > 0 ) { - NewLen = length()+len; - CheckSize(NewLen, 0); - memcpy(_data(0)+length(), buf, len); - setLength(NewLen); /* SetLength fait data()[len]=0 */ - } -} - -void XString::Cat(const XString &uneXString) -{ - CheckSize(length()+uneXString.length()); - memcpy(_data(0)+length(), uneXString.m_data, uneXString.length()); - setLength(length() + uneXString.length()); -} - -void XString::StrCat(const char *buf) -{ - if ( buf && *buf ) { - StrnCat(buf, (xsize)strlen(buf)); // overflow ? - } -} - -void XString::Delete(xsize pos, xsize count) -{ - if ( pos < length() ) { - if ( count != MAX_XSIZE && pos + count < length() ) { - memmove(_data(0)+pos, data()+pos+count, length()-pos-count); - setLength(length()-count); -// data()[length()] = 0; fait dans setlength(); - }else{ - setLength(pos); -// data()[length()] = 0; fait dans setlength(); - } - } -} - -void XString::Insert(xsize pos, const XString& Str) -{ - if ( pos < length() ) { - CheckSize(length()+Str.length()); - memmove(_data(0)+pos+Str.length(), data()+pos, length()-pos+1); // +1 to copy the NULL terminator - memcpy(_data(0)+pos, Str.data(), Str.length()); - }else{ - StrCat(Str); - } -} - -// Deactivate assignment during refactoring to avoid confusion -//void XString::Replace(char c1, char c2) -//{ -// char* p; -// -// p = data(); -// while ( *p ) { -// if ( *p == c1 ) *p = c2; -// p += 1; -// } -//} -// -//XString XString::SubStringReplace(char c1, char c2) -//{ -// char* p; -// XString Result; -// -// p = data(); -// while ( *p ) { -// if ( *p == c1 ) Result += c2; -// else Result += *p; -// p++; -// } -// return Result; -//} - -/* this is used when printf can only output unicode, so we need a conversion back to utf8 */ -//static XString* XString_sprintfBuf; -//static xsize XString_sprintfBuf_len; -//static wchar_t XString_char_wait; -// -//static unsigned int XString_transmitSPrintf_utf32(const wchar_t wchar1, const wchar_t wchar2) -//{ -// unsigned int ret = 0; -// UINTN utf32_char; -// -// if ((wchar1 & 0xFC00) == 0xD800) { /* surrogates */ -// if ((wchar2 & 0xFC00) == 0xDC00) { -// utf32_char = wchar1; -// utf32_char &= 0x03FF; -// utf32_char <<= 10; -// utf32_char |= ((UINTN)wchar2) & 0x03FF; -// utf32_char += 0x10000; -// ret = 2; -// }else{ -// // error -// return 1; // Ignore wchar1. Tell the caller we used wchar1 -// } -// }else{ -// utf32_char = wchar1; -// ret = 1; -// } -// -// /* assertion: utf32_char is a single UTF-4 value */ -// int bits; -// -// if (utf32_char < 0x80) { -// (*XString_sprintfBuf) += (char)utf32_char; -// bits = -6; -// } -// else if (utf32_char < 0x800) { -// (*XString_sprintfBuf) += (char)(((utf32_char >> 6) & 0x1F) | 0xC0); -// bits = 0; -// } -// else if (utf32_char < 0x10000) { -// (*XString_sprintfBuf) += (char)(((utf32_char >> 12) & 0x0F) | 0xE0); -// bits = 6; -// } -// else { -// (*XString_sprintfBuf) += (char)(((utf32_char >> 18) & 0x07) | 0xF0); -// bits = 12; -// } -// for (; bits >= 0; bits -= 6) { -// (*XString_sprintfBuf) += (char)(((utf32_char >> bits) & 0x3F) | 0x80); -// } -// return ret; -//} -// -// -//static void XString_transmitSPrintf(const wchar_t* buf, size_t nbchar) -//{ -// -// #if __WCHAR_MAX__ <= 0xFFFF -// // wchar_t is UTF16 -// -// unsigned int ret = 1; -// if ( XString_char_wait ) { -// ret = XString_transmitSPrintf_utf32(XString_char_wait, buf[0]); -// XString_char_wait = 0; -// } -// xsize i; -// for ( i = ret-1 ; i < nbchar-1 ; ) // cast ok, ret > -// { -// ret = XString_transmitSPrintf_utf32(buf[i], buf[i+1]); -// i += ret; -// } -// if ( i < nbchar ) XString_char_wait = buf[i]; -// #else -// #warning TODO -// #endif -//} -// -//void XString::vSPrintf(const char* format, va_list va) -//{ -// SetLength(0); -// -// XString_sprintfBuf = this; -// XString_sprintfBuf_len = 0; -// XString_char_wait = 0; -// vprintf_with_callback(format, va, XString_transmitSPrintf); -// if ( XString_char_wait ) XString_transmitSPrintf_utf32(XString_char_wait, 0); -//} - -//static XString* XString_sprintfBuf; - -static void XString_transmitSPrintf(const char* buf, unsigned int nbchar, void* context) -{ -// (*XString_sprintfBuf).StrnCat(buf, nbchar); - ((XString*)(context))->StrnCat(buf, (xsize)nbchar); // nbchar cannot be negative -} - -XString& XString::vSPrintf(const char* format, va_list va) -{ - setLength(0); - -// XString_sprintfBuf = this; - vprintf_with_callback(format, va, XString_transmitSPrintf, this); - return *this; -} - -//void XString::vSPrintf(const char* format, va_list va) -//{ - // This is an attempt to use _PPrint from IO.c. Problem is : you have to allocate the memory BEFORE calling it. -// POOL_PRINT spc; -// PRINT_STATE ps; -// -// ZeroMem(&spc, sizeof (spc)); -// spc.Str = data(); -// SetLength(0); -// spc.Len = 0; -// spc.Maxlen = m_size; -// ZeroMem(&ps, sizeof (ps)); -// ps.Output = (IN EFI_STATUS (EFIAPI *)(VOID *context, CONST CHAR16 *str))_PoolPrint; -// ps.Context = (void*)&spc; -// ps.fmt.u.pw = format; -// -// VA_COPY(ps.args, va); -// _PPrint (&ps); -// va_end(ps.args); -//} - -XString& XString::SPrintf(const char *Format, ...) -{ - va_list va; - - va_start(va, Format); - vSPrintf(Format, va); - va_end(va); - return *this; -} - - -// Deactivate assignment during refactoring to avoid confusion -XString XString::basename() const -{ - if ( lastChar() == PATH_SEPARATOR ) { - DebugLog(2, "XString::basename() -> LastChar() == PATH_SEPARATOR"); - panic(); - } - xsize idx = RIdxOf(XString().SPrintf("%c",PATH_SEPARATOR)); // ctor char disabled during refactoring to avoid confusion - if ( idx == MAX_XSIZE ) return NullXString; - return SubString(idx+1, length()-idx-1); -} - -XString XString::dirname() const -{ - xsize idx = RIdxOf(XString().SPrintf("%c",PATH_SEPARATOR)); // ctor char disabled during refactoring to avoid confusion - if ( idx == MAX_XSIZE ) return NullXString; - #ifdef __DEV_WIN32__ - if ( idx == 1 && *data(0) == PATH_SEPARATOR ) { - // this string is an icomplete UNC name : \\server - return NullXString; - } - #endif - return SubString(0, idx); -} - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Constructeurs Chaines -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -XString::XString(const XString &aString) -{ -//Debugf("Construteur const String & : %s\n", aString); - Init(aString.length()); - StrnCpy(aString.data(), aString.length()); -} - -XString::XString(XString&& aString) // Move constructor -{ - m_data = aString.m_data; - m_allocatedSize = aString.m_allocatedSize; - aString.m_data = 0; - aString.m_allocatedSize = 0; -} - -//// Deactivate assignment during refactoring to avoid confusion -//XString::XString(const wchar_t *S) -//{ -// Init(); -// SPrintf("%ls", S); -//} - -/* -XString::XString(const NSString* const aNSString, NSStringEncoding encoding) -{ - char buf[ [aNSString length]*MB_CUR_MAX+MB_CUR_MAX ]; - if ( [aNSString getCString:buf maxLength:[aNSString length]*MB_CUR_MAX+MB_CUR_MAX encoding:encoding] ) - { - Init(strlen(buf)); - StrnCpy(buf); - } - else { - Init(0); - } -} -*/ - -// -//XString::XString(const XConstString &aConstString) -//{ -////Debugf("Construteur const ConstString & : %s\n", aConstString); -// Init( aConstString.length() ); -// StrnCpy( aConstString.data() ); -//} - -// Deactivate assignment during refactoring to avoid confusion -//XString::XString(const char *S) -//{ -////Debugf("Construteur const char * : %s\n", S); -// Init((xsize)strlen(S)); // overflow ? -// if ( S ) StrCpy(S); -//} -// -//XString::XString(const char *S, xsize count) -//{ -////Debugf("Construteur const char *, unsigned int :%s %d\n", S, count); -// Init(count); -// StrnCpy(S, count); -//} - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Constructeurs CaractËres -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -// Deactivate assignment during refactoring to avoid confusion -//XString::XString(char aChar) -//{ -////TRACE("Construteur char \n"); -// Init(1); -// StrnCpy(&aChar, 1); -//} - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Constructeurs numériques -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -//XString::XString(int i) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Copy Constructor(int) -> (%lu) %d\n", this, i); -// len = sprintf(buf,"%d", i); -// Init(len); -// StrnCpy(buf, len); -//} - -//XString::XString(unsigned int ui) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Copy Constructor(unsigned int) -> (%lu) %u\n", this, ui); -// len = sprintf(buf,"%u", ui); -// Init(len); -// StrnCpy(buf, len); -//} -// -//XString::XString(long l) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Copy Constructor(long) -> (%lu) %ld\n", this, l); -// len = sprintf(buf,"%ld", l); -// Init(len); -// StrnCpy(buf, len); -//} -// -//XString::XString(unsigned long ul) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Copy Constructor(unsigned long long) -> (%lu) %lu\n", this, ul); -// len = sprintf(buf,"%lu", ul); -// Init(len); -// StrnCpy(buf, len); -//} -// - -//------------------------------------------------------------------------------------------------- -// StringCompare -//------------------------------------------------------------------------------------------------- -// -1 si buf1 est plus grand -// 0 si égal -// 1 si buf2 est plus grand -//------------------------------------------------------------------------------------------------- - - -XString XString::SubString(xsize pos, xsize count) const -{ - if ( count > length()-pos ) count = length()-pos; - return XString().takeValueFrom( &(data()[pos]), count); -} - -xsize XString::IdxOf(char aChar, xsize Pos) const -{ - xsize Idx; - - for ( Idx=Pos ; Idx length() ) pos = length(); - if ( pos < s_len ) return MAX_XSIZE; - pos -= s_len; - for ( Idx=pos+1 ; Idx-- > 0 ; ) { - i = 0; - while( i 0 ) - { - unsigned int ui; - - if ( FirstCharIsCap ) { -// data()[0] = Majuscule(data()[0]); - ui = 1; - }else{ - ui = 0; - } - for ( ; ui < size() ; ui+=1 ) { - m_data[ui] = to_lower(m_data[ui]); - } - } -} -#ifdef NOT_USED_ANYMORE_skqdjfhksqjhfksjqdf -bool XString::IsLetters() const -{ - const char *p; - char aChar; - - p = data(); - if ( !*p ) return false; - for ( ; *p ; p+=1 ) { - aChar = to_lowerSansAccent(*p); // toutes les lettres, avec accent ou pas, seront dans l'intervalle 'a'..'z' - if ( aChar < 'a' ) return false; - if ( aChar > 'z' ) return false; - } - return true; -} -#endif - -bool XString::IsDigits() const -{ - const char *p; - - p = data(); - if ( !*p ) return false; - for ( ; *p ; p+=1 ) { - if ( *p < '0' ) return false; - if ( *p > '9' ) return false; - } - return true; -} - -bool XString::IsDigits(xsize pos, xsize count) const -{ - const char *p; - const char *q; - - if ( pos >= length() ) { - DebugLog(2, "XString::IsDigits pos >= length()"); // We should #ifdef this to keep that for debug - return false; - } - if ( pos+count > length() ) { - DebugLog(2, "XString::IsDigits pos+count > length()"); // We should #ifdef this to keep that for debug - return false; - } - p = data() + pos; - q = p + count; - for ( ; p < q ; p+=1 ) { - if ( *p < '0' ) return false; - if ( *p > '9' ) return false; - } - return true; -} - -#ifdef NOT_USED_ANYMORE_skqdjfhksqjhfksjqdf -bool XString::IsLettersNoAccent() const -{ - const char *p; - char aChar; - - p = data(); - if ( !*p ) return false; - for ( ; *p ; p+=1 ) { - aChar = to_lower(*p); // Uniquement les lettres maj et min sans accent seront dans l'intervalle 'a'..'z' - if ( aChar < 'a' ) return false; - if ( aChar > 'z' ) return false; - } - return true; -} -#endif - -void XString::removeLastEspCtrl() -{ - char *p; - - if ( length() > 0 ) { - p = _data(0) + length() - 1; - if ( *p >= 0 && *p <= ' ' ) { - p -= 1; - while ( p>data() && *p >= 0 && *p <= ' ' ) p -= 1; - if ( p>data() ) { - setLength( (xsize)(p-data()+1) ); // safe (p-data()+1 < length() - }else{ - if ( *p >= 0 && *p <= ' ' ) setLength(0); - else setLength(1); - } - } - } -} -// -//int XString::ToInt() const -//{ -// int i; -// -// if ( sscanf(data(), "%d", &i) != 1 ) return NOTAINT; -// return i; -//} -// -//unsigned int XString::TOUInt() const -//{ -// unsigned int u; -// -// if ( sscanf(data(), "%u", &u) != 1 ) return MAXUINT; -// return u; -//} - -//------------------------------------------------------------------------------------------------- -// -//------------------------------------------------------------------------------------------------- -// -//bool XString::ReadFromBuf(const char *buf, size_t *idx, size_t count) -//{ -// xsize longueur; -// -////mylog2(::SPrintf("XString::ReadFromBuf *idx=%d count=%d - %d %d %d %d\n", *idx, count, buf[*idx+0], buf[*idx+1], buf[*idx+2], buf[*idx+3]).c); -// if ( count-*idx >= sizeof(longueur) ) { -// longueur = *((xsize *)(buf+*idx)); -////mylog2(::SPrintf("XString::ReadFromBuf *idx=%d count=%d longueur=%d\n", *idx, count, longueur).c); -// *idx += sizeof(longueur); -// if ( longueur > 0 && count-*idx>=longueur ) memcpy(DataWithSizeMin(0, longueur), buf+*idx, longueur); -// *idx += longueur; -// SetLength(longueur); -// return true; -// }else{ -// SetNull(); -// return false; -// } -//} -// -//bool XString::WriteToBuf(char *buf, size_t *idx, size_t count) const -//{ -// xsize longueur; -// -// if ( count-*idx < sizeof(longueur) + length() ) return false; -// longueur = length(); -// memcpy(buf+*idx, &longueur, sizeof(longueur)); -// *idx += sizeof(longueur); -// memcpy(buf+*idx, data(), length()); -// *idx += length(); -// return true; -//} -// -//bool XString::ReadFromFILE(FILE *fp) -//{ -// unsigned int longueur; -// -// if ( fread(&longueur, sizeof(longueur), 1, fp) != 1 ) goto fin; -// if ( longueur > 0 && fread(DataWithSizeMin(0, longueur), longueur, 1, fp) != 1 ) goto fin; -// SetLength(longueur); -// return true; -// fin: -// SetNull(); -// return false; -//} -// -//bool XString::WriteToFILE(FILE *fp) const -//{ -// xsize longueur; -// -// longueur = length(); -// if ( fwrite(&longueur, sizeof(longueur), 1, fp) != 1 ) return false; -// if ( longueur > 0 && fwrite(data(), longueur, 1, fp) != 1 ) return false; -// return true; -//} -// -//#ifdef __DEVTOOLS_SOCKETS__ -//void XString::ReadFromSOCKETT(SOCKET Sock, unsigned int LenMax, unsigned int TO, const char *ErrMsg) -//{ -// unsigned int longueur; -// -// SockReceiveT(Sock, &longueur, sizeof(longueur), TO, ErrMsg); -// if ( longueur > LenMax ) Throw("Longueur reÁue (%d) supérieure ‡ la longueur max (%d)", longueur, LenMax); -// if ( longueur > 0 ) SockReceiveT(Sock, DataWithSizeMin(0, longueur, 0), longueur, TO, ErrMsg); -// SetLength(longueur); -//} -// -//bool XString::ReadFromSOCKET(SOCKET Sock, unsigned int LenMax, unsigned int TO, const char *ErrMsg) -//{ -// try -// { -// ReadFromSOCKETT(Sock, LenMax, TO, ErrMsg); -// SetLastErrorFlag(false); -// } -// StdCatch(); -// return !LastErrorFlag(); -//} -// -//void XString::WriteToSOCKETT(SOCKET Sock, unsigned int TO,const char *ErrMsg) const -//{ -// unsigned int longueur; -// -// longueur = length(); -// SockSendT(Sock, &longueur, sizeof(longueur), TO, ErrMsg); -// if ( longueur > 0 ) SockSendT(Sock, data(), longueur, TO, ErrMsg); -//} -// -//bool XString::WriteToSOCKET(SOCKET Sock, unsigned int TO,const char *ErrMsg) const -//{ -// try -// { -// WriteToSOCKET(Sock, TO, ErrMsg); -// SetLastErrorFlag(false); -// } -// StdCatch(); -// return !LastErrorFlag(); -//} -//#endif -// -//bool XString::ReadFromXBuffer(XRBuffer &unXBuffer) -//{ -// xsize longueur; -// -// if ( !unXBuffer.GetXSize(&longueur) ) goto fin; -// if ( longueur>0 && !unXBuffer.Get(DataWithSizeMin(0, longueur), longueur) ) goto fin; -// SetLength(longueur); -// return true; -//fin: -// SetNull(); -// return false; -//} -// -//void XString::CatToXBuffer(XBuffer *unXBuffer) const -//{ -// (*unXBuffer).Cat(length()); -// (*unXBuffer).Cat(data(), length()); -//} - -//************************************************************************************************* -// -// Opérateurs = -// -//************************************************************************************************* - - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Opérateur = CaractËres -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -// Deactivate assignment during refactoring to avoid confusion -//const XString &XString::operator =(char aChar) -//{ -////TRACE("Operator =char \n"); -// StrnCpy(&aChar, 1); -// return *this; -//} - - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Opérateur = Chaines -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -const XString &XString::operator =(const XString &aString) -{ -//TRACE("Operator =const XString&\n"); - StrnCpy(aString.data(), aString.length()); - return *this; -} - -XString& XString::operator =(XString&& aString) -{ - delete m_data; // delete does nothing if m_data is NULL - m_data = aString.m_data; - m_allocatedSize = aString.m_allocatedSize; - aString.m_data = 0; - aString.m_allocatedSize = 0; - return *this; -} - -// -//const XString &XString::operator =(const XConstString &aConstString) -//{ -////TRACE("Operator =const XString&\n"); -// StrnCpy(aConstString.data()); -// return *this; -//} - -// Deactivate assignment during refactoring to avoid confusion -//const XString &XString::operator =(const char *S) -//{ -////TRACE("Operator =const char *\n"); -// StrCpy(S); -// return *this; -//} - - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Opérateur = numériques -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// -//const XString &XString::operator =(int i) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Opérateur =(int) -> (%lu) %d\n", this, i); -// len = sprintf(buf,"%d", i); -// StrnCpy(buf, len); -// return *this; -//} -// -//const XString &XString::operator =(unsigned int ui) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Opérateur =(long) -> (%lu) %u\n", this, ui); -// len = sprintf(buf,"%u", ui); -// StrnCpy(buf, len); -// return *this; -//} -// -//const XString &XString::operator =(long l) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Opérateur =(long) -> (%lu) %ld\n", this, l); -// len = sprintf(buf,"%ld", l); -// StrnCpy(buf, len); -// return *this; -//} -// -//const XString &XString::operator =(unsigned long ul) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Opérateur =(long) -> (%lu) %lu\n", this, ul); -// len = sprintf(buf,"%lu", ul); -// StrnCpy(buf, len); -// return *this; -//} -// - - -//************************************************************************************************* -// -// Opérateurs += -// -//************************************************************************************************* - - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Opérateur = CaractËres -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -// Deactivate assignment during refactoring to avoid confusion -//const XString &XString::operator +=(char aChar) -//{ -////TRACE("Operator +=char \n"); -// StrnCat(&aChar, 1); -// return *this; -//} - - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Opérateur = Chaines -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -const XString &XString::operator +=(const XString &aString) -{ -//TRACE("Operator +=const XString&\n"); - StrnCat(aString.data(), aString.length()); - return *this; -} -// -//const XString &XString::operator +=(const XConstString &aConstString) -//{ -////TRACE("Operator +=const EConstString&\n"); -// StrnCat(aConstString.data(), aConstString.length()); -// return *this; -//} - -const XString &XString::operator +=(const char *S) -{ -//TRACE("operator +=const char *\n"); - StrCat(S); - return *this; -} - - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Opérateur = numériques -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// -//const XString &XString::operator +=(int i) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Opérateur =(int) -> (%lu) %d\n", this, i); -// len = sprintf(buf,"%d", i); -// StrnCat(buf, len); -// return *this; -//} -// -//const XString &XString::operator +=(unsigned int ui) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Opérateur =(unsigned int) -> (%lu) %u\n", this, ui); -// len = sprintf(buf,"%u", ui); -// StrnCat(buf, len); -// return *this; -//} -// -//const XString &XString::operator +=(long l) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Opérateur =(long) -> (%lu) %ld\n", this, l); -// len = sprintf(buf,"%ld", l); -// StrnCat(buf, len); -// return *this; -//} -// -//const XString &XString::operator +=(unsigned long ul) -//{ -// char buf[1024]; -// unsigned int len; -// -////TRACE("Opérateur =(unsigned long long) -> (%lu) %lu\n", this, ul); -// len = sprintf(buf,"%lu", ul); -// StrnCat(buf, len); -// return *this; -//} - //----------------------------------------------------------------------------- -// Fonction +// Functions //----------------------------------------------------------------------------- XString operator"" _XS ( const char* s, size_t len) { XString returnValue; - if ( len > MAX_XSIZE ) len = MAX_XSIZE; returnValue.takeValueFrom(s, len); return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. } -XString SPrintf(const char *format, ...) +XString16 operator"" _XS16 ( const char16_t* s, size_t len) { - va_list va; - XString str; - - va_start (va, format); - str.vSPrintf(format, va); + XString16 returnValue; + returnValue.takeValueFrom(s, len); + return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +} + +XString32 operator"" _XS32 ( const char32_t* s, size_t len) +{ + XString32 returnValue; + returnValue.takeValueFrom(s, len); + return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +} + +XStringW operator"" _XSW ( const wchar_t* s, size_t len) +{ + XStringW returnValue; + returnValue.takeValueFrom(s, len); + return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +} + +const XString NullXString; +const XStringW NullXStringW; + + +XString SPrintf(const char* format, ...) +{ + va_list va; + XString str; + + va_start (va, format); + str.vSPrintf(format, va); va_end(va); - - return str; + + return str; } -XString SubString(const char *s, xsize s_len, xsize pos, xsize count) +XStringW SWPrintf(const char* format, ...) { - if ( pos >= s_len ) return NullXString; - if ( s_len-pos < count ) count = s_len-pos; - return XString().takeValueFrom( s+pos, count ); + va_list va; + XStringW str; + + va_start (va, format); + str.vSWPrintf(format, va); + va_end(va); + + return str; } -#ifdef NOT_USED_ANYMORE_skqdjfhksqjhfksjqdf -XString ToAlpha(const char *S) -{ - XString ReturnValue; - unsigned int i; - - for ( i=0 ; S[i] ; i+=1 ) { - ReturnValue += ToAlpha(S[i]); - } - return ReturnValue; -} - -XString ToAlpha(const XString &S) -{ - XString ReturnValue; - unsigned int i; - - for ( i=0 ; i=0 && S[i] < ' ' ) ReturnValue += 'x'; /* Les char sont signés !!! */ -// else ReturnValue += S[i]; +// +//XStringW CleanCtrl(const XStringW &S) +//{ +// XStringW ReturnValue; +// UINTN i; +// +// for ( i=0 ; i=0 && S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* wchar_t are signed */ +//#else +// if ( S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* wchar_t are unsigned */ +//#endif +// else ReturnValue += S.wc_str()[i]; // } // return ReturnValue; //} -#endif + diff --git a/rEFIt_UEFI/cpp_foundation/XString.h b/rEFIt_UEFI/cpp_foundation/XString.h index 7042a9fe8..68e7e3c14 100755 --- a/rEFIt_UEFI/cpp_foundation/XString.h +++ b/rEFIt_UEFI/cpp_foundation/XString.h @@ -1,329 +1,143 @@ //************************************************************************************************* //************************************************************************************************* // -// STRING +// STRING +// +// Developed by jief666, from 1997. // //************************************************************************************************* //************************************************************************************************* -#if !defined(__XSTRING_H__) -#define __XSTRING_H__ + +#if !defined(__XString_H__) +#define __XString_H__ #include "XToolsCommon.h" +#include "XStringAbstract.h" -#define PATH_SEPARATOR '\\' +#include "../../Include/Library/printf_lite.h" -extern UINTN XStringGrowByDefault; +#ifndef XString16GrowByDefault +#define XString16GrowByDefault 16 +#endif +//typedef XStringAbstract XString; -//class XConstString; -class XStringW; - -class XString +class XString : public XStringAbstract { - protected: - char *m_data; - xsize m_allocatedSize; - - // convenience method. Did it this way to avoid #define in header. They can have an impact on other headers - xsize min(xsize x1, xsize x2) const { if ( x1 < x2 ) return x1; return x2; } - xsize max(xsize x1, xsize x2) const { if ( x1 > x2 ) return x1; return x2; } - -// Next 2 methods are protected intentionally. They are const method returning non-const pointer. That's intentional, but dangerous. Do not expose to public. -// It's better practice, if you need a non-const pointer for low-level access, to use dataSized and ahev to specify the size -// It's possible to access data(m_allocatedSize) because the real allocated size is m_allocatedSize+1 - char* _data(unsigned int ui) const { if ( ui > m_allocatedSize ) panic("char* data(unsigned int ui=0) -> ui > m_allocatedSize"); return m_data+ui; } - char* _data(int i) const { if ( i<0 ) panic("char* data(int i) -> i < 0"); if ( (unsigned int)i > m_allocatedSize ) panic("char* data(int i) -> i > m_allocatedSize"); return m_data+i; } - char* _data(unsigned long ui) const { if ( ui > m_allocatedSize ) panic("char* data(unsigned long ui=0) -> ui > m_allocatedSize"); return m_data+ui; } - char* _data(long i) const { if ( i<0 ) panic("char* data(long i) -> i < 0"); if ( (unsigned long)i > m_allocatedSize ) panic("char* data(long i) -> i > m_allocatedSize"); return m_data+i; } - char* _data(xsize ui) const { if ( ui > m_allocatedSize ) panic("char* data(xsize ui=0) -> ui > m_allocatedSize"); return m_data+ui; } - char* _data(xisize i) const { if ( i<0 ) panic("char* data(xisize i) -> i < 0"); if ( (xsize)i > m_allocatedSize ) panic("char* data(xisize i) -> i > m_allocatedSize"); return m_data+i; } - public: + XString() : XStringAbstract() {}; + XString(const XString& S) : XStringAbstract(S) {} - void Init(xsize aSize=0); - XString(); - XString(const XString &aString); - XString(XString&& aString); // Move constructor + template + XString(const XStringAbstract &S) : XStringAbstract(S) {} + + XString& operator=(const XString &S) { this->XStringAbstract::operator=(S); return *this; } + + using XStringAbstract::operator =; -// XString(const XConstString &aConstString); -// XString(const char *S); -// XString(const char* S, xsize count); -// XString(const wchar_t *S); +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; -// XString(uchar); -// XString(char); -// XString(int); -// XString(unsigned long long); + va_start (va, format); + vSPrintf(format, va); + va_end(va); + } - ~XString(); - - public: - char *CheckSize(xsize nNewSize, xsize nGrowBy = XStringGrowByDefault); - - public: - const char* c_str() const { return m_data; } // same as std::string - const char* data(xsize ui=0) const { return _data(ui); } - const char* data(xisize i) const { return _data(i); } - - char* dataSized(xsize ui, xsize sizeMin, xsize nGrowBy=XStringGrowByDefault) { CheckSize(ui+sizeMin, nGrowBy); return _data(ui); } - - xsize length() const { return strlen(m_data); } - xsize size() const { return strlen(m_data); } - xsize allocatedSize() const { return m_allocatedSize; } - void setLength(xsize len); - - /* IsNull ? */ - void setEmpty() { setLength(0); } - bool isEmpty() const { return length() == 0; } - bool notEmpty() const { return !isEmpty(); } - - /* Cast */ -// operator const char *() const { return data(); } // disabled during big refactoring -// operator char *() { return data(); } - -// int ToInt() const; -// UINTN ToUINTN() const; - - /* char [] */ - char operator [](int i) const { return *_data(i); } - char operator [](unsigned int ui) const { return *_data(ui); } - char operator [](long i) const { return *_data(i); } - char operator [](unsigned long ui) const { return *_data(ui); } - char operator [](xisize i) const { return *data(i); } - char operator [](xsize ui) const { return *data(ui); } - - /* char& [] */ - char& operator [](int i) { return *_data(i); } - char& operator [](unsigned int ui) { return *_data(ui); } - char& operator [](long i) { return *_data(i); } - char& operator [](unsigned long ui) { return *_data(ui); } - char& operator [](xisize i) { return *_data(i); } - char& operator [](xsize ui) { return *_data(ui); } - - char lastChar() const { if ( length() > 0 ) return data()[length()-1]; else return 0; } - void removeLastEspCtrl(); - - void StrCpy(const char *buf); - void StrnCpy(const char *buf, xsize len); - void StrnCat(const char *buf, xsize len); - void StrCat(const char *buf); - void StrCat(const XString& S) { StrCat(S.c_str()) ; } - void Delete(xsize pos, xsize count=1); - - void Insert(xsize pos, const XString& Str); - - void Cat(const XString &uneXString); - - XString& vSPrintf(const char *Format, va_list va); - XString& SPrintf(const char *format, ...) __attribute__((format (printf, 2, 3))); // 2 and 3 because of hidden parameter 'this'. - - const XString& takeValueFrom(const char* S) { StrCpy(S); return *this; } - const XString& takeValueFrom(const char* S, xsize count) { StrnCpy(S, count); return *this; } - const XString& takeValueFrom(const wchar_t* S) { SPrintf("%ls", S); return *this; } - - const XString& operator =(const XString& aString); - XString& operator =(XString&& aString); -// const XString &operator =(const XConstString &aConstString); - -// Deactivate assignment during refactoring to avoid confusion -// const XString &operator =(const char* S); -// const XString &operator =(char); -// const XString &operator =(int); -// const XString &operator =(unsigned int); -// const XString &operator =(long); -// const XString &operator =(unsigned long long); - - const XString &operator += (const XString &); - const XString &operator += (const char* S); -// const XString &operator += (const XConstString &aConstString); - -// Deactivate assignment during refactoring to avoid confusion -// const XString &operator += (char); -// const XString &operator += (int); -// const XString &operator += (unsigned int); -// const XString &operator += (long); -// const XString &operator += (unsigned long long); - - XString SubString(xsize pos, xsize count) const; - - xsize IdxOf(char c, xsize Pos = 0) const; - - xsize IdxOf(const char* s, xsize s_len, xsize pos) const; - xsize IdxOf(const char* s, xsize pos = 0) const { return IdxOf(s, strlen(s), pos); } - xsize IdxOf(const XString &S, xsize pos = 0) const { return IdxOf(S.c_str(), S.length(), pos); } - bool ExistIn(const char* s, xsize s_len, xsize pos = 0) const { return IdxOf(s, s_len, pos) != MAX_XSIZE; } - bool ExistIn(const char* s, xsize pos = 0) const { return IdxOf(s, pos) != MAX_XSIZE; } - bool ExistIn(const XString &S, xsize pos = 0) const { return IdxOf(S, pos) != MAX_XSIZE; } - - xsize IdxOfIC(const char* s, xsize s_len, xsize pos) const; - xsize IdxOfIC(const char* s, xsize pos = 0) const { return IdxOfIC(s, strlen(s), pos); } - xsize IdxOfIC(const XString &S, xsize pos = 0) const { return IdxOfIC(S.c_str(), S.length(), pos); } - bool ExistInIC(const char* s, xsize s_len, xsize pos = 0) const { return IdxOfIC(s, s_len, pos) != MAX_XSIZE; } - bool ExistInIC(const char* s, xsize pos = 0) const { return IdxOfIC(s, pos) != MAX_XSIZE; } - bool ExistInIC(const XString &S, xsize pos = 0) const { return IdxOfIC(S, pos) != MAX_XSIZE; } - -#ifdef TODO_skqdjfhksqjhfksjqdf - bool ExistInIAC(const XString &S) const { return IdxOfIC(S) != MAX_XSIZE; } -#endif - - -#ifdef TODO_skqdjfhksqjhfksjqdf - xsize IdxOfIAC(const XString &S, xsize Pos = 0) const; -#endif - - - xsize RIdxOf(const char* s, xsize s_len, xsize pos) const; - xsize RIdxOf(const char* s, xsize pos = MAX_XSIZE) const { return IdxOf(s, strlen(s), pos); } - xsize RIdxOf(const XString &S, xsize pos = MAX_XSIZE) const { return IdxOf(S.c_str(), S.length(), pos); } - - void ToLower(bool FirstCharIsCap = false); - bool IsLetters() const; - bool IsLettersNoAccent() const; - bool IsDigits() const; - bool IsDigits(xsize pos, xsize count) const; - -#ifdef TODO_skqdjfhksqjhfksjqdf - bool DeleteIC(const XString &S); -#endif - void Replace(char c1, char c2); - XString SubStringReplace(char c1, char c2); - - int Compare(const char* S) const { return strcmp(data(), (S ? S : "")); }// AsciiStrCmp return 0 or !0, not usual strcmp -#ifdef TODO_skqdjfhksqjhfksjqdf - //IC - int CompareIC(const char* S) const { return StringCompareIC(data(), (S ? S : "")); } - // IA - int CompareIA(const char* S) const { return StringCompareIA(data(), (S ? S : "")); } - // IAC - int CompareIAC(const char* S) const { return StringCompareIAC(data(), (S ? S : "")); } -/* - int CompareIACSubString(const char* S, size_t LenS) const { return SubStringCompareIAC(data(), length(), S, LenS); } //SubStringCompareIC renvoi 0 (ÈgalitÈ) si Len1 ou Len2 == 0 - int CompareIACSubString(xsize Pos, const char* S, size_t LenS) const { return SubStringCompareIAC(data(Pos), length()-Pos, S, LenS); } //SubStringCompareIC renvoi 0 (ÈgalitÈ) si Len1 ou Len2 == 0 - int CompareIACSubString(xsize Pos, xsize Len, const char* S, size_t LenS) const { return SubStringCompareIAC(data(Pos), Len, S, LenS); } -*/ -#endif - -// bool Equal(const char* S) const { return strcmp(data(), (S ? S : "")) == 0; }; - bool Equal(const XString& S) const { return strcmp(c_str(), S.c_str()) == 0; }; -// bool BeginEqual(const char* S) const { return StringBeginEqual(data(), S); } -// bool SubStringEqual(xsize Pos, const char* S) const { return StringBeginEqual(data(Pos), S); } -#ifdef TODO_skqdjfhksqjhfksjqdf - // IC - bool EqualIC(const char* S) const { return StringEqualIC(data(), S); } - bool BeginEqualIC(const char* S) const { return StringBeginEqualIC(data(), S); } - bool SubStringEqualIC(xsize Pos, const char* S) const { return StringBeginEqualIC(data(Pos), S); } - bool EqualSubStringIC(const char* S) const { return StringBeginEqualIC(S, data()); } - // IA - bool EqualIA(const char* S) const { return CompareIA(S) == 0; }; - // IAC - bool EqualIAC(const char* S) const { return CompareIAC(S) == 0; }; - bool BeginEqualIAC(const char* S) const { return StringBeginEqualIAC(data(), S); } - bool SubStringEqualIAC(xsize Pos, const char* S) const { return StringBeginEqualIAC(data(Pos), S); } - bool EqualSubStringIAC(const char* S) const { return StringBeginEqualIAC(S, data()); } - - -/* bool EqualIACSubString(const char* S, size_t LenS) const { return CompareIACSubString(S, LenS) == 0; } - bool EqualIACSubString(xsize Pos, const char* S, size_t LenS) const { return CompareIACSubString(Pos, S, LenS) == 0; } - bool EqualIACSubString(xsize Pos, xsize Len, const char* S, size_t LenS) const { return CompareIACSubString(Pos, Len, S, LenS) == 0; } -*/ -#endif - - XString basename() const; - XString dirname() const; - -// size_t Sizeof() const { return size_t(sizeof(xsize)+length()); } // overflow ? underflow ? -// bool ReadFromBuf(const char *buf, size_t *idx, size_t count); -// bool WriteToBuf(char *buf, size_t *idx, size_t count) const; -// bool ReadFromFILE(FILE *fp); -// bool WriteToFILE(FILE *fp) const; -// // -// bool ReadFromXBuffer(XRBuffer &unXBuffer); // Impossible de mettre le XBuffer en const car il y a une variable d'instance de XBuffer incrÈmentÈe par ReadFromXBuffer -// void CatToXBuffer(XBuffer *unXBuffer) const; -//// void WriteToXBuffer(XBuffer *unXBuffer, xsize *idx) const; - - public: - // OpÈrateur + - // Chaines - friend XString operator + (const XString& p1, const XString& p2) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (const XString& p1, const char *p2 ) { XString s; s=p1; s+=p2; return s; } -// XString operator + (const char *p2 ) { XString s(*this); s+=p2; return s; } - - friend XString operator + (const char *p1, const XString& p2) { XString s; s.takeValueFrom(p1); s+=p2; return s; } -// friend XString operator + (const XConstString& p1, const XString& p2) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (const XString& p1, const XConstString& p2) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (const XConstString& p1, const XConstString& p2) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (const XConstString &p1, const char *p2 ) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (const char *p1, const XConstString &p2) { XString s; s=p1; s+=p2; return s; } - -// deactivate during refactoring -// // Char -// friend XString operator + (const XString& p1, char p2 ) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (char p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; } -// // NumÈrique -// friend XString operator + (const XString& p1, int p2 ) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (int p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (const XString& p1, unsigned int p2 ) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (unsigned int p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (const XString& p1, long p2 ) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (long p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (const XString& p1, unsigned long long p2 ) { XString s; s=p1; s+=p2; return s; } -// friend XString operator + (unsigned long long p1, const XString& p2 ) { XString s; s=p1; s+=p2; return s; } - - // OpÈrateur == - // Chaines - friend bool operator == (const XString& s1, const XString& s2) { return s1.Equal(s2); } -// friend bool operator == (const XString& s1, const char* s2 ) { return s1.Equal(s2); } // during refactor -// friend bool operator == (const char* s1, const XString& s2) { return s2.Equal(s1); } // during refactor -// friend bool operator == (const XConstString &s1, const XString& s2) { return s1.Compare(s2) == 0; } -// friend bool operator == (const XString &s1, const XConstString& s2) { return s1.Compare(s2) == 0; } -// friend bool operator == (const XConstString &s1, const XConstString& s2) { return s1.Compare(s2) == 0; } - - friend bool operator != (const XString& s1, const XString& s2) { return !s1.Equal(s2); } -// friend bool operator != (const XString& s1, const char* s2 ) { return !s1.Equal(s2); } // during refactor -// friend bool operator != (const char* s1, const XString& s2) { return !s2.Equal(s1); } // during refactor -// friend bool operator != (const XConstString &s1, const XString& s2) { return s1.Compare(s2) != 0; } -// friend bool operator != (const XString &s1, const XConstString& s2) { return s1.Compare(s2) != 0; } -// friend bool operator != (const XConstString &s1, const XConstString& s2) { return s1.Compare(s2) != 0; } - -// friend bool operator < (const XString& s1, const XString& s2) { return s1.Compare(s2) < 0; } -// friend bool operator < (const XString& s1, const char* s2 ) { return s1.Compare(s2) < 0; } -// friend bool operator < (const char* s1, const XString& s2) { return s2.Compare(s1) > 0; } -// -// friend bool operator > (const XString& s1, const XString& s2) { return s1.Compare(s2) > 0; } -// friend bool operator > (const XString& s1, const char* s2 ) { return s1.Compare(s2) > 0; } -// friend bool operator > (const char* s1, const XString& s2) { return s2.Compare(s1) < 0; } -// -// friend bool operator <= (const XString& s1, const XString& s2) { return s1.Compare(s2) <= 0; } -// friend bool operator <= (const XString& s1, const char* s2 ) { return s1.Compare(s2) <= 0; } -// friend bool operator <= (const char* s1, const XString& s2) { return s2.Compare(s1) >= 0; } -// -// friend bool operator >= (const XString& s1, const XString& s2) { return s1.Compare(s2) >= 0; } -// friend bool operator >= (const XString& s1, const char* s2 ) { return s1.Compare(s2) >= 0; } -// friend bool operator >= (const char* s1, const XString& s2) { return s2.Compare(s1) <= 0; } - - static char to_lower(char ch) { return (((ch >= 'A') && (ch <= 'Z')) ? ((ch - 'A') + 'a') : ch); } }; -extern const XString NullXString; +class XString16 : public XStringAbstract +{ + public: + XString16() : XStringAbstract() {}; + XString16(const XString16& S) : XStringAbstract(S) {} + + template + XString16(const XStringAbstract &S) : XStringAbstract(S) {} + + XString16& operator=(const XString16 &S) { this->XStringAbstract::operator=(S); return *this; } + + using XStringAbstract::operator =; +}; + +class XString32 : public XStringAbstract +{ + public: + XString32() : XStringAbstract() {}; + XString32(const XString32& S) : XStringAbstract(S) {} + + template + XString32(const XStringAbstract &S) : XStringAbstract(S) {} + + XString32& operator=(const XString32 &S) { this->XStringAbstract::operator=(S); return *this; } + + using XStringAbstract::operator =; +}; + +class XStringW : public XStringAbstract +{ + public: + XStringW() : XStringAbstract() {}; + XStringW(const XStringW& S) : XStringAbstract(S) {} + + template + XStringW(const OtherXStringClass& S) : XStringAbstract(S) {} + + XStringW& operator=(const XStringW &S) { this->XStringAbstract::operator=(S); return *this; } + + using XStringAbstract::operator =; + + + +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; + + va_start (va, format); + vSWPrintf(format, va); + va_end(va); + } + +}; XString operator"" _XS ( const char* s, size_t len); +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); -XString SPrintf(const char *format, ...) __attribute__((format(printf, 1, 2))); -XString SubString(const char *s, xsize s_len, xsize pos, xsize count); -inline XString SubString(const char *s, xsize pos, xsize count) { return SubString(s, strlen(s), pos, count); } -inline XString SubString(const XString& S, xsize pos, xsize count) { return SubString(S.c_str(), S.length(), pos, count); } +extern const XString NullXString; +extern const XStringW NullXStringW; - -#ifdef TODO_skqdjfhksqjhfksjqdf -XString ToAlpha(const char *S); -XString ToAlpha(const XString &S); -XString ToLower(const char *S, bool FirstCharIsCap = false); -XString ToUpper(const char *S); +#ifdef _MSC_VER +# define __attribute__(x) #endif -// Deactivate assignment during refactoring to avoid confusion -//XString CleanCtrl(const XString &S); + +XString SPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2))); +XStringW SWPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2))); #endif diff --git a/rEFIt_UEFI/cpp_foundation/XStringAbstract copy.h b/rEFIt_UEFI/cpp_foundation/XStringAbstract copy.h new file mode 100755 index 000000000..b01105595 --- /dev/null +++ b/rEFIt_UEFI/cpp_foundation/XStringAbstract copy.h @@ -0,0 +1,890 @@ +//************************************************************************************************* +//************************************************************************************************* +// +// XSTRING +// +//************************************************************************************************* +//************************************************************************************************* + +#if !defined(__XSTRINGABSTRACT_H__) +#define __XSTRINGABSTRACT_H__ + +#include "XToolsCommon.h" +#include "unicode_conversions.h" + +#ifndef DEBUG_ALL +#define DEBUG_XStringAbstract 0 +#else +#define DEBUG_TEXT DEBUG_ALL +#endif + +#if DEBUG_XStringAbstract == 0 +#define DBG_XSTRING(...) +#else +#define DBG_XSTRING(...) DebugLog(DEBUG_XStringAbstract, __VA_ARGS__) +#endif + +//#include + +#define LPATH_SEPARATOR L'\\' + +#if __WCHAR_MAX__ <= 0xFFFFu + #define wchar_cast char16_t +#else + #define wchar_cast char32_t +#endif + + +struct XStringAbstract__false_type { + static constexpr bool value = false; +}; + +struct XStringAbstract__true_type { + static constexpr bool value = true; +}; + +/* make unsigned */ +template +struct XStringAbstract__make_unsigned {}; + +//template <> struct __make_unsigned {}; +template <> struct XStringAbstract__make_unsigned< signed char> {typedef unsigned short type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned short type;}; +template <> struct XStringAbstract__make_unsigned< signed short> {typedef unsigned short type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned short type;}; +template <> struct XStringAbstract__make_unsigned< signed int> {typedef unsigned int type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned int type;}; +template <> struct XStringAbstract__make_unsigned< signed long> {typedef unsigned long type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned long type;}; +template <> struct XStringAbstract__make_unsigned< signed long long> {typedef unsigned long long type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned long long type;}; + +/* enable_if */ +template +struct XStringAbstract__enable_if_t +{}; + +template +struct XStringAbstract__enable_if_t { + typedef T type; +}; +//#define enable_if(x) XStringAbstract__enable_if_t(x, void)::type +#define enable_if(x) typename enable_if_type = typename XStringAbstract__enable_if_t::type +// +//template< bool B, class T = void > +//using XStringAbstract__enable_if_t = typename XStringAbstract__enable_if::type; + + +// is_integral +template struct XStringAbstract__is_integral_st : public XStringAbstract__false_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +#define is_integral(x) XStringAbstract__is_integral_st::value + + + + + + + +#define asciiToLower(ch) (((ch >= L'A') && (ch <= L'Z')) ? ((ch - L'A') + L'a') : ch) + +template +int XStringAbstract__compare(const S* src, const O* other, bool ignoreCase) +{ +// size_t len_s = length_of_utf_string(src); +// size_t len_other = length_of_utf_string(other); + size_t nb = 0; + const S* src2 = src; + const O* other2 = other; + + char32_t src_char32; + char32_t other_char32; + src2 = get_char32_from_string(src2, &src_char32); + other2 = get_char32_from_string(other2, &other_char32); + while ( src_char32 ) { + if ( ignoreCase ) { + src_char32 = asciiToLower(src_char32); + other_char32 = asciiToLower(other_char32); + } + if ( src_char32 != other_char32 ) break; + src2 = get_char32_from_string(src2, &src_char32); + other2 = get_char32_from_string(other2, &other_char32); + nb += 1; + }; + if ( src_char32 == other_char32 ) return 0; + return src_char32 > other_char32 ? 1 : -1; +} + +template +size_t XStringAbstract__indexOf(const O** s, const P* other, size_t offsetRet, bool toLower) +{ + size_t i; + size_t Idx = 0; + + char32_t s_char32; + char32_t other_char32; + + do + { + i = 0; + const O* s2 = *s; + const P* other2 = other; + do { + s2 = get_char32_from_string(s2, &s_char32); + other2 = get_char32_from_string(other2, &other_char32); + if ( toLower ) { + s_char32 = asciiToLower(s_char32); + other_char32 = asciiToLower(other_char32); + } + } while ( s_char32 && other_char32 && s_char32 == other_char32 ); + if ( other_char32 == 0 ) return Idx+offsetRet; + *s = get_char32_from_string(*s, &s_char32); + Idx++; + } while (s_char32); + return MAX_XSIZE; +} + +template +size_t XStringAbstract__indexOf(const O* s, size_t Pos, const P* other, bool toLower) +{ + if ( *other == 0 ) return Pos; + + char32_t char32 = 1; + for ( size_t Idx=0 ; Idx +size_t XStringAbstract__rindexOf(const O* s, size_t Pos, const P* other, bool toLower) +{ + if ( *other == 0 ) return Pos > length_of_utf_string(s) ? length_of_utf_string(s) : Pos; + + size_t index = XStringAbstract__indexOf(&s, other, 0, toLower); + size_t prev_index = index; // initialize to index in case of index is already == Pos + + char32_t char32; + s = get_char32_from_string(s, &char32); + while ( char32 && index < Pos ) { + prev_index = index; + index = XStringAbstract__indexOf(&s, other, index+1, toLower); + s = get_char32_from_string(s, &char32); + }; + if ( index == Pos ) return index; + if ( prev_index <= Pos ) return prev_index; + return MAX_XSIZE; +} + +//template +//size_t XStringAbstract__rindexOf(const O* s, size_t Pos, const P* other, bool toLower) +//{ +// size_t index = XStringAbstract__indexOf(s, 0, other, toLower); +// size_t prev_index = index; // initialize to index in case of index is already == Pos +// while ( index < Pos ) { +// prev_index = index; +// index = XStringAbstract__indexOf(s, index+1, other, toLower); +// }; +// if ( index == Pos ) return index; +// if ( prev_index <= Pos ) return prev_index; +// return MAX_XSIZE; +//} + + +//template +template +class XStringAbstract +{ +public: +// const SubType NullXString; + static T nullChar; + +class XString16; + XStringAbstract(const XString16 &S) + { + Init(0); + takeValueFrom(S); + } + +protected: + T *m_data; + size_t m_allocatedSize; + + // convenience method. Did it this way to avoid #define in header. They can have an impact on other headers + size_t min(size_t x1, size_t x2) const { if ( x1 < x2 ) return x1; return x2; } + size_t max(size_t x1, size_t x2) const { if ( x1 > x2 ) return x1; return x2; } + +// Methods _data is protected intentionally. They are const method returning non-const pointer. That's intentional, but dangerous. Do not expose to public. +// If you need a non-const pointer for low-level access, to use dataSized and have to specify the size + // pos is counted in logical char + template + T* _data(IntegralType pos) const + { + if ( pos<0 ) panic("T* data(int i) -> i < 0"); + size_t offset = size_of_utf_string_len(m_data, (typename XStringAbstract__make_unsigned::type)pos); // If pos is too big, size_of_utf_string_len returns the end of the string + return m_data + offset; + } + + //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + // Init , Alloc + //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + + void Init(size_t aSize=0) + { + //DBG_XSTRING("Init aSize=%d\n", aSize); + // We don't allocate any memory at first. To not have to test all the time if m_data is null, we init it to an empty string + m_data = &nullChar; + m_allocatedSize = 0; + // if aSize == 0, nothing is done, because m_allocatedSize == aSize + CheckSize(aSize, 0); + } +public: + T *CheckSize(size_t nNewSize, size_t nGrowBy = 16) // nNewSize is in number of chars, NOT bytes + { + //DBG_XSTRING("CheckSize: m_size=%d, nNewSize=%d\n", m_size, nNewSize); + + if ( m_allocatedSize < nNewSize ) + { + nNewSize += nGrowBy; + if ( m_allocatedSize == 0 ) m_data = (T*)malloc( (nNewSize+1)*sizeof(T) ); + else m_data = (T*)realloc(m_data, (nNewSize+1)*sizeof(T), (m_allocatedSize+1)*sizeof(T)); + if ( !m_data ) { + DebugLog(2, "XStringAbstract::CheckSize(%zu, %zu) : realloc(%" PRIuPTR ", %lu, %zd) returned NULL. System halted\n", nNewSize, nGrowBy, uintptr_t(m_data), nNewSize*sizeof(T), m_allocatedSize*sizeof(T)); + panic(); + } + m_allocatedSize = nNewSize; + m_data[m_allocatedSize] = 0; // we allocated one more char (nNewSize+1). This \0 is an extra precaution. It's not for the normal null terminator. All string operation must considered that only m_allocatedSize bytes were allocated. + } + return m_data; + } +// void setSize(size_t newSize) // nNewSize is in number of chars, NOT bytes +// { +// //DBG_XSTRING("setLength(%d)\n", len); +// CheckSize(newSize); +// // if ( len >= size() ) { +// // DBG_XSTRING("XStringAbstract::setLength(size_t len) : len >= size() (%d != %d). System halted\n", len, size()); +// // panic(); +// // } +// m_data[newSize] = 0; // we may rewrite a 0 in nullChar, if no memory were allocated. That's ok. +// } + + +// T* memoryOffset(size_t i) { +// +// } + +public: + XStringAbstract() + { + DBG_XSTRING("Construteur\n"); + Init(0); + } + + ~XStringAbstract() + { + //DBG_XSTRING("Destructor :%ls\n", data()); + if ( m_allocatedSize > 0 ) free((void*)m_data); + } + + template + T* data(IntegralType pos) const { return _data(pos); } + +// template::value, IntegralType>::type* = nullptr> + template + T* dataSized(IntegralType size) const + { + if ( size<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); + CheckSize((typename XStringAbstract__make_unsigned::type)size); + return s(); + } + + // Pos is counted in logical char but size is counted in physical char (char, char16_t, char32_t or wchar_t) + template + T* dataSized(IntegralType1 pos, IntegralType2 size) + { + if ( pos<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); + if ( size<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); + size_t offset = size_of_utf_string_len(m_data, (typename XStringAbstract__make_unsigned::type)pos); // If pos is too big, size_of_utf_string_len returns the end of the string + CheckSize(offset + (typename XStringAbstract__make_unsigned::type)size); + return _data(pos); + } + +// const T* data(unsigned int ui) const { return _data(ui); } +// const T* data(int i) const { return _data(i); } +// const T* data(size_t ui) const { return _data(ui); } +// const T* data(xisize i) const { return _data(i); } +// +// T* dataSized(unsigned int ui, size_t sizeMin, size_t nGrowBy=16) { CheckSize(ui+sizeMin, nGrowBy); return _data(ui); } +// T* dataSized(unsigned long ui, size_t sizeMin, size_t nGrowBy=16) { CheckSize(ui+sizeMin, nGrowBy); return _data(ui); } +// T* dataSized(unsigned long long ui, size_t sizeMin, size_t nGrowBy=16) { CheckSize(ui+sizeMin, nGrowBy); return _data(ui); } +// T* dataSized(int i, size_t sizeMin, size_t nGrowBy=16) { if ( i<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); CheckSize((unsigned int)i+sizeMin, nGrowBy); return _data(i); } +// T* dataSized(long i, size_t sizeMin, size_t nGrowBy=16) { if ( i<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); CheckSize((unsigned long)i+sizeMin, nGrowBy); return _data(i); } +// T* dataSized(long long i, size_t sizeMin, size_t nGrowBy=16) { if ( i<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); CheckSize((unsigned long long)i+sizeMin, nGrowBy); return _data(i); } + + T* forgetDataWithoutFreeing() + { + T* ret = m_data; + Init(0); + return ret; + } + + size_t length() const { return length_of_utf_string(m_data); } +// size_t sizeZZ() const { return size_of_utf_string(m_data); } + size_t sizeInBytes() const { return size_of_utf_string(m_data)*sizeof(T); } + size_t allocatedSize() const { return m_allocatedSize; } + + + const T* wc_str() const { return m_data; } + const T* c_str() const { return m_data; } + const T* s() const { return m_data; } + const T* data() const { return m_data; } // todo delete + + /* Empty ? */ + void setEmpty() { m_data[0] = 0; } // we may rewrite a 0 in nullChar if no memory were allocated (m_data == &nullChar). That's ok. + bool isEmpty() const { return m_data == nullptr || *m_data == 0; } + bool notEmpty() const { return !isEmpty(); } + + + //--------------------------------------------------------------------- cast + +// int ToInt() const; +// size_t ToUInt() const; + + + //--------------------------------------------------------------------- charAt, [] + + template + char32_t char32At(IntegralType i) const + { + if (i < 0) { + DBG_XSTRING("XStringAbstract::char32At(size_t i) : i < 0. System halted\n"); + panic(); + } + size_t nb = 0; + const T *p = m_data; + char32_t char32; + do { + p = get_char32_from_string(p, &char32); + if (!char32) { + panic("XStringAbstract::char32At(size_t i) : i >= length(). System halted\n"); + } + nb += 1; + } while (nb <= (typename XStringAbstract__make_unsigned::type)i ); + return char32; + } + + template + char16_t char16At(IntegralType i) const + { + char32_t char32 = char32At(i); + if ( char32 >= 0x10000 ) return 0xFFFD; // � REPLACEMENT CHARACTER used to replace an unknown, unrecognized or unrepresentable character + return (char16_t)char32; + } + + /* [] */ + template + const char32_t operator [](IntegralType i) const { return char32At(i); } + + + const char32_t LastChar() const { if ( length() > 0 ) return char32At(length()-1); else return 0; } + + //--------------------------------------------------------------------- strcat, strcpy, operator = + /* strncpy */ + template + void strncpy(const O* other, size_t other_len) + { + if ( other && *other && other_len > 0 ) { + size_t newSize = utf_size_of_utf_string_len(m_data, other, other_len); + CheckSize(newSize+1, 0); + utf_string_from_utf_string_len(m_data, m_allocatedSize, other, other_len); + m_data[newSize] = 0; + }else{ + setEmpty(); + } + } + // Old name. TODO remove + template + void StrnCpy(const O* other, size_t other_len) { strncpy(other, other_len); } + + /* strcpy */ + template + void strcpy(const O* other) + { + if ( other && *other ) { + size_t newSize = utf_size_of_utf_string(m_data, other); + CheckSize(newSize+1, 0); + utf_string_from_utf_string(m_data, m_allocatedSize, other); + m_data[newSize] = 0; + }else{ + setEmpty(); + } + } + /* strncat */ + template + void strncat(const O* other, size_t other_len) + { + if ( other && *other && other_len > 0 ) { + size_t currentSize = size_of_utf_string(m_data); + size_t newSize = currentSize + utf_size_of_utf_string_len(m_data, other, other_len); + CheckSize(newSize+1, 0); + utf_string_from_utf_string_len(m_data+currentSize, m_allocatedSize, other, other_len); + m_data[newSize] = 0; + }else{ + // nothing to do + } + } + /* strcat */ + template + void strcat(const O* other) + { + if ( other && *other ) { + size_t currentSize = size_of_utf_string(m_data); // size is number of T, not in bytes + size_t newSize = currentSize + utf_size_of_utf_string(m_data, other); // size is number of T, not in bytes + CheckSize(newSize+1, 0); + utf_string_from_utf_string(m_data+currentSize, m_allocatedSize-currentSize, other); + m_data[newSize] = 0; + }else{ + // nothing to do + } + } + /* takeValueFrom */ + template + XStringAbstract& takeValueFrom(const XStringAbstract& S) { strcpy(S.s()); return *this; } + template + XStringAbstract& takeValueFrom(const O* S) { strcpy(S); return *this; } + template + XStringAbstract& takeValueFrom(const XStringAbstract& S, size_t len) { strncpy(S.data(0), len); return *this; } + template + XStringAbstract& takeValueFrom(const O* S, size_t len) { strncpy(S, len); return *this; } + + /* copy ctor */ + XStringAbstract(const XStringAbstract &S) { Init(0); takeValueFrom(S); } + /* ctor */ + template + explicit XStringAbstract(const XStringAbstract &S) { Init(0); takeValueFrom(S); } + + /* Copy Assign */ // Only other XString, no litteral at the moment. + XStringAbstract& operator =(const XStringAbstract& S) { strcpy(S.s()); return *this; } + /* Assign */ + template + XStringAbstract& operator =(const XStringAbstract& S) { strcpy(S.s()); return *this; } + + /* += */ + template + XStringAbstract& operator += (const XStringAbstract& S) { strcat(S.s()); return *this; } + template + XStringAbstract& operator += (const O* S) { strcat(S); return *this; } + + // + operator + template + friend XStringAbstract operator + (const XStringAbstract& p1, const XStringAbstract& p2) { XStringAbstract s; s=p1; s+=p2; return s; } + template + friend XStringAbstract operator + (const XStringAbstract& p1, const O* p2 ) { XStringAbstract s; s=p1; s+=p2; return s; } + template + friend XStringAbstract operator + (const O *p1, const XStringAbstract& p2) { XStringAbstract s; s.strcat(p1); s.strcat(p2.s()); return s; } + + + + //--------------------------------------------------------------------- indexOf, rindexOf + + /* indexOf */ + size_t indexOf(char32_t char32Searched, size_t Pos = 0) const + { + char32_t buf[2] = { char32Searched, 0}; + return XStringAbstract__indexOf(m_data, Pos, buf, false); + } + template + size_t indexOf(const O* S, size_t Pos = 0) const { return XStringAbstract__indexOf(m_data, Pos, S, false); } + template + size_t indexOf(const XStringAbstract& S, size_t Pos = 0) const { return indexOf(S.s(), Pos); } + // old name : todo remove + size_t IdxOf(char c, size_t Pos = 0) const { return indexOf((char32_t)c, Pos); } + template + size_t IdxOf(const XStringAbstract& S, size_t Pos = 0) const { return indexOf(S, Pos); } + /* IC */ + size_t indexOfIC(char32_t char32Searched, size_t Pos = 0) const + { + char32_t buf[2] = { char32Searched, 0}; + return XStringAbstract__indexOf(m_data, Pos, buf, true); + } + template + size_t indexOfIC(const O* S, size_t Pos = 0) const { return XStringAbstract__indexOf(m_data, Pos, S, true); } + template + size_t indexOfIC(const XStringAbstract& S, size_t Pos = 0) const { return indexOfIC(S.s(), Pos); } + + + /* rindexOf */ + size_t rindexOf(const char32_t char32Searched, size_t Pos = MAX_XSIZE-1) const + { + char32_t buf[2] = { char32Searched, 0}; + return XStringAbstract__rindexOf(m_data, Pos, buf, false); + } + template + size_t rindexOf(const O* S, size_t Pos = MAX_XSIZE-1) const { return XStringAbstract__rindexOf(m_data, Pos, S, false); } + template + size_t rindexOf(const XStringAbstract& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); } + /* IC */ + size_t rindexOfIC(const char32_t char32Searched, size_t Pos = MAX_XSIZE-1) const + { + char32_t buf[2] = { char32Searched, 0}; + return XStringAbstract__rindexOf(m_data, Pos, buf, true); + } + template + size_t rindexOfIC(const O* S, size_t Pos = MAX_XSIZE-1) const { return XStringAbstract__rindexOf(m_data, Pos, S, true); } + template + size_t rindexOfIC(const XStringAbstract& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); } + + + //--------------------------------------------------------------------- + + XStringAbstract lowerAscii() + { + T* s = m_data; + while ( *s ) { + *s = asciiToLower(*s); + s++; + } + return *this; + } + +// void deleteCountCharsAt(size_t pos, size_t count=1); +//{ +// if ( pos < size() ) { +// if ( count != MAX_XSIZE && pos + count < size() ) { +// memmove( _data(pos), data(pos+count), (size()-pos-count)*sizeof(T)); // memmove handles overlapping memory move +// setLength(size()-count);/* data()[length()-count]=0 done in setLength */ +// }else{ +// setSize(pos);/* data()[pos]=0 done in setLength */ +// } +// } +//} +// void insert(const XStringAbstract& Str, size_t pos); +//{ +// if ( pos < size() ) { +// CheckSize(size()+Str.size()); +// memmove(_data(pos + Str.size()), data(pos), (size()-pos)*sizeof(T)); +// memmove(_data(pos), Str.data(), Str.size()*sizeof(T)); +// setLength(size()+Str.size()); +// }else{ +// StrCat(Str); +// } +//} + + XStringAbstract SubString(size_t pos, size_t count) const + { + if ( count > length()-pos ) count = length()-pos; + XStringAbstract ret; + + const T* src = m_data; + char32_t char32 = 1; + while ( char32 && pos > 0 ) { + src = get_char32_from_string(src, &char32); + pos -= 1; + }; + ret.strncat(src, count); + return ret; + } + + // todo rename to contains + template + bool ExistIn(const XStringAbstract& S) const { return indexOf(S) != MAX_XSIZE; } + template + bool ExistIn(const O* S) const { return indexOf(S) != MAX_XSIZE; } + template + size_t ExistInIC(const O* S) const { return indexOfIC(S) != MAX_XSIZE; } + template + size_t ExistInIC(const XStringAbstract& S) const { return indexOfIC(S) != MAX_XSIZE; } + + +// void ToLower(bool FirstCharIsCap = false); +// bool IsLetters() const; +// bool IsLettersNoAccent() const; +// bool IsDigits() const; +//{ +// const T *p; +// +// p = data(); +// if ( !*p ) return false; +// for ( ; *p ; p+=1 ) { +// if ( *p < '0' ) return false; +// if ( *p > '9' ) return false; +// } +// return true; +//} +// bool IsDigits(size_t pos, size_t count) const; +//{ +// const T *p; +// const T *q; +// +// if ( pos >= size() ) { +// return false; +// } +// if ( pos+count > size() ) { +// return false; +// } +// p = data() + pos; +// q = p + count; +// for ( ; p < q ; p+=1 ) { +// if ( *p < '0' ) return false; +// if ( *p > '9' ) return false; +// } +// return true; +//} + +// void Replace(T c1, T c2) +// { +// T* p; +// +// p = s(); +// while ( *p ) { +// if ( *p == c1 ) *p = c2; +// p += 1; +// } +// } +// XStringAbstract SubStringReplace(T c1, T c2); +//{ +// T* p; +// XStringAbstract Result; +// +// p = s(); +// while ( *p ) { +// if ( *p == c1 ) Result += c2; +// else Result += *p; +// p++; +// } +// return Result; +//} +// +// SubType basename() const +// { +// size_t idx = RIdxOf(LPATH_SEPARATOR); +// if ( idx == MAX_XSIZE ) return SubType(); +// return SubString(idx+1, size()-idx-1); +// } +// SubType dirname() const +// { +// size_t idx = RIdxOf(LPATH_SEPARATOR); +// if ( idx == MAX_XSIZE ) return SubType(); +// return SubString(0, idx); +// } +// void RemoveLastEspCtrl(); + + //--------------------------------------------------------------------- + + template + int strcmp(const O* S) const { return XStringAbstract__compare(m_data, S, false); } +// int Compare(const char* S) const { return ::Compare(m_data, S); } +// int Compare(const char16_t* S) const { return ::Compare(m_data, S); }; +// int Compare(const char32_t* S) const { return ::Compare(m_data, S); }; +// int Compare(const wchar_t* S) const { return ::Compare(m_data, S); }; +// + template + bool Equal(const O* S) const { return XStringAbstract__compare(m_data, S, false); } + template + bool EqualIC(const O* S) const { return XStringAbstract__compare(m_data, S, true); } + template + bool EqualIC(const XStringAbstract& S) const { return XStringAbstract__compare(m_data, S.s(), true); } +// bool BeginingEqual(const T* S) const { return (memcmp(data(), S, wcslen(S)) == 0); } +// bool SubStringEqual(size_t Pos, const T* S) const { return (memcmp(data(Pos), S, wcslen(S)) == 0); } + +public: + // == operator + template + friend bool operator == (const XStringAbstract& s1, const XStringAbstract& s2) { return s1.strcmp(s2.s()) == 0; } + template + friend bool operator == (const XStringAbstract& s1, const O* s2) { return s1.strcmp(s2) == 0; } + template + friend bool operator == (const O* s1, const XStringAbstract& s2) { return s2.strcmp(s1) == 0; } + + template + friend bool operator != (const XStringAbstract& s1, const XStringAbstract& s2) { return !(s1 == s2); } + template + friend bool operator != (const XStringAbstract& s1, const O* s2) { return !(s1 == s2); } + template + friend bool operator != (const O* s1, const XStringAbstract& s2) { return !(s2 == s1); } + + template + friend bool operator < (const XStringAbstract& s1, const XStringAbstract& s2) { return s1.strcmp(s2.s()) < 0; } + template + friend bool operator < (const XStringAbstract& s1, const O* s2 ) { return s1.strcmp(s2) < 0; } + template + friend bool operator < (const O* s1, const XStringAbstract& s2) { return s2.strcmp(s1) > 0; } + + template + friend bool operator > (const XStringAbstract& s1, const XStringAbstract& s2) { return s1.strcmp(s2.s()) > 0; } + template + friend bool operator > (const XStringAbstract& s1, const O* s2 ) { return s1.strcmp(s2) > 0; } + template + friend bool operator > (const O* s1, const XStringAbstract& s2) { return s2.strcmp(s1) < 0; } + + template + friend bool operator <= (const XStringAbstract& s1, const XStringAbstract& s2) { return s1.strcmp(s2.s()) <= 0; } + template + friend bool operator <= (const XStringAbstract& s1, const O* s2 ) { return s1.strcmp(s2) <= 0; } + template + friend bool operator <= (const O* s1, const XStringAbstract& s2) { return s2.strcmp(s1) >= 0; } + + template + friend bool operator >= (const XStringAbstract& s1, const XStringAbstract& s2) { return s1.strcmp(s2.s()) >= 0; } + template + friend bool operator >= (const XStringAbstract& s1, const O* s2 ) { return s1.strcmp(s2) >= 0; } + template + friend bool operator >= (const O* s1, const XStringAbstract& s2) { return s2.strcmp(s1) <= 0; } + +}; + + +template +T XStringAbstract::nullChar = 0; + + + +//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +// Constructor +//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + + +// +//template +//XStringAbstract::XStringAbstract(const XStringAbstract &aString) +//{ +//DBG_XSTRING("Constructor(const XStringAbstract &aString) : %ls\n", aString.data()); +// Init(aString.size()); +// memcpy(m_data, aString.m_data, aString.sizeInBytes()); +//} + + +// +//template +//void XStringAbstract::RemoveLastEspCtrl() +//{ +// T *p; +// +// if ( size() > 0 ) { +// p = s() + size() - 1; +// #if __WCHAR_MIN__ < 0 +// if ( *p >= 0 && *p <= ' ' ) { +// #else +// if ( *p <= ' ' ) { +// #endif +// p -= 1; +// #if __WCHAR_MIN__ < 0 +// while ( p>data() && *p >= 0 && *p <= ' ' ) p -= 1; +// #else +// while ( p>data() && *p <= ' ' ) p -= 1; +// #endif +// if ( p>data() ) { +// setSize( (size_t)(p-data())+1); +// }else{ +// #if __WCHAR_MIN__ < 0 +// if ( *p >= 0 && *p <= ' ' ) setSize(0); +// #else +// if ( *p <= ' ' ) setSize(0); +// #endif +// else setSize(1); +// } +// } +// } +//} + + + + + + + + +//----------------------------------------------------------------------------- +// Functions +//----------------------------------------------------------------------------- + +//XStringAbstract operator"" _XSW ( const T* s, size_t len) +//{ +// XStringAbstract returnValue; +// if ( len > MAX_XSIZE ) len = MAX_XSIZE; +// returnValue.takeValueFrom(s, len); +// return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +//} +// +//XStringAbstract SWPrintf(const char* format, ...) +//{ +// va_list va; +// XStringAbstract str; +// +// va_start (va, format); +// str.vSWPrintf(format, va); +// va_end(va); +// +// return str; +//} +// +//XStringAbstract SubString(const T *S, size_t pos, size_t count) +//{ +// if ( wcslen(S)-pos < count ) count = wcslen(S)-pos; +// XStringAbstract ret; +// ret.StrnCpy(S+pos, count); +//// return ( XStringAbstract(S+pos, count) ); +// return ret; +//} +// +// +//XStringAbstract CleanCtrl(const XStringAbstract &S) +//{ +// XStringAbstract ReturnValue; +// size_t i; +// +// for ( i=0 ; i=0 && S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* T are signed */ +//#else +// if ( S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* T are unsigned */ +//#endif +// else ReturnValue += S.wc_str()[i]; +// } +// return ReturnValue; +//} + + + + + + + + + +#undef DBG_XSTRING +#undef is_integral +#undef enable_if +#undef asciiToLower + + + + + + + +// +//extern const XStringAbstract NullXStringAbstract; +// +//XStringAbstract operator"" _XSW ( const T* s, size_t len); +// +//XStringAbstract SWPrintf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2))); +//XStringAbstract SubString(const T *S, size_t pos, size_t count); +//XStringAbstract CleanCtrl(const XStringAbstract &S); + + + +#endif // __XSTRINGABSTRACT_H__ diff --git a/rEFIt_UEFI/cpp_foundation/XStringAbstract.h b/rEFIt_UEFI/cpp_foundation/XStringAbstract.h new file mode 100755 index 000000000..e4cfbeb64 --- /dev/null +++ b/rEFIt_UEFI/cpp_foundation/XStringAbstract.h @@ -0,0 +1,921 @@ +//************************************************************************************************* +//************************************************************************************************* +// +// XSTRING +// +//************************************************************************************************* +//************************************************************************************************* + +#if !defined(__XSTRINGABSTRACT_H__) +#define __XSTRINGABSTRACT_H__ + +#include "XToolsCommon.h" +#include "unicode_conversions.h" + +#ifndef DEBUG_ALL +#define DEBUG_XStringAbstract 0 +#else +#define DEBUG_TEXT DEBUG_ALL +#endif + +#if DEBUG_XStringAbstract == 0 +#define DBG_XSTRING(...) +#else +#define DBG_XSTRING(...) DebugLog(DEBUG_XStringAbstract, __VA_ARGS__) +#endif + +//#include + +#define LPATH_SEPARATOR L'\\' + +#if __WCHAR_MAX__ <= 0xFFFFu + #define wchar_cast char16_t +#else + #define wchar_cast char32_t +#endif + + +struct XStringAbstract__false_type { + static constexpr bool value = false; + bool v() const { return false; } +}; + +struct XStringAbstract__true_type { + static constexpr bool value = true; + bool v() const { return true; } +}; + +/* make unsigned */ +template +struct XStringAbstract__make_unsigned {}; + +//template <> struct __make_unsigned {}; +template <> struct XStringAbstract__make_unsigned< signed char> {typedef unsigned short type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned short type;}; +template <> struct XStringAbstract__make_unsigned< signed short> {typedef unsigned short type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned short type;}; +template <> struct XStringAbstract__make_unsigned< signed int> {typedef unsigned int type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned int type;}; +template <> struct XStringAbstract__make_unsigned< signed long> {typedef unsigned long type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned long type;}; +template <> struct XStringAbstract__make_unsigned< signed long long> {typedef unsigned long long type;}; +template <> struct XStringAbstract__make_unsigned {typedef unsigned long long type;}; + +/* enable_if */ +template +struct XStringAbstract__enable_if_t +{}; + +template +struct XStringAbstract__enable_if_t { + typedef T type; +}; +//#define enable_if(x) XStringAbstract__enable_if_t(x, void)::type +#define enable_if(x) typename enable_if_type = typename XStringAbstract__enable_if_t::type +// +//template< bool B, class T = void > +//using XStringAbstract__enable_if_t = typename XStringAbstract__enable_if::type; + + +// is_integral +template struct XStringAbstract__is_integral_st : public XStringAbstract__false_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; +#define is_integral(x) XStringAbstract__is_integral_st::value + + +// is_char +template struct XStringAbstract__is_char_st : public XStringAbstract__false_type {}; +template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +//template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +//template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +template struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; +#define is_char(x) XStringAbstract__is_char_st::value + + + + + + + +#define asciiToLower(ch) (((ch >= L'A') && (ch <= L'Z')) ? ((ch - L'A') + L'a') : ch) + +template +int XStringAbstract__compare(const S* src, const O* other, bool ignoreCase) +{ +// size_t len_s = length_of_utf_string(src); +// size_t len_other = length_of_utf_string(other); + size_t nb = 0; + const S* src2 = src; + const O* other2 = other; + + char32_t src_char32; + char32_t other_char32; + src2 = get_char32_from_string(src2, &src_char32); + other2 = get_char32_from_string(other2, &other_char32); + while ( src_char32 ) { + if ( ignoreCase ) { + src_char32 = asciiToLower(src_char32); + other_char32 = asciiToLower(other_char32); + } + if ( src_char32 != other_char32 ) break; + src2 = get_char32_from_string(src2, &src_char32); + other2 = get_char32_from_string(other2, &other_char32); + nb += 1; + }; + if ( src_char32 == other_char32 ) return 0; + return src_char32 > other_char32 ? 1 : -1; +} + +template +size_t XStringAbstract__indexOf(const O** s, const P* other, size_t offsetRet, bool toLower) +{ + size_t i; + size_t Idx = 0; + + char32_t s_char32; + char32_t other_char32; + + do + { + i = 0; + const O* s2 = *s; + const P* other2 = other; + do { + s2 = get_char32_from_string(s2, &s_char32); + other2 = get_char32_from_string(other2, &other_char32); + if ( toLower ) { + s_char32 = asciiToLower(s_char32); + other_char32 = asciiToLower(other_char32); + } + } while ( s_char32 && other_char32 && s_char32 == other_char32 ); + if ( other_char32 == 0 ) return Idx+offsetRet; + *s = get_char32_from_string(*s, &s_char32); + Idx++; + } while (s_char32); + return MAX_XSIZE; +} + +template +size_t XStringAbstract__indexOf(const O* s, size_t Pos, const P* other, bool toLower) +{ + if ( *other == 0 ) return Pos; + + char32_t char32 = 1; + for ( size_t Idx=0 ; Idx +size_t XStringAbstract__rindexOf(const O* s, size_t Pos, const P* other, bool toLower) +{ + if ( *other == 0 ) return Pos > length_of_utf_string(s) ? length_of_utf_string(s) : Pos; + + size_t index = XStringAbstract__indexOf(&s, other, 0, toLower); + size_t prev_index = index; // initialize to index in case of index is already == Pos + + char32_t char32; + s = get_char32_from_string(s, &char32); + while ( char32 && index < Pos ) { + prev_index = index; + index = XStringAbstract__indexOf(&s, other, index+1, toLower); + s = get_char32_from_string(s, &char32); + }; + if ( index == Pos ) return index; + if ( prev_index <= Pos ) return prev_index; + return MAX_XSIZE; +} + +//template +//size_t XStringAbstract__rindexOf(const O* s, size_t Pos, const P* other, bool toLower) +//{ +// size_t index = XStringAbstract__indexOf(s, 0, other, toLower); +// size_t prev_index = index; // initialize to index in case of index is already == Pos +// while ( index < Pos ) { +// prev_index = index; +// index = XStringAbstract__indexOf(s, index+1, other, toLower); +// }; +// if ( index == Pos ) return index; +// if ( prev_index <= Pos ) return prev_index; +// return MAX_XSIZE; +//} + + +//template +template +class XStringAbstract +{ +public: +// const SubType NullXString; + static T nullChar; + +//class XString16; +// XStringAbstract(const XStringAbstract &S) +// { +// Init(0); +// takeValueFrom(S); +// } + +protected: + T *m_data; + size_t m_allocatedSize; + + // convenience method. Did it this way to avoid #define in header. They can have an impact on other headers + size_t min(size_t x1, size_t x2) const { if ( x1 < x2 ) return x1; return x2; } + size_t max(size_t x1, size_t x2) const { if ( x1 > x2 ) return x1; return x2; } + +// Methods _data is protected intentionally. They are const method returning non-const pointer. That's intentional, but dangerous. Do not expose to public. +// If you need a non-const pointer for low-level access, to use dataSized and have to specify the size + // pos is counted in logical char + template + T* _data(IntegralType pos) const + { + if ( pos<0 ) panic("T* data(int i) -> i < 0"); + size_t offset = size_of_utf_string_len(m_data, (typename XStringAbstract__make_unsigned::type)pos); // If pos is too big, size_of_utf_string_len returns the end of the string + return m_data + offset; + } + + //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + // Init , Alloc + //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + + void Init(size_t aSize=0) + { + //DBG_XSTRING("Init aSize=%d\n", aSize); + // We don't allocate any memory at first. To not have to test all the time if m_data is null, we init it to an empty string + m_data = &nullChar; + m_allocatedSize = 0; + // if aSize == 0, nothing is done, because m_allocatedSize == aSize + CheckSize(aSize, 0); + } +public: + T *CheckSize(size_t nNewSize, size_t nGrowBy = 16) // nNewSize is in number of chars, NOT bytes + { + //DBG_XSTRING("CheckSize: m_size=%d, nNewSize=%d\n", m_size, nNewSize); + + if ( m_allocatedSize < nNewSize ) + { + nNewSize += nGrowBy; + if ( m_allocatedSize == 0 ) m_data = (T*)malloc( (nNewSize+1)*sizeof(T) ); + else m_data = (T*)realloc(m_data, (nNewSize+1)*sizeof(T), (m_allocatedSize+1)*sizeof(T)); + if ( !m_data ) { + DebugLog(2, "XStringAbstract::CheckSize(%zu, %zu) : realloc(%" PRIuPTR ", %lu, %zd) returned NULL. System halted\n", nNewSize, nGrowBy, uintptr_t(m_data), nNewSize*sizeof(T), m_allocatedSize*sizeof(T)); + panic(); + } + m_allocatedSize = nNewSize; + m_data[m_allocatedSize] = 0; // we allocated one more char (nNewSize+1). This \0 is an extra precaution. It's not for the normal null terminator. All string operation must considered that only m_allocatedSize bytes were allocated. + } + return m_data; + } +// void setSize(size_t newSize) // nNewSize is in number of chars, NOT bytes +// { +// //DBG_XSTRING("setLength(%d)\n", len); +// CheckSize(newSize); +// // if ( len >= size() ) { +// // DBG_XSTRING("XStringAbstract::setLength(size_t len) : len >= size() (%d != %d). System halted\n", len, size()); +// // panic(); +// // } +// m_data[newSize] = 0; // we may rewrite a 0 in nullChar, if no memory were allocated. That's ok. +// } + + +// T* memoryOffset(size_t i) { +// +// } + +public: + XStringAbstract() + { + DBG_XSTRING("Construteur\n"); + Init(0); + } + + ~XStringAbstract() + { + //DBG_XSTRING("Destructor :%ls\n", data()); + if ( m_allocatedSize > 0 ) free((void*)m_data); + } + + template + T* data(IntegralType pos) const { return _data(pos); } + +// template::value, IntegralType>::type* = nullptr> + template + T* dataSized(IntegralType size) const + { + if ( size<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); + CheckSize((typename XStringAbstract__make_unsigned::type)size); + return s(); + } + + // Pos is counted in logical char but size is counted in physical char (char, char16_t, char32_t or wchar_t) + template + T* dataSized(IntegralType1 pos, IntegralType2 size) + { + if ( pos<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); + if ( size<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); + size_t offset = size_of_utf_string_len(m_data, (typename XStringAbstract__make_unsigned::type)pos); // If pos is too big, size_of_utf_string_len returns the end of the string + CheckSize(offset + (typename XStringAbstract__make_unsigned::type)size); + return _data(pos); + } + +// const T* data(unsigned int ui) const { return _data(ui); } +// const T* data(int i) const { return _data(i); } +// const T* data(size_t ui) const { return _data(ui); } +// const T* data(xisize i) const { return _data(i); } +// +// T* dataSized(unsigned int ui, size_t sizeMin, size_t nGrowBy=16) { CheckSize(ui+sizeMin, nGrowBy); return _data(ui); } +// T* dataSized(unsigned long ui, size_t sizeMin, size_t nGrowBy=16) { CheckSize(ui+sizeMin, nGrowBy); return _data(ui); } +// T* dataSized(unsigned long long ui, size_t sizeMin, size_t nGrowBy=16) { CheckSize(ui+sizeMin, nGrowBy); return _data(ui); } +// T* dataSized(int i, size_t sizeMin, size_t nGrowBy=16) { if ( i<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); CheckSize((unsigned int)i+sizeMin, nGrowBy); return _data(i); } +// T* dataSized(long i, size_t sizeMin, size_t nGrowBy=16) { if ( i<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); CheckSize((unsigned long)i+sizeMin, nGrowBy); return _data(i); } +// T* dataSized(long long i, size_t sizeMin, size_t nGrowBy=16) { if ( i<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); CheckSize((unsigned long long)i+sizeMin, nGrowBy); return _data(i); } + + T* forgetDataWithoutFreeing() + { + T* ret = m_data; + Init(0); + return ret; + } + + size_t length() const { return length_of_utf_string(m_data); } +// size_t sizeZZ() const { return size_of_utf_string(m_data); } + size_t sizeInBytes() const { return size_of_utf_string(m_data)*sizeof(T); } + size_t allocatedSize() const { return m_allocatedSize; } + + + const T* wc_str() const { return m_data; } + const T* c_str() const { return m_data; } + const T* s() const { return m_data; } + const T* data() const { return m_data; } // todo delete + + /* Empty ? */ + void setEmpty() { m_data[0] = 0; } // we may rewrite a 0 in nullChar if no memory were allocated (m_data == &nullChar). That's ok. + bool isEmpty() const { return m_data == nullptr || *m_data == 0; } + bool notEmpty() const { return !isEmpty(); } + + + //--------------------------------------------------------------------- cast + +// int ToInt() const; +// size_t ToUInt() const; + + + //--------------------------------------------------------------------- charAt, [] + + template + char32_t char32At(IntegralType i) const + { + if (i < 0) { + DBG_XSTRING("XStringAbstract::char32At(size_t i) : i < 0. System halted\n"); + panic(); + } + size_t nb = 0; + const T *p = m_data; + char32_t char32; + do { + p = get_char32_from_string(p, &char32); + if (!char32) { + panic("XStringAbstract::char32At(size_t i) : i >= length(). System halted\n"); + } + nb += 1; + } while (nb <= (typename XStringAbstract__make_unsigned::type)i ); + return char32; + } + + template + char16_t char16At(IntegralType i) const + { + char32_t char32 = char32At(i); + if ( char32 >= 0x10000 ) return 0xFFFD; // � REPLACEMENT CHARACTER used to replace an unknown, unrecognized or unrepresentable character + return (char16_t)char32; + } + + /* [] */ + template + char32_t operator [](IntegralType i) const { return char32At(i); } + + + char32_t LastChar() const { if ( length() > 0 ) return char32At(length()-1); else return 0; } + + //--------------------------------------------------------------------- strcat, strcpy, operator = + /* strncpy */ + template + void strncpy(const O* other, size_t other_len) + { + if ( other && *other && other_len > 0 ) { + size_t newSize = utf_size_of_utf_string_len(m_data, other, other_len); + CheckSize(newSize+1, 0); + utf_string_from_utf_string_len(m_data, m_allocatedSize, other, other_len); + m_data[newSize] = 0; + }else{ + setEmpty(); + } + } + // Old name. TODO remove + template + void StrnCpy(const O* other, size_t other_len) { strncpy(other, other_len); } + + /* strcpy */ + template + void strcpy(const O* other) + { + if ( other && *other ) { + size_t newSize = utf_size_of_utf_string(m_data, other); + CheckSize(newSize+1, 0); + utf_string_from_utf_string(m_data, m_allocatedSize, other); + m_data[newSize] = 0; + }else{ + setEmpty(); + } + } + /* strncat */ + template + void strncat(const O* other, size_t other_len) + { + if ( other && *other && other_len > 0 ) { + size_t currentSize = size_of_utf_string(m_data); + size_t newSize = currentSize + utf_size_of_utf_string_len(m_data, other, other_len); + CheckSize(newSize+1, 0); + utf_string_from_utf_string_len(m_data+currentSize, m_allocatedSize, other, other_len); + m_data[newSize] = 0; + }else{ + // nothing to do + } + } + /* strcat */ + template + void strcat(const O* other) + { + if ( other && *other ) { + size_t currentSize = size_of_utf_string(m_data); // size is number of T, not in bytes + size_t newSize = currentSize + utf_size_of_utf_string(m_data, other); // size is number of T, not in bytes + CheckSize(newSize+1, 0); + utf_string_from_utf_string(m_data+currentSize, m_allocatedSize-currentSize, other); + m_data[newSize] = 0; + }else{ + // nothing to do + } + } + /* takeValueFrom */ + template + ThisXStringClass& takeValueFrom(const XStringAbstract& S) { strcpy(S.s()); return *((ThisXStringClass*)this); } + template + ThisXStringClass& takeValueFrom(const O* S) { strcpy(S); return *((ThisXStringClass*)this); } + template + ThisXStringClass& takeValueFrom(const XStringAbstract& S, size_t len) { strncpy(S.data(0), len); return *((ThisXStringClass*)this); } + template + ThisXStringClass& takeValueFrom(const O* S, size_t len) { strncpy(S, len); return *((ThisXStringClass*)this); } + + /* copy ctor */ + XStringAbstract(const XStringAbstract &S) { Init(0); takeValueFrom(S); } + /* ctor */ + template + explicit XStringAbstract(const XStringAbstract& S) { Init(0); takeValueFrom(S); } + template + explicit XStringAbstract(const O* S) { Init(0); takeValueFrom(S); } + + /* Copy Assign */ // Only other XString, no litteral at the moment. + XStringAbstract& operator =(const XStringAbstract& S) { strcpy(S.s()); return *this; } + /* Assign */ + template + ThisXStringClass& operator =(const XStringAbstract& S) { strcpy(S.s()); return *((ThisXStringClass*)this); } + template + ThisXStringClass& operator =(const O* S) { strcpy(S); return *this; } + + /* += */ + template + ThisXStringClass& operator += (const XStringAbstract& S) { strcat(S.s()); return *((ThisXStringClass*)this); } + template + ThisXStringClass& operator += (const O* S) { strcat(S); return *((ThisXStringClass*)this); } + + // + operator +// template +// friend ThisXStringClass operator + (const XStringClass& p1, const XStringAbstract& p2) { XStringAbstract s; s=p1; s+=p2; return s; } +// template +// friend ThisXStringClass operator + (const XStringAbstract& p1, const O* p2 ) { XStringAbstract s; s=p1; s+=p2; return s; } +// template +// friend ThisXStringClass operator + (const O *p1, const XStringAbstract& p2) { XStringAbstract s; s.strcat(p1); s.strcat(p2.s()); return s; } + + template + ThisXStringClass operator + (const XStringAbstract& p2) const { XStringAbstract s; s=*this; s+=p2; return s; } + template + ThisXStringClass operator + (const O* p2) const { XStringAbstract s; s=*this; s+=p2; return s; } + template + friend ThisXStringClass operator + (const O *p1, const ThisXStringClass& p2) { XStringAbstract s; s.strcat(p1); s.strcat(p2.s()); return s; } + + + //--------------------------------------------------------------------- indexOf, rindexOf + + /* indexOf */ + size_t indexOf(char32_t char32Searched, size_t Pos = 0) const + { + char32_t buf[2] = { char32Searched, 0}; + return XStringAbstract__indexOf(m_data, Pos, buf, false); + } + template + size_t indexOf(const O* S, size_t Pos = 0) const { return XStringAbstract__indexOf(m_data, Pos, S, false); } + template + size_t indexOf(const XStringAbstract& S, size_t Pos = 0) const { return indexOf(S.s(), Pos); } + // old name : todo remove + size_t IdxOf(char c, size_t Pos = 0) const { return indexOf((char32_t)c, Pos); } + template + size_t IdxOf(const XStringAbstract& S, size_t Pos = 0) const { return indexOf(S, Pos); } + /* IC */ + size_t indexOfIC(char32_t char32Searched, size_t Pos = 0) const + { + char32_t buf[2] = { char32Searched, 0}; + return XStringAbstract__indexOf(m_data, Pos, buf, true); + } + template + size_t indexOfIC(const O* S, size_t Pos = 0) const { return XStringAbstract__indexOf(m_data, Pos, S, true); } + template + size_t indexOfIC(const XStringAbstract& S, size_t Pos = 0) const { return indexOfIC(S.s(), Pos); } + + + /* rindexOf */ + size_t rindexOf(const char32_t char32Searched, size_t Pos = MAX_XSIZE-1) const + { + char32_t buf[2] = { char32Searched, 0}; + return XStringAbstract__rindexOf(m_data, Pos, buf, false); + } + template + size_t rindexOf(const O* S, size_t Pos = MAX_XSIZE-1) const { return XStringAbstract__rindexOf(m_data, Pos, S, false); } + template + size_t rindexOf(const XStringAbstract& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); } + /* IC */ + size_t rindexOfIC(const char32_t char32Searched, size_t Pos = MAX_XSIZE-1) const + { + char32_t buf[2] = { char32Searched, 0}; + return XStringAbstract__rindexOf(m_data, Pos, buf, true); + } + template + size_t rindexOfIC(const O* S, size_t Pos = MAX_XSIZE-1) const { return XStringAbstract__rindexOf(m_data, Pos, S, true); } + template + size_t rindexOfIC(const XStringAbstract& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); } + + + //--------------------------------------------------------------------- + + XStringAbstract lowerAscii() + { + T* s = m_data; + while ( *s ) { + *s = asciiToLower(*s); + s++; + } + return *this; + } + +// void deleteCountCharsAt(size_t pos, size_t count=1); +//{ +// if ( pos < size() ) { +// if ( count != MAX_XSIZE && pos + count < size() ) { +// memmove( _data(pos), data(pos+count), (size()-pos-count)*sizeof(T)); // memmove handles overlapping memory move +// setLength(size()-count);/* data()[length()-count]=0 done in setLength */ +// }else{ +// setSize(pos);/* data()[pos]=0 done in setLength */ +// } +// } +//} +// void insert(const XStringAbstract& Str, size_t pos); +//{ +// if ( pos < size() ) { +// CheckSize(size()+Str.size()); +// memmove(_data(pos + Str.size()), data(pos), (size()-pos)*sizeof(T)); +// memmove(_data(pos), Str.data(), Str.size()*sizeof(T)); +// setLength(size()+Str.size()); +// }else{ +// StrCat(Str); +// } +//} + + XStringAbstract SubString(size_t pos, size_t count) const + { + if ( count > length()-pos ) count = length()-pos; + XStringAbstract ret; + + const T* src = m_data; + char32_t char32 = 1; + while ( char32 && pos > 0 ) { + src = get_char32_from_string(src, &char32); + pos -= 1; + }; + ret.strncat(src, count); + return ret; + } + + // todo rename to contains + template + bool ExistIn(const XStringAbstract& S) const { return indexOf(S) != MAX_XSIZE; } + template + bool ExistIn(const O* S) const { return indexOf(S) != MAX_XSIZE; } + template + size_t ExistInIC(const XStringAbstract& S) const { return indexOfIC(S) != MAX_XSIZE; } + template + size_t ExistInIC(const O* S) const { return indexOfIC(S) != MAX_XSIZE; } + + +// void ToLower(bool FirstCharIsCap = false); +// bool IsLetters() const; +// bool IsLettersNoAccent() const; +// bool IsDigits() const; +//{ +// const T *p; +// +// p = data(); +// if ( !*p ) return false; +// for ( ; *p ; p+=1 ) { +// if ( *p < '0' ) return false; +// if ( *p > '9' ) return false; +// } +// return true; +//} +// bool IsDigits(size_t pos, size_t count) const; +//{ +// const T *p; +// const T *q; +// +// if ( pos >= size() ) { +// return false; +// } +// if ( pos+count > size() ) { +// return false; +// } +// p = data() + pos; +// q = p + count; +// for ( ; p < q ; p+=1 ) { +// if ( *p < '0' ) return false; +// if ( *p > '9' ) return false; +// } +// return true; +//} + +// void Replace(T c1, T c2) +// { +// T* p; +// +// p = s(); +// while ( *p ) { +// if ( *p == c1 ) *p = c2; +// p += 1; +// } +// } +// XStringAbstract SubStringReplace(T c1, T c2); +//{ +// T* p; +// XStringAbstract Result; +// +// p = s(); +// while ( *p ) { +// if ( *p == c1 ) Result += c2; +// else Result += *p; +// p++; +// } +// return Result; +//} +// +// SubType basename() const +// { +// size_t idx = RIdxOf(LPATH_SEPARATOR); +// if ( idx == MAX_XSIZE ) return SubType(); +// return SubString(idx+1, size()-idx-1); +// } +// SubType dirname() const +// { +// size_t idx = RIdxOf(LPATH_SEPARATOR); +// if ( idx == MAX_XSIZE ) return SubType(); +// return SubString(0, idx); +// } +// void RemoveLastEspCtrl(); + + //--------------------------------------------------------------------- + + template + int strcmp(const O* S) const { return XStringAbstract__compare(m_data, S, false); } +// int Compare(const char* S) const { return ::Compare(m_data, S); } +// int Compare(const char16_t* S) const { return ::Compare(m_data, S); }; +// int Compare(const char32_t* S) const { return ::Compare(m_data, S); }; +// int Compare(const wchar_t* S) const { return ::Compare(m_data, S); }; +// + template + bool Equal(const O* S) const { return XStringAbstract__compare(m_data, S, false); } + template + bool EqualIC(const XStringAbstract& S) const { return XStringAbstract__compare(m_data, S.s(), true); } + template + bool EqualIC(const O* S) const { return XStringAbstract__compare(m_data, S, true); } +// bool BeginingEqual(const T* S) const { return (memcmp(data(), S, wcslen(S)) == 0); } +// bool SubStringEqual(size_t Pos, const T* S) const { return (memcmp(data(Pos), S, wcslen(S)) == 0); } + +public: + // == operator + template + bool operator == (const XStringAbstract& s2) const { return (*this).strcmp(s2.s()) == 0; } + template + bool operator == (const O* s2) const { return (*this).strcmp(s2) == 0; } + template + friend bool operator == (const O* s1, ThisXStringClass& s2) { return s2.strcmp(s1) == 0; } + + template + bool operator != (const XStringAbstract& s2) const { return !(*this == s2); } + template + bool operator != (const O* s2) const { return !(*this == s2); } + template + friend bool operator != (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) != 0; } + + template + bool operator < (const XStringAbstract& s2) const { return (*this).strcmp(s2.s()) < 0; } + template + bool operator < (const O* s2) const { return (*this).strcmp(s2) < 0; } + template + friend bool operator < (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) > 0; } + + template + bool operator > (const XStringAbstract& s2) const { return (*this).strcmp(s2.s()) > 0; } + template + bool operator > (const O* s2) const { return (*this).strcmp(s2) > 0; } + template + friend bool operator > (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) < 0; } + + template + bool operator <= (const XStringAbstract& s2) const { return (*this).strcmp(s2.s()) <= 0; } + template + bool operator <= (const O* s2) const { return (*this).strcmp(s2) <= 0; } + template + friend bool operator <= (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) >= 0; } + + template + bool operator >= (const XStringAbstract& s2) const { return (*this).strcmp(s2.s()) >= 0; } + template + bool operator >= (const O* s2) const { return (*this).strcmp(s2) >= 0; } + template + friend bool operator >= (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) <= 0; } + +}; + + +template +T XStringAbstract::nullChar = 0; + + + +//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +// Constructor +//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + + +// +//template +//XStringAbstract::XStringAbstract(const XStringAbstract &aString) +//{ +//DBG_XSTRING("Constructor(const XStringAbstract &aString) : %ls\n", aString.data()); +// Init(aString.size()); +// memcpy(m_data, aString.m_data, aString.sizeInBytes()); +//} + + +// +//template +//void XStringAbstract::RemoveLastEspCtrl() +//{ +// T *p; +// +// if ( size() > 0 ) { +// p = s() + size() - 1; +// #if __WCHAR_MIN__ < 0 +// if ( *p >= 0 && *p <= ' ' ) { +// #else +// if ( *p <= ' ' ) { +// #endif +// p -= 1; +// #if __WCHAR_MIN__ < 0 +// while ( p>data() && *p >= 0 && *p <= ' ' ) p -= 1; +// #else +// while ( p>data() && *p <= ' ' ) p -= 1; +// #endif +// if ( p>data() ) { +// setSize( (size_t)(p-data())+1); +// }else{ +// #if __WCHAR_MIN__ < 0 +// if ( *p >= 0 && *p <= ' ' ) setSize(0); +// #else +// if ( *p <= ' ' ) setSize(0); +// #endif +// else setSize(1); +// } +// } +// } +//} + + + + + + + + +//----------------------------------------------------------------------------- +// Functions +//----------------------------------------------------------------------------- + +//XStringAbstract operator"" _XSW ( const T* s, size_t len) +//{ +// XStringAbstract returnValue; +// if ( len > MAX_XSIZE ) len = MAX_XSIZE; +// returnValue.takeValueFrom(s, len); +// return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +//} +// +//XStringAbstract SWPrintf(const char* format, ...) +//{ +// va_list va; +// XStringAbstract str; +// +// va_start (va, format); +// str.vSWPrintf(format, va); +// va_end(va); +// +// return str; +//} +// +//XStringAbstract SubString(const T *S, size_t pos, size_t count) +//{ +// if ( wcslen(S)-pos < count ) count = wcslen(S)-pos; +// XStringAbstract ret; +// ret.StrnCpy(S+pos, count); +//// return ( XStringAbstract(S+pos, count) ); +// return ret; +//} +// +// +//XStringAbstract CleanCtrl(const XStringAbstract &S) +//{ +// XStringAbstract ReturnValue; +// size_t i; +// +// for ( i=0 ; i=0 && S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* T are signed */ +//#else +// if ( S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* T are unsigned */ +//#endif +// else ReturnValue += S.wc_str()[i]; +// } +// return ReturnValue; +//} + + + + + + + + + +#undef DBG_XSTRING +#undef is_integral +//#undef enable_if +#undef asciiToLower + + + + + + + +// +//extern const XStringAbstract NullXStringAbstract; +// +//XStringAbstract operator"" _XSW ( const T* s, size_t len); +// +//XStringAbstract SWPrintf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2))); +//XStringAbstract SubString(const T *S, size_t pos, size_t count); +//XStringAbstract CleanCtrl(const XStringAbstract &S); + + + +#endif // __XSTRINGABSTRACT_H__ diff --git a/rEFIt_UEFI/cpp_foundation/XStringArray.cpp b/rEFIt_UEFI/cpp_foundation/XStringArray.cpp index ee35820d7..600db69a4 100755 --- a/rEFIt_UEFI/cpp_foundation/XStringArray.cpp +++ b/rEFIt_UEFI/cpp_foundation/XStringArray.cpp @@ -129,11 +129,11 @@ XStringArray Split(const XString &S, const XString &Separator) idxB = 0; idxE = S.IdxOf(Separator, idxB); while ( idxE != MAX_XSIZE ) { - Ss.AddCopy(SubString(S, idxB, idxE-idxB)); + Ss.AddCopy(S.SubString(idxB, idxE-idxB)); idxB = idxE + Separator.length(); idxE = S.IdxOf(Separator, idxB); } - if ( idxB < S.length() ) Ss.AddCopy(SubString(S, idxB, S.length()-idxB)); + if ( idxB < S.length() ) Ss.AddCopy(S.SubString(idxB, S.length()-idxB)); return Ss; } diff --git a/rEFIt_UEFI/cpp_foundation/XStringW.cpp b/rEFIt_UEFI/cpp_foundation/XStringW.cpp deleted file mode 100755 index 61891ecbe..000000000 --- a/rEFIt_UEFI/cpp_foundation/XStringW.cpp +++ /dev/null @@ -1,625 +0,0 @@ -//************************************************************************************************* -//************************************************************************************************* -// -// STRING -// -// Developed by jief666, from 1997. -// -//************************************************************************************************* -//************************************************************************************************* - - -#if !defined(__XStringW_CPP__) -#define __XStringW_CPP__ - -#if 0 -#define DBG(...) DebugLog(2, __VA_ARGS__) -#else -#define DBG(...) -#endif - -#include "XToolsCommon.h" -#include "XStringW.h" - -#include "../../Include/Library/printf_lite.h" - -UINTN XStringWGrowByDefault = 1024; -const XStringW NullXStringW; - - -void XStringW::Init(UINTN aSize) -{ -//DBG("Init aSize=%d\n", aSize); - m_data = (wchar_t*)malloc( (aSize+1)*sizeof(wchar_t) ); /* le 0 terminal n'est pas compté dans mSize */ - if ( !m_data ) { - DebugLog(2, "XStringW::Init(%llu) : Xalloc returned NULL. Cpu halted\n", (aSize+1)*sizeof(wchar_t)); - panic(); - } - m_allocatedSize = aSize; - m_len = 0; - m_data[0] = 0; -} - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Constructor -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -XStringW::XStringW() -{ -DBG("Construteur\n"); - Init(); -} - -XStringW::XStringW(const XStringW &aString) -{ -DBG("Constructor(const XStringW &aString) : %ls\n", aString.data()); - Init(aString.size()); - StrnCpy(aString.data(), aString.size()); -} -// -//XStringW::XStringW(const wchar_t *S) -//{ -// if ( !S ) { -// DebugLog(2, "XStringW(const wchar_t *S) called with NULL. Use setEmpty()\n"); -// panic(); -// } -//DBG("Constructor(const wchar_t *S) : %ls, StrLen(S)=%d\n", S, StrLen(S)); -// Init(StrLen(S)); -// StrCpy(S); -//} -// -//XStringW::XStringW(const wchar_t *S, UINTN count) -//{ -//DBG("Constructor(const wchar_t *S, UINTN count) : %ls, %d\n", S, count); -// Init(count); -// StrnCpy(S, count); -//} -// -//XStringW::XStringW(const wchar_t aChar) -//{ -//DBG("Constructor(const wchar_t aChar)\n"); -// Init(1); -// StrnCpy(&aChar, 1); -//} -// -//XStringW::XStringW(const char* S) -//{ -//DBG("Constructor(const char* S)\n"); -// xsize newLen = StrLenInWChar(S, strlen(S)); -// Init(newLen); -// utf8ToWChar(m_data, m_allocatedSize+1, S, strlen(S)); // m_size doesn't count the NULL terminator -// SetLength(newLen); -//} -wchar_t * XStringW::forgetDataWithoutFreeing() -{ - wchar_t* ret = m_data; - Init(); - return ret; -} - -XStringW& XStringW::takeValueFrom(const wchar_t* S, xsize count) -{ - if ( !S ) { -// DebugLog(2, "takeValueFrom(const wchar_t* S) called with NULL. Use setEmpty()\n"); -// panic(); - Init(0); - return *this; - } - Init(count); - StrCpy(S); - return *this; -} - -XStringW& XStringW::takeValueFrom(const wchar_t* S) -{ - if ( S ) return takeValueFrom(S, wcslen(S)); - Init(0); - return *this; -} - -XStringW& XStringW::takeValueFrom(const char* S) -{ - xsize newLen = utf_size_of_utf_string(m_data, S); - Init(newLen); - wchar_string_from_utf8_string(m_data, m_allocatedSize+1, S); // m_size doesn't count the NULL terminator - SetLength(newLen); - return *this; -} - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// Destructor -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - - -XStringW::~XStringW() -{ -DBG("Destructor :%ls\n", data()); - free((void*)m_data); -} - -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -// -//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -void XStringW::SetLength(UINTN len) -{ -//DBG("SetLength(%d)\n", len); - CheckSize(len); - - m_len = len; - m_data[len] = 0; - - if ( wcslen(data()) != len ) { - DBG("XStringW::SetLength(UINTN len) : StrLen(data()) != len (%d != %d). System halted\n", StrLen(data()), len); - panic(); - } -} - -/* CheckSize() */ -wchar_t *XStringW::CheckSize(UINTN nNewSize, UINTN nGrowBy) -{ -//DBG("CheckSize: m_size=%d, nNewSize=%d\n", m_size, nNewSize); - - if ( m_allocatedSize < nNewSize ) - { - nNewSize += nGrowBy; - m_data = (wchar_t*)realloc(m_data, (nNewSize+1)*sizeof(wchar_t), m_allocatedSize*sizeof(wchar_t)); - if ( !m_data ) { - DBG("XStringW::CheckSize(%d, %d) : Xrealloc(%d, %d, %d) returned NULL. System halted\n", nNewSize, nGrowBy, m_size, (nNewSize+1)*sizeof(wchar_t), m_data); - panic(); - } - m_allocatedSize = nNewSize; - } - return m_data; -} - -void XStringW::StrnCpy(const wchar_t *buf, UINTN len) -{ - UINTN newLen = 0; - if ( buf && *buf && len > 0 ) { - CheckSize(len, 0); - while ( *buf && newLen < len ) { - m_data[newLen++] = *buf++; - } -// memmove(data(), buf, len*sizeof(wchar_t)); - } - SetLength(newLen); /* data()[len]=0 done in SetLength */ -} - -void XStringW::StrCpy(const wchar_t *buf) -{ - if ( buf && *buf ) { - StrnCpy(buf, wcslen(buf)); - }else{ - SetLength(0); /* data()[0]=0 done in SetLength */ - } -} - -void XStringW::StrnCat(const wchar_t *buf, UINTN len) -{ - UINTN NewLen; - - if ( buf && *buf && len > 0 ) { - NewLen = size()+len; - CheckSize(NewLen, 0); - memmove(_data(size()), buf, len*sizeof(wchar_t)); - SetLength(NewLen); /* data()[NewLen]=0 done in SetLength */ - } -} - -void XStringW::StrCat(const wchar_t *buf) -{ - if ( buf && *buf ) { - StrnCat(buf, wcslen(buf)); - } -} - -void XStringW::StrCat(const XStringW &uneXStringWW) -{ - StrnCat(uneXStringWW.data(), uneXStringWW.size()); -} - -void XStringW::Delete(UINTN pos, UINTN count) -{ - if ( pos < size() ) { - if ( count != MAX_XSIZE && pos + count < size() ) { - memmove( _data(pos), data(pos+count), (size()-pos-count)*sizeof(wchar_t)); // memmove handles overlapping memory move - SetLength(size()-count);/* data()[length()-count]=0 done in SetLength */ - }else{ - SetLength(pos);/* data()[pos]=0 done in SetLength */ - } - } -} - -void XStringW::Insert(UINTN pos, const XStringW& Str) -{ - if ( pos < size() ) { - CheckSize(size()+Str.size()); - memmove(_data(pos + Str.size()), data(pos), (size()-pos)*sizeof(wchar_t)); - memmove(_data(pos), Str.data(), Str.size()*sizeof(wchar_t)); - SetLength(size()+Str.size()); - }else{ - StrCat(Str); - } -} - -void XStringW::Replace(wchar_t c1, wchar_t c2) -{ - wchar_t* p; - - p = _data(0); - while ( *p ) { - if ( *p == c1 ) *p = c2; - p += 1; - } -} - -XStringW XStringW::SubStringReplace(wchar_t c1, wchar_t c2) -{ - wchar_t* p; - XStringW Result; - - p = _data(0); - while ( *p ) { - if ( *p == c1 ) Result += c2; - else Result += *p; - p++; - } - return Result; -} - -//static XStringW* XStringW_sprintfBuf; - -static void XStringW_transmitSPrintf(const wchar_t* buf, unsigned int nbchar, void* context) -{ -// (*XStringW_sprintfBuf).StrnCat(buf, nbchar); - ((XStringW*)(context))->StrnCat(buf, nbchar); -} - -void XStringW::vSWPrintf(const char* format, va_list va) -{ - SetLength(0); - -// XStringW_sprintfBuf = this; - - vwprintf_with_callback(format, va, XStringW_transmitSPrintf, this); -} - -// This is an attempt to use _PPrint from IO.c. Problem is : you have to allocate the memory BEFORE calling it. -//void XStringW::vSPrintf(const char* format, va_list va) -//{ -// POOL_PRINT spc; -// PRINT_STATE ps; -// -// ZeroMem(&spc, sizeof (spc)); -// spc.Str = data(); -// SetLength(0); -// spc.Len = 0; -// spc.Maxlen = m_size; -// ZeroMem(&ps, sizeof (ps)); -// ps.Output = (IN EFI_STATUS (EFIAPI *)(VOID *context, CONST CHAR16 *str))_PoolPrint; -// ps.Context = (void*)&spc; -// ps.fmt.u.pw = format; -// -// VA_COPY(ps.args, va); -// _PPrint (&ps); -// va_end(ps.args); -//} - -void XStringW::SWPrintf(const char* format, ...) -{ - va_list va; - - va_start (va, format); - vSWPrintf(format, va); - va_end(va); -} - -XStringW XStringW::basename() const -{ - UINTN idx = RIdxOf(LPATH_SEPARATOR); - if ( idx == MAX_XSIZE ) return NullXStringW; - return SubString(idx+1, size()-idx-1); -} - -XStringW XStringW::dirname() const -{ - UINTN idx = RIdxOf(LPATH_SEPARATOR); - if ( idx == MAX_XSIZE ) return NullXStringW; - return SubString(0, idx); -} - -XStringW XStringW::SubString(UINTN pos, UINTN count) const -{ - if ( count > size()-pos ) count = size()-pos; - XStringW ret; - ret.StrnCat(&(data()[pos]), count); - return ret; -} - -UINTN XStringW::IdxOf(wchar_t aChar, UINTN Pos) const -{ - UINTN Idx; - - for ( Idx=Pos ; Idx size() ) Pos = size(); - if ( Pos < 1 ) return MAX_XSIZE; - for ( Idx=Pos ; Idx-- > 0 ; ) { - if ( m_data[Idx] == charToSearch ) return Idx; - } - return MAX_XSIZE; -} - -UINTN XStringW::RIdxOf(const XStringW &S, UINTN Pos) const -{ - UINTN i; - UINTN Idx; - - if ( S.size() == 0 ) return MAX_XSIZE; - if ( Pos > size() ) Pos = size(); - if ( Pos < S.size() ) return MAX_XSIZE; - Pos -= S.size(); - for ( Idx=Pos+1 ; Idx-- > 0 ; ) { - i = 0; - while( i '9' ) return false; - } - return true; -} - -bool XStringW::IsDigits(UINTN pos, UINTN count) const -{ - const wchar_t *p; - const wchar_t *q; - - if ( pos >= size() ) { - return false; - } - if ( pos+count > size() ) { - return false; - } - p = data() + pos; - q = p + count; - for ( ; p < q ; p+=1 ) { - if ( *p < '0' ) return false; - if ( *p > '9' ) return false; - } - return true; -} - -void XStringW::ToLower(bool FirstCharIsCap) -{ - if ( size() > 0 ) - { - unsigned int ui; - - if ( FirstCharIsCap ) { - // data()[0] = Majuscule(data()[0]); //keep as is - ui = 1; - }else{ - ui = 0; - } - for ( ; ui < size() ; ui++ ) { - m_data[ui] = to_lower(m_data[ui]); - } - } -} - - -#if __WCHAR_MIN__ < 0 -void XStringW::RemoveLastEspCtrl() -{ - wchar_t *p; - - if ( size() > 0 ) { - p = _data(0) + size() - 1; - if ( *p >= 0 && *p <= ' ' ) { - p -= 1; - while ( p>data() && *p >= 0 && *p <= ' ' ) p -= 1; - if ( p>data() ) { - SetLength( (UINTN)(p-data())+1); - }else{ - if ( *p >= 0 && *p <= ' ' ) SetLength(0); - else SetLength(1); - } - } - } -} -#else - void XStringW::RemoveLastEspCtrl() - { - wchar_t *p; - - if ( size() > 0 ) { - p = _data(0) + size() - 1; - if ( *p <= ' ' ) { - p -= 1; - while ( p>data() && *p <= ' ' ) p -= 1; - if ( p>data() ) { - SetLength( (UINTN)(p-data())+1); - }else{ - if ( *p <= ' ' ) SetLength(0); - else SetLength(1); - } - } - } - } -#endif - -//------------------------------------------------------------------------------------------------- -// -//------------------------------------------------------------------------------------------------- -//bool XStringW::ReadFromFILE(FILE *fp) -//{ -// UINTN longueur; -// -// if ( fread(&longueur, sizeof(longueur), 1, fp) != 1 ) goto fin; -// if ( longueur > 0 && fread(dataWithSizeMin(0, longueur), sizeof(wchar_t), longueur, fp) != 1 ) goto fin; -// SetLength(longueur); -// return true; -// fin: -// SetNull(); -// return false; -//} -// -//bool XStringW::WriteToFILE(FILE *fp) const -//{ -// UINTN longueur; -// -// longueur = length(); -// if ( fwrite(&longueur, sizeof(longueur), 1, fp) != 1 ) return false; -// if ( longueur > 0 && fwrite(data(), sizeof(wchar_t), longueur, fp) != 1 ) return false; -// return true; -//} - - -//************************************************************************************************* -// -// Operators = -// -//************************************************************************************************* - -const XStringW &XStringW::operator =(const XStringW &aString) -{ -//TRACE("Operator =const XStringW&\n"); - StrnCpy(aString.data(), aString.size()); - return *this; -} - -// -//const XStringW &XStringW::operator =(wchar_t aChar) -//{ -////TRACE("Operator =wchar_t \n"); -// StrnCpy(&aChar, 1); -// return *this; -//} - -//const XStringW &XStringW::operator =(const wchar_t *S) -//{ -////TRACE("Operator =const wchar_t *\n"); -// if ( S == NULL ) { -// DBG("operator =(const wchar_t *S) called with NULL\n"); -// panic(); -// } -// StrCpy(S); -// return *this; -//} - - - -//************************************************************************************************* -// -// Operators += -// -//************************************************************************************************* - -XStringW &XStringW::operator +=(wchar_t aChar) -{ -//TRACE("Operator +=wchar_t \n"); - StrnCat(&aChar, 1); - return *this; -} - -XStringW &XStringW::operator +=(const XStringW &aString) -{ -//TRACE("Operator +=const XStringW&\n"); - StrnCat(aString.data(), aString.size()); - return *this; -} - -XStringW &XStringW::operator +=(const wchar_t *S) -{ -//TRACE("operator +=const wchar_t *\n"); - StrCat(S); - return *this; -} - - -//----------------------------------------------------------------------------- -// Functions -//----------------------------------------------------------------------------- - -XStringW operator"" _XSW ( const wchar_t* s, size_t len) -{ - XStringW returnValue; - if ( len > MAX_XSIZE ) len = MAX_XSIZE; - returnValue.takeValueFrom(s, len); - return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. -} - -XStringW SWPrintf(const char* format, ...) -{ - va_list va; - XStringW str; - - va_start (va, format); - str.vSWPrintf(format, va); - va_end(va); - - return str; -} - -XStringW SubString(const wchar_t *S, UINTN pos, UINTN count) -{ - if ( wcslen(S)-pos < count ) count = wcslen(S)-pos; - XStringW ret; - ret.StrnCpy(S+pos, count); -// return ( XStringW(S+pos, count) ); - return ret; -} - - -XStringW CleanCtrl(const XStringW &S) -{ - XStringW ReturnValue; - UINTN i; - - for ( i=0 ; i=0 && S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* wchar_t are signed */ -#else - if ( S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* wchar_t are unsigned */ -#endif - else ReturnValue += S.wc_str()[i]; - } - return ReturnValue; -} - -#endif diff --git a/rEFIt_UEFI/cpp_foundation/XStringW.h b/rEFIt_UEFI/cpp_foundation/XStringW.h deleted file mode 100755 index 51d975bc8..000000000 --- a/rEFIt_UEFI/cpp_foundation/XStringW.h +++ /dev/null @@ -1,222 +0,0 @@ -//************************************************************************************************* -//************************************************************************************************* -// -// STRING -// -//************************************************************************************************* -//************************************************************************************************* - -#if !defined(__XSTRINGW_H__) -#define __XSTRINGW_H__ - -#include "XToolsCommon.h" -#include "unicode_conversions.h" - -#define LPATH_SEPARATOR L'\\' - -extern xsize XStringWGrowByDefault; -//extern void __GLOBAL__sub_I_XStringW(); - -class XStringW -{ -protected: - wchar_t *m_data; - xsize m_len; - xsize m_allocatedSize; - - // convenience method. Did it this way to avoid #define in header. They can have an impact on other headers - xsize min(xsize x1, xsize x2) const { if ( x1 < x2 ) return x1; return x2; } - xsize max(xsize x1, xsize x2) const { if ( x1 > x2 ) return x1; return x2; } - -// Next 2 methods are protected intentionally. They are const method returning non-const pointer. That's intentional, but dangerous. Do not expose to public. -// It's better practice, if you need a non-const pointer for low-level access, to use dataSized and ahev to specify the size - wchar_t* _data(unsigned int ui) const { if ( ui >= m_allocatedSize ) panic("wchar_t* data(unsigned int ui=0) -> ui >= m_allocatedSize"); return m_data+ui; } - wchar_t* _data(int i) const { if ( i<0 ) panic("wchar_t* data(int i) -> i < 0"); if ( (unsigned int)i >= m_allocatedSize ) panic("wchar_t* data(int i) -> i >= m_allocatedSize"); return m_data+i; } - wchar_t* _data(unsigned long ui) const { if ( ui >= m_allocatedSize ) panic("wchar_t* data(unsigned long ui=0) -> ui >= m_allocatedSize"); return m_data+ui; } - wchar_t* _data(long i) const { if ( i<0 ) panic("wchar_t* data(long i) -> i < 0"); if ( (unsigned long)i >= m_allocatedSize ) panic("wchar_t* data(long i) -> i >= m_allocatedSize"); return m_data+i; } - wchar_t* _data(xsize ui) const { if ( ui >= m_allocatedSize ) panic("wchar_t* data(xsize ui=0) -> ui >= m_allocatedSize"); return m_data+ui; } - wchar_t* _data(xisize i) const { if ( i<0 ) panic("wchar_t* data(xisize i) -> i < 0"); if ( (xsize)i >= m_allocatedSize ) panic("wchar_t* data(xisize i) -> i >= m_allocatedSize"); return m_data+i; } - -public: - void Init(xsize aSize=0); - XStringW(); - XStringW(const XStringW &aString); -// XStringW(const wchar_t *); -// XStringW(const wchar_t* S, xsize count); -// XStringW(const wchar_t); -// XStringW(const char*); - - ~XStringW(); - -protected: - wchar_t *CheckSize(xsize nNewSize, xsize nGrowBy = XStringWGrowByDefault); - -public: - const wchar_t* wc_str() const { return m_data; } // equivalent as std::string - const wchar_t *data(xsize ui=0) const { return m_data+ui; } // do not multiply by sizeof(wchar_t), it's done by the compiler. - const wchar_t *data(xisize i) const { if ( i<0 ) panic("const wchar_t *data(INTN i=0) const -> i < 0"); return m_data+i; } // do not multiply by sizeof(wchar_t), it's done by the compiler. - - wchar_t* dataSized(xsize ui, xsize sizeMin, xsize nGrowBy=XStringWGrowByDefault) { CheckSize(ui+sizeMin, nGrowBy); return _data(ui); } - wchar_t* dataSized(xisize i, xsize sizeMin, xsize nGrowBy=XStringWGrowByDefault) { if ( i<0 ) panic("wchar_t* dataSized(xisize i, xsize sizeMin, xsize nGrowBy) -> i < 0"); CheckSize((xsize)i+sizeMin, nGrowBy); return _data(i); } - wchar_t* forgetDataWithoutFreeing(); - -// xsize length() const { return m_len; } - xsize size() const { return m_len; } - xsize sizeInBytes() const { return m_len*sizeof(wchar_t); } - xsize allocatedSize() const { return m_allocatedSize; } - void SetLength(xsize len); - const wchar_t* s() { return m_data; } - - /* Empty ? */ - void setEmpty() { m_len = 0; } - bool isEmpty() const { return size() == 0; } - bool notEmpty() const { return !isEmpty(); } - - /* Cast */ -// operator const wchar_t *() const { return data(); } - - #if defined(__APPLE__) && defined(__OBJC__) - operator NSString*() const { return [[[NSString alloc] initWithBytes:data() length:length()*sizeof(wchar_t) encoding:NSUTF32LittleEndianStringEncoding] autorelease]; } - #endif - - int ToInt() const; - xsize ToUInt() const; - -// XString mbs() const; - -// /* wchar_t [] */ -// wchar_t operator [](int i) const { return *_data(i); } -// wchar_t operator [](unsigned int ui) const { return *_data(ui); } -// wchar_t operator [](long i) const { return *_data(i); } -// wchar_t operator [](unsigned long ui) const { return *_data(ui); } -// wchar_t operator [](xisize i) const { return *data(i); } -// wchar_t operator [](xsize ui) const { return *data(ui); } -// -// /* wchar_t& [] */ -// wchar_t& operator [](int i) { return *_data(i); } -// wchar_t& operator [](unsigned int ui) { return *_data(ui); } -// wchar_t& operator [](long i) { return *_data(i); } -// wchar_t& operator [](unsigned long ui) { return *_data(ui); } -// wchar_t& operator [](xisize i) { return *_data(i); } -// wchar_t& operator [](xsize ui) { return *_data(ui); } - - wchar_t LastChar() const { if ( size() > 0 ) return data()[size()-1]; else return 0; } - void RemoveLastEspCtrl(); - - void SetNull() { SetLength(0); }; - - void StrnCpy(const wchar_t *buf, xsize len); - void StrCpy(const wchar_t *buf); - void StrnCat(const wchar_t *buf, xsize len); - void StrCat(const wchar_t *buf); - void StrCat(const XStringW &uneXStringW); - void Delete(xsize pos, xsize count=1); - - void Insert(xsize pos, const XStringW& Str); - - - void vSWPrintf(const char* format, va_list va); - void SWPrintf(const char* format, ...) __attribute__((__format__(__printf__, 2, 3))); - - const XStringW &operator =(const XStringW &aString); -// const XStringW &operator =(const wchar_t* S) {fdsf}; -// const XStringW &operator =(wchar_t); - - XStringW& takeValueFrom(const wchar_t* S); - XStringW& takeValueFrom(const wchar_t* S, xsize count); - XStringW& takeValueFrom(const char* S); - - XStringW& operator += (const XStringW &); - XStringW& operator += (const wchar_t* S); - XStringW& operator += (wchar_t); - - XStringW SubString(xsize pos, xsize count) const; - xsize IdxOf(wchar_t c, xsize Pos = 0) const; - xsize IdxOf(const XStringW& S, xsize Pos = 0) const; - xsize RIdxOf(const wchar_t c, xsize Pos = MAX_XSIZE) const; - xsize RIdxOf(const XStringW& S, xsize Pos = MAX_XSIZE) const; - - void ToLower(bool FirstCharIsCap = false); - bool IsLetters() const; - bool IsLettersNoAccent() const; - bool IsDigits() const; - bool IsDigits(xsize pos, xsize count) const; - - bool ExistIn(const XStringW &S) const { return IdxOf(S) != MAX_XSIZE; } - void Replace(wchar_t c1, wchar_t c2); - XStringW SubStringReplace(wchar_t c1, wchar_t c2); - - int Compare(const wchar_t* S) const { return (int)memcmp(data(), S, min(wcslen(S), size())*sizeof(wchar_t)); } - - bool Equal(const wchar_t* S) const { return Compare(S) == 0; }; - bool BeginingEqual(const wchar_t* S) const { return (memcmp(data(), S, wcslen(S)) == 0); } - bool SubStringEqual(xsize Pos, const wchar_t* S) const { return (memcmp(data(Pos), S, wcslen(S)) == 0); } - - XStringW basename() const; - XStringW dirname() const; - -// bool ReadFromBuf(const char *buf, xsize *idx, xsize count); -// bool WriteToBuf(char *buf, xsize *idx, xsize count) const; -// bool ReadFromFILE(FILE *fp); -// bool WriteToFILE(FILE *fp) const; - // -// bool ReadFromXBuffer(XRBuffer &unXBuffer); // Impossible de mettre le XBuffer en const car il y a une variable d'instance de XBuffer incrémentée par ReadFromXBuffer -// void CatToXBuffer(XBuffer *unXBuffer) const; -// void WriteToXBuffer(XBuffer *unXBuffer, xsize *idx) const; - -public: - // + operator - // with XStringW - friend XStringW operator + (const XStringW& p1, const XStringW& p2) { XStringW s; s=p1; s+=p2; return s; } - // with const wchar_t - friend XStringW operator + (const XStringW& p1, const wchar_t *p2 ) { XStringW s; s=p1; s+=p2; return s; } - friend XStringW operator + (const wchar_t *p1, const XStringW& p2) { XStringW s; s.StrCat(p1); s.StrCat(p2); return s; } -// // with wchar_t -// friend XStringW operator + (const XStringW& p1, wchar_t p2 ) { XStringW s; s=p1; s+=p2; return s; } -// friend XStringW operator + (wchar_t p1, const XStringW& p2 ) { XStringW s; s=p1; s+=p2; return s; } - - - // == operator - friend bool operator == (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) == 0; } -// friend bool operator == (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) == 0; } -// friend bool operator == (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) == 0; } - - friend bool operator != (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) != 0; } -// friend bool operator != (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) != 0; } -// friend bool operator != (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) != 0; } - - friend bool operator < (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) < 0; } -// friend bool operator < (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) < 0; } -// friend bool operator < (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) > 0; } - - friend bool operator > (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) > 0; } -// friend bool operator > (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) > 0; } -// friend bool operator > (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) < 0; } - - friend bool operator <= (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) <= 0; } -// friend bool operator <= (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) <= 0; } -// friend bool operator <= (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) >= 0; } - - friend bool operator >= (const XStringW& s1, const XStringW& s2) { return s1.Compare(s2._data(0)) >= 0; } -// friend bool operator >= (const XStringW& s1, const wchar_t* s2 ) { return s1.Compare(s2) >= 0; } -// friend bool operator >= (const wchar_t* s1, const XStringW& s2) { return s2.Compare(s1) <= 0; } - - static wchar_t to_lower(wchar_t ch) { - if (ch <= L'Z') - return ((ch >= L'A') ? ((ch - L'A') + L'a') : ch); - else if (ch == L'Ё') return L'ё'; - else if (ch <= L'Я') - return ((ch >= L'А') ? ((ch - L'А') + L'а') : ch); //русские буквы - else return ch; - } -}; - -extern const XStringW NullXStringW; - -XStringW operator"" _XSW ( const wchar_t* s, size_t len); - -XStringW SWPrintf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2))); -XStringW SubString(const wchar_t *S, xsize pos, xsize count); -XStringW CleanCtrl(const XStringW &S); - -#endif diff --git a/rEFIt_UEFI/cpp_foundation/XStringWArray.cpp b/rEFIt_UEFI/cpp_foundation/XStringWArray.cpp index 02db25c61..e70eab5da 100755 --- a/rEFIt_UEFI/cpp_foundation/XStringWArray.cpp +++ b/rEFIt_UEFI/cpp_foundation/XStringWArray.cpp @@ -130,13 +130,13 @@ XStringWArray Split(const XStringW &S, const XStringW &Separator) xsize idxB, idxE; idxB = 0; - idxE = S.IdxOf(Separator, idxB); + idxE = S.indexOf(Separator, idxB); while ( idxE != MAX_XSIZE ) { - Ss.AddCopy(SubString(S.wc_str(), idxB, idxE-idxB)); - idxB = idxE + Separator.size(); - idxE = S.IdxOf(Separator, idxB); + Ss.AddCopy(S.SubString(idxB, idxE-idxB)); + idxB = idxE + Separator.length(); + idxE = S.indexOf(Separator, idxB); } - if ( idxB < S.size() ) Ss.AddCopy(SubString(S.wc_str(), idxB, S.size()-idxB)); + if ( idxB < S.length() ) Ss.AddCopy(S.SubString(idxB, S.length()-idxB)); return Ss; } diff --git a/rEFIt_UEFI/cpp_foundation/XStringWArray.h b/rEFIt_UEFI/cpp_foundation/XStringWArray.h index 1dddc3b13..3dab104b8 100755 --- a/rEFIt_UEFI/cpp_foundation/XStringWArray.h +++ b/rEFIt_UEFI/cpp_foundation/XStringWArray.h @@ -11,7 +11,7 @@ #include "XToolsCommon.h" #include "XObjArray.h" -#include "XStringW.h" +#include "XString.h" #define XStringWArraySuper XObjArray diff --git a/rEFIt_UEFI/cpp_foundation/unicode_conversions.cpp b/rEFIt_UEFI/cpp_foundation/unicode_conversions.cpp index 4616e3810..3dc3a5f32 100755 --- a/rEFIt_UEFI/cpp_foundation/unicode_conversions.cpp +++ b/rEFIt_UEFI/cpp_foundation/unicode_conversions.cpp @@ -60,7 +60,7 @@ static inline char32_t surrogate_to_utf32(char16_t high, char16_t low) { #define UNI_SUR_LOW_START 0xDC00u -/************************************************************* utf8 - char32 *********************************************************/ +/************************************************************* Utility *********************************************************/ /* * Size of an UTF32 char when represented in UTF8 @@ -74,6 +74,18 @@ size_t utf8_size_of_utf32_char(char32_t c) { else return 4; } +/* + * Size in bytes of an utf32 string if it were converted to utf8 + * Return value : pointer to the end of string or at the error + */ +size_t utf8_size_of_utf32_string(const char32_t* s) +{ + if ( !s ) return 0; + size_t size = 0; + while ( *s ) s = utf8_size_of_utf32_char_ptr(s, &size); + return size; +} + /* * Increment size and return a pointer to the next char * Return value : pointer to the end of string or at the error @@ -86,63 +98,107 @@ const char32_t* utf8_size_of_utf32_char_ptr(const char32_t *s, size_t* size) } /* - * Store an utf32 char in dst, if there is enough room (dst_max_len is >= size of utf32 char) - * If there is enough room, dst_max_len is decrement and dst is increment and returned - * If there isn't enough room, dst_max_len is set to 0 and dst is returned + * Store an utf32 char in dst, if there is enough room (dst_max_size is >= size of converted utf32 char) + * If there is enough room, dst_max_size is decrement and dst is increment and returned + * If there isn't enough room, dst_max_size is set to 0 and dst is returned */ -char* get_utf8_from_char32(char* dst, size_t* dst_max_len, char32_t utf32_char) +char* get_utf8_from_char32(char* dst, size_t* dst_max_size, char32_t utf32_char) { #ifdef JIEF_DEBUG char* dst_debug = dst; (void)dst_debug; #endif - if ( *dst_max_len <= 0 ) return dst; + if ( *dst_max_size <= 0 ) return dst; /* assertion: utf32_char is a single UTF-4 value */ int bits = 0; // just to silence the warning if (utf32_char < 0x80) { *dst++ = (char)utf32_char; - *dst_max_len -= 1; + *dst_max_size -= 1; bits = -6; } else if (utf32_char < 0x800) { - if ( *dst_max_len < 2 ) { - *dst_max_len = 0; + if ( *dst_max_size < 2 ) { + *dst_max_size = 0; return dst; } *dst++ = (char)(((utf32_char >> 6) & 0x1F) | 0xC0); - *dst_max_len -= 1; + *dst_max_size -= 1; bits = 0; } else if (utf32_char < 0x10000) { - if ( *dst_max_len < 3 ) { - *dst_max_len = 0; + if ( *dst_max_size < 3 ) { + *dst_max_size = 0; return dst; } *dst++ = (char)(((utf32_char >> 12) & 0x0F) | 0xE0); - *dst_max_len -= 1; + *dst_max_size -= 1; bits = 6; } else { - if ( *dst_max_len < 4 ) { - *dst_max_len = 0; + if ( *dst_max_size < 4 ) { + *dst_max_size = 0; return dst; } *dst++ = (char)(((utf32_char >> 18) & 0x07) | 0xF0); - *dst_max_len -= 1; + *dst_max_size -= 1; bits = 12; } - for ( ; /* *dst_max_len > 0 && */ bits >= 0 ; bits -= 6 ) { // no need to check dst_max_len, it's made before + for ( ; /* *dst_max_size > 0 && */ bits >= 0 ; bits -= 6 ) { // no need to check dst_max_size, it's made before *dst++ = (char)(((utf32_char >> bits) & 0x3F) | 0x80); - *dst_max_len -= 1; + *dst_max_size -= 1; } #ifdef JIEF_DEBUG - if ( *dst_max_len > 0 ) *dst = 0; + if ( *dst_max_size > 0 ) *dst = 0; #endif return dst; } + +/* + * Store an utf32 char in dst, if there is enough room (dst_max_size is >= size of converted utf32 char) + * If there is enough room, dst_max_size is decrement and dst is increment and returned + * If there isn't enough room, dst_max_size is set to 0 and dst is returned + */ +char16_t* get_utf16_from_char32(char16_t* dst, size_t* dst_max_size, char32_t utf32_char) +{ + if ( *dst_max_size <= 0 ) return dst; + + char16_t char16_1, char16_2; + get_char16_from_char32(utf32_char, &char16_1, &char16_2); + if ( char16_2 != 0 ) { + if ( *dst_max_size < 2 ) { + *dst_max_size = 0; + }else{ + *dst++ = char16_1; + *dst++ = char16_2; + *dst_max_size -= 2; + } + }else{ + if ( *dst_max_size < 1 ) { + *dst_max_size = 0; + }else{ + *dst++ = char16_1; + *dst_max_size -= 1; + } + } + return dst; +} + +/* + * Store an utf32 char in dst, if there is enough room (dst_max_size is >= size of converted utf32 char) + * If there is enough room, dst_max_size is decrement and dst is increment and returned + * If there isn't enough room, dst_max_size is set to 0 and dst is returned + */ +char32_t* get_utf32_from_char32(char32_t* dst, size_t* dst_max_size, char32_t utf32_char) +{ + if ( *dst_max_size <= 0 ) return dst; + *dst = utf32_char; + *dst_max_size -= 1; + return dst + 1; +} + /* Number Bits for First Last Byte 1 Byte 2 Byte 3 cByte 4 of bytes code point @@ -166,7 +222,7 @@ const char* get_char32_from_utf8_string(const char* s, char32_t* char32) if (*s & 0x80) { if ((*(s+1) & 0xc0) != 0x80) { // 0xc0 = 0b11000000. Equivalent to if ( *(s+1) != 0x10xxxxxx ) // Finished in the middle of an utf8 multibyte char - char32 = 0; + *char32 = 0; return s; } if ((*s & 0xe0) == 0xe0) { // 0xe0 == 0b11100000. Equivalent to if ( *(s) == 0x111xxxxx ) @@ -174,7 +230,7 @@ const char* get_char32_from_utf8_string(const char* s, char32_t* char32) // Byte 3 has to be 0x10xxxxxx if ((*(s+2) & 0xc0) != 0x80) { // 0xc0 = 0b11000000. Equivalent to if ( *(s+2) != 0x10xxxxxx ) // Finished in the middle of an utf8 multibyte char - char32 = 0; + *char32 = 0; return s; } if ((*s & 0xf0) == 0xf0) { // 0xf0 = 0b1111xxxx. Equivalent to if ( *(s) == 0x1111xxxx ) @@ -182,7 +238,7 @@ const char* get_char32_from_utf8_string(const char* s, char32_t* char32) // Byte 4 has to be 0x10xxxxxx if ((*s & 0xf8) != 0xf0 || (*(s+3) & 0xc0) != 0x80) { // 0xf8 = 0b11111xxx. Equivalent to if ( *(s) != 0x11110xxx || *(s+3) != 0x10xxxxxx ) // Finished in the middle of an utf8 multibyte char - char32 = 0; + *char32 = 0; return s; } /* 4-byte code */ @@ -213,16 +269,43 @@ const char* get_char32_from_utf8_string(const char* s, char32_t* char32) return s; } +/* + * get nth char32 of an utf8 string + * Return value : pointer to the end of string or at the error + */ +char32_t get_char32_from_utf8_string_at_pos(const char* s, size_t pos) +{ + if ( !s ) return 0; + char32_t char32; + s = get_char32_from_utf8_string(s, &char32); + while ( char32 && pos > 0 ) { + s = get_char32_from_utf8_string(s, &char32); + pos--; + } + return char32; +} + + +/************************************************************* utf8 - char32 *********************************************************/ + +//const char* utf8_move_forward(const char* s) +//{ +//} /* * Size in bytes of an utf32 string if it were converted to utf8 * Return value : pointer to the end of string or at the error */ -size_t utf8_size_of_utf32_string(const char32_t* s) +size_t utf32_size_of_utf8_string(const char* s) { if ( !s ) return 0; size_t size = 0; - while ( *s ) s = utf8_size_of_utf32_char_ptr(s, &size); + char32_t char32; + s = get_char32_from_utf8_string(s, &char32); + while ( char32 ) { + size += 1; + s = get_char32_from_utf8_string(s, &char32); + } return size; } @@ -241,17 +324,24 @@ size_t utf8_size_of_utf32_string_len(const char32_t* s, size_t len) return size; } -size_t utf32_size_of_utf8_string(const char* s) +size_t utf32_string_from_utf8_string(char32_t* dst, size_t dst_max_size, const char* s) { - if ( !s ) return 0; - size_t size = 0; + if ( dst_max_size <= 0 ) return 0; + if ( !s ) { + *dst = 0; + return 0; + } + char32_t* p = dst; + char32_t* p_max = dst + dst_max_size - 1; + char32_t char32; s = get_char32_from_utf8_string(s, &char32); - while ( char32 ) { - size += 1; + while ( char32 != 0 && p < p_max ) { + *p++ = char32; s = get_char32_from_utf8_string(s, &char32); } - return size; + *p = 0; + return (size_t)(p-dst); } size_t utf32_size_of_utf8_string_len(const char* s, size_t len) @@ -268,38 +358,59 @@ size_t utf32_size_of_utf8_string_len(const char* s, size_t len) return size; } - -size_t utf32_string_from_utf8_string(char32_t* dst, size_t dst_max_len, const char* s) +size_t utf32_string_from_utf8_string_len(char32_t* dst, size_t dst_max_size, const char* s, size_t len) { - if ( !s && dst_max_len == 0 ) return 0; + if ( dst_max_size <= 0 ) return 0; + if ( !s || len <= 0 ) { + *dst = 0; + return 0; + } char32_t* p = dst; - char32_t* p_max = dst + dst_max_len - 1; + char32_t* p_max = dst + dst_max_size - 1; char32_t char32; s = get_char32_from_utf8_string(s, &char32); - while ( char32 != 0 && p < p_max ) { + while ( char32 != 0 && p < p_max && len > 0 ) { *p++ = char32; s = get_char32_from_utf8_string(s, &char32); + len--; } *p = 0; return (size_t)(p-dst); } -size_t utf8_string_from_utf32_string(char* dst, size_t dst_max_len, const char32_t *s) +size_t utf8_string_from_utf32_string(char* dst, size_t dst_max_size, const char32_t *s) { - if ( !s || dst_max_len <= 1 ) { - if ( dst_max_len > 0 ) *dst = 0; + if ( dst_max_size <= 0 ) return 0; + if ( !s ) { + *dst = 0; return 0; } - dst_max_len -= 1; + dst_max_size -= 1; char* p = dst; - while ( *s && dst_max_len > 0 ) { - p = get_utf8_from_char32(p, &dst_max_len, *s++); + while ( *s && dst_max_size > 0 ) { + p = get_utf8_from_char32(p, &dst_max_size, *s++); } *p = 0; return (size_t)(p-dst); } +size_t utf8_string_from_utf32_string_len(char* dst, size_t dst_max_size, const char32_t *s, size_t len) +{ + if ( dst_max_size <= 0 ) return 0; + if ( !s || len <= 0 ) { + *dst = 0; + return 0; + } + dst_max_size -= 1; + char* p = dst; + while ( *s && dst_max_size > 0 && len > 0 ) { + p = get_utf8_from_char32(p, &dst_max_size, *s++); + len--; + } + *p = 0; + return (size_t)(p-dst); +} /************************************************************* utf8 - char16 *********************************************************/ @@ -376,54 +487,91 @@ size_t utf16_size_of_utf8_string_len(const char* s, size_t len) -size_t utf8_string_from_utf16_string(char* dst, size_t dst_max_len, const char16_t *s) +size_t utf8_string_from_utf16_string(char* dst, size_t dst_max_size, const char16_t *s) { - if ( !s || dst_max_len <= 0 ) return 0; + if ( dst_max_size <= 0 ) return 0; + if ( !s ) { + *dst = 0; + return 0; + } char* p = dst; - dst_max_len -= 1; - while ( *s && dst_max_len > 0 ) { + dst_max_size -= 1; + while ( *s && dst_max_size > 0 ) { char32_t utf32_char; s = get_char32_from_utf16_string(s, &utf32_char); - p = get_utf8_from_char32(p, &dst_max_len, utf32_char); + p = get_utf8_from_char32(p, &dst_max_size, utf32_char); + } + *p = 0; + return (size_t)(p-dst); +} + +size_t utf8_string_from_utf16_string_len(char* dst, size_t dst_max_size, const char16_t *s, size_t len) +{ + if ( dst_max_size <= 0 ) return 0; + if ( !s || len <= 0 ) { + *dst = 0; + return 0; + } + char* p = dst; + dst_max_size -= 1; + while ( *s && dst_max_size > 0 && len > 0 ) { + char32_t utf32_char; + s = get_char32_from_utf16_string(s, &utf32_char); + p = get_utf8_from_char32(p, &dst_max_size, utf32_char); + len--; } *p = 0; return (size_t)(p-dst); } - -size_t utf16_string_from_utf8_string(char16_t* dst, size_t dst_max_len, const char* s) +size_t utf16_string_from_utf8_string(char16_t* dst, size_t dst_max_size, const char* s) { - if ( dst_max_len == 0 ) return 0; - dst_max_len -= 1; + if ( dst_max_size <= 0 ) return 0; + if ( !s ) { + *dst = 0; + return 0; + } + dst_max_size -= 1; // size_t dst_len = 0; char16_t* p = dst; - char16_t* p_max = dst + dst_max_len; +// char16_t* p_max = dst + dst_max_size; char32_t char32; s = get_char32_from_utf8_string(s, &char32); - while ( char32 && p < p_max ) { - if ( char32 == 0 ) return (size_t)(p-dst); - char16_t char16_1, char16_2; - get_char16_from_char32(char32, &char16_1, &char16_2); - if ( char16_2 != 0 ) { - if ( p < p_max-1 ) { - *p++ = char16_1; - *p++ = char16_2; - }else{ - *p = 0; - return (size_t)(p-dst); - } - }else{ - *p++ = char16_1; - } + while ( char32 && dst_max_size > 0 ) { + p = get_utf16_from_char32(p, &dst_max_size, char32); s = get_char32_from_utf8_string(s, &char32); } *p = 0; return (size_t)(p-dst); } +size_t utf16_string_from_utf8_string_len(char16_t* dst, size_t dst_max_size, const char* s, size_t len) +{ + if ( dst_max_size <= 0 ) return 0; + if ( !s || len <= 0 ) { + *dst = 0; + return 0; + } + dst_max_size -= 1; + +// size_t dst_len = 0; + char16_t* p = dst; +// char16_t* p_max = dst + dst_max_size; + + char32_t char32; + s = get_char32_from_utf8_string(s, &char32); + while ( char32 && dst_max_size > 0 && len > 0 ) { + p = get_utf16_from_char32(p, &dst_max_size, char32); + s = get_char32_from_utf8_string(s, &char32); + len--; + } + *p = 0; + return (size_t)(p-dst); +} + /************************************************************* utf16 - utf32 *********************************************************/ @@ -464,7 +612,12 @@ char32_t get_char32_from_char16(char16_t char16_1, char16_t char16_2) */ const char16_t* get_char32_from_utf16_string(const char16_t* s, char32_t* char32) { - const char16_t char16_1 = *s++; + const char16_t char16_1 = *s; + if ( char16_1 == 0 ) { + *char32 = 0; + return s; + } + s++; if (!is_surrogate(char16_1)) { *char32 = char16_1; return s; @@ -530,39 +683,54 @@ size_t utf32_size_of_utf16_string_len(const char16_t *s, size_t len) } -size_t utf16_string_from_utf32_string(char16_t* dst, size_t dst_max_len, const char32_t *s) +size_t utf16_string_from_utf32_string(char16_t* dst, size_t dst_max_size, const char32_t *s) { - if ( dst_max_len == 0 ) return 0; + if ( dst_max_size <= 0 ) return 0; + if ( !s ) { + *dst = 0; + return 0; + } char16_t* p = dst; - char16_t* p_max = dst + dst_max_len - 1; +// char16_t* p_max = dst + dst_max_size - 1; - while ( *s && p < p_max ) { - char16_t char16_1, char16_2; - get_char16_from_char32(*s++, &char16_1, &char16_2); - if ( char16_2 != 0 ) { - if ( p < p_max-1 ) { - *p++ = char16_1; - *p++ = char16_2; - }else{ - *p = 0; - return (size_t)(p-dst); - } - }else{ - *p++ = char16_1; - } + while ( *s && dst_max_size > 0 ) { + p = get_utf16_from_char32(p, &dst_max_size, *s++); } *p = 0; return (size_t)(p-dst); } -size_t utf32_string_from_utf16_string(char32_t* dst, size_t dst_max_len, const char16_t *s) +size_t utf16_string_from_utf32_string_len(char16_t* dst, size_t dst_max_size, const char32_t *s, size_t len) { - if ( dst_max_len == 0 ) return 0; - char32_t* p = dst; - char32_t* p_max = dst + dst_max_len - 1; + if ( dst_max_size <= 0 ) return 0; + if ( !s || len <= 0 ) { + *dst = 0; + return 0; + } + char16_t* p = dst; +// char16_t* p_max = dst + dst_max_size - 1; + dst_max_size--; + while ( *s && dst_max_size > 0 && len > 0 ) { + p = get_utf16_from_char32(p, &dst_max_size, *s++); + len--; + } + *p = 0; + return (size_t)(p-dst); +} + +size_t utf32_string_from_utf16_string(char32_t* dst, size_t dst_max_size, const char16_t *s) +{ + if ( dst_max_size <= 0 ) return 0; + if ( !s ) { + *dst = 0; + return 0; + } + char32_t* p = dst; + char32_t* p_max = dst + dst_max_size - 1; + + char32_t c; while ( *s && p < p_max ) { - char32_t c; s = get_char32_from_utf16_string(s, &c); if ( c == 0 ) return (size_t)(p-dst); *p++ = c; @@ -571,6 +739,28 @@ size_t utf32_string_from_utf16_string(char32_t* dst, size_t dst_max_len, const c return (size_t)(p-dst); } +size_t utf32_string_from_utf16_string_len(char32_t* dst, size_t dst_max_size, const char16_t *s, size_t len) +{ + if ( dst_max_size <= 0 ) return 0; + if ( !s || len <= 0 ) { + *dst = 0; + return 0; + } + char32_t* p = dst; + char32_t* p_max = dst + dst_max_size - 1; + + char32_t c; + while ( *s && p < p_max && len > 0 ) { + s = get_char32_from_utf16_string(s, &c); + if ( c == 0 ) return (size_t)(p-dst); + *p++ = c; + len--; + } + *p = 0; + return (size_t)(p-dst); +} + + /************************************************************* utf8 - wchar_t *********************************************************/ @@ -611,21 +801,39 @@ size_t wchar_size_of_utf8_string_len(const char* s, size_t len) #endif } -size_t utf8_string_from_wchar_string(char* dst, size_t dst_max_len, const wchar_t* s) +size_t utf8_string_from_wchar_string(char* dst, size_t dst_max_size, const wchar_t* s) { #if __WCHAR_MAX__ <= 0xFFFFu - return utf8_string_from_utf16_string(dst, dst_max_len, (char16_t*)s); + return utf8_string_from_utf16_string(dst, dst_max_size, (char16_t*)s); #else - return utf8_string_from_utf32_string(dst, dst_max_len, (char32_t*)s); + return utf8_string_from_utf32_string(dst, dst_max_size, (char32_t*)s); #endif } -size_t wchar_string_from_utf8_string(wchar_t* dst, size_t dst_max_len, const char* s) +size_t utf8_string_from_wchar_string_len(char* dst, size_t dst_max_size, const wchar_t* s, size_t len) { #if __WCHAR_MAX__ <= 0xFFFFu - return utf16_string_from_utf8_string((char16_t*)dst, dst_max_len, s); + return utf8_string_from_utf16_string_len(dst, dst_max_size, (char16_t*)s, len); #else - return utf32_string_from_utf8_string((char32_t*)dst, dst_max_len, s); + return utf8_string_from_utf32_string_len(dst, dst_max_size, (char32_t*)s, len); +#endif +} + +size_t wchar_string_from_utf8_string(wchar_t* dst, size_t dst_max_size, const char* s) +{ +#if __WCHAR_MAX__ <= 0xFFFFu + return utf16_string_from_utf8_string((char16_t*)dst, dst_max_size, s); +#else + return utf32_string_from_utf8_string((char32_t*)dst, dst_max_size, s); +#endif +} + +size_t wchar_string_from_utf8_string_len(wchar_t* dst, size_t dst_max_size, const char* s, size_t len) +{ +#if __WCHAR_MAX__ <= 0xFFFFu + return utf16_string_from_utf8_string_len((char16_t*)dst, dst_max_size, s, len); +#else + return utf32_string_from_utf8_string_len((char32_t*)dst, dst_max_size, s, len); #endif } @@ -668,21 +876,39 @@ size_t wchar_size_of_utf16_string_len(const char16_t* s, size_t len) #endif } -size_t utf16_string_from_wchar_string(char16_t* dst, size_t dst_max_len, const wchar_t* s) +size_t utf16_string_from_wchar_string(char16_t* dst, size_t dst_max_size, const wchar_t* s) { #if __WCHAR_MAX__ <= 0xFFFFu - return utf16_string_from_utf16_string(dst, dst_max_len, (char16_t*)s); + return utf16_string_from_utf16_string(dst, dst_max_size, (char16_t*)s); #else - return utf16_string_from_utf32_string(dst, dst_max_len, (char32_t*)s); + return utf16_string_from_utf32_string(dst, dst_max_size, (char32_t*)s); #endif } -size_t wchar_string_from_utf16_string(wchar_t* dst, size_t dst_max_len, const char16_t* s) +size_t utf16_string_from_wchar_string_len(char16_t* dst, size_t dst_max_size, const wchar_t* s, size_t len) { #if __WCHAR_MAX__ <= 0xFFFFu - return utf16_string_from_utf16_string((char16_t*)dst, dst_max_len, s); + return utf16_string_from_utf16_string_len(dst, dst_max_size, (char16_t*)s, len); #else - return utf32_string_from_utf16_string((char32_t*)dst, dst_max_len, s); + return utf16_string_from_utf32_string_len(dst, dst_max_size, (char32_t*)s, len); +#endif +} + +size_t wchar_string_from_utf16_string(wchar_t* dst, size_t dst_max_size, const char16_t* s) +{ +#if __WCHAR_MAX__ <= 0xFFFFu + return utf16_string_from_utf16_string((char16_t*)dst, dst_max_size, s); +#else + return utf32_string_from_utf16_string((char32_t*)dst, dst_max_size, s); +#endif +} + +size_t wchar_string_from_utf16_string_len(wchar_t* dst, size_t dst_max_size, const char16_t* s, size_t len) +{ +#if __WCHAR_MAX__ <= 0xFFFFu + return utf16_string_from_utf16_string_len((char16_t*)dst, dst_max_size, s, len); +#else + return utf32_string_from_utf16_string_len((char32_t*)dst, dst_max_size, s, len); #endif } @@ -726,21 +952,21 @@ size_t wchar_size_of_utf32_string_len(const char32_t* s, size_t len) #endif } -size_t utf32_string_from_wchar_string(char32_t* dst, size_t dst_max_len, const wchar_t* s) +size_t utf32_string_from_wchar_string(char32_t* dst, size_t dst_max_size, const wchar_t* s) { #if __WCHAR_MAX__ <= 0xFFFFu - return utf32_string_from_utf16_string(dst, dst_max_len, (char16_t*)s); + return utf32_string_from_utf16_string(dst, dst_max_size, (char16_t*)s); #else - return utf32_string_from_utf32_string(dst, dst_max_len, (char32_t*)s); + return utf32_string_from_utf32_string(dst, dst_max_size, (char32_t*)s); #endif } -size_t wchar_string_from_utf32_string(wchar_t* dst, size_t dst_max_len, const char32_t* s) +size_t wchar_string_from_utf32_string(wchar_t* dst, size_t dst_max_size, const char32_t* s) { #if __WCHAR_MAX__ <= 0xFFFFu - return utf16_string_from_utf32_string((char16_t*)dst, dst_max_len, s); + return utf16_string_from_utf32_string((char16_t*)dst, dst_max_size, s); #else - return utf32_string_from_utf32_string((char32_t*)dst, dst_max_len, s); + return utf32_string_from_utf32_string((char32_t*)dst, dst_max_size, s); #endif } @@ -754,9 +980,17 @@ size_t wchar_string_from_utf32_string(wchar_t* dst, size_t dst_max_len, const ch // Not efficient. Could be map to the ones provided by operating system size_t utf8_size_of_utf8_string(const char* s) { - const char* p = s; - while ( *p++ ); - return (size_t)(p-s-1); + if ( !s ) return 0; + char32_t char32 = 1; + const char* p = s; // = get_char32_from_utf8_string(s, &char32); + while ( char32 ) { + p = get_char32_from_utf8_string(p, &char32); + } + return (uintptr_t(p)-uintptr_t(s)); +// +// const char* p = s; +// while ( *p++ ); +// return (size_t)(p-s-1); } size_t utf8_size_of_utf8_string_len(const char* s, size_t len) @@ -768,14 +1002,21 @@ size_t utf8_size_of_utf8_string_len(const char* s, size_t len) p = get_char32_from_utf8_string(p, &char32); len -= 1; } - return (uintptr_t(p)-uintptr_t(s)); + return (size_t)(p-s);// p-s is in number of char32_t, not bytes. Careful, uintptr_t(p)-uintptr_t(s) would be in bytes } size_t utf16_size_of_utf16_string(const char16_t* s) { - const char16_t* p = s; - while ( *p++ ); - return (size_t)(p-s-1); + if ( !s ) return 0; + char32_t char32 = 1; + const char16_t* p = s; // = get_char32_from_utf8_string(s, &char32); + while ( char32 ) { + p = get_char32_from_utf16_string(p, &char32); + } + return (size_t)(p-s);// p-s is in number of char32_t, not bytes. Careful, uintptr_t(p)-uintptr_t(s) would be in bytes +// const char16_t* p = s; +// while ( *p++ ); +// return (size_t)(p-s-1); } size_t utf16_size_of_utf16_string_len(const char16_t* s, size_t len) @@ -796,14 +1037,14 @@ size_t utf32_size_of_utf32_string(const char32_t* s) { const char32_t* p = s; while ( *p++ ); - return (size_t)(p-s-1); + return ((size_t)(p-s-1)); // p-s is in number of char32_t, not bytes. // Let's hope that p-s-1 is not > MAX_SIZET } size_t utf32_size_of_utf32_string_len(const char32_t* s, size_t len) { const char32_t* p = s; while ( *p++ && len > 0 ) len -= 1; - return (size_t)(p-s-1); + return ((size_t)(p-s-1)); // p-s is in number of char32_t, not bytes. // Let's hope that p-s-1 is not > MAX_SIZET } size_t wchar_size_of_wchar_string(const wchar_t* s) @@ -826,58 +1067,129 @@ size_t wchar_size_of_wchar_string_len(const wchar_t* s, size_t len) -size_t utf8_string_from_utf8_string(char* dst, size_t dst_max_len, const char *s) +size_t utf8_string_from_utf8_string(char* dst, size_t dst_max_size, const char *s) { - if ( !s || dst_max_len <= 1 ) { - if ( dst_max_len > 0 ) *dst = 0; + if ( !s || dst_max_size <= 1 ) { + if ( dst_max_size > 0 ) *dst = 0; return 0; } - dst_max_len -= 1; + dst_max_size -= 1; char* p = dst; char32_t char32; s = get_char32_from_utf8_string(s, &char32); - while ( char32 && dst_max_len > 0 ) { - p = get_utf8_from_char32(p, &dst_max_len, char32); + while ( char32 && dst_max_size > 0 ) { + p = get_utf8_from_char32(p, &dst_max_size, char32); s = get_char32_from_utf8_string(s, &char32); } *p = 0; return uintptr_t(p)-uintptr_t(dst)-1; } -size_t utf16_string_from_utf16_string(char16_t* dst, size_t dst_max_len, const char16_t *s) +size_t utf8_string_from_utf8_string_len(char* dst, size_t dst_max_size, const char *s, size_t len) { - if ( !s || dst_max_len <= 1 ) { - if ( dst_max_len > 0 ) *dst = 0; + if ( !s || len <= 0 || dst_max_size <= 1 ) { + if ( dst_max_size > 0 ) *dst = 0; return 0; } - size_t s_len = utf16_size_of_utf16_string(s); - if ( dst_max_len > s_len ) dst_max_len = s_len; - else dst_max_len -= 1; - memcpy((void*)dst, (void*)s, dst_max_len * sizeof(char16_t)); - dst[dst_max_len] = 0; - return dst_max_len * sizeof(char16_t); + dst_max_size -= 1; + char* p = dst; + char32_t char32; + s = get_char32_from_utf8_string(s, &char32); + while ( char32 && dst_max_size > 0 && len > 0) { + p = get_utf8_from_char32(p, &dst_max_size, char32); + s = get_char32_from_utf8_string(s, &char32); + len--; + } + *p = 0; + return uintptr_t(p)-uintptr_t(dst)-1; } -size_t utf32_string_from_utf32_string(char32_t* dst, size_t dst_max_len, const char32_t *s) +size_t utf16_string_from_utf16_string(char16_t* dst, size_t dst_max_size, const char16_t *s) { - if ( !s || dst_max_len <= 1 ) { - if ( dst_max_len > 0 ) *dst = 0; + if ( !s || dst_max_size <= 1 ) { + if ( dst_max_size > 0 ) *dst = 0; + return 0; + } + dst_max_size -= 1; + char16_t* p = dst; + char32_t char32; + s = get_char32_from_utf16_string(s, &char32); + while ( char32 && dst_max_size > 0 ) { + p = get_utf16_from_char32(p, &dst_max_size, char32); + s = get_char32_from_utf16_string(s, &char32); + } + *p = 0; + return uintptr_t(p)-uintptr_t(dst)-1; +// size_t s_len = utf16_size_of_utf16_string(s); +// if ( dst_max_size > s_len ) dst_max_size = s_len; +// else dst_max_size -= 1; +// memcpy((void*)dst, (void*)s, dst_max_size * sizeof(char16_t)); +// dst[dst_max_size] = 0; +// return dst_max_size * sizeof(char16_t); +} + +size_t utf16_string_from_utf16_string_len(char16_t* dst, size_t dst_max_size, const char16_t *s, size_t len) +{ + if ( !s || len <= 0 || dst_max_size <= 1 ) { + if ( dst_max_size > 0 ) *dst = 0; + return 0; + } + dst_max_size -= 1; + char16_t* p = dst; + char32_t char32; + s = get_char32_from_utf16_string(s, &char32); + while ( char32 && dst_max_size > 0 && len > 0) { + p = get_utf16_from_char32(p, &dst_max_size, char32); + s = get_char32_from_utf16_string(s, &char32); + len--; + } + *p = 0; + return uintptr_t(p)-uintptr_t(dst)-1; +} + +size_t utf32_string_from_utf32_string(char32_t* dst, size_t dst_max_size, const char32_t *s) +{ + if ( !s || dst_max_size <= 1 ) { + if ( dst_max_size > 0 ) *dst = 0; return 0; } size_t s_len = utf32_size_of_utf32_string(s); - if ( dst_max_len > s_len ) dst_max_len = s_len; - else dst_max_len -= 1; - memcpy((void*)dst, (void*)s, dst_max_len * sizeof(char32_t)); - dst[dst_max_len] = 0; - return dst_max_len * sizeof(char32_t); + if ( dst_max_size > s_len ) dst_max_size = s_len; + else dst_max_size -= 1; + memcpy((void*)dst, (void*)s, dst_max_size * sizeof(char32_t)); + dst[dst_max_size] = 0; + return dst_max_size * sizeof(char32_t); } -size_t wchar_string_from_wchar_string(wchar_t* dst, size_t dst_max_len, const wchar_t *s) +size_t utf32_string_from_utf32_string_len(char32_t* dst, size_t dst_max_size, const char32_t *s, size_t len) +{ + if ( !s || len <= 0 || dst_max_size <= 1 ) { + if ( dst_max_size > 0 ) *dst = 0; + return 0; + } + size_t s_len = utf32_size_of_utf32_string_len(s, len); + if ( dst_max_size > s_len ) dst_max_size = s_len; + else dst_max_size -= 1; + memcpy((void*)dst, (void*)s, dst_max_size * sizeof(char32_t)); + dst[dst_max_size] = 0; + return dst_max_size * sizeof(char32_t); +} + +size_t wchar_string_from_wchar_string(wchar_t* dst, size_t dst_max_size, const wchar_t *s) { #if __WCHAR_MAX__ <= 0xFFFFu - return utf16_string_from_utf16_string((char16_t*)dst, dst_max_len, (char16_t*)s); + return utf16_string_from_utf16_string((char16_t*)dst, dst_max_size, (char16_t*)s); #else - return utf32_string_from_utf32_string((char32_t*)dst, dst_max_len, (char32_t*)s); + return utf32_string_from_utf32_string((char32_t*)dst, dst_max_size, (char32_t*)s); +#endif +} + +size_t wchar_string_from_wchar_string_len(wchar_t* dst, size_t dst_max_size, const wchar_t *s, size_t len) +{ +#if __WCHAR_MAX__ <= 0xFFFFu + return utf16_string_from_utf16_string_len((char16_t*)dst, dst_max_size, (char16_t*)s, len); +#else + return utf32_string_from_utf32_string_len((char32_t*)dst, dst_max_size, (char32_t*)s, len); #endif } diff --git a/rEFIt_UEFI/cpp_foundation/unicode_conversions.h b/rEFIt_UEFI/cpp_foundation/unicode_conversions.h index 4423032b4..4c2f7acef 100644 --- a/rEFIt_UEFI/cpp_foundation/unicode_conversions.h +++ b/rEFIt_UEFI/cpp_foundation/unicode_conversions.h @@ -18,7 +18,7 @@ typedef uint16_t char16_t; #endif #ifndef __WCHAR_MAX__ -#define __WCHAR_MAX__ 0xFFFFu +#define __WCHAR_MAX__ WCHAR_MAX #endif #if __WCHAR_MAX__ <= 0xFFFFu @@ -41,9 +41,6 @@ typedef uint16_t char16_t; /****** utility *****/ - -/****** utf8 - utf32 *****/ - /* * Size of an UTF32 char when represented in UTF8 * Return value : size @@ -57,11 +54,25 @@ size_t utf8_size_of_utf32_char(char32_t c); const char32_t* utf8_size_of_utf32_char_ptr(const char32_t *s, size_t* size); /* - * Store an utf32 char in dst, if there is enough room (dst_max_len is >= size of utf32 char) - * If there is enough room, dst_max_len is decrement and dst is increment and returned - * If there isn't enough room, dst_max_len is set to 0 and dst is returned + * Store an utf32 char in dst, if there is enough room (dst_max_size is >= size of converted utf32 char) + * If there is enough room, dst_max_size is decrement and dst is increment and returned + * If there isn't enough room, dst_max_size is set to 0 and dst is returned */ -char* get_utf8_from_char32(char* dst, size_t* dst_max_len, char32_t utf32_char); +char* get_utf8_from_char32(char* dst, size_t* dst_max_size, char32_t utf32_char); + +/* + * Store an utf32 char in dst, if there is enough room (dst_max_size is >= size of converted utf32 char) + * If there is enough room, dst_max_size is decrement and dst is increment and returned + * If there isn't enough room, dst_max_size is set to 0 and dst is returned + */ +char16_t* get_utf16_from_char32(char16_t* dst, size_t* dst_max_size, char32_t utf32_char); + +/* + * Store an utf32 char in dst, if there is enough room (dst_max_size is >= size of converted utf32 char) + * If there is enough room, dst_max_size is decrement and dst is increment and returned + * If there isn't enough room, dst_max_size is set to 0 and dst is returned + */ +char32_t* get_utf32_from_char32(char32_t* dst, size_t* dst_max_size, char32_t utf32_char); /* * char32 will be set to 0 at the end of string or at error @@ -69,8 +80,15 @@ char* get_utf8_from_char32(char* dst, size_t* dst_max_len, char32_t utf32_char); */ const char* get_char32_from_utf8_string(const char* s, char32_t* char32); +/* + * get nth char32 of an utf8 string + * Return value : pointer to the end of string or at the error + */ +char32_t get_char32_from_utf8_string_at_pos(const char* s, size_t n); +/****** utf8 - utf32 *****/ + /* * Size in bytes of an utf32 string if it were converted to utf8 * Return value : pointer to the end of string or at the error @@ -85,8 +103,10 @@ size_t utf8_size_of_utf32_string_len(const char32_t* s, size_t len); size_t utf32_size_of_utf8_string(const char* s); size_t utf32_size_of_utf8_string_len(const char* s, size_t len); -size_t utf32_string_from_utf8_string(char32_t* dst, size_t dst_max_len, const char* s); -size_t utf8_string_from_utf32_string(char* dst, size_t dst_max_len, const char32_t *s); +size_t utf32_string_from_utf8_string(char32_t* dst, size_t dst_max_size, const char* s); +size_t utf32_string_from_utf8_string_len(char32_t* dst, size_t dst_max_size, const char* s, size_t len); +size_t utf8_string_from_utf32_string(char* dst, size_t dst_max_size, const char32_t *s); +size_t utf8_string_from_utf32_string_len(char* dst, size_t dst_max_size, const char32_t *s, size_t len); /****** utf8 - utf16 *****/ @@ -103,8 +123,10 @@ size_t utf8_size_of_utf16_string_len(const char16_t* s, size_t len); size_t utf16_size_of_utf8_string(const char* s); size_t utf16_size_of_utf8_string_len(const char* s, size_t len); -size_t utf8_string_from_utf16_string(char* dst, size_t dst_max_len, const char16_t *s); -size_t utf16_string_from_utf8_string(char16_t* dst, size_t dst_max_len, const char* s); +size_t utf8_string_from_utf16_string(char* dst, size_t dst_max_size, const char16_t *s); +size_t utf8_string_from_utf16_string_len(char* dst, size_t dst_max_size, const char16_t *s, size_t len); +size_t utf16_string_from_utf8_string(char16_t* dst, size_t dst_max_size, const char* s); +size_t utf16_string_from_utf8_string_len(char16_t* dst, size_t dst_max_size, const char* s, size_t len); /****** utf16 - utf32 *****/ @@ -120,8 +142,10 @@ size_t utf16_size_of_utf32_string_len(const char32_t *s, size_t len); size_t utf32_size_of_utf16_string(const char16_t *s); size_t utf32_size_of_utf16_string_len(const char16_t *s, size_t len); -size_t utf16_string_from_utf32_string(char16_t* dst, size_t dst_max_len, const char32_t *s); -size_t utf32_string_from_utf16_string(char32_t* dst, size_t dst_max_len, const char16_t *s); +size_t utf16_string_from_utf32_string(char16_t* dst, size_t dst_max_size, const char32_t *s); +size_t utf16_string_from_utf32_string_len(char16_t* dst, size_t dst_max_size, const char32_t *s, size_t len); +size_t utf32_string_from_utf16_string(char32_t* dst, size_t dst_max_size, const char16_t *s); +size_t utf32_string_from_utf16_string_len(char32_t* dst, size_t dst_max_size, const char16_t *s, size_t len); /****** utf8 - wchar_t *****/ @@ -131,8 +155,10 @@ size_t utf8_size_of_wchar_string_len(const wchar_t* s, size_t len); size_t wchar_size_of_utf8_string(const char* s); size_t wchar_size_of_utf8_string_len(const char* s, size_t len); -size_t utf8_string_from_wchar_string(char* dst, size_t dst_max_len, const wchar_t* s); -size_t wchar_string_from_utf8_string(wchar_t* dst, size_t dst_max_len, const char* s); +size_t utf8_string_from_wchar_string(char* dst, size_t dst_max_size, const wchar_t* s); +size_t utf8_string_from_wchar_string_len(char* dst, size_t dst_max_size, const wchar_t* s, size_t len); +size_t wchar_string_from_utf8_string(wchar_t* dst, size_t dst_max_size, const char* s); +size_t wchar_string_from_utf8_string_len(wchar_t* dst, size_t dst_max_size, const char* s, size_t len); /****** utf16 - wchar_t *****/ @@ -141,8 +167,10 @@ size_t utf16_size_of_wchar_string_len(const wchar_t* s, size_t len); size_t wchar_size_of_utf16_string(const char16_t *s); size_t wchar_size_of_utf16_string_len(const char16_t *s, size_t len); -size_t utf16_string_from_wchar_string(char16_t* dst, size_t dst_max_len, const wchar_t* s); -size_t wchar_string_from_utf16_string(wchar_t* dst, size_t dst_max_len, const char16_t* s); +size_t utf16_string_from_wchar_string(char16_t* dst, size_t dst_max_size, const wchar_t* s); +size_t utf16_string_from_wchar_string_len(char16_t* dst, size_t dst_max_size, const wchar_t* s, size_t len); +size_t wchar_string_from_utf16_string(wchar_t* dst, size_t dst_max_size, const char16_t* s); +size_t wchar_string_from_utf16_string_len(wchar_t* dst, size_t dst_max_size, const char16_t* s, size_t len); /****** utf32 - wchar_t *****/ @@ -151,8 +179,10 @@ size_t utf32_size_of_wchar_string_len(const wchar_t* s, size_t len); size_t wchar_size_of_utf32_string(const char32_t *s); size_t wchar_size_of_utf32_string_len(const char32_t *s, size_t len); -size_t utf32_string_from_wchar_string(char32_t* dst, size_t dst_max_len, const wchar_t* s); -size_t wchar_string_from_utf32_string(wchar_t* dst, size_t dst_max_len, const char32_t* s); +size_t utf32_string_from_wchar_string(char32_t* dst, size_t dst_max_size, const wchar_t* s); +size_t utf32_string_from_wchar_string_len(char32_t* dst, size_t dst_max_size, const wchar_t* s, size_t len); +size_t wchar_string_from_utf32_string(wchar_t* dst, size_t dst_max_size, const char32_t* s); +size_t wchar_string_from_utf32_string_len(wchar_t* dst, size_t dst_max_size, const char32_t* s, size_t len); /****** no conversion *****/ @@ -166,10 +196,14 @@ size_t utf32_size_of_utf32_string_len(const char32_t* s, size_t len); size_t wchar_size_of_wchar_string(const wchar_t* s); size_t wchar_size_of_wchar_string_len(const wchar_t* s, size_t len); -size_t utf8_string_from_utf8_string(char* dst, size_t dst_max_len, const char *s); -size_t utf16_string_from_utf16_string(char16_t* dst, size_t dst_max_len, const char16_t *s); -size_t utf32_string_from_utf32_string(char32_t* dst, size_t dst_max_len, const char32_t *s); -size_t wchar_string_from_wchar_string(wchar_t* dst, size_t dst_max_len, const wchar_t *s); +size_t utf8_string_from_utf8_string(char* dst, size_t dst_max_size, const char *s); +size_t utf8_string_from_utf8_string_len(char* dst, size_t dst_max_size, const char *s, size_t len); +size_t utf16_string_from_utf16_string(char16_t* dst, size_t dst_max_size, const char16_t *s); +size_t utf16_string_from_utf16_string_len(char16_t* dst, size_t dst_max_size, const char16_t *s, size_t len); +size_t utf32_string_from_utf32_string(char32_t* dst, size_t dst_max_size, const char32_t *s); +size_t utf32_string_from_utf32_string_len(char32_t* dst, size_t dst_max_size, const char32_t *s, size_t len); +size_t wchar_string_from_wchar_string(wchar_t* dst, size_t dst_max_size, const wchar_t *s); +size_t wchar_string_from_wchar_string_len(wchar_t* dst, size_t dst_max_size, const wchar_t *s, size_t len); /****** convenience *****/ @@ -186,6 +220,12 @@ inline const char16_t* get_char32_from_string(const char16_t* s, char32_t* char3 inline const char32_t* get_char32_from_string(const char32_t* s, char32_t* char32) { *char32 = *s; return s+1; } inline const wchar_t* get_char32_from_string(const wchar_t* s, char32_t* char32) { return (wchar_t*)get_char32_from_string((wchar_cast*)s, char32); } +inline char* store_utf_from_char32(char* dst, size_t* dst_max_size, char32_t utf32_char) { return get_utf8_from_char32(dst, dst_max_size, utf32_char); } +inline char16_t* store_utf_from_char32(char16_t* dst, size_t* dst_max_size, char32_t utf32_char) { return get_utf16_from_char32(dst, dst_max_size, utf32_char); } +inline char32_t* store_utf_from_char32(char32_t* dst, size_t* dst_max_size, char32_t utf32_char) { return get_utf32_from_char32(dst, dst_max_size, utf32_char); } +inline wchar_t* store_utf_from_char32(wchar_t* dst, size_t* dst_max_size, char32_t utf32_char) { return (wchar_t*)store_utf_from_char32((wchar_cast*)dst, dst_max_size, utf32_char); } + + inline size_t length_of_utf_string(const char* s) { return utf32_size_of_utf8_string(s); }; inline size_t length_of_utf_string(const char16_t* s) { return utf32_size_of_utf16_string(s); }; @@ -240,34 +280,59 @@ inline size_t utf_size_of_utf_string_len(const char16_t*, const char32_t* s, siz inline size_t utf_size_of_utf_string_len(const char32_t*, const char32_t* s, size_t len) { return utf32_size_of_utf32_string_len(s, len); } inline size_t utf_size_of_utf_string_len(const wchar_t* t, const char32_t* s, size_t len) { return utf_size_of_utf_string_len((wchar_cast*)t, s, len); } -inline size_t utf_size_of_utf_string_len(const char* t, const wchar_t* s, size_t len) { return utf_size_of_utf_string_len((wchar_cast*)t, (wchar_cast*)s, len); } -inline size_t utf_size_of_utf_string_len(const char16_t* t, const wchar_t* s, size_t len) { return utf_size_of_utf_string_len((wchar_cast*)t, (wchar_cast*)s, len); } -inline size_t utf_size_of_utf_string_len(const char32_t* t, const wchar_t* s, size_t len) { return utf_size_of_utf_string_len((wchar_cast*)t, (wchar_cast*)s, len); } +inline size_t utf_size_of_utf_string_len(const char* t, const wchar_t* s, size_t len) { return utf_size_of_utf_string_len(t, (wchar_cast*)s, len); } +inline size_t utf_size_of_utf_string_len(const char16_t* t, const wchar_t* s, size_t len) { return utf_size_of_utf_string_len(t, (wchar_cast*)s, len); } +inline size_t utf_size_of_utf_string_len(const char32_t* t, const wchar_t* s, size_t len) { return utf_size_of_utf_string_len(t, (wchar_cast*)s, len); } inline size_t utf_size_of_utf_string_len(const wchar_t* t, const wchar_t* s, size_t len) { return utf_size_of_utf_string_len((wchar_cast*)t, (wchar_cast*)s, len); } -inline size_t utf_string_from_utf_string(char* dst, size_t dst_max_len, const char* s) { return utf8_string_from_utf8_string(dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(char16_t* dst, size_t dst_max_len, const char* s) { return utf16_string_from_utf8_string(dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(char32_t* dst, size_t dst_max_len, const char* s) { return utf32_string_from_utf8_string(dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(wchar_t* dst, size_t dst_max_len, const char* s) { return utf_string_from_utf_string((wchar_cast*)dst, dst_max_len, s); } +inline size_t utf_string_from_utf_string(char* dst, size_t dst_max_size, const char* s) { return utf8_string_from_utf8_string(dst, dst_max_size, s); } +inline size_t utf_string_from_utf_string(char16_t* dst, size_t dst_max_size, const char* s) { return utf16_string_from_utf8_string(dst, dst_max_size, s); } +inline size_t utf_string_from_utf_string(char32_t* dst, size_t dst_max_size, const char* s) { return utf32_string_from_utf8_string(dst, dst_max_size, s); } +inline size_t utf_string_from_utf_string(wchar_t* dst, size_t dst_max_size, const char* s) { return utf_string_from_utf_string((wchar_cast*)dst, dst_max_size, s); } -inline size_t utf_string_from_utf_string(char* dst, size_t dst_max_len, const char16_t *s) { return utf8_string_from_utf16_string(dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(char16_t* dst, size_t dst_max_len, const char16_t *s) { return utf16_string_from_utf16_string(dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(char32_t* dst, size_t dst_max_len, const char16_t *s) { return utf32_string_from_utf16_string(dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(wchar_t* dst, size_t dst_max_len, const char16_t *s) { return utf_string_from_utf_string((wchar_cast*)dst, dst_max_len, s); } +inline size_t utf_string_from_utf_string(char* dst, size_t dst_max_size, const char16_t *s) { return utf8_string_from_utf16_string(dst, dst_max_size, s); } +inline size_t utf_string_from_utf_string(char16_t* dst, size_t dst_max_size, const char16_t *s) { return utf16_string_from_utf16_string(dst, dst_max_size, s); } +inline size_t utf_string_from_utf_string(char32_t* dst, size_t dst_max_size, const char16_t *s) { return utf32_string_from_utf16_string(dst, dst_max_size, s); } +inline size_t utf_string_from_utf_string(wchar_t* dst, size_t dst_max_size, const char16_t *s) { return utf_string_from_utf_string((wchar_cast*)dst, dst_max_size, s); } + +inline size_t utf_string_from_utf_string(char* dst, size_t dst_max_size, const char32_t *s) { return utf8_string_from_utf32_string(dst, dst_max_size, s); } +inline size_t utf_string_from_utf_string(char16_t* dst, size_t dst_max_size, const char32_t *s) { return utf16_string_from_utf32_string(dst, dst_max_size, s); } +inline size_t utf_string_from_utf_string(char32_t* dst, size_t dst_max_size, const char32_t *s) { return utf32_string_from_utf32_string(dst, dst_max_size, s); } +inline size_t utf_string_from_utf_string(wchar_t* dst, size_t dst_max_size, const char32_t *s) { return utf_string_from_utf_string((wchar_cast*)dst, dst_max_size, s); } + +inline size_t utf_string_from_utf_string(char* dst, size_t dst_max_size, const wchar_t *s) { return utf_string_from_utf_string(dst, dst_max_size, (wchar_cast*)s); } +inline size_t utf_string_from_utf_string(char16_t* dst, size_t dst_max_size, const wchar_t *s) { return utf_string_from_utf_string(dst, dst_max_size, (wchar_cast*)s); } +inline size_t utf_string_from_utf_string(char32_t* dst, size_t dst_max_size, const wchar_t *s) { return utf_string_from_utf_string(dst, dst_max_size, (wchar_cast*)s); } +inline size_t utf_string_from_utf_string(wchar_t* dst, size_t dst_max_size, const wchar_t *s) { return utf_string_from_utf_string(dst, dst_max_size, (wchar_cast*)s); } + + + + +inline size_t utf_string_from_utf_string_len(char* dst, size_t dst_max_size, const char* s, size_t len) { return utf8_string_from_utf8_string_len(dst, dst_max_size, s, len); } +inline size_t utf_string_from_utf_string_len(char16_t* dst, size_t dst_max_size, const char* s, size_t len) { return utf16_string_from_utf8_string_len(dst, dst_max_size, s, len); } +inline size_t utf_string_from_utf_string_len(char32_t* dst, size_t dst_max_size, const char* s, size_t len) { return utf32_string_from_utf8_string_len(dst, dst_max_size, s, len); } +inline size_t utf_string_from_utf_string_len(wchar_t* dst, size_t dst_max_size, const char* s, size_t len) { return utf_string_from_utf_string_len((wchar_cast*)dst, dst_max_size, s, len); } + +inline size_t utf_string_from_utf_string_len(char* dst, size_t dst_max_size, const char16_t * s, size_t len) { return utf8_string_from_utf16_string_len(dst, dst_max_size, s, len); } +inline size_t utf_string_from_utf_string_len(char16_t* dst, size_t dst_max_size, const char16_t * s, size_t len) { return utf16_string_from_utf16_string_len(dst, dst_max_size, s, len); } +inline size_t utf_string_from_utf_string_len(char32_t* dst, size_t dst_max_size, const char16_t * s, size_t len) { return utf32_string_from_utf16_string_len(dst, dst_max_size, s, len); } +inline size_t utf_string_from_utf_string_len(wchar_t* dst, size_t dst_max_size, const char16_t * s, size_t len) { return utf_string_from_utf_string_len((wchar_cast*)dst, dst_max_size, s, len); } + +inline size_t utf_string_from_utf_string_len(char* dst, size_t dst_max_size, const char32_t * s, size_t len) { return utf8_string_from_utf32_string_len(dst, dst_max_size, s, len); } +inline size_t utf_string_from_utf_string_len(char16_t* dst, size_t dst_max_size, const char32_t * s, size_t len) { return utf16_string_from_utf32_string_len(dst, dst_max_size, s, len); } +inline size_t utf_string_from_utf_string_len(char32_t* dst, size_t dst_max_size, const char32_t * s, size_t len) { return utf32_string_from_utf32_string_len(dst, dst_max_size, s, len); } +inline size_t utf_string_from_utf_string_len(wchar_t* dst, size_t dst_max_size, const char32_t * s, size_t len) { return utf_string_from_utf_string_len((wchar_cast*)dst, dst_max_size, s, len); } + +inline size_t utf_string_from_utf_string_len(char* dst, size_t dst_max_size, const wchar_t * s, size_t len) { return utf_string_from_utf_string_len(dst, dst_max_size, (wchar_cast*)s, len); } +inline size_t utf_string_from_utf_string_len(char16_t* dst, size_t dst_max_size, const wchar_t * s, size_t len) { return utf_string_from_utf_string_len(dst, dst_max_size, (wchar_cast*)s, len); } +inline size_t utf_string_from_utf_string_len(char32_t* dst, size_t dst_max_size, const wchar_t * s, size_t len) { return utf_string_from_utf_string_len(dst, dst_max_size, (wchar_cast*)s, len); } +inline size_t utf_string_from_utf_string_len(wchar_t* dst, size_t dst_max_size, const wchar_t * s, size_t len) { return utf_string_from_utf_string_len(dst, dst_max_size, (wchar_cast*)s, len); } -inline size_t utf_string_from_utf_string(char* dst, size_t dst_max_len, const char32_t *s) { return utf8_string_from_utf32_string(dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(char16_t* dst, size_t dst_max_len, const char32_t *s) { return utf16_string_from_utf32_string(dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(char32_t* dst, size_t dst_max_len, const char32_t *s) { return utf32_string_from_utf32_string(dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(wchar_t* dst, size_t dst_max_len, const char32_t *s) { return utf_string_from_utf_string((wchar_cast*)dst, dst_max_len, s); } -inline size_t utf_string_from_utf_string(char* dst, size_t dst_max_len, const wchar_t *s) { return utf_string_from_utf_string(dst, dst_max_len, (wchar_cast*)s); } -inline size_t utf_string_from_utf_string(char16_t* dst, size_t dst_max_len, const wchar_t *s) { return utf_string_from_utf_string(dst, dst_max_len, (wchar_cast*)s); } -inline size_t utf_string_from_utf_string(char32_t* dst, size_t dst_max_len, const wchar_t *s) { return utf_string_from_utf_string(dst, dst_max_len, (wchar_cast*)s); } -inline size_t utf_string_from_utf_string(wchar_t* dst, size_t dst_max_len, const wchar_t *s) { return utf_string_from_utf_string(dst, dst_max_len, (wchar_cast*)s); } #endif // __cplusplus diff --git a/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp b/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp index 5231b747d..e2bee8f6b 100755 --- a/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp @@ -1,7 +1,6 @@ #include #include "../cpp_foundation/XString.h" #include "../cpp_foundation/XStringArray.h" -#include "../cpp_foundation/XStringW.h" #include "global_test.h" @@ -40,7 +39,7 @@ CHAR16 *Old1_RemoveLoadOption(IN CONST CHAR16 *LoadOptions, IN CONST CHAR16 *Loa if (Placement == NULL) return EfiStrDuplicate(LoadOptions); // Get placement of option in original options - Offset = (Placement - LoadOptions); + Offset = UINTN(Placement - LoadOptions); Length = StrLen(LoadOptions); OptionLength = StrLen(LoadOption); diff --git a/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp b/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp index d153f6f61..307117a63 100644 --- a/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp @@ -1,6 +1,5 @@ #include #include "../cpp_foundation/XStringWArray.h" -#include "../cpp_foundation/XStringW.h" int XStringWArray_tests() { diff --git a/rEFIt_UEFI/cpp_unit_test/XStringW_test.cpp b/rEFIt_UEFI/cpp_unit_test/XStringW_test.cpp deleted file mode 100755 index 7fb0f3bdf..000000000 --- a/rEFIt_UEFI/cpp_unit_test/XStringW_test.cpp +++ /dev/null @@ -1,191 +0,0 @@ -#include -#include "../cpp_foundation/XStringW.h" -#include "../cpp_foundation/unicode_conversions.h" -#include "global_test.h" - - -//#include - - -int XStringW_tests() -{ - -#ifdef JIEF_DEBUG - - XStringW a = L"toto"_XSW; - -// DebugLog(2, "XStringW_tests -> Enter\n"); -#endif - - if ( global_str3 != L"global_str3"_XSW ) return 1; - if ( global_str4 != L"global_str4"_XSW ) return 2; - - // Check default ctor - { - XStringW str; - if (str.size() != 0) return 3; - if (str.wc_str() == NULL) return 4; - } - - - // Check ctor with value (or check takeValueFrom while we are waiting to put back ctor(const char*) -#ifdef XSTRINGW_HAS_CTOR_LITTERAL - { - { - XStringW str(""); - if ( str != "" ) return 100; - } - { - XStringW str("1"); - if ( str != "1" ) return 101; - } - } -#else - { - XStringW str; - str.takeValueFrom(""); - if (str.size() != 0) return 110; - str.takeValueFrom("1"); - if ( str != L"1"_XSW ) return 111; - str.StrCat(L"2"); - if ( str != L"12"_XSW ) return 112; - } -#endif - -// // check [] operator -// { -// XStringW str; -// str.takeValueFrom("01234567890123456789"); -// wchar_t c; -// c = str[(char)1]; -// if ( c != '1' ) return 201; -// c = str[(unsigned char)2]; -// if ( c != '2' ) return 202; -// c = str[(short)3]; -// if ( c != '3' ) return 203; -// c = str[(unsigned short)4]; -// if ( c != '4' ) return 204; -// c = str[(int)5]; -// if ( c != '5' ) return 205; -// c = str[(unsigned int)6]; -// if ( c != '6' ) return 206; -// c = str[(long)7]; -// if ( c != '7' ) return 207; -// c = str[(unsigned long)8]; -// if ( c != '8' ) return 208; -// c = str[(long long)9]; -// if ( c != '9' ) return 209; -// c = str[(unsigned long long)10]; -// if ( c != '0' ) return 210; -// } - - // Quick check of StrnCpy,StrnCat,Insert,+= - { - XStringW str; - str.takeValueFrom(L"12"); - XStringW str2; - if ( !str2.isEmpty() ) return 10; - str2.StrnCpy(str.data(), 2); - if ( str2 != L"12"_XSW ) return 11; - str2.StrnCat(L"345", 2); - if ( str2 != L"1234"_XSW ) return 12; - str2.Insert(1, str); - if ( str2 != L"112234"_XSW ) return 13; - str2 += L"6"; - if ( str2 != L"1122346"_XSW ) return 14; - } - -//wchar_t c2 = L'Ň'; -//printf("1=%lc\n", c2); -//const char* s1 = "𐌾"; - XStringW str2; - str2.SWPrintf("%c", 'a'); // signle UTF8 ascii char - if ( str2 != L"a"_XSW ) return 20; - str2.takeValueFrom(L"ab"); // UTF16(32) string containing ascii char - if ( str2 != L"ab"_XSW ) return 21; -#ifdef _MSC_VER - // IMPORTANT : you can't pass a litteral char in a vararg function with Visual Studio (Microsoft strikes again :-). - // At least, you got a warning C4066 - // IMPORTANT2 : Litteral string containing UTF16 char are WRONG. And you don't get a warning !!! If litteral is only ascii, it's ok. - // Maybe it's compilation option but I didn't find them. - wchar_t c = 'Ň'; // using an imtermediary var for Microsoft. - - - wchar_t s[2]; // wchar_t s2[] = L"Ň"; - s[0] = 'Ň'; - s[1] = 0; - - str2.SWPrintf("%lc", c); // UTF16(32) char. (2 bytes in total if UTF16) - if (str2 != s) return 22; - str2.takeValueFrom(""); - if (str2.size() != 0) return 221; - str2.takeValueFrom(s); // this is a UTF8 string 2 bytes long - if (str2 != s) return 23; -#else - str2.SWPrintf("%lc", L'Ň'); // signe UTF16(32) char. (2 bytes in total if UTF16) - if ( str2 != L"Ň"_XSW ) return 22; - str2.takeValueFrom(""); - if (str2.size() != 0) return 221; -#ifdef XSTRINGW_HAS_CTOR_LITTERAL - str2.takeValueFrom("Ň"); // this is a UTF8 string 2 bytes long - if (str2 != "Ň") return 23; // utf8 litteral are converted to an XStringW if ctor is available. -#endif - str2.takeValueFrom(""); - if (str2.size() != 0) return 231; -#ifdef XSTRINGW_HAS_CTOR_LITTERAL - str2.takeValueFrom(L"Ň"); // this is a UTF8 string 2 bytes long - if (str2 != "Ň") return 24; -#endif -#endif - -#if __WCHAR_MAX__ > 0xFFFFu - str2.SWPrintf("%lc", L'𐌾'); // L'𐌾' // this char cannot convert to an UTF16 char. So it doesn't compile with -fshort-wchar - if ( str2 != L"𐌾" ) return 30; -#endif - - -#ifndef _MSC_VER - // "𐌾" in UTF16 is 2 char : 0xd800, 0xdf3e - - str2.takeValueFrom(L"𐌾"); // this is a UTF8 string 4 bytes long - if ( str2 != L"𐌾"_XSW ) return 31; - str2.takeValueFrom(L"𐌾"); // this is a UTF16 or UTF32 string (depending of -fshort-wchar) - if ( str2 != L"𐌾"_XSW ) return 32; - -#ifdef XSTRINGW_HAS_CTOR_LITTERAL - { - XStringW str3("a"); - if ( str3 != L"a" ) return 40; - XStringW str4("aŇ𐌾"); - if ( str4 != L"aŇ𐌾" ) return 41; - } -#endif -#endif - - { - XStringW utf16; - utf16.takeValueFrom(L"Выход из подменю, обновление главного меню"); - for ( size_t i = 0 ; i < utf16.size() ; i++ ) { - if ( utf16.wc_str()[i] != utf16.wc_str()[i] ) { - return 100; - } - } - XStringW utf16_2; - utf16_2.takeValueFrom("Выход из подменю, обновление главного меню"); - if ( utf16 != utf16_2 ) { - return 101; - } - } - - -#ifndef _MSC_VER - wchar_t* s = XStringW().takeValueFrom("aa").forgetDataWithoutFreeing(); - if ( memcmp(s, L"aa", sizeof(L"aa")*sizeof(wchar_t) ) == 0 ) return 102; // sizeof(L"aa") include null terminator -#endif -// XStringW CommonName(L"EFI\\CLOVER\\misc\\screenshot"); -// for (UINTN Index = 0; Index < 20; Index++) { -// XStringW Name = CommonName + SPrintf("%lld", Index) + L".png"; -// DebugLog(2, "XStringW_test shot: %s\n", Name.data()); -// } - return 0; -} diff --git a/rEFIt_UEFI/cpp_unit_test/XStringW_test.h b/rEFIt_UEFI/cpp_unit_test/XStringW_test.h deleted file mode 100644 index a51cd767f..000000000 --- a/rEFIt_UEFI/cpp_unit_test/XStringW_test.h +++ /dev/null @@ -1 +0,0 @@ -int XStringW_tests(); diff --git a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp index 805b380c0..32e366f58 100755 --- a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp @@ -1,192 +1,1362 @@ #include #include "../cpp_foundation/XString.h" #include "../cpp_foundation/unicode_conversions.h" -#include "global_test.h" -template -class Xtest + + +int nbTest = 0; +int nbTestFailed = 0; +bool displayOnlyFailed = true; + + +#define STRINGIFY_(s) #s +#define STRINGIFY(s) STRINGIFY_(s) + +#define CONCATENATE(e1, e2) e1 ## e2 +#define PREFIX_L(s) CONCATENATE(L, s) +#define PREFIX_u(s) CONCATENATE(u, s) +#define PREFIX_U(s) CONCATENATE(U, s) + + + +template +struct make_unsigned { - char m_data[m_size]; - public: - int size() { return m_size; } }; -int XString_tests() -{ -// Commented during refactoring because of disabling operator == with litteral (to be able to catch test like : XString == NULL -// -// XString a = "toto"_XS; -// -//// Xtest<5> b; -//// int bs = b.size(); -// -//#ifdef JIEF_DEBUG -//#endif -// -//#ifdef JIEF_DEBUG -//// DebugLog(2, "XStringW_tests -> Enter\n"); -//#endif -// -// if ( global_str1 != "global_str1" ) return 1; -// if ( global_str2 != "global_str2" ) return 2; -// -// // Check default ctor -// { -// XString str; -// if (str.length() != 0) return 3; -// if (str.c_str() == NULL) return 4; -// } -// -// // Check ctor with value (or check takeValueFrom while we are waiting to put back ctor(const char*) -//#ifdef XSTRINGW_HAS_CTOR_LITTERAL -// { -// { -// XString str(""); -// if ( str != "" ) return 100; -// } -// { -// XString str("1"); -// if ( str != "1" ) return 101; -// } -// } -//#else -// { -// XString str; -// str.takeValueFrom(""); -// if (str.length() != 0) return 110; -// str.takeValueFrom("1"); -// if ( str != "1" ) return 111; -// str.StrCat("2"); -// if ( str != "12" ) return 112; -// } -//#endif -// -// // Move assignment. -// { -// XString str1; -// str1.takeValueFrom("str1"); -// XString str2(str1 + "b"); -// str2 += "a"; // this is more efficient than str2 = str2 + "a", of course -// if ( str2 != "str1ba" ) return 120; -// str2 = str2 + "a"; -// if ( str2 != "str1baa" ) return 121; -// str2 = str1 + "a"; // this must call the move assignment operator -// if ( str2 != "str1a" ) return 122; -// } -// -// // check [] operator -// { -// XString str; -// str.takeValueFrom("01234567890123456789"); -// char c; -// c = str[(char)1]; -// if ( c != '1' ) return 201; -// c = str[(unsigned char)2]; -// if ( c != '2' ) return 202; -// c = str[(short)3]; -// if ( c != '3' ) return 203; -// c = str[(unsigned short)4]; -// if ( c != '4' ) return 204; -// c = str[(int)5]; -// if ( c != '5' ) return 205; -// c = str[(unsigned int)6]; -// if ( c != '6' ) return 206; -// c = str[(long)7]; -// if ( c != '7' ) return 207; -// c = str[(unsigned long)8]; -// if ( c != '8' ) return 208; -// c = str[(long long)9]; -// if ( c != '9' ) return 209; -// c = str[(unsigned long long)10]; -// if ( c != '0' ) return 210; -// } -// -// // Check StrCat. TODO more test, and test StrnCat -// { -// XString str; -// str.takeValueFrom("1"); -// str.StrCat("2"); -// if ( str != "12" ) return 50; -// } -// -// // check takeValueFrom from utf8 string -// XString str; -// str.takeValueFrom("Ň"); // this is a UTF8 string 2 bytes long -// if (str != "Ň") return 80; // utf8 litteral are converted to an XStringW if ctor is available. -// str.takeValueFrom("𐌾"); // this is a UTF8 string 4 bytes long -// if ( str != "𐌾" ) return 81; -// str.takeValueFrom("𐌾"); // this is a UTF16 or UTF32 string (depending of -fshort-wchar) -// if ( str != "𐌾" ) return 82; -// -// // check takeValueFrom from UTF16 or 32 string -// str.takeValueFrom(L"Ň"); // this is a UTF8 string 2 bytes long -// if (str != "Ň") return 83; // utf8 litteral are converted to an XStringW if ctor is available. -// str.takeValueFrom(L"𐌾"); // this is a UTF8 string 4 bytes long -// if ( str != "𐌾" ) return 84; -// str.takeValueFrom(L"𐌾"); // this is a UTF16 or UTF32 string (depending of -fshort-wchar) -// if ( str != "𐌾" ) return 85; -// -// // Quick check of StrnCpy,StrnCat,Insert,+= -// str.takeValueFrom("12"); -// XString str2; -// if ( !str2.isEmpty() ) return 100; -// str2.StrnCpy(str.data(), 2); -// if ( str2 != "12" ) return 101; -// str2.StrnCat("345", 2); -// if ( str2 != "1234" ) return 102; -// str2.Insert(1, str); -// if ( str2 != "112234" ) return 103; -// str2 += "6"; -// if ( str2 != "1122346" ) return 104; -// // Check Insert at beginning and end -// str2.takeValueFrom("123"); -// str2.Insert(0, XString().takeValueFrom("x")); -// if ( str2 != "x123" ) return 105; -// str2.Insert(4, XString().takeValueFrom("y")); -// if ( str2 != "x123y" ) return 106; -// -////wchar_t c2 = L'Ň'; -////printf("1=%lc\n", c2); -////const char* s1 = "𐌾"; -// // Check SPrintf -// str2.SPrintf("%c", 'a'); // single UTF8 ascii char -// if ( str2 != "a" ) return 200; -// #ifndef _MSC_VER -// str2.SPrintf("%lc", L'Ň'); // single UTF16(32) char. (2 bytes in total if UTF16) -// if ( str2 != "Ň" ) return 202; -// #endif -// str2.SPrintf("%s", "Ň"); // this is a UTF8 string 2 bytes long -// if (str2 != "Ň") return 203; // utf8 litteral are converted to an XStringW if ctor is available. -// str2.SPrintf("%ls", L"Ň"); // this is a UTF8 string 2 bytes long -// if (str2 != "Ň") return 204; // utf8 litteral are converted to an XStringW if ctor is available. -//#if __WCHAR_MAX__ > 0xFFFFu -// str2.SPrintf("%lc", L'𐌾'); // L'𐌾' // this char cannot convert to an UTF16 char. So it doesn't compile with -fshort-wchar -// if ( str2 != "𐌾" ) return 205; -//#endif -// -///* Stil doesn't work as VS doesn't encode correctly litteral */ -//#ifndef _MSC_VER -// -//// int i1 = sizeof(wchar_t); -//// int i2 = sizeof(char16_t); -//// const wchar_t* ls = L"Выход"; -//// const char16_t* us = u"Выход"; -//// const char32_t* Us = U"Выход"; -// XString str3; -// str3.takeValueFrom(L"Выход"); -// if ( str3 != "Выход" ) return 500; -//#endif -////MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", L"ascii char in ucs-2 string\n"); -////MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", "ascii char in ucs-2 string\n"); -////MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", "ascii char in ucs-2 string\n"); -//// -////MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", L"Выход из подменю, обновление главного меню\n"); -////MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", "Выход из подменю, обновление главного меню\n"); -////MsgLog("Test MsgLog ascii=%ls ucs-2=%ls\n", "a string", "Выход из подменю, обновление главного меню\n"); -//// -////DBG("Test ascii=%ls ucs-2=%ls\n", "a string", L"Выход из подменю, обновление главного меню\n"); -////DBG("Test ascii=%ls ucs-2=%ls\n", "a string", "Выход из подменю, обновление главного меню\n"); -////DBG("Test ascii=%ls ucs-2=%ls\n", "a string", "Выход из подменю, обновление главного меню\n"); +//template <> struct __make_unsigned {}; +template <> struct make_unsigned< signed char> {typedef unsigned short type;}; +template <> struct make_unsigned {typedef unsigned short type;}; +template <> struct make_unsigned< signed short> {typedef unsigned short type;}; +template <> struct make_unsigned {typedef unsigned short type;}; +template <> struct make_unsigned< signed int> {typedef unsigned int type;}; +template <> struct make_unsigned {typedef unsigned int type;}; +template <> struct make_unsigned< signed long> {typedef unsigned long type;}; +template <> struct make_unsigned {typedef unsigned long type;}; +template <> struct make_unsigned< signed long long> {typedef unsigned long long type;}; +template <> struct make_unsigned {typedef unsigned long long type;}; + + +/* + * Set a breakpoint here to catch failed test under debugger + */ +void breakpoint() +{ + int a; + (void)a; +} + +class SimpleString +{ + char* data; + size_t allocatedSize; +public: + SimpleString() : data(NULL) {} + SimpleString(const SimpleString& simpleString) { + allocatedSize = strlen(simpleString.data)+1; + data = (char*)malloc(allocatedSize); + strcpy(data, simpleString.data); + } + SimpleString(const char* s) { + allocatedSize = strlen(s)+1; + data = (char*)malloc(allocatedSize); + strcpy(data, s); + } + SimpleString(const char16_t* s) { + #if defined(__GNUC__) && !defined(__clang__) + data = 0; // silence warning + #endif + allocatedSize = utf_size_of_utf_string(data, s)+1; + data = (char*)malloc(allocatedSize); + utf_string_from_utf_string(data, allocatedSize, s); + } + SimpleString(const char32_t* s) { + #if defined(__GNUC__) && !defined(__clang__) + data = 0; // silence warning + #endif + allocatedSize = utf_size_of_utf_string(data, s)+1; + data = (char*)malloc(allocatedSize); + utf_string_from_utf_string(data, allocatedSize, s); + } + SimpleString(const wchar_t* s) { + #if defined(__GNUC__) && !defined(__clang__) + data = 0; // silence warning + #endif + allocatedSize = utf_size_of_utf_string(data, s)+1; + data = (char*)malloc(allocatedSize); + utf_string_from_utf_string(data, allocatedSize, s); + } + SimpleString& operator =(const SimpleString& simpleString) + { + size_t newSize = strlen(simpleString.data)+1; + data = (char*)realloc(data, newSize+1, allocatedSize); + allocatedSize = newSize+1; + strncpy(data, simpleString.data, allocatedSize); + return *this; + } + + const char* c_str() const { return data; } + + SimpleString& svprintf(const char* format, va_list va) + { + VA_LIST va2; + VA_COPY(va2, va); + size_t size = (size_t)vsnprintf(NULL, 0, format, va); + data = (char*)realloc(data, size+1, allocatedSize); + allocatedSize = size+1; + data[size] = 0; + vsnprintf(data, allocatedSize, format, va2); + VA_END(va); + return *this; + } + + ~SimpleString() { delete data; } +}; + +SimpleString sprintf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2))); +SimpleString sprintf(const char* format, ...) +{ + SimpleString ss; + va_list va; + va_start(va, format); + ss.svprintf(format, va); + va_end(va); + return ss; +} + + + +// "" +// Don't put any "" in test strings or it will break indexOf and rindexOf tests. +#define utf8_1 "Āࠀ𐀀🧊Выход'UTF16'из" +#define utf8_2 "൧൨൩൪൫൬൭൮" +#define utf8_3 "éàùœ°æƒÌÚ®" +#define utf8_4 "ﰨﰩﰪﰫﰬﰭﰮﰯﰰﰱﰲﰳ" +#define utf8_5 "ォオカガキギクグケゲ" +#define utf8_6 "ꇆꇇꇈꇉꇊꇋꇌꇍ" +#define utf8_7 "伻似伽伾伿佀佁佂佃佄" +#define utf8_8 "楔楕楖楗楘楙楚楛楜楝楞楟楠楡" + +//#define utf8_9 "abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįijĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷÿźżžɓƃƅɔƈɖɗƌǝəɛƒɠɣɩɨƙɯɲɵơƣƥƨʃƭʈưʊʋƴƶʒƹƽdždžljljnjnjǎǐǒǔǖǘ" +//#define utf8_10 "ἯἸἹἺἻἼἽἾἿὈὉὊὋὌὍὙὛὝὟὨὩὪὫὬὭὮὯάέήίόύώᾈᾉᾊᾋᾌᾍᾎᾏᾘᾙᾚᾛᾜᾝᾞᾟᾨᾩᾪᾫᾬᾭᾮᾯᾸᾹᾺΆᾼιῈΈῊΉῌΐῘῙῚΊΰῨῩῪΎῬ΅`ῸΌῺΏῼ´  ΩKÅℲⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮⱠⱢⱣⱤⱧⱩⱫⱭⱮⱯⱰⱲⱵⱾⱿⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢⳫⳭⳲ〈〉Ꙁ" +//#define utf8_11 "煉璉秊練聯輦蓮連鍊列劣咽烈裂說廉念捻殮簾獵令囹寧嶺怜玲瑩羚聆鈴零靈領例禮醴隸惡了僚寮尿料樂燎療蓼遼龍暈阮劉杻柳流溜琉留硫紐類六戮陸倫崙淪輪律慄栗率隆利吏履易李梨泥理痢罹裏裡里離匿溺吝燐璘藺隣鱗麟林淋臨立笠粒狀炙識什茶刺切度拓糖宅洞暴輻行降見廓兀嗀塚晴凞猪益礼神祥福靖精羽蘒諸逸都飯飼館鶴郞隷侮僧免勉勤卑喝嘆器塀墨層屮悔慨憎懲敏既暑梅海渚漢煮爫琢碑社祉祈祐祖祝禍禎穀突節練縉繁署者臭艹艹著褐視謁謹賓贈辶逸難響頻恵舘並况全侀充冀勇勺喝啕喙嗢塚墳奄奔婢嬨廒廙彩徭惘慎愈憎慠懲戴揄搜摒敖晴朗望杖歹殺流滛滋漢瀞煮瞧爵犯猪" + + + + +struct AbstractTestString +{ + size_t size; // size in nb of char (or char16_t, char32_t or wchar_t) not bytes, not including null termiator + size_t utf32_length; // length in nb of UTF32 char, not including null termiator + //size_t utf32_size; // size == length for UTF32 + const char32_t* utf32; + AbstractTestString(size_t _size, size_t _utf32_length, const char32_t* _utf32) + : size(_size), utf32_length(_utf32_length), utf32(_utf32) { + } +}; + +template +struct TestString : public AbstractTestString +{ + const CharType* cha; + TestString(size_t _size, const CharType* _cha, size_t _utf32_length, const char32_t* _utf32) : AbstractTestString(_size, _utf32_length, _utf32), cha(_cha) { + } +}; + + +struct TestStringMultiCoded +{ + TestString utf8; + TestString utf16; + TestString utf32; + TestString wchar; + +// template +// TestStringRet& getTestString4Encoding(const char* enc) { +// if ( strcmp(enc, "utf8") == 0 ) return utf8; +// if ( strcmp(enc, "utf16") == 0 ) return utf16; +// if ( strcmp(enc, "utf32") == 0 ) return utf32; +// if ( strcmp(enc, "wchar") == 0 ) return wchar; +// panic(); +// } +}; + + +#define nbchar(s) (sizeof(s)/sizeof(*s)-1) + +#define testStringArray_LINE(utf) { \ + TestString(nbchar(utf), utf, nbchar(PREFIX_U(utf)), PREFIX_U(utf)), \ + TestString(nbchar(PREFIX_u(utf)), PREFIX_u(utf), nbchar(PREFIX_U(utf)), PREFIX_U(utf)), \ + TestString(nbchar(PREFIX_U(utf)), PREFIX_U(utf), nbchar(PREFIX_U(utf)), PREFIX_U(utf)), \ + TestString(nbchar(PREFIX_L(utf)), PREFIX_L(utf), nbchar(PREFIX_U(utf)), PREFIX_U(utf)), \ +} + +//TestString foo("", "utf8", 1, "a", 1, U"a"); + +const TestStringMultiCoded testStringMultiCodedArray[] = { + testStringArray_LINE(""), + testStringArray_LINE("a"), + testStringArray_LINE(utf8_1), + testStringArray_LINE(utf8_2), + testStringArray_LINE(utf8_3), + testStringArray_LINE(utf8_4), + testStringArray_LINE(utf8_5), + testStringArray_LINE(utf8_6), + testStringArray_LINE(utf8_7), + testStringArray_LINE(utf8_8), +// testStringArray_LINE(utf8_9), +// testStringArray_LINE(utf8_10), +// testStringArray_LINE(utf8_11), +}; + +size_t nbTestStringMultiCoded = *(&testStringMultiCodedArray + 1) - testStringMultiCodedArray; + +const TestStringMultiCoded testStringMultiCoded4CaseArray[] = { + testStringArray_LINE("ABCDEF"), + testStringArray_LINE("abcdeFGHIjklmn"), +}; + +size_t nbTestStringMultiCoded4CaseArray = *(&testStringMultiCoded4CaseArray + 1) - testStringMultiCoded4CaseArray; + + + + +template +struct XStringClassInfo +{ + typedef XStringType xs_t; + static const char* xStringClassName; +}; + +template<> +struct XStringClassInfo +{ + typedef char ch_t; + typedef XString xs_t; + static constexpr const char* prefix = ""; + static constexpr const char* xStringClassName = "XString"; +}; + +template<> +struct XStringClassInfo +{ + typedef char16_t ch_t; + typedef XString16 xs_t; + static constexpr const char* prefix = "u"; + static constexpr const char* xStringClassName = "XString16"; +}; + +template<> +struct XStringClassInfo +{ + typedef char32_t ch_t; + typedef XString32 xs_t; + static constexpr const char* prefix = "U"; + static constexpr const char* xStringClassName = "XString32"; +}; + +template<> +struct XStringClassInfo +{ + typedef wchar_t ch_t; + typedef XStringW xs_t; + static constexpr const char* prefix = "L"; + static constexpr const char* xStringClassName = "XStringW"; +}; + +template<> +struct XStringClassInfo +{ + typedef char ch_t; + typedef XString xs_t; + static constexpr const char* prefix = ""; + static constexpr const char* xStringClassName = "XString"; +}; + +template<> +struct XStringClassInfo +{ + typedef char16_t ch_t; + typedef XString16 xs_t; + static constexpr const char* prefix = "u"; + static constexpr const char* xStringClassName = "XString16"; +}; + +template<> +struct XStringClassInfo +{ + typedef char32_t ch_t; + typedef XString32 xs_t; + static constexpr const char* prefix = "U"; + static constexpr const char* xStringClassName = "XString32"; +}; + +template<> +struct XStringClassInfo +{ + typedef wchar_t ch_t; + typedef XStringW xs_t; + static constexpr const char* prefix = "L"; + static constexpr const char* xStringClassName = "XStringW"; +}; + +template<> +struct XStringClassInfo> +{ + typedef char ch_t; + typedef XString xs_t; + static constexpr const char* prefix = ""; + static constexpr const char* xStringClassName = "XString"; +}; + +template<> +struct XStringClassInfo> +{ + typedef char16_t ch_t; + typedef XString16 xs_t; + static constexpr const char* prefix = "u"; + static constexpr const char* xStringClassName = "XString16"; +}; + +template<> +struct XStringClassInfo> +{ + typedef char32_t ch_t; + typedef XString32 xs_t; + static constexpr const char* prefix = "U"; + static constexpr const char* xStringClassName = "XString32"; +}; + +template<> +struct XStringClassInfo> +{ + typedef wchar_t ch_t; + typedef XStringW xs_t; + static constexpr const char* prefix = "L"; + static constexpr const char* xStringClassName = "XStringW"; +}; + + + + + + +SimpleString title_tmp; +bool title_tmp_needs_reprinted; +bool displayOnlyIfFailed_tmp; + +#define TEST_TITLE(__displayOnlyIfFailed__, title) \ + do { \ + displayOnlyIfFailed_tmp = __displayOnlyIfFailed__; \ + title_tmp = title; \ + title_tmp_needs_reprinted = true; \ + if ( !displayOnlyIfFailed_tmp ) { \ + printf("%s", title_tmp.c_str()); \ + title_tmp_needs_reprinted = false; \ + } \ + }while(0); + + +#define CHECK_RESULT(condition, okmessage, failedmessage) \ + do { \ + if ( !(condition) ) { \ + if ( title_tmp_needs_reprinted ) { \ + printf("%s", title_tmp.c_str()); \ + } \ + printf(" : -> "); \ + printf("%s", failedmessage.c_str()); \ + printf("\n"); \ + title_tmp_needs_reprinted = true; \ + nbTestFailed += 1; \ + }else if ( !displayOnlyIfFailed_tmp ) { \ + if ( title_tmp_needs_reprinted ) { \ + printf("%s", title_tmp.c_str()); \ + } \ + title_tmp_needs_reprinted = true; \ + printf(" -> OK : %s\n", okmessage.c_str()); \ + } \ + nbTest += 1; \ + if ( !(condition) ) breakpoint(); \ + }while(0); + + + + + +#define __TEST0(test, XStringClass, classEncoding) \ + test(XStringClass, classEncoding); \ + +#define __TEST1(test, XStringClass, classEncoding, encoding1) \ + test(XStringClass, classEncoding, encoding1); \ + +#define __TEST2(test, XStringClass, classEncoding, encoding1, encoding2) \ + test(XStringClass, classEncoding, encoding1, encoding2); \ + + +#define __TEST_ALL_UTF2(test, XStringClass, classEncoding, encoding1) \ + __TEST2(test, XStringClass, classEncoding, encoding1, utf8); \ + __TEST2(test, XStringClass, classEncoding, encoding1, utf16); \ + __TEST2(test, XStringClass, classEncoding, encoding1, utf32); \ + __TEST2(test, XStringClass, classEncoding, encoding1, wchar); \ + + +#define TEST_ALL_INTEGRAL(test, XStringClass, classEncoding) \ + __TEST1(test, XStringClass, classEncoding, signed char); \ + __TEST1(test, XStringClass, classEncoding, unsigned char); \ + __TEST1(test, XStringClass, classEncoding, signed short); \ + __TEST1(test, XStringClass, classEncoding, unsigned short); \ + + +#define TEST_ALL_UTF(test, XStringClass, classEncoding) \ + __TEST1(test, XStringClass, classEncoding, utf8); \ + __TEST1(test, XStringClass, classEncoding, utf16); \ + __TEST1(test, XStringClass, classEncoding, utf32); \ + __TEST1(test, XStringClass, classEncoding, wchar); \ + +#define TEST_ALL_UTF_ALL_UTF(test, XStringClass, classEncoding) \ + __TEST_ALL_UTF2(test, XStringClass, classEncoding, utf8); \ + __TEST_ALL_UTF2(test, XStringClass, classEncoding, utf16); \ + __TEST_ALL_UTF2(test, XStringClass, classEncoding, utf32); \ + __TEST_ALL_UTF2(test, XStringClass, classEncoding, wchar); \ + +#define TEST_ALL_CLASSES(test, macro) \ + macro(test, XString, utf8); \ + macro(test, XString16, utf16); \ + macro(test, XString32, utf32); \ + macro(test, XStringW, wchar); \ + + + +/***************************** Default ctor *****************************/ +template +SimpleString testDefaultCtor_() +{ + XStringClass xstr; + TEST_TITLE(displayOnlyFailed, sprintf("Test default ctor of %s", XStringClassInfo::xStringClassName)); + + CHECK_RESULT(xstr.length() == 0, + sprintf("xstr.length() == 0"), + sprintf("xstr.length() != 0") + ); + CHECK_RESULT(xstr.sizeInBytes() == 0, + sprintf("xstr.sizeInBytes() == 0"), + sprintf("xstr.sizeInBytes() != 0") + ); + CHECK_RESULT(*xstr.s() == 0, + sprintf("*xstr.s() == 0"), + sprintf("*xstr.s() != 0") + ); + return SimpleString(); +} + +#define testDefaultCtor(XStringClass, classEncoding) \ + printf("Test %s::testDefaultCtor\n", STRINGIFY(XStringClass)); \ + testDefaultCtor_(); + + +/***************************** takeValueFrom(char type) *****************************/ +template +SimpleString testTakeValueFrom_(const TestStringSrc& src, const TestStringExpectedResult& expectedResult) +{ + + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::testTakeValueFrom(%s\"%s\")", XStringClassInfo::xStringClassName, XStringClassInfo::prefix, SimpleString(src.cha).c_str())); + + XStringClass xstr; + xstr.takeValueFrom(src.cha); + + size_t expectedSize = expectedResult.size*sizeof(expectedResult.cha[0]); + CHECK_RESULT(xstr.sizeInBytes() == expectedSize, + sprintf("xstr.sizeInBytes() == expectedSize (%zu)", expectedSize), + sprintf("xstr.sizeInBytes() != expectedSize (%zu!=%zu)", xstr.sizeInBytes(), expectedSize) + ); + CHECK_RESULT(memcmp(xstr.s(), expectedResult.cha, expectedSize) == 0, + sprintf("memcmp(xstr.s(), expectedResult.cha, expectedSize) == 0"), + sprintf("memcmp(xstr.s(), expectedResult.cha, expectedSize) != 0") + ); + +// TODO test ctor with litteral +// XStringClass xstr2; +// xstr2 = src.cha; + + return SimpleString(); +} + +#define testTakeValueFrom(XStringClass, classEncoding, encoding1) \ + printf("Test %s::testTakeValueFrom(%s)\n", STRINGIFY(XStringClass), STRINGIFY(encoding1)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + testTakeValueFrom_(testStringMultiCodedArray[i].encoding1, testStringMultiCodedArray[i].classEncoding); \ + } \ + + +/***************************** takeValueFrom(XString), ctor(XString), operator =(XString) *****************************/ +template +SimpleString testTakeValueFromXString_(const TestStringSrc& src, const TestStringExpectedResult& expectedResult) +{ +// TODO test ctor with litteral + + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::testTakeValueFrom(%s\"%s\")", XStringClassInfo::xStringClassName, XStringClassInfo::prefix, SimpleString(src.cha).c_str())); + + typename XStringClassInfo::xs_t srcXString; + srcXString.takeValueFrom(src.cha); + + XStringClass xstr; + xstr.takeValueFrom(srcXString); + + size_t expectedSize = expectedResult.size*sizeof(expectedResult.cha[0]); + CHECK_RESULT(xstr.sizeInBytes() == expectedSize, + sprintf("xstr.sizeInBytes() == expectedSize (%zu)", expectedSize), + sprintf("xstr.sizeInBytes() != expectedSize (%zu!=%zu)", xstr.sizeInBytes(), expectedSize) + ); + CHECK_RESULT(memcmp(xstr.s(), expectedResult.cha, expectedSize+sizeof(expectedResult.cha[0])) == 0, + sprintf("memcmp(xstr.s(), expectedResult.cha, expectedResult.size) == 0"), + sprintf("memcmp(xstr.s(), expectedResult.cha, expectedResult.size) != 0") + ); + { + XStringClass xstr2(srcXString); + // We don't use operator == to check xstr == xstr2 because operator == is not tested yet. + CHECK_RESULT(xstr2.sizeInBytes() == xstr.sizeInBytes(), + sprintf("xstr2.sizeInBytes() == xstr.sizeInBytes() (%zu)", xstr.sizeInBytes()), + sprintf("xstr2.sizeInBytes() != xstr.sizeInBytes() (%zu!=%zu)", xstr2.sizeInBytes(), xstr.sizeInBytes()) + ); + CHECK_RESULT(memcmp(xstr2.s(), xstr.s(), xstr.sizeInBytes()+sizeof(xstr.s()[0])) == 0, + sprintf("memcmp(xstr2.s(), xstr.s(), xstr.sizeInBytes()) == 0"), + sprintf("memcmp(xstr2.s(), xstr.s(), xstr.sizeInBytes()) != 0") + ); + } + { + XStringClass xstr2; + xstr2 = srcXString; + // We don't use operator == to check xstr == xstr2 because operator == is not tested yet. + CHECK_RESULT(xstr2.sizeInBytes() == xstr.sizeInBytes(), + sprintf("xstr2.sizeInBytes() == xstr.sizeInBytes() (%zu)", xstr.sizeInBytes()), + sprintf("xstr2.sizeInBytes() != xstr.sizeInBytes() (%zu!=%zu)", xstr2.sizeInBytes(), xstr.sizeInBytes()) + ); + CHECK_RESULT(memcmp(xstr2.s(), xstr.s(), xstr.sizeInBytes()+sizeof(xstr.s()[0])) == 0, + sprintf("memcmp(xstr2.s(), xstr.s(), xstr.sizeInBytes()) == 0"), + sprintf("memcmp(xstr2.s(), xstr.s(), xstr.sizeInBytes()) != 0") + ); + } + return SimpleString(); +} + +#define testTakeValueFromXString(XStringClass, classEncoding, encoding1) \ + printf("Test %s::testTakeValueFromXString(%s)\n", STRINGIFY(XStringClass), STRINGIFY(encoding1)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + testTakeValueFromXString_(testStringMultiCodedArray[i].encoding1, testStringMultiCodedArray[i].classEncoding); \ + } \ + + + +/***************************** Default isEmpty, SetEmpty *****************************/ +template +SimpleString testEmpty_() +{ + TEST_TITLE(displayOnlyFailed, sprintf("Test isEmpty(),notEmpty(),setEmpty() of %s", XStringClassInfo::xStringClassName)); + + XStringClass str; + str.takeValueFrom("aa"); + + CHECK_RESULT(str.isEmpty() == false, + sprintf("str.isEmpty() == false"), + sprintf("str.isEmpty() != true") + ); + CHECK_RESULT(str.notEmpty() == true, + sprintf("str.notEmpty() == true"), + sprintf("str.notEmpty() != false") + ); + + str.setEmpty(); + + CHECK_RESULT(str.isEmpty() == true, + sprintf("str.isEmpty() == true"), + sprintf("str.isEmpty() != false") + ); + CHECK_RESULT(str.notEmpty() == false, + sprintf("str.notEmpty() == false"), + sprintf("str.notEmpty() != true") + ); + + return SimpleString(); +} + +#define testEmpty(XStringClass, classEncoding) \ + printf("Test %s::testEmpty\n", STRINGIFY(XStringClass)); \ + testEmpty_(); \ + + +/***************************** char32At_u *****************************/ +template +SimpleString testchar32At_u_(const InitialValue& initialValue) +{ + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::char32At_u()", XStringClassInfo::xStringClassName)); + + XStringClass xstr; + xstr.takeValueFrom(initialValue.cha); + for ( integralType i=0 ; (typename make_unsigned::type)i < xstr.length() ; i++ ) + { + CHECK_RESULT(xstr[i] == initialValue.utf32[i], + sprintf("xstr[i] == dst.cha[i] (%d)", initialValue.utf32[i]), + sprintf("xstr[i] != dst.cha[i] (%d!=%d)", xstr[i], initialValue.utf32[i]) + ); + } + return SimpleString(); +} + +#define testchar32At_u(XStringClass, classEncoding, integralType) \ + printf("Test %s::testchar32At_u\n", STRINGIFY(XStringClass)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + testchar32At_u_(testStringMultiCodedArray[i].classEncoding); \ + } + + + + +/***************************** strcpy *****************************/ +template +SimpleString teststrcpy_(const TestStringSameAsClass& encodedSameAsClass, const TestStringSrc& src) +{ + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::strcpy(%s\"%s\")", XStringClassInfo::xStringClassName, XStringClassInfo::prefix, SimpleString(src.cha).c_str())); + + XStringClass xstr; + xstr.takeValueFrom("foobar"); + xstr.strcpy(src.cha); + + size_t expectedSize = encodedSameAsClass.size*sizeof(encodedSameAsClass.cha[0]); + CHECK_RESULT(xstr.sizeInBytes() == expectedSize, + sprintf("xstr.sizeInBytes() == dst.size (%zu)", expectedSize), + sprintf("xstr.sizeInBytes() != dst.size (%zu!=%zu)", xstr.sizeInBytes(), expectedSize) + ); + CHECK_RESULT(memcmp(xstr.s(), encodedSameAsClass.cha, expectedSize+sizeof(encodedSameAsClass.cha[0])) == 0, + sprintf("memcmp(xstr.s(), dst.cha, dst.size) == 0"), + sprintf("memcmp(xstr.s(), dst.cha, dst.size) != 0") + ); + return SimpleString(); +} + +#define teststrcpy(XStringClass, classEncoding, encoding1) \ + printf("Test %s::teststrcpy(%s)\n", STRINGIFY(XStringClass), STRINGIFY(encoding1)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + teststrcpy_(testStringMultiCodedArray[i].classEncoding, testStringMultiCodedArray[i].encoding1); \ + } \ + + + +/***************************** strncpy *****************************/ +template +SimpleString teststrncpy_(const TestStringSameAsClass& encodedSameAsClass, const TestStringSrc& src) +{ + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::strncpy(%s\"%s\")", XStringClassInfo::xStringClassName, XStringClassInfo::prefix, SimpleString(src.cha).c_str())); + + for ( size_t i = 0 ; i < length_of_utf_string(src.cha)+5 ; i++ ) + { + XStringClass xstr; + xstr.takeValueFrom("foobar"); + xstr.strncpy(src.cha, i); + + CHECK_RESULT((length_of_utf_string(encodedSameAsClass.cha) >= i && xstr.length() == i) || (xstr.length() == length_of_utf_string(encodedSameAsClass.cha)), + sprintf("xstr.sizeInBytes() == dst.size (%zu)", xstr.sizeInBytes()), + sprintf("xstr.sizeInBytes() != dst.size (%zu!=%zu)", xstr.sizeInBytes(), encodedSameAsClass.size) + ); + CHECK_RESULT(memcmp(xstr.s(), encodedSameAsClass.cha, xstr.sizeInBytes()) == 0, + sprintf("memcmp(xstr.s(), dst.cha, dst.size) == 0"), + sprintf("memcmp(xstr.s(), dst.cha, dst.size) != 0") + ); + } + return SimpleString(); +} + +#define teststrncpy(XStringClass, classEncoding, encoding1) \ + printf("Test %s::teststrncpy(%s)\n", STRINGIFY(XStringClass), STRINGIFY(encoding1)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + teststrncpy_(testStringMultiCodedArray[i].classEncoding, testStringMultiCodedArray[i].encoding1); \ + } \ + + +/***************************** strcat *****************************/ +template +static void teststrcatCheckResult(size_t expectedLength, size_t expectedSize, ch_t* expectedString, XStringClass xstr) +{ + CHECK_RESULT(xstr.length() == expectedLength, + sprintf("xstr.length() == expectedLength (%zu)", expectedLength), + sprintf("xstr.length() != expectedLength (%zu!=%zu)", xstr.length(), expectedLength) + ); + //expectedLength = length_of_utf_string(initialValue.cha) + length_of_utf_string(valueToCat.cha); + //xstr.takeValueFrom(initialValue.cha); + //xstr.strcat(valueToCat.cha); + + CHECK_RESULT(xstr.sizeInBytes() == expectedSize, + sprintf("xstr.sizeInBytes() == expectedSize (%zu)", expectedSize), + sprintf("xstr.sizeInBytes() != expectedSize (%zu!=%zu)", xstr.sizeInBytes(), expectedSize) + ); + + CHECK_RESULT(memcmp(xstr.s(), expectedString, expectedSize+sizeof(ch_t)) == 0, + sprintf("memcmp(xstr.s(), dst.cha, dst.size) == 0"), + sprintf("memcmp(xstr.s(), dst.cha, dst.size) != 0") + ); +} + +template +SimpleString teststrcat_(const InitialValue& initialValue, const ValueToCat& valueToCat) +{ + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::strcpy(%s\"%s\") strcat(%s\"%s\")", XStringClassInfo::xStringClassName, XStringClassInfo::prefix, SimpleString(initialValue.cha).c_str(), XStringClassInfo::prefix, SimpleString(valueToCat.cha).c_str())); + + typedef typename XStringClassInfo::ch_t ch_t; + ch_t c; // dummy for call utf function + + size_t expectedLength = length_of_utf_string(initialValue.cha) + length_of_utf_string(valueToCat.cha); + size_t expectedSize = (utf_size_of_utf_string(&c, initialValue.cha) + utf_size_of_utf_string(&c, valueToCat.cha))*sizeof(ch_t); + ch_t* expectedString = (ch_t*)malloc(expectedSize + sizeof(ch_t)); + utf_string_from_utf_string(expectedString, expectedSize*sizeof(ch_t) + 1, initialValue.cha); + utf_string_from_utf_string(expectedString + size_of_utf_string(expectedString), expectedSize*sizeof(ch_t) + 1 - size_of_utf_string(expectedString), valueToCat.cha); + + // strcat native type + { + XStringClass xstr; + xstr.takeValueFrom(initialValue.cha); + xstr.strcat(valueToCat.cha); + teststrcatCheckResult(expectedLength, expectedSize, expectedString, xstr); + } + // += native type + { + XStringClass xstr; + xstr.takeValueFrom(initialValue.cha); + xstr += valueToCat.cha; + teststrcatCheckResult(expectedLength, expectedSize, expectedString, xstr); + } + // strcat XString + { + typename XStringClassInfo::xs_t valueToCatXString; + valueToCatXString.takeValueFrom(valueToCat.cha); + XStringClass xstr; + xstr.takeValueFrom(initialValue.cha); + xstr += valueToCatXString; + teststrcatCheckResult(expectedLength, expectedSize, expectedString, xstr); + } + // XString + native type + { + XStringClass xinitialValue; + xinitialValue.takeValueFrom(initialValue.cha); + XStringClass xstr; + xstr = xinitialValue + valueToCat.cha; + teststrcatCheckResult(expectedLength, expectedSize, expectedString, xstr); + } + // XString + XString + { + XStringClass xinitialValue; + xinitialValue.takeValueFrom(initialValue.cha); + typename XStringClassInfo::xs_t valueToCatXString; + valueToCatXString.takeValueFrom(valueToCat.cha); + XStringClass xstr; + xstr = xinitialValue + valueToCatXString; + teststrcatCheckResult(expectedLength, expectedSize, expectedString, xstr); + } + // native type + XString + { + typename XStringClassInfo::xs_t valueToCatXString; + valueToCatXString.takeValueFrom(valueToCat.cha); + XStringClass xstr; + xstr = initialValue.cha + valueToCatXString; + teststrcatCheckResult(expectedLength, expectedSize, expectedString, xstr); + } + + free(expectedString); + return SimpleString(); +} + +#define teststrcat(XStringClass, classEncoding, encoding1, encoding2) \ + printf("Test %s(%s)::teststrcat(%s)\n", STRINGIFY(XStringClass), STRINGIFY(encoding1), STRINGIFY(encoding2)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + for ( size_t j = 0 ; j < nbTestStringMultiCoded ; j++ ) { \ + teststrcat_(testStringMultiCodedArray[i].encoding1, testStringMultiCodedArray[i].encoding2); \ + } \ + } \ + +#define min(x,y) ( (x) < (y) ? (x) : (y) ) +#define max(x,y) ( (x) > (y) ? (x) : (y) ) + +/***************************** strncat *****************************/ +template +SimpleString teststrncat_(const InitialValue& initialValue, const ValueToCat& valueToCat) +{ + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::strcpy(%s\"%s\") strncat(%s\"%s\")", XStringClassInfo::xStringClassName, XStringClassInfo::prefix, SimpleString(initialValue.cha).c_str(), XStringClassInfo::prefix, SimpleString(valueToCat.cha).c_str())); + + for ( size_t i = 0 ; i < valueToCat.utf32_length+5 ; i++ ) + { + + typedef typename XStringClassInfo::ch_t ch_t; + ch_t c; // dummy for call utf function + + XStringClass xstr; + xstr.takeValueFrom(initialValue.cha); + xstr.strncat(valueToCat.cha, i); + + size_t expectedLength = length_of_utf_string(initialValue.cha) + min(i, valueToCat.utf32_length); + CHECK_RESULT(xstr.length() == expectedLength, + sprintf("xstr.length() == expectedLength (%zu)", expectedLength), + sprintf("xstr.length() != expectedLength (%zu!=%zu)", xstr.length(), expectedLength) + ); +//expectedLength = length_of_utf_string(initialValue.cha) + min(i, valueToCat.utf32_length); +//xstr.takeValueFrom(initialValue.cha); +//xstr.strncat(valueToCat.cha, i); + + size_t expectedSize = (utf_size_of_utf_string(&c, initialValue.cha) + utf_size_of_utf_string_len(&c, valueToCat.cha, i))*sizeof(ch_t); + CHECK_RESULT(xstr.sizeInBytes() == expectedSize, + sprintf("xstr.sizeInBytes() == expectedSize (%zu)", expectedSize), + sprintf("xstr.sizeInBytes() != expectedSize (%zu!=%zu)", xstr.sizeInBytes(), expectedSize) + ); + + ch_t* expectedString = (ch_t*)malloc(expectedSize*sizeof(ch_t)*sizeof(ch_t) + 1); + utf_string_from_utf_string(expectedString, expectedSize*sizeof(ch_t) + 1, initialValue.cha); + utf_string_from_utf_string_len(expectedString + utf_size_of_utf_string(&c, initialValue.cha), expectedSize*sizeof(ch_t) + 1 - size_of_utf_string(expectedString), valueToCat.cha, i); + CHECK_RESULT(memcmp(xstr.s(), expectedString, expectedSize+sizeof(ch_t)) == 0, + sprintf("memcmp(xstr.s(), expectedString, dst.size) == 0"), + sprintf("memcmp(xstr.s(), expectedString, dst.size) != 0") + ); +//utf_string_from_utf_string(expectedString, expectedSize*sizeof(XStringCharClass) + 1, initialValue.cha); +//utf_string_from_utf_string_len(expectedString + utf_size_of_utf_string(&c, initialValue.cha), expectedSize*sizeof(XStringCharClass) + 1 - size_of_utf_string(expectedString), valueToCat.cha, i); +//expectedLength = length_of_utf_string(initialValue.cha) + min(i, valueToCat.utf32_length); +//xstr.takeValueFrom(initialValue.cha); +//xstr.strncat(valueToCat.cha, i); + + free(expectedString); + } + return SimpleString(); +} + +#define teststrncat(XStringClass, classEncoding, encoding1, encoding2) \ + printf("Test %s(%s)::teststrncat(%s)\n", STRINGIFY(XStringClass), STRINGIFY(encoding1), STRINGIFY(encoding2)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + for ( size_t j = 0 ; j < nbTestStringMultiCoded ; j++ ) { \ + teststrncat_(testStringMultiCodedArray[i].encoding1, testStringMultiCodedArray[i].encoding2); \ + } \ + } \ + + +/***************************** subString *****************************/ +template +SimpleString testSubString_(const InitialValue& initialValue) +{ + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::subString(%s\"%s\"", XStringClassInfo::xStringClassName, XStringClassInfo::prefix, SimpleString(initialValue.cha).c_str())); + + typedef typename XStringClassInfo::ch_t ch_t; + ch_t c; // dummy for call utf function + + XStringClass str; + str.takeValueFrom(initialValue.cha); + + for ( size_t pos = 0 ; pos < initialValue.utf32_length+3 ; pos+=1 ) { + for ( size_t count = 0 ; count < initialValue.utf32_length-pos+3 ; count+=1 ) + { + size_t expectedLength = 0; + if ( pos < initialValue.utf32_length ) expectedLength = min( count, initialValue.utf32_length - pos); + + size_t expectedSize = 0; + if ( pos < initialValue.utf32_length ) expectedSize = utf_size_of_utf_string_len(&c, initialValue.cha, pos+count) - utf_size_of_utf_string_len(&c, initialValue.cha, pos); + + size_t offset; + if ( pos < initialValue.utf32_length ) offset = utf_size_of_utf_string_len(&c, initialValue.cha, pos); + else offset = utf_size_of_utf_string(&c, initialValue.cha); + + XStringClass subStr = str.SubString(pos, count); + + CHECK_RESULT(subStr.length() == expectedLength, + sprintf("subStr.length() == expectedLength (%zu)", expectedLength), + sprintf("subStr.length() != expectedLength (%zu!=%zu)", subStr.length(), expectedLength) + ); + CHECK_RESULT(memcmp(subStr.s(), initialValue.cha + offset, expectedSize) == 0, + sprintf("memcmp == 0"), + sprintf("memcmp != 0)") + ); + } + } + + return SimpleString(); +} + +#define testSubString(XStringClass, classEncoding) \ + printf("Test %s::testSubString\n", STRINGIFY(XStringClass)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + testSubString_(testStringMultiCodedArray[i].classEncoding); \ + } \ + + +/***************************** Compare *****************************/ +template +CharType* incrementChar(const CharType* s, size_t pos, int increment) +{ + size_t initialSize = size_of_utf_string(s); + CharType* buf = (CharType*)malloc( (initialSize+1)*sizeof(CharType) ); + size_t dst_max_len = initialSize+1; + + char32_t char32; + size_t n = 0; + CharType* d = buf; + s = get_char32_from_string(s, &char32); + while ( char32 ) { + if ( n == pos ) { + if ( increment >= 0 ) { + d = store_utf_from_char32(d, &dst_max_len, char32+(unsigned int)increment); + }else{ + d = store_utf_from_char32(d, &dst_max_len, char32-(unsigned int)(-increment)); // avoid signedness warning + } + }else{ + d = store_utf_from_char32(d, &dst_max_len, char32); + } + s = get_char32_from_string(s, &char32); + n++; + } + return buf; +} + +template +SimpleString testCompare_(const InitialValue& initialValue) +{ + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::strcmp(%s\"%s\")", XStringClassInfo::xStringClassName, XStringClassInfo::prefix, SimpleString(initialValue.cha).c_str())); + +// typedef typename XStringClassInfo::ch_t xs_ch_t; +// ch_t c; // dummy for call utf function + + XStringClass xstr; + xstr.takeValueFrom(initialValue.cha); + + typename XStringClassInfo::xs_t xstr2; + xstr2.takeValueFrom(initialValue.cha); + + CHECK_RESULT(xstr.strcmp(xstr2.s()) == 0, + sprintf("subStr.length() == 0"), + sprintf("subStr.length() != 0 (%d)", xstr.strcmp(xstr2.s())) + ); + + CHECK_RESULT(xstr == xstr2.s(), + sprintf("subStr.length() == 0"), + sprintf("subStr.length() != 0 (%d)", xstr.strcmp(xstr2.s())) + ); + CHECK_RESULT(xstr == xstr2, + sprintf("subStr.length() == 0"), + sprintf("subStr.length() != 0 (%d)", xstr.strcmp(xstr2.s())) + ); + CHECK_RESULT(!(xstr != xstr2.s()), + sprintf("subStr.length() == 0"), + sprintf("subStr.length() != 0 (%d)", xstr.strcmp(xstr2.s())) + ); + + CHECK_RESULT(!(xstr != xstr2), + sprintf("subStr.length() == 0"), + sprintf("subStr.length() != 0 (%d)", xstr.strcmp(xstr2.s())) + ); + CHECK_RESULT(!(xstr != xstr2.s()), + sprintf("subStr.length() == 0"), + sprintf("subStr.length() != 0 (%d)", xstr.strcmp(xstr2.s())) + ); + CHECK_RESULT(!(xstr != xstr2), + sprintf("subStr.length() == 0"), + sprintf("subStr.length() != 0 (%d)", xstr.strcmp(xstr2.s())) + ); +//res = xstr.strcmp(xstr2.s()); + + typedef typename XStringClassInfo::ch_t ch_t; + + for ( size_t pos = 0 ; pos < initialValue.utf32_length ; pos++) // this avoid empty string + { + const ch_t* s = incrementChar(initialValue.cha, pos, 1); + CHECK_RESULT(xstr.strcmp(s) == -1, + sprintf("xstr.strcmp(s) == -1"), + sprintf("xstr.strcmp(s) != -1 (%d)", xstr.strcmp(s)) + ); + /* operator comparison with native type */ + CHECK_RESULT(!(xstr == s), + sprintf("!(xstr == s)"), + sprintf("!!(xstr == s)") + ); + CHECK_RESULT(!(s == xstr), + sprintf("!(s == xstr)"), + sprintf("!!(s == xstr)") + ); + CHECK_RESULT(xstr != s, + sprintf("xstr != s"), + sprintf("!xstr != s") + ); + CHECK_RESULT(s != xstr, + sprintf("s != xstr"), + sprintf("!s != xstr") + ); + CHECK_RESULT(xstr < s, + sprintf("xstr < s"), + sprintf("!xstr < s") + ); + CHECK_RESULT(s > xstr, + sprintf("s > xstr"), + sprintf("!s > xstr") + ); + CHECK_RESULT(xstr <= s, + sprintf("xstr <= s"), + sprintf("!xstr <= s") + ); + CHECK_RESULT(s >= xstr, + sprintf("s >= xstr"), + sprintf("!s >= xstr") + ); + CHECK_RESULT(!(xstr > s), + sprintf("!(xstr > s)"), + sprintf("!!(xstr < s)") + ); + CHECK_RESULT(!(s < xstr), + sprintf("!(s < xstr)"), + sprintf("!!(s < xstr)") + ); + CHECK_RESULT(!(xstr >= s), + sprintf("!(xstr >= s)"), + sprintf("!!(xstr >= s)") + ); + CHECK_RESULT(!(s <= xstr), + sprintf("!(s <= xstr)"), + sprintf("!!(s <= xstr)") + ); + + /* operator comparison with other XString */ + xstr2.takeValueFrom(s); + CHECK_RESULT(!(xstr == xstr2), + sprintf("!(xstr == xstr2)"), + sprintf("!!(xstr == xstr2)") + ); + CHECK_RESULT(!(xstr2 == xstr), + sprintf("!(xstr2 == xstr)"), + sprintf("!!(xstr2 == xstr)") + ); + CHECK_RESULT(xstr != xstr2, + sprintf("xstr != xstr2"), + sprintf("!xstr != xstr2") + ); + CHECK_RESULT(xstr2 != xstr, + sprintf("xstr2 != xstr"), + sprintf("!xstr2 != xstr") + ); + CHECK_RESULT(xstr < xstr2, + sprintf("xstr < xstr2"), + sprintf("!xstr < xstr2") + ); + CHECK_RESULT(xstr2 > xstr, + sprintf("xstr2 > xstr"), + sprintf("!xstr2 > xstr") + ); + CHECK_RESULT(xstr <= xstr2, + sprintf("xstr <= xstr2"), + sprintf("!xstr <= xstr2") + ); + CHECK_RESULT(xstr2 >= xstr, + sprintf("xstr2 >= xstr"), + sprintf("!xstr2 >= xstr") + ); + CHECK_RESULT(!(xstr > xstr2), + sprintf("!(xstr > xstr2)"), + sprintf("!!(xstr < xstr2)") + ); + CHECK_RESULT(!(xstr2 < xstr), + sprintf("!(xstr2 < xstr)"), + sprintf("!!(xstr2 < xstr)") + ); + CHECK_RESULT(!(xstr >= xstr2), + sprintf("!(xstr >= xstr2)"), + sprintf("!!(xstr >= xstr2)") + ); + CHECK_RESULT(!(xstr2 <= xstr), + sprintf("!(xstr2 <= xstr)"), + sprintf("!!(xstr2 <= xstr)") + ); + + } + + for ( size_t pos = 0 ; pos < initialValue.utf32_length ; pos++) // this avoid empty string + { + const ch_t* s = incrementChar(initialValue.cha, pos, -1); + CHECK_RESULT(xstr.strcmp(s) == 1, + sprintf("xstr.strcmp(s) == 1"), + sprintf("xstr.strcmp(s) != 1 (%d)", xstr.strcmp(s)) + ); +//const ch_t* s2 = incrementChar(initialValue.cha, pos, 1); + } + + + return SimpleString(); +} + +#define testCompare(XStringClass, classEncoding, encoding) \ + printf("Test %s::strcmp(%s)\n", STRINGIFY(XStringClass), STRINGIFY(encoding)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + testCompare_(testStringMultiCodedArray[i].encoding); \ + } \ + + +/***************************** indexOf, rindexOf *****************************/ + +template +static void testIdxOf__(XStringClass subStr, bool ignoreCase, + size_t (XStringClass::*indexOfChar)(char32_t, size_t) const, + size_t (XStringClass::*indexOfString)(const ch_t*, size_t) const, + size_t (XStringClass::*rindexOfChar)(char32_t, size_t) const, + size_t (XStringClass::*rindexOfString)(const ch_t*, size_t) const + ) +{ + XStringClass testStr; + + testStr = subStr; + if ( ignoreCase ) testStr.lowerAscii(); + CHECK_RESULT((testStr.*indexOfString)(subStr.s(), 0) == 0, + sprintf("testStr.IdxOf(subStr.s(), 0) == 0"), + sprintf("testStr.IdxOf(subStr.s(), 0) != 0 (%zu)", (testStr.*indexOfString)(subStr.s(), 0)) + ); + (testStr.*indexOfString)(subStr.s(), 0); + size_t expectedPos = subStr.length()==0 ? testStr.length() : 0; + CHECK_RESULT((testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1) == expectedPos, + sprintf("testStr.IdxOf(subStr.s(), 0) == expectedPos (%zu)", expectedPos), + sprintf("testStr.IdxOf(subStr.s(), 0) != 0 (%zu!=%zu)", (testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1), expectedPos) + ); + (testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1); + + XStringClass apple; + apple.takeValueFrom(""); + CHECK_RESULT((testStr.*indexOfString)(apple.s(), 0) == MAX_XSIZE, + sprintf("testStr.*indexOfString)(\"\", 0) == MAX_XSIZE"), + sprintf("testStr.*indexOfString)(\"\", 0) != MAX_XSIZE (%zu)", (testStr.*indexOfString)(subStr.s(), 0)) + ); + //(testStr.*indexOfString)(""); + CHECK_RESULT((testStr.*rindexOfString)(apple.s(), MAX_XSIZE-1) == MAX_XSIZE, + sprintf("(testStr.*rindexOfString)(\"\", MAX_XSIZE-1) == MAX_XSIZE"), + sprintf("(testStr.*rindexOfString)(\"\", MAX_XSIZE-1) != MAX_XSIZE (%zu)", (testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1)) + ); + + if ( subStr.length() > 0 ) + { + testStr.takeValueFrom(""); + testStr.strcat(subStr.s()); + if ( ignoreCase ) testStr.lowerAscii(); + CHECK_RESULT((testStr.*indexOfString)(subStr.s(), 0) == 3, + sprintf("testStr.IdxOf(subStr.s(), 0) == 3"), + sprintf("testStr.IdxOf(subStr.s(), 0) != 3 (%zu)", (testStr.*indexOfString)(subStr.s(), 0)) + ); +(testStr.*indexOfString)(subStr.s(), 0); + CHECK_RESULT((testStr.*indexOfString)(subStr.s(), 0) == 3, + sprintf("(testStr.*indexOfString)(subStr.s(), 0) == 3"), + sprintf("(testStr.*indexOfString)(subStr.s(), 0) != 3 (%zu)", (testStr.*indexOfString)(subStr.s(), 0)) + ); + CHECK_RESULT((testStr.*indexOfChar)(subStr[0], 0) == 3, + sprintf("(testStr.*indexOfString)(subStr[0]) == 3"), + sprintf("(testStr.*indexOfString)(subStr[0]) != 3 (%zu)", (testStr.*indexOfChar)(subStr[0], 0)) + ); + CHECK_RESULT((testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1) == 3, + sprintf("testStr.IdxOf(subStr.s(), MAX_XSIZE-1) == 3"), + sprintf("testStr.IdxOf(subStr.s(), MAX_XSIZE-1) != 3 (%zu)", (testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1)) + ); +(testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1); + CHECK_RESULT((testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1) == 3, + sprintf("(testStr.*rindexOfString)(subStr.s(), 0) == 3"), + sprintf("(testStr.*rindexOfString)(subStr.s(), 0) != 3 (%zu)", (testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1)) + ); + CHECK_RESULT((testStr.*rindexOfChar)(subStr[subStr.length()-1], MAX_XSIZE-1) == 3 + subStr.length() - 1, + sprintf("(testStr.*rindexOfString)(subStr[subStr.length()-1]) == 3 + subStr.length() - 1 (%zu)", 3 + subStr.length() - 1), + sprintf("(testStr.*rindexOfString)(subStr[subStr.length()-1]) == 3 + subStr.length() - 1 (%zu!=%zu)", (testStr.*rindexOfChar)(subStr[subStr.length()-1], MAX_XSIZE-1), 3 + subStr.length() - 1) + ); + + testStr.takeValueFrom(""); + testStr.strcat(subStr.s()); + testStr.strcat(""); + if ( ignoreCase ) testStr.lowerAscii(); + CHECK_RESULT((testStr.*indexOfString)(subStr.s(), 0) == 4, + sprintf("testStr.IdxOf(subStr.s(), 0) == 4"), + sprintf("testStr.IdxOf(subStr.s(), 0) != 4 (%zu)", (testStr.*indexOfString)(subStr.s(), 0)) + ); + (testStr.*indexOfString)(subStr.s(), 0); + CHECK_RESULT((testStr.*indexOfString)(subStr.s(), 0) == 4, + sprintf("(testStr.*indexOfString)(subStr.s(), 0) == 4"), + sprintf("(testStr.*indexOfString)(subStr.s(), 0) != 4 (%zu)", (testStr.*indexOfString)(subStr.s(), 0)) + ); + CHECK_RESULT((testStr.*indexOfChar)(subStr[0], 0) == 4, + sprintf("(testStr.*indexOfString)(subStr[0]) == 4"), + sprintf("(testStr.*indexOfString)(subStr[0]) != 4 (%zu)", (testStr.*indexOfChar)(subStr[0], 0)) + ); + CHECK_RESULT((testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1) == 4, + sprintf("testStr.IdxOf(subStr.s(), 0) == 4"), + sprintf("testStr.IdxOf(subStr.s(), 0) != 4 (%zu)", (testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1)) + ); + CHECK_RESULT((testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1) == 4, + sprintf("(testStr.*rindexOfString)(subStr.s(), 0) == 4"), + sprintf("(testStr.*rindexOfString)(subStr.s(), 0) != 4 (%zu)", (testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1)) + ); + CHECK_RESULT((testStr.*rindexOfChar)(subStr[subStr.length()-1], MAX_XSIZE-1) == 4 + subStr.length() - 1, + sprintf("(testStr.*rindexOfString)(subStr[subStr.length()-1]) == 4 + subStr.length() - 1 (%zu)", 4 + subStr.length() - 1), + sprintf("(testStr.*rindexOfString)(subStr[subStr.length()-1]) == 4 + subStr.length() - 1 (%zu!=%zu)", (testStr.*rindexOfChar)(subStr[subStr.length()-1], MAX_XSIZE-1), 4 + subStr.length() - 1) + ); + + testStr.takeValueFrom(""); + testStr.strcat(subStr.s()); + testStr.strcat(""); + testStr.strcat(subStr.s()); + testStr.strcat(""); + if ( ignoreCase ) testStr.lowerAscii(); + CHECK_RESULT((testStr.*indexOfString)(subStr.s(), 0) == 5, + sprintf("testStr.IdxOf(subStr.s(), 0) == 5"), + sprintf("testStr.IdxOf(subStr.s(), 0) != 5 (%zu)", (testStr.*indexOfString)(subStr.s(), 0)) + ); + CHECK_RESULT((testStr.*indexOfString)(subStr.s(), 0) == 5, + sprintf("(testStr.*indexOfString)(subStr.s(), 0) == 5"), + sprintf("(testStr.*indexOfString)(subStr.s(), 0) != 5 (%zu)", (testStr.*indexOfString)(subStr.s(), 0)) + ); + CHECK_RESULT((testStr.*indexOfChar)(subStr[0], 0) == 5, + sprintf("(testStr.*indexOfString)(subStr[0]) == 5"), + sprintf("(testStr.*indexOfString)(subStr[0]) != 5 (%zu)", (testStr.*indexOfChar)(subStr[0], 0)) + ); + CHECK_RESULT((testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1) == 5 + subStr.length() + 6, + sprintf("testStr.IdxOf(subStr.s(), 0) == 5 + subStr.length() + 6"), + sprintf("testStr.IdxOf(subStr.s(), 0) != 5 + subStr.length() + 6 (%zu!=%zu)", (testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1), 5 + subStr.length() + 6) + ); +(testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1); + CHECK_RESULT((testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1) == 5 + subStr.length() + 6, + sprintf("(testStr.*rindexOfString)(subStr.s(), 0) == 5 + subStr.length() + 6"), + sprintf("(testStr.*rindexOfString)(subStr.s(), 0) != 5 + subStr.length() + 6 (%zu!=%zu)", (testStr.*rindexOfString)(subStr.s(), MAX_XSIZE-1), 5 + subStr.length() + 6) + ); + CHECK_RESULT((testStr.*rindexOfChar)(subStr[subStr.length()-1], MAX_XSIZE-1) == 5 + subStr.length() + 6 + subStr.length() - 1, + sprintf("(testStr.*rindexOfString)(subStr[subStr.length()-1]) == 5 + subStr.length() + 6 + subStr.length() - 1 (%zu)", 5 + subStr.length() + 6 + subStr.length() - 1), + sprintf("(testStr.*rindexOfString)(subStr[subStr.length()-1]) == 5 + subStr.length() + 6 + subStr.length() - 1 (%zu!=%zu)", (testStr.*rindexOfChar)(subStr[subStr.length()-1], MAX_XSIZE-1), 5 + subStr.length() + 6 + subStr.length() - 1) + ); + } +} + +template +SimpleString testIdxOf_(const InitialValue& initialValue) +{ + TEST_TITLE(displayOnlyFailed, sprintf("Test %s::idxOf", XStringClassInfo::xStringClassName)); + + typedef typename XStringClassInfo::xs_t ixs_t; + typedef typename XStringClassInfo::ch_t ich_t; +// ch_t c; // dummy for call utf function + + ixs_t str; + str.takeValueFrom(initialValue.cha); + + for ( size_t pos = 0 ; pos < initialValue.utf32_length+3 ; pos+=1 ) { + for ( size_t count = 0 ; count < initialValue.utf32_length-pos+3 ; count+=1 ) + { + ixs_t subStr = str.SubString(pos, count); + +// size_t (ixs_t::*p)(const ich_t* S, size_t Pos) const = &ixs_t::template indexOf; + testIdxOf__(subStr, false, &ixs_t::indexOf, &ixs_t::template indexOf, &ixs_t::rindexOf, &ixs_t::template rindexOf); + + ixs_t subStrLower = subStr; + testIdxOf__(subStrLower, true, &ixs_t::indexOfIC, &ixs_t::template indexOfIC, &ixs_t::rindexOfIC, &ixs_t::template rindexOfIC); +// if ( subStrLower != subStr ) { +// } + } + } + + return SimpleString(); +} + +#define testIdxOf(XStringClass, classEncoding, encoding) \ + printf("Test %s::testIdxOf(%s)\n", STRINGIFY(XStringClass), STRINGIFY(encoding)); \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded ; i++ ) { \ + testIdxOf_(testStringMultiCodedArray[i].encoding); \ + } \ + for ( size_t i = 0 ; i < nbTestStringMultiCoded4CaseArray ; i++ ) { \ + testIdxOf_(testStringMultiCoded4CaseArray[i].encoding); \ + } \ + + + + +/***************************** *****************************/ +#undef realloc +// +//#include +//#include +//#include + +//std::is_class + +void func_test(XStringW& xsw) +{ + (void)xsw; +} + +int XStringx_tests() +{ +#ifdef JIEF_DEBUG +// DebugLog(2, "XString16_tests -> Enter\n"); +#endif + +//const char c = ' '; +//const char* cc = " "; +//char buf[64]; +//char16_t* buf16 = (char16_t*)u"foo16"; +XString x1; +x1.takeValueFrom("a"); +XString x2; +x2.takeValueFrom("b"); + +XStringW xw1; xw1.takeValueFrom("c"); + +auto x3 = xw1 = x1; +func_test(x3); +// +//XStringAbstract__is_char_st a; +//printf("a.v()=%d\n", a.v()); + +//XStringW sw1 = buf16; + +//std::is_array b; + +//XStringAbstract__enable_if_t::type a; + +//printf("%ls", XStringW().takeValueFrom(" ").s()); +//func_test(XStringW().takeValueFrom(" ")); + +// testDefaultCtor("XString"); +// XString16 a = u"toto"_XS16; +// teststrncpy_("utf8", testStringMultiCodedArray[1].utf8, testStringMultiCodedArray[1].wchar); +//testIdxOf(XString, utf8, utf16); +//testCompare(XString, utf8, utf8); + testIdxOf_(testStringMultiCoded4CaseArray[0].utf8); \ + +//size_t size = sizeof("ギ")-1; // this char is 6 bytes long ! +//size_t size = sizeof("ꇉ")-1; // this char is 3 bytes long +//size_t size = sizeof("伽")-1; // this char is 3 bytes long +//size_t size = sizeof("楘")-1; // this char is 3 bytes long +//XString str = "ギꇉ伽楘"_XS; +//char* s = str.data(42); + + TEST_ALL_CLASSES(testDefaultCtor, __TEST0); + TEST_ALL_CLASSES(testEmpty, __TEST0); + TEST_ALL_CLASSES(testTakeValueFrom, TEST_ALL_UTF); + TEST_ALL_CLASSES(testTakeValueFromXString, TEST_ALL_UTF); + TEST_ALL_CLASSES(testchar32At_u, TEST_ALL_INTEGRAL); + + TEST_ALL_CLASSES(teststrcpy, TEST_ALL_UTF); + TEST_ALL_CLASSES(teststrncpy, TEST_ALL_UTF); // 26944 tests + TEST_ALL_CLASSES(teststrcat, TEST_ALL_UTF_ALL_UTF); + TEST_ALL_CLASSES(teststrncat, TEST_ALL_UTF_ALL_UTF); // 2101632 tests + + TEST_ALL_CLASSES(testSubString, __TEST0); + TEST_ALL_CLASSES(testCompare, TEST_ALL_UTF); + TEST_ALL_CLASSES(testIdxOf, TEST_ALL_UTF); + + + +// +//// str2.insert(1, str); +// +// str2.SPrintf("%c", 'a'); // signle UTF8 ascii char +// if ( str2 != L"a" ) return + + + // IMPORTANT : you can't pass a litteral char in a vararg function with Visual Studio (Microsoft strikes again :-). + // At least, you got a warning C4066 + // IMPORTANT2 : Litteral string containing UTF16 char are WRONG. And you don't get a warning !!! If litteral is only ascii, it's ok. + // Maybe it's compilation option but I didn't find them. + + +#ifdef JIEF_DEBUG + if ( nbTestFailed == 0 ) printf("All %d tests succeeded.\n", nbTest); + else printf("%d tests succeeded out of %d.\n", nbTest-nbTestFailed, nbTestFailed); +#endif return 0; } diff --git a/rEFIt_UEFI/cpp_unit_test/XString_test.h b/rEFIt_UEFI/cpp_unit_test/XString_test.h index 1e172548c..a26f39311 100644 --- a/rEFIt_UEFI/cpp_unit_test/XString_test.h +++ b/rEFIt_UEFI/cpp_unit_test/XString_test.h @@ -1 +1 @@ -int XString_tests(); +int XStringx_tests(); diff --git a/rEFIt_UEFI/cpp_unit_test/all_tests.cpp b/rEFIt_UEFI/cpp_unit_test/all_tests.cpp index 48e70041a..8deddc5b7 100644 --- a/rEFIt_UEFI/cpp_unit_test/all_tests.cpp +++ b/rEFIt_UEFI/cpp_unit_test/all_tests.cpp @@ -1,5 +1,4 @@ #include // Only use angled for Platform, else, xcode project won't compile -#include "../cpp_foundation/XStringW.h" #include "../cpp_foundation/XArray.h" #include "../cpp_foundation/XObjArray.h" @@ -9,7 +8,6 @@ #include "XObjArray_tests.h" #include "XStringWArray_test.h" #include "XString_test.h" -#include "XStringW_test.h" #include "strcmp_test.h" #include "strncmp_test.h" #include "strlen_test.h" @@ -33,7 +31,13 @@ bool all_tests() bool all_ok = true; int ret; -#ifdef JIEF_DEBUG +#ifdef XSTRING16_DEV + ret = XStringx_tests(); + if ( ret != 0 ) { + DebugLog(2, "XString16_tests() failed at test %d\n", ret); + all_ok = false; + } +return ret; // ret = XUINTN_tests(); // if ( ret != 0 ) { // DebugLog(2, "XUINTN_tests() failed at test %d\n", ret); @@ -92,18 +96,6 @@ bool all_tests() DebugLog(2, "XObjArray_tests() failed at test %d\n", ret); all_ok = false; } -#ifndef _MSC_VER - ret = XString_tests(); - if ( ret != 0 ) { - DebugLog(2, "XString_tests() failed at test %d\n", ret); - all_ok = false; - } - ret = XStringW_tests(); - if ( ret != 0 ) { - DebugLog(2, "XStringW_tests() failed at test %d\n", ret); - all_ok = false; - } -#endif ret = XStringWArray_tests(); if ( ret != 0 ) { DebugLog(2, "XStringWArray_tests() failed at test %d\n", ret); diff --git a/rEFIt_UEFI/cpp_unit_test/global_test.cpp b/rEFIt_UEFI/cpp_unit_test/global_test.cpp index a6ef97966..606ed2986 100644 --- a/rEFIt_UEFI/cpp_unit_test/global_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/global_test.cpp @@ -1,7 +1,6 @@ #include #include "global_test.h" #include "../cpp_foundation/XString.h" -#include "../cpp_foundation/XStringW.h" diff --git a/rEFIt_UEFI/cpp_unit_test/global_test.h b/rEFIt_UEFI/cpp_unit_test/global_test.h index b222f0753..9b797eea7 100644 --- a/rEFIt_UEFI/cpp_unit_test/global_test.h +++ b/rEFIt_UEFI/cpp_unit_test/global_test.h @@ -1,12 +1,11 @@ #include "../cpp_foundation/XString.h" -#include "../cpp_foundation/XStringW.h" class XStringWTest : public XStringW { public: XStringWTest(const wchar_t *S) : XStringW() { - StrCpy(S); + strcpy(S); } }; @@ -15,7 +14,7 @@ class XStringTest : public XString public: XStringTest(const char *S) : XString() { - StrCpy(S); + strcpy(S); } }; diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index 02085690d..a85db6939 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -34,7 +34,7 @@ */ #include "loader.h" -#include "../cpp_foundation/XStringW.h" +#include "../cpp_foundation/XString.h" #include "entry_scan.h" #include "../Platform/Settings.h" #include "../Platform/Hibernate.h" @@ -251,7 +251,7 @@ UINT8 GetOSTypeFromPath(IN CONST CHAR16 *Path) // (StriCmp(Path, L"\\bootmgr.efi") == 0) || //never worked, just extra icon in menu (StriCmp(Path, L"\\EFI\\MICROSOFT\\BOOT\\cdboot.efi") == 0)) { return OSTYPE_WINEFI; - } else if (StrniCmp(Path, LINUX_FULL_LOADER_PATH.wc_str(), LINUX_FULL_LOADER_PATH.size()) == 0) { + } else if (LINUX_FULL_LOADER_PATH.EqualIC(Path)) { return OSTYPE_LINEFI; } else if (StriStr(Path, L"grubx64.efi") != NULL) { return OSTYPE_LINEFI; @@ -301,7 +301,7 @@ STATIC CONST CHAR16 *LinuxIconNameFromPath(IN CONST CHAR16 *Path, } // Try to open the linux issue - if ((RootDir != NULL) && (StrniCmp(Path, LINUX_FULL_LOADER_PATH.wc_str(), LINUX_FULL_LOADER_PATH.size()) == 0)) { + if ((RootDir != NULL) && LINUX_FULL_LOADER_PATH.EqualIC(Path)) { CHAR8 *Issue = NULL; UINTN IssueLen = 0; if (!EFI_ERROR(egLoadFile(RootDir, LINUX_ISSUE_PATH.wc_str(), (UINT8 **)&Issue, &IssueLen)) && (Issue != NULL)) { @@ -1259,7 +1259,7 @@ VOID ScanLoader(VOID) if (FileExists(SelfRootDir, File.wc_str())) { XStringW LoaderTitle = SWPrintf("%s OS EFI boot menu", OSName.c_str()); XString IconXS = OSName + ",linux"_XS; - IconXS.ToLower(); //to avoid misconception + IconXS.lowerAscii(); //to avoid misconception DBG(" found entry %s\n", IconXS.c_str()); XImage ImageX; //will the image be destroyed or rewritten by next image after the cycle end? ImageX = ThemeX.LoadOSIcon(IconXS); diff --git a/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp b/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp index 69fb638f9..f4cde5e2a 100644 --- a/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp +++ b/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp @@ -1069,7 +1069,7 @@ VOID REFIT_MENU_SCREEN::TextMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamT // determine width of the menu TextMenuWidth = 50; // minimum for (i = 0; i <= ScrollState.MaxIndex; i++) { - ItemWidth = Entries[i].Title.size(); + ItemWidth = Entries[i].Title.length(); if (TextMenuWidth < ItemWidth) { TextMenuWidth = ItemWidth; @@ -1636,7 +1636,7 @@ VOID REFIT_MENU_SCREEN::GraphicsMenuStyle(IN UINTN Function, IN CONST CHAR16 *Pa for (INTN i = ScrollState.FirstVisible, j = 0; i <= ScrollState.LastVisible; i++, j++) { REFIT_ABSTRACT_MENU_ENTRY *Entry = &Entries[i]; - TitleLen = Entry->Title.size(); + TitleLen = Entry->Title.length(); Entry->Place.XPos = EntriesPosX; Entry->Place.YPos = EntriesPosY + j * ThemeX.TextHeight; @@ -1656,7 +1656,7 @@ VOID REFIT_MENU_SCREEN::GraphicsMenuStyle(IN UINTN Function, IN CONST CHAR16 *Pa if ( Entry->getREFIT_INPUT_DIALOG() ) { REFIT_INPUT_DIALOG* inputDialogEntry = Entry->getREFIT_INPUT_DIALOG(); if (inputDialogEntry->Item && inputDialogEntry->Item->ItemType == BoolValue) { - Entry->Place.Width = ResultString.size() * ScaledWidth; + Entry->Place.Width = ResultString.length() * ScaledWidth; //possible artefacts DrawMenuText(XStringW().takeValueFrom(" "), 0, EntriesPosX, Entry->Place.YPos, 0xFFFF); DrawMenuText(ResultString, (i == ScrollState.CurrentSelection) ? (MenuWidth) : 0, @@ -1667,7 +1667,7 @@ VOID REFIT_MENU_SCREEN::GraphicsMenuStyle(IN UINTN Function, IN CONST CHAR16 *Pa // text input ResultString += ((REFIT_INPUT_DIALOG*)(Entry))->Item->SValue; ResultString += L" "; - Entry->Place.Width = ResultString.size() * ScaledWidth; + Entry->Place.Width = ResultString.length() * ScaledWidth; // Slice - suppose to use Row as Cursor in text DrawMenuText(ResultString, (i == ScrollState.CurrentSelection) ? MenuWidth : 0, EntriesPosX, @@ -1714,7 +1714,7 @@ VOID REFIT_MENU_SCREEN::GraphicsMenuStyle(IN UINTN Function, IN CONST CHAR16 *Pa // last selection REFIT_ABSTRACT_MENU_ENTRY *EntryL = &Entries[ScrollState.LastSelection]; REFIT_ABSTRACT_MENU_ENTRY *EntryC = &Entries[ScrollState.CurrentSelection]; - TitleLen = EntryL->Title.size(); + TitleLen = EntryL->Title.length(); ResultString = EntryL->Title; //clovy//PlaceCentre = (TextHeight - (INTN)(Buttons[2]->Height * GlobalConfig.Scale)) / 2; //clovy//PlaceCentre = (PlaceCentre>0)?PlaceCentre:0; @@ -1774,7 +1774,7 @@ VOID REFIT_MENU_SCREEN::GraphicsMenuStyle(IN UINTN Function, IN CONST CHAR16 *Pa // current selection ResultString = EntryC->Title; - TitleLen = EntryC->Title.size(); + TitleLen = EntryC->Title.length(); if ( EntryC->getREFIT_MENU_SWITCH() ) { if (EntryC->getREFIT_MENU_SWITCH()->Item->IValue == 3) { OldChosenItem = (OldChosenTheme == 0xFFFF) ? 0: OldChosenTheme + 1;; diff --git a/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.h b/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.h index 5fb6bc2f6..a043802a2 100644 --- a/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.h +++ b/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.h @@ -40,8 +40,8 @@ #include "../refit/lib.h" #include "../cpp_foundation/XObjArray.h" +#include "../cpp_foundation/XString.h" #include "../cpp_foundation/XStringWArray.h" -#include "../cpp_foundation/XStringW.h" #include "../libeg/XPointer.h" #include "../libeg/XCinema.h" #include "menu_items/menu_items.h" diff --git a/rEFIt_UEFI/gui/menu_items/menu_items.cpp b/rEFIt_UEFI/gui/menu_items/menu_items.cpp index 37f5c8f7f..3c7ae4d38 100644 --- a/rEFIt_UEFI/gui/menu_items/menu_items.cpp +++ b/rEFIt_UEFI/gui/menu_items/menu_items.cpp @@ -40,8 +40,8 @@ #include "../../refit/lib.h" #ifdef __cplusplus #include "../../cpp_foundation/XObjArray.h" +#include "../../cpp_foundation/XString.h" #include "../../cpp_foundation/XStringWArray.h" -#include "../../cpp_foundation/XStringW.h" #include "../../libeg/XPointer.h" #endif diff --git a/rEFIt_UEFI/gui/menu_items/menu_items.h b/rEFIt_UEFI/gui/menu_items/menu_items.h index fdeb207fe..591523faf 100644 --- a/rEFIt_UEFI/gui/menu_items/menu_items.h +++ b/rEFIt_UEFI/gui/menu_items/menu_items.h @@ -42,7 +42,6 @@ #include "../../cpp_foundation/XObjArray.h" #include "../../cpp_foundation/XStringWArray.h" #include "../../cpp_foundation/XString.h" -#include "../../cpp_foundation/XStringW.h" #include "../../libeg/XPointer.h" #endif diff --git a/rEFIt_UEFI/libeg/VectorGraphics.cpp b/rEFIt_UEFI/libeg/VectorGraphics.cpp index ac6bb9eeb..ccc43365f 100755 --- a/rEFIt_UEFI/libeg/VectorGraphics.cpp +++ b/rEFIt_UEFI/libeg/VectorGraphics.cpp @@ -454,7 +454,7 @@ INTN renderSVGtext(XImage* TextBufferXY_ptr, INTN posX, INTN posY, INTN textType XImage& TextBufferXY = *TextBufferXY_ptr; INTN Width; // UINTN i; - UINTN len; +// UINTN len; NSVGparser* p; NSVGrasterizer* rast; if (!textFace[textType].valid) { @@ -492,7 +492,6 @@ INTN renderSVGtext(XImage* TextBufferXY_ptr, INTN posX, INTN posY, INTN textType nsvg__xformIdentity(text->xform); p->text = text; - len = string.size(); Width = TextBufferXY.GetWidth(); if ( fontSVG->unitsPerEm < 1.f ) { fontSVG->unitsPerEm = 1000.f; @@ -508,8 +507,9 @@ INTN renderSVGtext(XImage* TextBufferXY_ptr, INTN posX, INTN posY, INTN textType x = (float)posX; //0.f; y = (float)posY + fontSVG->bbox[1] * Scale; p->isText = TRUE; - for (UINTN i=0; i < len; i++) { - CHAR16 letter = string.wc_str()[i]; + size_t len = string.length(); + for (size_t i=0; i < len; i++) { + CHAR16 letter = string.char16At(i); if (!letter) { break; } diff --git a/rEFIt_UEFI/libeg/VectorGraphics.h b/rEFIt_UEFI/libeg/VectorGraphics.h index e0cf7c8de..543c550e6 100644 --- a/rEFIt_UEFI/libeg/VectorGraphics.h +++ b/rEFIt_UEFI/libeg/VectorGraphics.h @@ -8,7 +8,7 @@ #ifndef LIBEG_VECTORGRAPHICS_H_ #define LIBEG_VECTORGRAPHICS_H_ -#include "../cpp_foundation/XStringW.h" +#include "../cpp_foundation/XString.h" #include "../Platform/plist.h" #include "XImage.h" diff --git a/rEFIt_UEFI/libeg/XCinema.h b/rEFIt_UEFI/libeg/XCinema.h index 04e582a6d..aa0319b53 100644 --- a/rEFIt_UEFI/libeg/XCinema.h +++ b/rEFIt_UEFI/libeg/XCinema.h @@ -14,7 +14,7 @@ extern "C" { } #include "../cpp_foundation/XToolsCommon.h" #include "../cpp_foundation/XArray.h" -#include "../cpp_foundation/XStringW.h" +#include "../cpp_foundation/XString.h" #include "../libeg/libeg.h" #include "XImage.h" #include "XTheme.h" diff --git a/rEFIt_UEFI/libeg/XImage.h b/rEFIt_UEFI/libeg/XImage.h index 5a4a2d9e3..c880906e0 100644 --- a/rEFIt_UEFI/libeg/XImage.h +++ b/rEFIt_UEFI/libeg/XImage.h @@ -13,7 +13,7 @@ extern "C" { } #include "../cpp_foundation/XToolsCommon.h" #include "../cpp_foundation/XArray.h" -#include "../cpp_foundation/XStringW.h" +#include "../cpp_foundation/XString.h" #include "../libeg/libeg.h" //#include "lodepng.h" // diff --git a/rEFIt_UEFI/libeg/XTheme.cpp b/rEFIt_UEFI/libeg/XTheme.cpp index b5ddb5d0c..8b951481c 100644 --- a/rEFIt_UEFI/libeg/XTheme.cpp +++ b/rEFIt_UEFI/libeg/XTheme.cpp @@ -396,7 +396,7 @@ const XImage& XTheme::LoadOSIcon(const XString& Full) XString Third; const XImage *ReturnImage; UINTN Comma = Full.IdxOf(','); - UINTN Size = Full.size(); + UINTN Size = Full.length(); // DBG("IconName=%ls comma=%lld size=%lld\n", OSIconName, Comma, Size); if (Comma != MAX_XSIZE) { //Comma First = "os_"_XS + Full.SubString(0, Comma); diff --git a/rEFIt_UEFI/refit.inf b/rEFIt_UEFI/refit.inf index aa5d99de1..22ba015ad 100644 --- a/rEFIt_UEFI/refit.inf +++ b/rEFIt_UEFI/refit.inf @@ -242,12 +242,13 @@ cpp_foundation/unicode_conversions.h cpp_foundation/XArray.h cpp_foundation/XObjArray.h - cpp_foundation/XString.cpp - cpp_foundation/XString.h + # cpp_foundation/XString.cpp +# cpp_foundation/XString.h cpp_foundation/XStringArray.cpp cpp_foundation/XStringArray.h - cpp_foundation/XStringW.cpp - cpp_foundation/XStringW.h +# cpp_foundation/XStringW.cpp +# cpp_foundation/XStringW.h + cpp_foundation/XStringUtf.cpp cpp_foundation/XStringWArray.cpp cpp_foundation/XStringWArray.h cpp_foundation/XToolsCommon.cpp @@ -275,10 +276,11 @@ cpp_unit_test/XArray_tests.h cpp_unit_test/XObjArray_tests.cpp cpp_unit_test/XObjArray_tests.h - cpp_unit_test/XString_test.cpp - cpp_unit_test/XString_test.h - cpp_unit_test/XStringW_test.cpp - cpp_unit_test/XStringW_test.h +# cpp_unit_test/XString_test.cpp +# cpp_unit_test/XString_test.h +# cpp_unit_test/XStringW_test.cpp +# cpp_unit_test/XStringW_test.h + cpp_unit_test/XStringx_test.cpp cpp_unit_test/XStringWArray_test.cpp cpp_unit_test/XStringWArray_test.h # cpp_unit_test/XUINTN_test.cpp diff --git a/rEFIt_UEFI/refit/lib.h b/rEFIt_UEFI/refit/lib.h index bb2cddaee..00235258a 100644 --- a/rEFIt_UEFI/refit/lib.h +++ b/rEFIt_UEFI/refit/lib.h @@ -60,8 +60,8 @@ #include "../libeg/libeg.h" #ifdef __cplusplus #include "../cpp_foundation/XObjArray.h" +#include "../cpp_foundation/XString.h" #include "../cpp_foundation/XStringWArray.h" -#include "../cpp_foundation/XStringW.h" #include "../libeg/XTheme.h" extern XTheme ThemeX; //global variable defined in lib.cpp diff --git a/rEFIt_UEFI/refit/menu.h b/rEFIt_UEFI/refit/menu.h index 3102e9f52..80ae7cc7b 100644 --- a/rEFIt_UEFI/refit/menu.h +++ b/rEFIt_UEFI/refit/menu.h @@ -1,7 +1,7 @@ #ifndef __MENU_H__ #define __MENU_H__ -#include "../cpp_foundation/XStringW.h" +#include "../cpp_foundation/XString.h" #include "../gui/menu_items/menu_items.h" //VOID AddMenuInfoLine(IN REFIT_MENU_SCREEN *Screen, IN CONST CHAR16 *InfoLine);