macOS support

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2024-02-08 12:09:33 +01:00
parent b6be4f040e
commit 08a18d1519
19 changed files with 342 additions and 289 deletions

View File

@ -58,6 +58,9 @@
F4C07F582AB08E690044EDC0 /* sgml.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sgml.cpp; sourceTree = "<group>"; }; F4C07F582AB08E690044EDC0 /* sgml.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sgml.cpp; sourceTree = "<group>"; };
F4C07F592AB08E690044EDC0 /* ring.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ring.cpp; sourceTree = "<group>"; }; F4C07F592AB08E690044EDC0 /* ring.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ring.cpp; sourceTree = "<group>"; };
F4C07F5A2AB08E690044EDC0 /* stream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stream.cpp; sourceTree = "<group>"; }; F4C07F5A2AB08E690044EDC0 /* stream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stream.cpp; sourceTree = "<group>"; };
F4CCA3B62B73B912007B857B /* watchdog.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = watchdog.cpp; sourceTree = "<group>"; };
F4CCA3B72B73B940007B857B /* pool.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = pool.cpp; sourceTree = "<group>"; };
F4CCA3B82B73D2E2007B857B /* string.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = string.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -110,12 +113,15 @@
F4C07F562AB08E690044EDC0 /* parser.cpp */, F4C07F562AB08E690044EDC0 /* parser.cpp */,
F4C07F512AB059580044EDC0 /* pch.cpp */, F4C07F512AB059580044EDC0 /* pch.cpp */,
F4C07F502AB059580044EDC0 /* pch.hpp */, F4C07F502AB059580044EDC0 /* pch.hpp */,
F4CCA3B72B73B940007B857B /* pool.cpp */,
F4B7FBDD2AAF49BC00C6BE9F /* Products */, F4B7FBDD2AAF49BC00C6BE9F /* Products */,
F4C07F592AB08E690044EDC0 /* ring.cpp */, F4C07F592AB08E690044EDC0 /* ring.cpp */,
F4C07F582AB08E690044EDC0 /* sgml.cpp */, F4C07F582AB08E690044EDC0 /* sgml.cpp */,
F4213D162ABB14AA00F72674 /* stdex */, F4213D162ABB14AA00F72674 /* stdex */,
F4C07F5A2AB08E690044EDC0 /* stream.cpp */, F4C07F5A2AB08E690044EDC0 /* stream.cpp */,
F4CCA3B82B73D2E2007B857B /* string.cpp */,
F4C07F572AB08E690044EDC0 /* unicode.cpp */, F4C07F572AB08E690044EDC0 /* unicode.cpp */,
F4CCA3B62B73B912007B857B /* watchdog.cpp */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
usesTabs = 1; usesTabs = 1;

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -6,10 +6,12 @@
#include "pch.hpp" #include "pch.hpp"
#include "hash.cpp" #include "hash.cpp"
#include "math.cpp" #include "math.cpp"
#include "pool.cpp"
#include "parser.cpp" #include "parser.cpp"
#include "ring.cpp" #include "ring.cpp"
#include "sgml.cpp" #include "sgml.cpp"
#include "stream.cpp" #include "stream.cpp"
#include "string.cpp"
#include "unicode.cpp" #include "unicode.cpp"
#include "watchdog.cpp" #include "watchdog.cpp"
#include <iostream> #include <iostream>
@ -25,6 +27,7 @@ int main(int argc, const char * argv[])
UnitTests::parser::wtest(); UnitTests::parser::wtest();
UnitTests::parser::sgml_test(); UnitTests::parser::sgml_test();
UnitTests::parser::http_test(); UnitTests::parser::http_test();
UnitTests::pool::test();
UnitTests::ring::test(); UnitTests::ring::test();
UnitTests::sgml::sgml2str(); UnitTests::sgml::sgml2str();
UnitTests::sgml::str2sgml(); UnitTests::sgml::str2sgml();
@ -32,9 +35,11 @@ int main(int argc, const char * argv[])
UnitTests::stream::replicator(); UnitTests::stream::replicator();
UnitTests::stream::open_close(); UnitTests::stream::open_close();
UnitTests::stream::file_stat(); UnitTests::stream::file_stat();
UnitTests::string::sprintf();
UnitTests::unicode::str2wstr(); UnitTests::unicode::str2wstr();
UnitTests::unicode::wstr2str(); UnitTests::unicode::wstr2str();
UnitTests::unicode::charset_encoder(); UnitTests::unicode::charset_encoder();
UnitTests::unicode::normalize();
UnitTests::watchdog::test(); UnitTests::watchdog::test();
std::cout << "PASS\n"; std::cout << "PASS\n";
return 0; return 0;

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -6,15 +6,13 @@
#include "pch.hpp" #include "pch.hpp"
using namespace std; using namespace std;
using namespace stdex;
using namespace stdex::parser;
#ifdef _WIN32 #ifdef _WIN32
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Microsoft { namespace Microsoft {
namespace VisualStudio { namespace VisualStudio {
namespace CppUnitTestFramework { namespace CppUnitTestFramework {
static std::wstring ToString(const stdex::interval<size_t>& q) static wstring ToString(const stdex::interval<size_t>& q)
{ {
return stdex::sprintf(L"<%zu, %zu>", nullptr, q.start, q.end); return stdex::sprintf(L"<%zu, %zu>", nullptr, q.start, q.end);
} }
@ -33,22 +31,22 @@ namespace UnitTests
static const wchar_t text[] = L"This is a test.\nSecond line."; static const wchar_t text[] = L"This is a test.\nSecond line.";
{ {
wnoop p; stdex::parser::wnoop p;
Assert::IsTrue(p.match(text)); Assert::IsTrue(p.match(text));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)0, p.interval.end); Assert::AreEqual((size_t)0, p.interval.end);
} }
{ {
wcu p(L't'); stdex::parser::wcu p(L't');
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 0, _countof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)1, p.interval.end); Assert::AreEqual((size_t)1, p.interval.end);
} }
{ {
wspace_cu p; stdex::parser::wspace_cu p;
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 4)); Assert::IsTrue(p.match(text, 4));
Assert::AreEqual((size_t)4, p.interval.start); Assert::AreEqual((size_t)4, p.interval.start);
@ -56,7 +54,7 @@ namespace UnitTests
} }
{ {
wpunct_cu p; stdex::parser::wpunct_cu p;
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 14)); Assert::IsTrue(p.match(text, 14));
Assert::AreEqual((size_t)14, p.interval.start); Assert::AreEqual((size_t)14, p.interval.start);
@ -64,7 +62,7 @@ namespace UnitTests
} }
{ {
wspace_or_punct_cu p; stdex::parser::wspace_or_punct_cu p;
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 4)); Assert::IsTrue(p.match(text, 4));
Assert::AreEqual((size_t)4, p.interval.start); Assert::AreEqual((size_t)4, p.interval.start);
@ -75,7 +73,7 @@ namespace UnitTests
} }
{ {
wbol p; stdex::parser::wbol p;
Assert::IsTrue(p.match(text)); Assert::IsTrue(p.match(text));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)0, p.interval.end); Assert::AreEqual((size_t)0, p.interval.end);
@ -87,7 +85,7 @@ namespace UnitTests
} }
{ {
weol p; stdex::parser::weol p;
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsFalse(p.match(text, 1)); Assert::IsFalse(p.match(text, 1));
Assert::IsTrue(p.match(text, 15)); Assert::IsTrue(p.match(text, 15));
@ -97,14 +95,14 @@ namespace UnitTests
} }
{ {
wcu_set p(L"abcD"); stdex::parser::wcu_set p(L"abcD");
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 8)); Assert::IsTrue(p.match(text, 8));
Assert::AreEqual((size_t)8, p.interval.start); Assert::AreEqual((size_t)8, p.interval.start);
Assert::AreEqual((size_t)9, p.interval.end); Assert::AreEqual((size_t)9, p.interval.end);
Assert::AreEqual((size_t)0, p.hit_offset); Assert::AreEqual((size_t)0, p.hit_offset);
Assert::IsFalse(p.match(text, 21)); Assert::IsFalse(p.match(text, 21));
Assert::IsTrue(p.match(text, 21, _countof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 21, _countof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)21, p.interval.start); Assert::AreEqual((size_t)21, p.interval.start);
Assert::AreEqual((size_t)22, p.interval.end); Assert::AreEqual((size_t)22, p.interval.end);
Assert::AreEqual((size_t)3, p.hit_offset); Assert::AreEqual((size_t)3, p.hit_offset);
@ -113,83 +111,83 @@ namespace UnitTests
{ {
stdex::parser::wstring p(L"this"); stdex::parser::wstring p(L"this");
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 0, sizeof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 0, sizeof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)4, p.interval.end); Assert::AreEqual((size_t)4, p.interval.end);
} }
{ {
wany_cu chr; stdex::parser::wany_cu chr;
witerations p(make_shared_no_delete(&chr), 1, 5); stdex::parser::witerations p(stdex::make_shared_no_delete(&chr), 1, 5);
Assert::IsTrue(p.match(text)); Assert::IsTrue(p.match(text));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)5, p.interval.end); Assert::AreEqual((size_t)5, p.interval.end);
} }
{ {
wspace_cu nospace(true); stdex::parser::wspace_cu nospace(true);
witerations p(make_shared_no_delete(&nospace), 1); stdex::parser::witerations p(stdex::make_shared_no_delete(&nospace), 1);
Assert::IsTrue(p.match(text)); Assert::IsTrue(p.match(text));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)4, p.interval.end); Assert::AreEqual((size_t)4, p.interval.end);
} }
{ {
wcu chr_t(L't'), chr_h(L'h'), chr_i(L'i'), chr_s(L's'); stdex::parser::wcu chr_t(L't'), chr_h(L'h'), chr_i(L'i'), chr_s(L's');
wspace_cu space; stdex::parser::wspace_cu space;
wsequence p({ stdex::parser::wsequence p({
make_shared_no_delete(&chr_t), stdex::make_shared_no_delete(&chr_t),
make_shared_no_delete(&chr_h), stdex::make_shared_no_delete(&chr_h),
make_shared_no_delete(&chr_i), stdex::make_shared_no_delete(&chr_i),
make_shared_no_delete(&chr_s), stdex::make_shared_no_delete(&chr_s),
make_shared_no_delete(&space) }); stdex::make_shared_no_delete(&space) });
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 0, _countof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)5, p.interval.end); Assert::AreEqual((size_t)5, p.interval.end);
} }
{ {
stdex::parser::wstring apple(L"apple"), orange(L"orange"), _this(L"this"); stdex::parser::wstring apple(L"apple"), orange(L"orange"), _this(L"this");
wspace_cu space; stdex::parser::wspace_cu space;
wbranch p({ stdex::parser::wbranch p({
make_shared_no_delete(&apple), stdex::make_shared_no_delete(&apple),
make_shared_no_delete(&orange), stdex::make_shared_no_delete(&orange),
make_shared_no_delete(&_this), stdex::make_shared_no_delete(&_this),
make_shared_no_delete(&space) }); stdex::make_shared_no_delete(&space) });
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 0, _countof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)2, p.hit_offset); Assert::AreEqual((size_t)2, p.hit_offset);
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)4, p.interval.end); Assert::AreEqual((size_t)4, p.interval.end);
} }
{ {
wstring_branch p(L"apple", L"orange", L"this", nullptr); stdex::parser::wstring_branch p(L"apple", L"orange", L"this", nullptr);
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 0, _countof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)2, p.hit_offset); Assert::AreEqual((size_t)2, p.hit_offset);
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)4, p.interval.end); Assert::AreEqual((size_t)4, p.interval.end);
} }
{ {
wcu chr_s(L's'), chr_h(L'h'), chr_i(L'i'), chr_t(L't'); stdex::parser::wcu chr_s(L's'), chr_h(L'h'), chr_i(L'i'), chr_t(L't');
wpermutation p({ stdex::parser::wpermutation p({
make_shared_no_delete(&chr_s), stdex::make_shared_no_delete(&chr_s),
make_shared_no_delete(&chr_h), stdex::make_shared_no_delete(&chr_h),
make_shared_no_delete(&chr_i), stdex::make_shared_no_delete(&chr_i),
make_shared_no_delete(&chr_t) }); stdex::make_shared_no_delete(&chr_t) });
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 0, _countof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)4, p.interval.end); Assert::AreEqual((size_t)4, p.interval.end);
} }
{ {
std::locale locale_slSI("sl_SI"); std::locale locale_slSI("sl_SI");
wspace_cu space(false, locale_slSI); stdex::parser::wspace_cu space(false, locale_slSI);
wiban p(make_shared_no_delete(&space), locale_slSI); stdex::parser::wiban p(stdex::make_shared_no_delete(&space), locale_slSI);
Assert::IsTrue(p.match(L"SI56023120015226972", 0, SIZE_MAX)); Assert::IsTrue(p.match(L"SI56023120015226972", 0, SIZE_MAX));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::AreEqual(L"SI", p.country); Assert::AreEqual(L"SI", p.country);
@ -202,7 +200,7 @@ namespace UnitTests
Assert::AreEqual(L"023120015226972", p.bban); Assert::AreEqual(L"023120015226972", p.bban);
Assert::IsFalse(p.match(L"si56 0231 2001 5226 972", 0, SIZE_MAX)); Assert::IsFalse(p.match(L"si56 0231 2001 5226 972", 0, SIZE_MAX));
Assert::IsFalse(p.is_valid); Assert::IsFalse(p.is_valid);
Assert::IsTrue(p.match(L"si56 0231 2001 5226 972", 0, SIZE_MAX, match_case_insensitive)); Assert::IsTrue(p.match(L"si56 0231 2001 5226 972", 0, SIZE_MAX, stdex::parser::match_case_insensitive));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::IsTrue(p.match(L"SI56 0231 2001 5226 9720", 0, SIZE_MAX)); Assert::IsTrue(p.match(L"SI56 0231 2001 5226 9720", 0, SIZE_MAX));
Assert::AreEqual(stdex::interval<size_t>(0, 23), p.interval); Assert::AreEqual(stdex::interval<size_t>(0, 23), p.interval);
@ -250,8 +248,8 @@ namespace UnitTests
{ {
std::locale locale_slSI("sl_SI"); std::locale locale_slSI("sl_SI");
wspace_cu space(false, locale_slSI); stdex::parser::wspace_cu space(false, locale_slSI);
wcreditor_reference p(make_shared_no_delete(&space), locale_slSI); stdex::parser::wcreditor_reference p(stdex::make_shared_no_delete(&space), locale_slSI);
Assert::IsTrue(p.match(L"RF18539007547034", 0, SIZE_MAX)); Assert::IsTrue(p.match(L"RF18539007547034", 0, SIZE_MAX));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::AreEqual(L"18", p.check_digits); Assert::AreEqual(L"18", p.check_digits);
@ -262,7 +260,7 @@ namespace UnitTests
Assert::AreEqual(L"000000000539007547034", p.reference); Assert::AreEqual(L"000000000539007547034", p.reference);
Assert::IsFalse(p.match(L"rf18 5390 0754 7034", 0, SIZE_MAX)); Assert::IsFalse(p.match(L"rf18 5390 0754 7034", 0, SIZE_MAX));
Assert::IsFalse(p.is_valid); Assert::IsFalse(p.is_valid);
Assert::IsTrue(p.match(L"rf18 5390 0754 7034", 0, SIZE_MAX, match_case_insensitive)); Assert::IsTrue(p.match(L"rf18 5390 0754 7034", 0, SIZE_MAX, stdex::parser::match_case_insensitive));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::IsTrue(p.match(L"RF18 5390 0754 70340", 0, SIZE_MAX)); Assert::IsTrue(p.match(L"RF18 5390 0754 70340", 0, SIZE_MAX));
Assert::IsFalse(p.is_valid); Assert::IsFalse(p.is_valid);
@ -274,8 +272,8 @@ namespace UnitTests
{ {
std::locale locale_slSI("sl_SI"); std::locale locale_slSI("sl_SI");
wspace_cu space(false, locale_slSI); stdex::parser::wspace_cu space(false, locale_slSI);
wsi_reference p(make_shared_no_delete(&space), locale_slSI); stdex::parser::wsi_reference p(stdex::make_shared_no_delete(&space), locale_slSI);
Assert::IsTrue(p.match(L"SI121234567890120", 0, SIZE_MAX)); Assert::IsTrue(p.match(L"SI121234567890120", 0, SIZE_MAX));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::AreEqual(L"12", p.model); Assert::AreEqual(L"12", p.model);
@ -285,7 +283,7 @@ namespace UnitTests
Assert::AreEqual(L"12", p.model); Assert::AreEqual(L"12", p.model);
Assert::AreEqual(stdex::interval<size_t>(5, 18), p.part1.interval); Assert::AreEqual(stdex::interval<size_t>(5, 18), p.part1.interval);
Assert::IsFalse(p.match(L"si12 1234567890120", 0, SIZE_MAX)); Assert::IsFalse(p.match(L"si12 1234567890120", 0, SIZE_MAX));
Assert::IsTrue(p.match(L"si12 1234567890120", 0, SIZE_MAX, match_case_insensitive)); Assert::IsTrue(p.match(L"si12 1234567890120", 0, SIZE_MAX, stdex::parser::match_case_insensitive));
Assert::IsTrue(p.match(L"...SI12 1234567890120...", 3, SIZE_MAX)); Assert::IsTrue(p.match(L"...SI12 1234567890120...", 3, SIZE_MAX));
Assert::IsTrue(p.match(L"SI12 1234567890120", 0, SIZE_MAX)); // no-break space Assert::IsTrue(p.match(L"SI12 1234567890120", 0, SIZE_MAX)); // no-break space
} }
@ -297,30 +295,30 @@ namespace UnitTests
static const char text[] = "V ko&zcaron;u&scaron;&ccaron;ku zlobnega mizarja stopiclja fant\nin kli&ccaron;e&nbsp;1234567890."; static const char text[] = "V ko&zcaron;u&scaron;&ccaron;ku zlobnega mizarja stopiclja fant\nin kli&ccaron;e&nbsp;1234567890.";
{ {
sgml_noop p; stdex::parser::sgml_noop p;
Assert::IsTrue(p.match(text)); Assert::IsTrue(p.match(text));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)0, p.interval.end); Assert::AreEqual((size_t)0, p.interval.end);
} }
{ {
sgml_cp p("v"); stdex::parser::sgml_cp p("v");
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 0, _countof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 0, _countof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)1, p.interval.end); Assert::AreEqual((size_t)1, p.interval.end);
} }
{ {
sgml_cp p("&Zcaron;", SIZE_MAX, false, locale_slSI); stdex::parser::sgml_cp p("&Zcaron;", SIZE_MAX, false, locale_slSI);
Assert::IsFalse(p.match(text, 4)); Assert::IsFalse(p.match(text, 4));
Assert::IsTrue(p.match(text, 4, _countof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 4, _countof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)4, p.interval.start); Assert::AreEqual((size_t)4, p.interval.start);
Assert::AreEqual((size_t)12, p.interval.end); Assert::AreEqual((size_t)12, p.interval.end);
} }
{ {
sgml_space_cp p(false, locale_slSI); stdex::parser::sgml_space_cp p(false, locale_slSI);
Assert::IsFalse(p.match(text)); Assert::IsFalse(p.match(text));
Assert::IsTrue(p.match(text, 1)); Assert::IsTrue(p.match(text, 1));
Assert::AreEqual((size_t)1, p.interval.start); Assert::AreEqual((size_t)1, p.interval.start);
@ -331,17 +329,17 @@ namespace UnitTests
} }
{ {
sgml_string_branch p(locale_slSI, "apple", "orange", "Ko&Zcaron;u&Scaron;&ccaron;Ku", nullptr); stdex::parser::sgml_string_branch p(locale_slSI, "apple", "orange", "Ko&Zcaron;u&Scaron;&ccaron;Ku", nullptr);
Assert::IsFalse(p.match(text, 2)); Assert::IsFalse(p.match(text, 2));
Assert::IsTrue(p.match(text, 2, _countof(text), match_case_insensitive)); Assert::IsTrue(p.match(text, 2, _countof(text), stdex::parser::match_case_insensitive));
Assert::AreEqual((size_t)2, p.hit_offset); Assert::AreEqual((size_t)2, p.hit_offset);
Assert::AreEqual((size_t)2, p.interval.start); Assert::AreEqual((size_t)2, p.interval.start);
Assert::AreEqual((size_t)31, p.interval.end); Assert::AreEqual((size_t)31, p.interval.end);
} }
{ {
sgml_space_cp space(false, locale_slSI); stdex::parser::sgml_space_cp space(false, locale_slSI);
sgml_iban p(make_shared_no_delete(&space), locale_slSI); stdex::parser::sgml_iban p(stdex::make_shared_no_delete(&space), locale_slSI);
Assert::IsTrue(p.match("SI56023120015226972", 0, SIZE_MAX)); Assert::IsTrue(p.match("SI56023120015226972", 0, SIZE_MAX));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::AreEqual("SI", p.country); Assert::AreEqual("SI", p.country);
@ -354,7 +352,7 @@ namespace UnitTests
Assert::AreEqual("023120015226972", p.bban); Assert::AreEqual("023120015226972", p.bban);
Assert::IsFalse(p.match("si56 0231 2001 5226 972", 0, SIZE_MAX)); Assert::IsFalse(p.match("si56 0231 2001 5226 972", 0, SIZE_MAX));
Assert::IsFalse(p.is_valid); Assert::IsFalse(p.is_valid);
Assert::IsTrue(p.match("si56 0231 2001 5226 972", 0, SIZE_MAX, match_case_insensitive)); Assert::IsTrue(p.match("si56 0231 2001 5226 972", 0, SIZE_MAX, stdex::parser::match_case_insensitive));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::IsTrue(p.match("SI56 0231 2001 5226 9720", 0, SIZE_MAX)); Assert::IsTrue(p.match("SI56 0231 2001 5226 9720", 0, SIZE_MAX));
Assert::AreEqual(stdex::interval<size_t>(0, 23), p.interval); Assert::AreEqual(stdex::interval<size_t>(0, 23), p.interval);
@ -366,8 +364,8 @@ namespace UnitTests
} }
{ {
sgml_space_cp space(false, locale_slSI); stdex::parser::sgml_space_cp space(false, locale_slSI);
sgml_creditor_reference p(make_shared_no_delete(&space), locale_slSI); stdex::parser::sgml_creditor_reference p(stdex::make_shared_no_delete(&space), locale_slSI);
Assert::IsTrue(p.match("RF18539007547034", 0, SIZE_MAX)); Assert::IsTrue(p.match("RF18539007547034", 0, SIZE_MAX));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::AreEqual("18", p.check_digits); Assert::AreEqual("18", p.check_digits);
@ -378,7 +376,7 @@ namespace UnitTests
Assert::AreEqual("000000000539007547034", p.reference); Assert::AreEqual("000000000539007547034", p.reference);
Assert::IsFalse(p.match("rf18 5390 0754 7034", 0, SIZE_MAX)); Assert::IsFalse(p.match("rf18 5390 0754 7034", 0, SIZE_MAX));
Assert::IsFalse(p.is_valid); Assert::IsFalse(p.is_valid);
Assert::IsTrue(p.match("rf18 5390 0754 7034", 0, SIZE_MAX, match_case_insensitive)); Assert::IsTrue(p.match("rf18 5390 0754 7034", 0, SIZE_MAX, stdex::parser::match_case_insensitive));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::IsTrue(p.match("RF18 5390 0754 70340", 0, SIZE_MAX)); Assert::IsTrue(p.match("RF18 5390 0754 70340", 0, SIZE_MAX));
Assert::IsFalse(p.is_valid); Assert::IsFalse(p.is_valid);
@ -389,8 +387,8 @@ namespace UnitTests
} }
{ {
sgml_space_cp space(false, locale_slSI); stdex::parser::sgml_space_cp space(false, locale_slSI);
sgml_si_reference p(make_shared_no_delete(&space), locale_slSI); stdex::parser::sgml_si_reference p(stdex::make_shared_no_delete(&space), locale_slSI);
Assert::IsTrue(p.match("SI121234567890120", 0, SIZE_MAX)); Assert::IsTrue(p.match("SI121234567890120", 0, SIZE_MAX));
Assert::IsTrue(p.is_valid); Assert::IsTrue(p.is_valid);
Assert::AreEqual("12", p.model); Assert::AreEqual("12", p.model);
@ -400,7 +398,7 @@ namespace UnitTests
Assert::AreEqual("12", p.model); Assert::AreEqual("12", p.model);
Assert::AreEqual(stdex::interval<size_t>(5, 18), p.part1.interval); Assert::AreEqual(stdex::interval<size_t>(5, 18), p.part1.interval);
Assert::IsFalse(p.match("si12 1234567890120", 0, SIZE_MAX)); Assert::IsFalse(p.match("si12 1234567890120", 0, SIZE_MAX));
Assert::IsTrue(p.match("si12 1234567890120", 0, SIZE_MAX, match_case_insensitive)); Assert::IsTrue(p.match("si12 1234567890120", 0, SIZE_MAX, stdex::parser::match_case_insensitive));
Assert::IsTrue(p.match("...SI12 1234567890120...", 3, SIZE_MAX)); Assert::IsTrue(p.match("...SI12 1234567890120...", 3, SIZE_MAX));
Assert::IsTrue(p.match("SI12&nbsp;1234567890120", 0, SIZE_MAX)); Assert::IsTrue(p.match("SI12&nbsp;1234567890120", 0, SIZE_MAX));
} }
@ -429,7 +427,7 @@ namespace UnitTests
"\r\n"; "\r\n";
{ {
http_request p(locale); stdex::parser::http_request p(locale);
Assert::IsTrue(p.match(request)); Assert::IsTrue(p.match(request));
Assert::AreEqual((size_t)0, p.interval.start); Assert::AreEqual((size_t)0, p.interval.start);
Assert::AreEqual((size_t)14, p.interval.end); Assert::AreEqual((size_t)14, p.interval.end);
@ -443,10 +441,10 @@ namespace UnitTests
} }
{ {
std::list<http_header> hdrs; list<stdex::parser::http_header> hdrs;
size_t offset = 14; size_t offset = 14;
for (;;) { for (;;) {
http_header h; stdex::parser::http_header h;
if (h.match(request, offset)) { if (h.match(request, offset)) {
offset = h.interval.end; offset = h.interval.end;
hdrs.push_back(std::move(h)); hdrs.push_back(std::move(h));
@ -455,19 +453,19 @@ namespace UnitTests
break; break;
} }
Assert::AreEqual((size_t)15, hdrs.size()); Assert::AreEqual((size_t)15, hdrs.size());
http_weighted_collection<http_weighted_value<http_language>> langs; stdex::parser::http_weighted_collection<stdex::parser::http_weighted_value<stdex::parser::http_language>> langs;
for (const auto& h : hdrs) for (const auto& h : hdrs)
if (strnicmp(request + h.name.start, h.name.size(), "Accept-Language", SIZE_MAX, locale) == 0) if (stdex::strnicmp(request + h.name.start, h.name.size(), "Accept-Language", SIZE_MAX, locale) == 0)
langs.insert(request, h.value.start, h.value.end); langs.insert(request, h.value.start, h.value.end);
Assert::IsTrue(!langs.empty()); Assert::IsTrue(!langs.empty());
{ {
const vector<std::string> control = { const vector<string> control = {
"sl", "en-US", "en", "de-DE", "de" "sl", "en-US", "en", "de-DE", "de"
}; };
auto c = control.cbegin(); auto c = control.cbegin();
auto l = langs.cbegin(); auto l = langs.cbegin();
for (; c != control.cend() && l != langs.cend(); ++c, ++l) for (; c != control.cend() && l != langs.cend(); ++c, ++l)
Assert::IsTrue(strnicmp(request + l->value.interval.start, l->value.interval.size(), c->c_str(), c->size(), locale) == 0); Assert::IsTrue(stdex::strnicmp(request + l->value.interval.start, l->value.interval.size(), c->c_str(), c->size(), locale) == 0);
Assert::IsTrue(c == control.cend()); Assert::IsTrue(c == control.cend());
Assert::IsTrue(l == langs.cend()); Assert::IsTrue(l == langs.cend());
} }

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -12,7 +12,7 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTests namespace UnitTests
{ {
constexpr size_t capacity = 50; constexpr size_t pool_capacity = 50;
TEST_CLASS(pool) TEST_CLASS(pool)
{ {
@ -24,15 +24,15 @@ namespace UnitTests
pool_t pool; pool_t pool;
list<thread> workers; list<thread> workers;
for (auto n = thread::hardware_concurrency(); n--; ) { for (auto n = thread::hardware_concurrency(); n--; ) {
workers.push_back(std::move(thread([](_Inout_ pool_t& pool) workers.push_back(thread([](_Inout_ pool_t& pool)
{ {
for (size_t n = 10000; n--; ) { for (size_t n = 10000; n--; ) {
worker_t el = move(pool.pop()); worker_t el = pool.pop();
if (!el) if (!el)
el.reset(new int(1)); el.reset(new int(1));
pool.push(move(el)); pool.push(std::move(el));
} }
}, ref(pool)))); }, ref(pool)));
} }
for (auto& w : workers) for (auto& w : workers)

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -12,20 +12,20 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTests namespace UnitTests
{ {
constexpr size_t capacity = 50; constexpr size_t ring_capacity = 50;
TEST_CLASS(ring) TEST_CLASS(ring)
{ {
public: public:
TEST_METHOD(test) TEST_METHOD(test)
{ {
using ring_t = stdex::ring<int, capacity>; using ring_t = stdex::ring<int, ring_capacity>;
ring_t ring; ring_t ring;
thread writer([](_Inout_ ring_t& ring) thread writer([](_Inout_ ring_t& ring)
{ {
int seed = 0; int seed = 0;
for (size_t retries = 1000; retries--;) { for (size_t retries = 1000; retries--;) {
for (auto to_write = static_cast<size_t>(static_cast<uint64_t>(::rand()) * capacity / 5 / RAND_MAX); to_write;) { for (auto to_write = static_cast<size_t>(static_cast<uint64_t>(::rand()) * ring_capacity / 5 / RAND_MAX); to_write;) {
int* ptr; size_t num_write; int* ptr; size_t num_write;
tie(ptr, num_write) = ring.back(); tie(ptr, num_write) = ring.back();
if (to_write < num_write) if (to_write < num_write)

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -6,8 +6,6 @@
#include "pch.hpp" #include "pch.hpp"
using namespace std; using namespace std;
using namespace stdex;
using namespace stdex::stream;
#ifdef _WIN32 #ifdef _WIN32
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
#endif #endif
@ -20,9 +18,9 @@ namespace UnitTests
TEST_METHOD(async) TEST_METHOD(async)
{ {
constexpr uint32_t total = 1000; constexpr uint32_t total = 1000;
memory_file source(mul(total, sizeof(uint32_t))); stdex::stream::memory_file source(stdex::mul(total, sizeof(uint32_t)));
{ {
async_writer<70> writer(source); stdex::stream::async_writer<70> writer(source);
for (uint32_t i = 0; i < total; ++i) { for (uint32_t i = 0; i < total; ++i) {
Assert::IsTrue(writer.ok()); Assert::IsTrue(writer.ok());
writer << i; writer << i;
@ -30,7 +28,7 @@ namespace UnitTests
} }
Assert::AreEqual<stdex::stream::fpos_t>(0, source.seekbeg(0)); Assert::AreEqual<stdex::stream::fpos_t>(0, source.seekbeg(0));
{ {
async_reader<50> reader(source); stdex::stream::async_reader<50> reader(source);
uint32_t x; uint32_t x;
for (uint32_t i = 0; i < total; ++i) { for (uint32_t i = 0; i < total; ++i) {
reader >> x; reader >> x;
@ -46,24 +44,24 @@ namespace UnitTests
{ {
constexpr uint32_t total = 1000; constexpr uint32_t total = 1000;
memory_file f1(mul(total, sizeof(uint32_t))); stdex::stream::memory_file f1(stdex::mul(total, sizeof(uint32_t)));
sstring filename2, filename3; stdex::sstring filename2, filename3;
filename2 = filename3 = temp_path(); filename2 = filename3 = temp_path();
filename2 += _T("stdex-stream-replicator-2.tmp"); filename2 += _T("stdex-stream-replicator-2.tmp");
file f2( stdex::stream::file f2(
filename2.c_str(), filename2.c_str(),
mode_for_reading | mode_for_writing | mode_create | mode_binary); stdex::stream::mode_for_reading | stdex::stream::mode_for_writing | stdex::stream::mode_create | stdex::stream::mode_binary);
filename3 += _T("stdex-stream-replicator-3.tmp"); filename3 += _T("stdex-stream-replicator-3.tmp");
cached_file f3( stdex::stream::cached_file f3(
filename3.c_str(), filename3.c_str(),
mode_for_reading | mode_for_writing | mode_create | mode_binary, stdex::stream::mode_for_reading | stdex::stream::mode_for_writing | stdex::stream::mode_create | stdex::stream::mode_binary,
128); 128);
{ {
stdex::stream::replicator writer; stdex::stream::replicator writer;
buffer f2_buf(f2, 0, 32); stdex::stream::buffer f2_buf(f2, 0, 32);
writer.push_back(&f1); writer.push_back(&f1);
writer.push_back(&f2_buf); writer.push_back(&f2_buf);
writer.push_back(&f3); writer.push_back(&f3);
@ -77,7 +75,7 @@ namespace UnitTests
f2.seekbeg(0); f2.seekbeg(0);
f3.seekbeg(0); f3.seekbeg(0);
{ {
buffer f2_buf(f2, 64, 0); stdex::stream::buffer f2_buf(f2, 64, 0);
uint32_t x; uint32_t x;
for (uint32_t i = 0; i < total; ++i) { for (uint32_t i = 0; i < total; ++i) {
f1 >> x; f1 >> x;
@ -106,17 +104,17 @@ namespace UnitTests
TEST_METHOD(open_close) TEST_METHOD(open_close)
{ {
cached_file dat(invalid_handle, state_t::fail, 4096); stdex::stream::cached_file dat(stdex::invalid_handle, stdex::stream::state_t::fail, 4096);
const sstring filepath = temp_path(); const stdex::sstring filepath = temp_path();
constexpr uint32_t count = 3; constexpr uint32_t count = 3;
sstring filename[count]; stdex::sstring filename[count];
stdex::stream::fpos_t start[count]; stdex::stream::fpos_t start[count];
for (uint32_t i = 0; i < count; ++i) { for (uint32_t i = 0; i < count; ++i) {
filename[i] = filepath + sprintf(_T("stdex-stream-open_close%u.tmp"), NULL, i); filename[i] = filepath + stdex::sprintf(_T("stdex-stream-open_close%u.tmp"), NULL, i);
dat.open(filename[i].c_str(), mode_for_reading | mode_for_writing | share_none | mode_preserve_existing | mode_binary); dat.open(filename[i].c_str(), stdex::stream::mode_for_reading | stdex::stream::mode_for_writing | stdex::stream::share_none | stdex::stream::mode_preserve_existing | stdex::stream::mode_binary);
Assert::IsTrue(dat.ok()); Assert::IsTrue(dat.ok());
start[i] = dat.tell(); start[i] = dat.tell();
Assert::AreNotEqual(fpos_max, start[i]); Assert::AreNotEqual(stdex::stream::fpos_max, start[i]);
for (uint32_t j = 0; j < 31 + 11 * i; ++j) { for (uint32_t j = 0; j < 31 + 11 * i; ++j) {
dat << j * count + i; dat << j * count + i;
Assert::IsTrue(dat.ok()); Assert::IsTrue(dat.ok());
@ -124,7 +122,7 @@ namespace UnitTests
dat.close(); dat.close();
} }
for (uint32_t i = 0; i < count; ++i) { for (uint32_t i = 0; i < count; ++i) {
dat.open(filename[i].c_str(), mode_for_reading | mode_open_existing | share_none | mode_binary); dat.open(filename[i].c_str(), stdex::stream::mode_for_reading | stdex::stream::mode_open_existing | stdex::stream::share_none | stdex::stream::mode_binary);
Assert::IsTrue(dat.ok()); Assert::IsTrue(dat.ok());
for (;;) { for (;;) {
uint32_t x; uint32_t x;
@ -141,13 +139,13 @@ namespace UnitTests
TEST_METHOD(file_stat) TEST_METHOD(file_stat)
{ {
sstring path(temp_path()); stdex::sstring path(temp_path());
Assert::IsTrue(stdex::stream::file::exists(path)); Assert::IsTrue(stdex::stream::file::exists(path));
Assert::IsFalse(stdex::stream::file::readonly(path)); Assert::IsFalse(stdex::stream::file::readonly(path));
} }
protected: protected:
static sstring temp_path() static stdex::sstring temp_path()
{ {
#ifdef _WIN32 #ifdef _WIN32
TCHAR temp_path[MAX_PATH]; TCHAR temp_path[MAX_PATH];

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -17,19 +17,23 @@ namespace UnitTests
public: public:
TEST_METHOD(sprintf) TEST_METHOD(sprintf)
{ {
Assert::AreEqual(L"This is a test.", stdex::sprintf(L"This is %s.", stdex::locale_default, L"a test").c_str()); Assert::AreEqual(L"This is a test.", stdex::sprintf(L"This is %ls.", stdex::locale_default, L"a test").c_str());
Assert::AreEqual<size_t>(15, stdex::sprintf(L"This is %s.", stdex::locale_default, L"a test").size()); Assert::AreEqual<size_t>(15, stdex::sprintf(L"This is %ls.", stdex::locale_default, L"a test").size());
Assert::AreEqual("This is a test.", stdex::sprintf("This is %s.", stdex::locale_default, "a test").c_str()); Assert::AreEqual("This is a test.", stdex::sprintf("This is %s.", stdex::locale_default, "a test").c_str());
Assert::AreEqual<size_t>(15, stdex::sprintf("This is %s.", stdex::locale_default, "a test").size()); Assert::AreEqual<size_t>(15, stdex::sprintf("This is %s.", stdex::locale_default, "a test").size());
// swprintf functions return EILSEQ when %ls inserts contain emoji on Mac. 😢
Assert::AreEqual(L"This is a tést.", stdex::sprintf(L"This is %ls.", stdex::locale_default, L"a tést").c_str());
Assert::AreEqual("This is a 🐔Test🐮.", stdex::sprintf("This is %s.", stdex::locale_default, "a 🐔Test🐮").c_str());
wstring wstr; wstring wstr;
std::string str; std::string str;
for (size_t i = 0; i < 2000; i++) { for (size_t i = 0; i < 2000; i++) {
wstr += L"🐔Test🐮\r\n"; wstr += L"tést\r\n";
str += "🐔Test🐮\r\n"; str += "🐔Test🐮\r\n";
} }
Assert::AreEqual(wstr.c_str(), stdex::sprintf(L"%s", stdex::locale_default, wstr.data()).c_str()); Assert::AreEqual(wstr.c_str(), stdex::sprintf(L"%ls", stdex::locale_default, wstr.data()).c_str());
Assert::AreEqual(wstr.size(), stdex::sprintf(L"%s", stdex::locale_default, wstr.data()).size()); Assert::AreEqual(wstr.size(), stdex::sprintf(L"%ls", stdex::locale_default, wstr.data()).size());
Assert::AreEqual(str.c_str(), stdex::sprintf("%s", stdex::locale_utf8, str.data()).c_str()); Assert::AreEqual(str.c_str(), stdex::sprintf("%s", stdex::locale_utf8, str.data()).c_str());
Assert::AreEqual(str.size(), stdex::sprintf("%s", stdex::locale_utf8, str.data()).size()); Assert::AreEqual(str.size(), stdex::sprintf("%s", stdex::locale_utf8, str.data()).size());
} }

View File

@ -8,7 +8,8 @@
using namespace std; using namespace std;
#ifdef _WIN32 #ifdef _WIN32
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;
#else #endif
#ifdef __GNUC__
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
@ -102,6 +103,6 @@ namespace UnitTests
}; };
} }
#ifndef _WIN32 #ifdef __GNUC__
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2016-2024 Amebis Copyright © 2016-2024 Amebis
*/ */
@ -820,8 +820,9 @@ namespace stdex
case element_t::big: case element_t::big:
case element_t::small: case element_t::small:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -844,8 +845,9 @@ namespace stdex
case element_t::acronym: case element_t::acronym:
case element_t::xmp: case element_t::xmp:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -877,8 +879,9 @@ namespace stdex
case element_t::iframe: case element_t::iframe:
case element_t::nobr: case element_t::nobr:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -895,8 +898,9 @@ namespace stdex
case element_t::label: case element_t::label:
case element_t::button: case element_t::button:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -929,8 +933,9 @@ namespace stdex
case element_t::h5: case element_t::h5:
case element_t::h6: case element_t::h6:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -946,8 +951,9 @@ namespace stdex
case element_t::dir: case element_t::dir:
case element_t::menu: case element_t::menu:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -961,9 +967,10 @@ namespace stdex
case element_t::pre: case element_t::pre:
case element_t::listing: case element_t::listing:
return true; return true;
} default:
return false; return false;
} }
}
/// ///
/// Is element typically displayed as a stand-alone section of text? /// Is element typically displayed as a stand-alone section of text?
@ -992,8 +999,9 @@ namespace stdex
case element_t::fieldset: case element_t::fieldset:
case element_t::address: case element_t::address:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -1019,8 +1027,9 @@ namespace stdex
case element_t::base: case element_t::base:
case element_t::nextid: case element_t::nextid:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -1037,12 +1046,13 @@ namespace stdex
case element_t::link: case element_t::link:
case element_t::object: case element_t::object:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
/// May element be a part of <pre>? /// May element be a part of `<pre></pre>`?
/// ///
/// \param[in] code Element code /// \param[in] code Element code
/// ///
@ -1062,8 +1072,9 @@ namespace stdex
case element_t::basefont: case element_t::basefont:
case element_t::nobr: case element_t::nobr:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -1078,8 +1089,9 @@ namespace stdex
case element_t::body: case element_t::body:
case element_t::frameset: case element_t::frameset:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -1105,8 +1117,9 @@ namespace stdex
case element_t::th: case element_t::th:
case element_t::tr: case element_t::tr:
return true; return true;
}; default:
return false; return false;
};
} }
/// ///
@ -1205,8 +1218,8 @@ namespace stdex
case element_t::ul: return child == element_t::li; case element_t::ul: return child == element_t::li;
case element_t::wbr: return false; case element_t::wbr: return false;
case element_t::unknown: return true; case element_t::unknown: return true;
default: return false;
} }
return false;
} }
/// ///
@ -1260,8 +1273,8 @@ namespace stdex
case element_t::table: return !stdex::strnicmp(attr_name, num_chars, "background", SIZE_MAX); case element_t::table: return !stdex::strnicmp(attr_name, num_chars, "background", SIZE_MAX);
case element_t::td: return !stdex::strnicmp(attr_name, num_chars, "background", SIZE_MAX); case element_t::td: return !stdex::strnicmp(attr_name, num_chars, "background", SIZE_MAX);
case element_t::th: return !stdex::strnicmp(attr_name, num_chars, "background", SIZE_MAX); case element_t::th: return !stdex::strnicmp(attr_name, num_chars, "background", SIZE_MAX);
default: return false;
} }
return false;
} }
/// ///
@ -1286,8 +1299,8 @@ namespace stdex
case element_t::table: return !stdex::strnicmp(attr_name, num_chars, "summary", SIZE_MAX); case element_t::table: return !stdex::strnicmp(attr_name, num_chars, "summary", SIZE_MAX);
case element_t::td: return !stdex::strnicmp(attr_name, num_chars, "abbr", SIZE_MAX); case element_t::td: return !stdex::strnicmp(attr_name, num_chars, "abbr", SIZE_MAX);
case element_t::th: return !stdex::strnicmp(attr_name, num_chars, "abbr", SIZE_MAX); case element_t::th: return !stdex::strnicmp(attr_name, num_chars, "abbr", SIZE_MAX);
default: return false;
} }
return false;
} }
}; };
@ -1754,6 +1767,7 @@ namespace stdex
case element_t::style: case element_t::style:
m_is_special_element = true; m_is_special_element = true;
break; break;
default:;
} }
} }
} }
@ -1793,7 +1807,7 @@ namespace stdex
auto starting_tag = m_element_stack[j]; auto starting_tag = m_element_stack[j];
_Assume_(starting_tag && starting_tag->type == stdex::parser::html_sequence_t::element_start); _Assume_(starting_tag && starting_tag->type == stdex::parser::html_sequence_t::element_start);
if (starting_tag->code == e->code || if (starting_tag->code == e->code ||
starting_tag->code == element_t::unknown && e->code == element_t::unknown && !stdex::strnicmp(source + starting_tag->name.start, starting_tag->name.size(), source + e->name.start, e->name.size())) (starting_tag->code == element_t::unknown && e->code == element_t::unknown && !stdex::strnicmp(source + starting_tag->name.start, starting_tag->name.size(), source + e->name.start, e->name.size())))
{ {
e->start = starting_tag; e->start = starting_tag;
e->parent = starting_tag->parent; e->parent = starting_tag->parent;
@ -2098,7 +2112,7 @@ namespace stdex
_In_opt_ stdex::html::sequence* sequence = nullptr, _In_opt_ stdex::html::sequence* sequence = nullptr,
_In_opt_ stdex::html::sequence* _end_sequence = nullptr, _In_opt_ stdex::html::sequence* _end_sequence = nullptr,
_In_ uintptr_t data = 0) : _In_ uintptr_t data = 0) :
text_token(token_t::starting, _text, num_chars_text, text_type, sequence, data), text_token<T, TR, AX>(token_t::starting, _text, num_chars_text, text_type, sequence, data),
name(_name, num_chars_name), name(_name, num_chars_name),
end_sequence(_end_sequence) end_sequence(_end_sequence)
{} {}
@ -2621,8 +2635,8 @@ namespace stdex
start = m_css_cdc.interval.end; start = m_css_cdc.interval.end;
} }
else if ( else if (
m_css_import.match(m_source, start, end) && (section = m_css_import.interval, content = m_css_import.content, true) || (m_css_import.match(m_source, start, end) && ((void)(section = m_css_import.interval), (void)(content = m_css_import.content), true)) ||
m_css_uri.match(m_source, start, end) && (section = m_css_uri.interval, content = m_css_uri.content, true)) (m_css_uri.match(m_source, start, end) && ((void)(section = m_css_uri.interval), (void)(content = m_css_uri.content), true)))
{ {
std::unique_ptr<url_token<T, TR, AX>> t_url( std::unique_ptr<url_token<T, TR, AX>> t_url(
new url_token<T, TR, AX>( new url_token<T, TR, AX>(

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2016-2024 Amebis Copyright © 2016-2024 Amebis
*/ */
@ -75,12 +75,14 @@ namespace stdex
{} {}
locale(_In_ int category, _In_z_ const char* locale) : locale(_In_ int category, _In_z_ const char* locale) :
locale(create_locale(category, locale)) stdex::locale(create_locale(category, locale))
{} {}
#ifdef _WIN32
locale(_In_ int category, _In_z_ const wchar_t* locale) : locale(_In_ int category, _In_z_ const wchar_t* locale) :
locale(create_locale(category, locale)) stdex::locale(create_locale(category, locale))
{} {}
#endif
operator locale_t() const { return get(); } operator locale_t() const { return get(); }
}; };

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -7371,7 +7371,7 @@ namespace stdex
virtual void invalidate() virtual void invalidate()
{ {
this->content.invalidate(); this->content.invalidate();
basic_parser::invalidate(); basic_parser<T>::invalidate();
} }
stdex::interval<size_t> content; ///< content position in source stdex::interval<size_t> content; ///< content position in source
@ -7506,7 +7506,7 @@ namespace stdex
virtual void invalidate() virtual void invalidate()
{ {
this->content.invalidate(); this->content.invalidate();
basic_parser::invalidate(); basic_parser<T>::invalidate();
} }
stdex::interval<size_t> content; ///< content position in source stdex::interval<size_t> content; ///< content position in source
@ -7573,7 +7573,7 @@ namespace stdex
virtual void invalidate() virtual void invalidate()
{ {
this->content.invalidate(); this->content.invalidate();
basic_parser::invalidate(); basic_parser<T>::invalidate();
} }
stdex::interval<size_t> content; ///< content position in source stdex::interval<size_t> content; ///< content position in source
@ -7598,7 +7598,7 @@ namespace stdex
this->interval.end = this->interval.end + 4; this->interval.end = this->interval.end + 4;
// Skip whitespace. // Skip whitespace.
const auto& ctype = std::use_facet<std::ctype<T>>(m_locale); const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++); for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
if (this->interval.end < end && if (this->interval.end < end &&
@ -7683,7 +7683,7 @@ namespace stdex
virtual void invalidate() virtual void invalidate()
{ {
this->content.invalidate(); this->content.invalidate();
basic_parser::invalidate(); basic_parser<T>::invalidate();
} }
stdex::interval<size_t> content; ///< content position in source stdex::interval<size_t> content; ///< content position in source
@ -7711,7 +7711,7 @@ namespace stdex
this->interval.end = this->interval.end + 7; this->interval.end = this->interval.end + 7;
// Skip whitespace. // Skip whitespace.
const auto& ctype = std::use_facet<std::ctype<T>>(m_locale); const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++); for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
if (this->interval.end < end && if (this->interval.end < end &&
@ -7769,7 +7769,7 @@ namespace stdex
this->base_type.invalidate(); this->base_type.invalidate();
this->sub_type.invalidate(); this->sub_type.invalidate();
this->charset.invalidate(); this->charset.invalidate();
basic_parser::invalidate(); basic_parser<T>::invalidate();
} }
stdex::interval<size_t> base_type; ///< basic type position in source stdex::interval<size_t> base_type; ///< basic type position in source
@ -7784,7 +7784,7 @@ namespace stdex
_In_ int flags = match_multiline) _In_ int flags = match_multiline)
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
const auto& ctype = std::use_facet<std::ctype<T>>(m_locale); const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
this->interval.end = start; this->interval.end = start;
this->base_type.start = this->interval.end; this->base_type.start = this->interval.end;
@ -7904,7 +7904,7 @@ namespace stdex
_In_ int flags = match_default) _In_ int flags = match_default)
{ {
_Unreferenced_(flags); _Unreferenced_(flags);
const auto& ctype = std::use_facet<std::ctype<T>>(m_locale); const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
this->interval.end = start; this->interval.end = start;
for (;;) { for (;;) {
_Assume_(text || this->interval.end >= end); _Assume_(text || this->interval.end >= end);
@ -7918,7 +7918,7 @@ namespace stdex
} }
if (text[this->interval.end] == '>' || if (text[this->interval.end] == '>' ||
text[this->interval.end] == '=' || text[this->interval.end] == '=' ||
text[this->interval.end] == '/' && this->interval.end + 1 < end && text[this->interval.end + 1] == '>' || (text[this->interval.end] == '/' && this->interval.end + 1 < end && text[this->interval.end + 1] == '>') ||
ctype.is(ctype.space, text[this->interval.end])) ctype.is(ctype.space, text[this->interval.end]))
{ {
this->interval.start = start; this->interval.start = start;
@ -7947,7 +7947,7 @@ namespace stdex
virtual void invalidate() virtual void invalidate()
{ {
this->content.invalidate(); this->content.invalidate();
basic_parser::invalidate(); basic_parser<T>::invalidate();
} }
stdex::interval<size_t> content; ///< content position in source stdex::interval<size_t> content; ///< content position in source
@ -7988,7 +7988,7 @@ namespace stdex
// Nonquoted // Nonquoted
this->content.start = this->interval.end; this->content.start = this->interval.end;
const auto& ctype = std::use_facet<std::ctype<T>>(m_locale); const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
for (;;) { for (;;) {
_Assume_(text || this->interval.end >= end); _Assume_(text || this->interval.end >= end);
if (this->interval.end >= end || !text[this->interval.end]) { if (this->interval.end >= end || !text[this->interval.end]) {
@ -7997,7 +7997,7 @@ namespace stdex
return true; return true;
} }
if (text[this->interval.end] == '>' || if (text[this->interval.end] == '>' ||
text[this->interval.end] == '/' && this->interval.end + 1 < end && text[this->interval.end + 1] == '>' || (text[this->interval.end] == '/' && this->interval.end + 1 < end && text[this->interval.end + 1] == '>') ||
ctype.is(ctype.space, text[this->interval.end])) ctype.is(ctype.space, text[this->interval.end]))
{ {
this->content.end = this->interval.end; this->content.end = this->interval.end;
@ -8050,7 +8050,7 @@ namespace stdex
{ {
public: public:
basic_html_tag(_In_ const std::locale& locale = std::locale()) : basic_html_tag(_In_ const std::locale& locale = std::locale()) :
basic_parser(locale), basic_parser<T>(locale),
type(html_sequence_t::unknown) type(html_sequence_t::unknown)
{} {}
@ -8059,7 +8059,7 @@ namespace stdex
this->type = html_sequence_t::unknown; this->type = html_sequence_t::unknown;
this->name.invalidate(); this->name.invalidate();
this->attributes.clear(); this->attributes.clear();
basic_parser::invalidate(); basic_parser<T>::invalidate();
} }
html_sequence_t type; ///< tag type html_sequence_t type; ///< tag type
@ -8157,8 +8157,9 @@ namespace stdex
else else
goto error; goto error;
{
// Skip whitespace. // Skip whitespace.
const auto& ctype = std::use_facet<std::ctype<T>>(m_locale); const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++); for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
this->attributes.clear(); this->attributes.clear();
@ -8255,6 +8256,7 @@ namespace stdex
a->value.invalidate(); a->value.invalidate();
} }
} }
}
this->interval.start = start; this->interval.start = start;
return true; return true;
@ -8286,7 +8288,7 @@ namespace stdex
virtual void invalidate() virtual void invalidate()
{ {
this->condition.invalidate(); this->condition.invalidate();
basic_parser::invalidate(); basic_parser<T>::invalidate();
} }
stdex::interval<size_t> condition; /// condition position in source stdex::interval<size_t> condition; /// condition position in source
@ -8308,7 +8310,7 @@ namespace stdex
this->interval.end = start + 3; this->interval.end = start + 3;
// Skip whitespace. // Skip whitespace.
const auto& ctype = std::use_facet<std::ctype<T>>(m_locale); const auto& ctype = std::use_facet<std::ctype<T>>(this->m_locale);
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++); for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
this->condition.start = this->condition.end = this->interval.end; this->condition.start = this->condition.end = this->interval.end;

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -7,7 +7,9 @@
#include "compat.hpp" #include "compat.hpp"
#include "spinlock.hpp" #include "spinlock.hpp"
#ifdef _WIN32
#include "windows.h" #include "windows.h"
#endif
#include <list> #include <list>
#include <map> #include <map>
#include <mutex> #include <mutex>
@ -39,11 +41,13 @@ namespace stdex
private: private:
static numaid_t numa_node() static numaid_t numa_node()
{ {
#ifdef _WIN32 #if defined(_WIN32)
PROCESSOR_NUMBER Processor; PROCESSOR_NUMBER Processor;
GetCurrentProcessorNumberEx(&Processor); GetCurrentProcessorNumberEx(&Processor);
USHORT NodeNumber = 0; USHORT NodeNumber = 0;
return GetNumaProcessorNodeEx(&Processor, &NodeNumber) ? NodeNumber : 0; return GetNumaProcessorNodeEx(&Processor, &NodeNumber) ? NodeNumber : 0;
#elif defined(__APPLE__)
return 0;
#else #else
return numa_node_of_cpu(sched_getcpu()); return numa_node_of_cpu(sched_getcpu());
#endif #endif

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -207,7 +207,7 @@ namespace stdex
virtual bool cancel() virtual bool cancel()
{ {
return return
m_host && m_host->cancel() || (m_host && m_host->cancel()) ||
m_deadline < std::chrono::high_resolution_clock::now(); m_deadline < std::chrono::high_resolution_clock::now();
} }

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -43,7 +43,7 @@ namespace stdex
#elif _M_IX86 || _M_X64 #elif _M_IX86 || _M_X64
_mm_pause(); _mm_pause();
#elif __aarch64__ #elif __aarch64__
__yield(); asm volatile("yield");
#elif __i386__ || __x86_64__ #elif __i386__ || __x86_64__
__builtin_ia32_pause(); __builtin_ia32_pause();
#endif #endif

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -2408,8 +2408,8 @@ namespace stdex
_Assume_(data || !length); _Assume_(data || !length);
constexpr int block_size = 0x10000000; constexpr int block_size = 0x10000000;
for (size_t to_read = length;;) { for (size_t to_read = length;;) {
int num_read = recv(m_h, reinterpret_cast<char*>(data), static_cast<int>(std::min<size_t>(to_read, block_size)), 0); auto num_read = recv(m_h, reinterpret_cast<char*>(data), static_cast<int>(std::min<size_t>(to_read, block_size)), 0);
if (num_read == SOCKET_ERROR) _Unlikely_ { if (num_read == -1) _Unlikely_ {
m_state = to_read < length ? state_t::ok : state_t::fail; m_state = to_read < length ? state_t::ok : state_t::fail;
return length - to_read; return length - to_read;
} }
@ -2432,8 +2432,8 @@ namespace stdex
_Assume_(data || !length); _Assume_(data || !length);
constexpr int block_size = 0x10000000; constexpr int block_size = 0x10000000;
for (size_t to_write = length;;) { for (size_t to_write = length;;) {
int num_written = send(m_h, reinterpret_cast<const char*>(data), static_cast<int>(std::min<size_t>(to_write, block_size)), 0); auto num_written = send(m_h, reinterpret_cast<const char*>(data), static_cast<int>(std::min<size_t>(to_write, block_size)), 0);
if (num_written == SOCKET_ERROR) _Unlikely_ { if (num_written == -1) _Unlikely_ {
m_state = state_t::fail; m_state = state_t::fail;
return length - to_write; return length - to_write;
} }

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2016-2024 Amebis Copyright © 2016-2024 Amebis
*/ */
@ -2328,7 +2328,7 @@ namespace stdex
#pragma warning(suppress: 4996) #pragma warning(suppress: 4996)
return _vsnprintf_l(str, capacity, format, locale, arg); return _vsnprintf_l(str, capacity, format, locale, arg);
#else #else
return ::vsnprintf(str, capacity, format, arg); return ::vsnprintf_l(str, capacity, locale, format, arg);
#endif #endif
} }
@ -2338,7 +2338,7 @@ namespace stdex
#pragma warning(suppress: 4996) #pragma warning(suppress: 4996)
return _vsnwprintf_l(str, capacity, format, locale, arg); return _vsnwprintf_l(str, capacity, format, locale, arg);
#else #else
return vswprintf(str, capacity, format, arg); return ::vswprintf_l(str, capacity, locale, format, arg);
#endif #endif
} }
/// \endcond /// \endcond
@ -2360,11 +2360,12 @@ namespace stdex
// Try with stack buffer first. // Try with stack buffer first.
int count = vsnprintf(buf, _countof(buf), format, locale, arg); int count = vsnprintf(buf, _countof(buf), format, locale, arg);
if (0 <= count && count < _countof(buf)) { if (0 <= count && count <= _countof(buf)) {
// Copy from stack. // Copy from stack.
str.append(buf, count); str.append(buf, count);
return count; return count;
} }
#ifdef _WIN32
if (count < 0) { if (count < 0) {
switch (errno) { switch (errno) {
case 0: case 0:
@ -2380,6 +2381,25 @@ namespace stdex
str.resize(offset + count); str.resize(offset + count);
if (vsnprintf(&str[offset], count + 1, format, locale, arg) != count) _Unlikely_ if (vsnprintf(&str[offset], count + 1, format, locale, arg) != count) _Unlikely_
throw std::runtime_error("failed to format string"); throw std::runtime_error("failed to format string");
#else
size_t offset = str.size();
for (size_t capacity = 2 * 1024 / sizeof(T);; capacity *= 2) {
switch (errno) {
case EOVERFLOW:
// Allocate on heap and retry.
str.resize(offset + capacity);
count = vsnprintf(&str[offset], capacity, format, locale, arg);
if (0 <= count && count <= capacity) {
str.resize(offset + count);
return count;
}
break;
case EINVAL: throw std::invalid_argument("invalid vsnprintf arguments");
case EILSEQ: throw std::runtime_error("encoding error");
default: throw std::runtime_error("failed to format string");
}
}
#endif
return count; return count;
} }
@ -2538,7 +2558,6 @@ namespace stdex
/// ///
/// Formats a time string using `strftime()`. /// Formats a time string using `strftime()`.
/// ///
/// \param[out] str String to append formatted time text
/// \param[in ] format String template using `strftime()` style /// \param[in ] format String template using `strftime()` style
/// \param[in ] time Time /// \param[in ] time Time
/// \param[in ] locale Stdlib locale used to perform formatting. Use `NULL` to use locale globally set by `setlocale()`. /// \param[in ] locale Stdlib locale used to perform formatting. Use `NULL` to use locale globally set by `setlocale()`.
@ -2619,7 +2638,7 @@ namespace stdex
template<class T, size_t N> template<class T, size_t N>
inline void strlwr(_Inout_ T (&str)[N]) inline void strlwr(_Inout_ T (&str)[N])
{ {
strlwr(str, count); strlwr(str, N);
} }
/// ///
@ -2631,7 +2650,7 @@ namespace stdex
template<class T, size_t N> template<class T, size_t N>
inline void strlwr(_Inout_ T (&str)[N], _In_ const std::locale& locale) inline void strlwr(_Inout_ T (&str)[N], _In_ const std::locale& locale)
{ {
strlwr(str, count, locale); strlwr(str, N, locale);
} }
/// ///

View File

@ -1,4 +1,4 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Copyright © 2023-2024 Amebis Copyright © 2023-2024 Amebis
*/ */
@ -7,7 +7,7 @@
#include "compat.hpp" #include "compat.hpp"
#include "system.hpp" #include "system.hpp"
#ifdef _WIN32 #if defined(_WIN32)
#include "windows.h" #include "windows.h"
#include <stdlib.h> #include <stdlib.h>
#include <tchar.h> #include <tchar.h>
@ -35,12 +35,12 @@ constexpr stdex::platform_id IMAGE_FILE_MACHINE_AMD64 = "x86_64";
constexpr stdex::platform_id IMAGE_FILE_MACHINE_ARMNT = "arm"; constexpr stdex::platform_id IMAGE_FILE_MACHINE_ARMNT = "arm";
constexpr stdex::platform_id IMAGE_FILE_MACHINE_ARM64 = "aarch64"; constexpr stdex::platform_id IMAGE_FILE_MACHINE_ARM64 = "aarch64";
inline bool operator ==(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a == b; } //inline bool operator ==(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a == b; }
inline bool operator !=(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a != b; } //inline bool operator !=(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a != b; }
inline bool operator <(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a == IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) < 0; } //inline bool operator <(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return (a == IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN) || (a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) < 0); }
inline bool operator <=(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a == IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) <= 0; } //inline bool operator <=(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a == IMAGE_FILE_MACHINE_UNKNOWN || (a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) <= 0); }
inline bool operator >(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a != IMAGE_FILE_MACHINE_UNKNOWN && b == IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) > 0; } //inline bool operator >(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return (a != IMAGE_FILE_MACHINE_UNKNOWN && b == IMAGE_FILE_MACHINE_UNKNOWN) || (a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) > 0); }
inline bool operator >=(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return b == IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) >= 0; } //inline bool operator >=(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return b == IMAGE_FILE_MACHINE_UNKNOWN || (a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) >= 0); }
#endif #endif
namespace stdex namespace stdex
@ -189,8 +189,8 @@ namespace stdex
} }
#elif defined(__APPLE__) #elif defined(__APPLE__)
{ {
gid_t gids[NGROUPS + 1]; // A user cannot be member in more than NGROUPS groups, not counting the default group (hence the + 1) gid_t gids[NGROUPS_MAX];
for (int i = 0, n = getgroups(_countof(gids), gids); i < n; ++i) { for (int i = 0, n = getgroups(NGROUPS_MAX, gids); i < n; ++i) {
struct group* group = getgrgid(gids[i]); struct group* group = getgrgid(gids[i]);
if (!group) continue; if (!group) continue;
if (strcmp(group->gr_name, "admin") == 0) { if (strcmp(group->gr_name, "admin") == 0) {

View File

@ -6,7 +6,7 @@
#pragma once #pragma once
#include "compat.hpp" #include "compat.hpp"
#ifdef _WIN32 #if defined(_WIN32)
#include "windows.h" #include "windows.h"
#include <oaidl.h> #include <oaidl.h>
#include <tchar.h> #include <tchar.h>

View File

@ -18,7 +18,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#ifndef _WIN32 #ifdef __GNUC__
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif #endif
@ -976,6 +976,6 @@ namespace stdex
#endif #endif
} }
#ifndef _WIN32 #ifdef __GNUC__
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif