@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2016-2024 Amebis
|
||||
*/
|
||||
@@ -820,8 +820,9 @@ namespace stdex
|
||||
case element_t::big:
|
||||
case element_t::small:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -844,8 +845,9 @@ namespace stdex
|
||||
case element_t::acronym:
|
||||
case element_t::xmp:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -877,8 +879,9 @@ namespace stdex
|
||||
case element_t::iframe:
|
||||
case element_t::nobr:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -895,8 +898,9 @@ namespace stdex
|
||||
case element_t::label:
|
||||
case element_t::button:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -929,8 +933,9 @@ namespace stdex
|
||||
case element_t::h5:
|
||||
case element_t::h6:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -946,8 +951,9 @@ namespace stdex
|
||||
case element_t::dir:
|
||||
case element_t::menu:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -961,8 +967,9 @@ namespace stdex
|
||||
case element_t::pre:
|
||||
case element_t::listing:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -992,8 +999,9 @@ namespace stdex
|
||||
case element_t::fieldset:
|
||||
case element_t::address:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -1019,8 +1027,9 @@ namespace stdex
|
||||
case element_t::base:
|
||||
case element_t::nextid:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -1037,12 +1046,13 @@ namespace stdex
|
||||
case element_t::link:
|
||||
case element_t::object:
|
||||
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
|
||||
///
|
||||
@@ -1062,8 +1072,9 @@ namespace stdex
|
||||
case element_t::basefont:
|
||||
case element_t::nobr:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -1078,8 +1089,9 @@ namespace stdex
|
||||
case element_t::body:
|
||||
case element_t::frameset:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -1105,8 +1117,9 @@ namespace stdex
|
||||
case element_t::th:
|
||||
case element_t::tr:
|
||||
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::wbr: return false;
|
||||
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::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);
|
||||
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::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);
|
||||
default: return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1754,6 +1767,7 @@ namespace stdex
|
||||
case element_t::style:
|
||||
m_is_special_element = true;
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1793,7 +1807,7 @@ namespace stdex
|
||||
auto starting_tag = m_element_stack[j];
|
||||
_Assume_(starting_tag && starting_tag->type == stdex::parser::html_sequence_t::element_start);
|
||||
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->parent = starting_tag->parent;
|
||||
@@ -2098,7 +2112,7 @@ namespace stdex
|
||||
_In_opt_ stdex::html::sequence* sequence = nullptr,
|
||||
_In_opt_ stdex::html::sequence* _end_sequence = nullptr,
|
||||
_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),
|
||||
end_sequence(_end_sequence)
|
||||
{}
|
||||
@@ -2621,8 +2635,8 @@ namespace stdex
|
||||
start = m_css_cdc.interval.end;
|
||||
}
|
||||
else if (
|
||||
m_css_import.match(m_source, start, end) && (section = m_css_import.interval, 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_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) && ((void)(section = m_css_uri.interval), (void)(content = m_css_uri.content), true)))
|
||||
{
|
||||
std::unique_ptr<url_token<T, TR, AX>> t_url(
|
||||
new url_token<T, TR, AX>(
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2016-2024 Amebis
|
||||
*/
|
||||
@@ -75,12 +75,14 @@ namespace stdex
|
||||
{}
|
||||
|
||||
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(create_locale(category, locale))
|
||||
stdex::locale(create_locale(category, locale))
|
||||
{}
|
||||
#endif
|
||||
|
||||
operator locale_t() const { return get(); }
|
||||
};
|
||||
@@ -109,4 +111,4 @@ namespace stdex
|
||||
""
|
||||
#endif
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023-2024 Amebis
|
||||
*/
|
||||
@@ -7371,7 +7371,7 @@ namespace stdex
|
||||
virtual void invalidate()
|
||||
{
|
||||
this->content.invalidate();
|
||||
basic_parser::invalidate();
|
||||
basic_parser<T>::invalidate();
|
||||
}
|
||||
|
||||
stdex::interval<size_t> content; ///< content position in source
|
||||
@@ -7506,7 +7506,7 @@ namespace stdex
|
||||
virtual void invalidate()
|
||||
{
|
||||
this->content.invalidate();
|
||||
basic_parser::invalidate();
|
||||
basic_parser<T>::invalidate();
|
||||
}
|
||||
|
||||
stdex::interval<size_t> content; ///< content position in source
|
||||
@@ -7573,7 +7573,7 @@ namespace stdex
|
||||
virtual void invalidate()
|
||||
{
|
||||
this->content.invalidate();
|
||||
basic_parser::invalidate();
|
||||
basic_parser<T>::invalidate();
|
||||
}
|
||||
|
||||
stdex::interval<size_t> content; ///< content position in source
|
||||
@@ -7598,7 +7598,7 @@ namespace stdex
|
||||
this->interval.end = this->interval.end + 4;
|
||||
|
||||
// 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++);
|
||||
|
||||
if (this->interval.end < end &&
|
||||
@@ -7683,7 +7683,7 @@ namespace stdex
|
||||
virtual void invalidate()
|
||||
{
|
||||
this->content.invalidate();
|
||||
basic_parser::invalidate();
|
||||
basic_parser<T>::invalidate();
|
||||
}
|
||||
|
||||
stdex::interval<size_t> content; ///< content position in source
|
||||
@@ -7711,7 +7711,7 @@ namespace stdex
|
||||
this->interval.end = this->interval.end + 7;
|
||||
|
||||
// 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++);
|
||||
|
||||
if (this->interval.end < end &&
|
||||
@@ -7769,7 +7769,7 @@ namespace stdex
|
||||
this->base_type.invalidate();
|
||||
this->sub_type.invalidate();
|
||||
this->charset.invalidate();
|
||||
basic_parser::invalidate();
|
||||
basic_parser<T>::invalidate();
|
||||
}
|
||||
|
||||
stdex::interval<size_t> base_type; ///< basic type position in source
|
||||
@@ -7784,7 +7784,7 @@ namespace stdex
|
||||
_In_ int flags = match_multiline)
|
||||
{
|
||||
_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->base_type.start = this->interval.end;
|
||||
@@ -7904,7 +7904,7 @@ namespace stdex
|
||||
_In_ int flags = match_default)
|
||||
{
|
||||
_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;
|
||||
for (;;) {
|
||||
_Assume_(text || this->interval.end >= end);
|
||||
@@ -7918,7 +7918,7 @@ namespace stdex
|
||||
}
|
||||
if (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]))
|
||||
{
|
||||
this->interval.start = start;
|
||||
@@ -7947,7 +7947,7 @@ namespace stdex
|
||||
virtual void invalidate()
|
||||
{
|
||||
this->content.invalidate();
|
||||
basic_parser::invalidate();
|
||||
basic_parser<T>::invalidate();
|
||||
}
|
||||
|
||||
stdex::interval<size_t> content; ///< content position in source
|
||||
@@ -7988,7 +7988,7 @@ namespace stdex
|
||||
|
||||
// Nonquoted
|
||||
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 (;;) {
|
||||
_Assume_(text || this->interval.end >= end);
|
||||
if (this->interval.end >= end || !text[this->interval.end]) {
|
||||
@@ -7997,7 +7997,7 @@ namespace stdex
|
||||
return true;
|
||||
}
|
||||
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]))
|
||||
{
|
||||
this->content.end = this->interval.end;
|
||||
@@ -8050,7 +8050,7 @@ namespace stdex
|
||||
{
|
||||
public:
|
||||
basic_html_tag(_In_ const std::locale& locale = std::locale()) :
|
||||
basic_parser(locale),
|
||||
basic_parser<T>(locale),
|
||||
type(html_sequence_t::unknown)
|
||||
{}
|
||||
|
||||
@@ -8059,7 +8059,7 @@ namespace stdex
|
||||
this->type = html_sequence_t::unknown;
|
||||
this->name.invalidate();
|
||||
this->attributes.clear();
|
||||
basic_parser::invalidate();
|
||||
basic_parser<T>::invalidate();
|
||||
}
|
||||
|
||||
html_sequence_t type; ///< tag type
|
||||
@@ -8157,102 +8157,104 @@ namespace stdex
|
||||
else
|
||||
goto error;
|
||||
|
||||
// Skip whitespace.
|
||||
const auto& ctype = std::use_facet<std::ctype<T>>(m_locale);
|
||||
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
|
||||
|
||||
this->attributes.clear();
|
||||
for (;;) {
|
||||
if (this->type == html_sequence_t::element_start &&
|
||||
this->interval.end + 1 < end &&
|
||||
text[this->interval.end] == '/' &&
|
||||
text[this->interval.end + 1] == '>')
|
||||
{
|
||||
// <tag .../>
|
||||
this->type = html_sequence_t::element;
|
||||
this->interval.end = this->interval.end + 2;
|
||||
break;
|
||||
}
|
||||
if (this->interval.end < end &&
|
||||
text[this->interval.end] == '>')
|
||||
{
|
||||
// <tag ...>
|
||||
this->interval.end++;
|
||||
break;
|
||||
}
|
||||
if (this->type == html_sequence_t::declaration &&
|
||||
this->interval.end + 1 < end &&
|
||||
text[this->interval.end] == '!' &&
|
||||
text[this->interval.end + 1] == '>')
|
||||
{
|
||||
// "<!...!>".
|
||||
this->interval.end = this->interval.end + 2;
|
||||
break;
|
||||
}
|
||||
if (this->type == html_sequence_t::declaration &&
|
||||
this->interval.end + 1 < end &&
|
||||
text[this->interval.end] == '-' &&
|
||||
text[this->interval.end + 1] == '-')
|
||||
{
|
||||
// "<! ... --...".
|
||||
this->interval.end = this->interval.end + 2;
|
||||
for (;;) {
|
||||
if (this->interval.end >= end || !text[this->interval.end])
|
||||
goto error;
|
||||
if (this->interval.end + 1 < end &&
|
||||
text[this->interval.end] == '-' &&
|
||||
text[this->interval.end + 1] == '-')
|
||||
{
|
||||
// "<! ... --...--".
|
||||
this->interval.end = this->interval.end + 2;
|
||||
break;
|
||||
}
|
||||
this->interval.end++;
|
||||
}
|
||||
|
||||
// Skip whitespace.
|
||||
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this->interval.end >= end || !text[this->interval.end])
|
||||
goto error;
|
||||
|
||||
// Attributes follow...
|
||||
html_attribute* a = nullptr;
|
||||
if (this->m_ident.match(text, this->interval.end, end, flags)) {
|
||||
this->attributes.push_back(std::move(html_attribute{ this->m_ident.interval }));
|
||||
a = &this->attributes.back();
|
||||
_Assume_(a);
|
||||
this->interval.end = this->m_ident.interval.end;
|
||||
}
|
||||
else {
|
||||
// What was that?! Skip.
|
||||
this->interval.end++;
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
// Skip whitespace.
|
||||
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++);
|
||||
|
||||
if (this->interval.end < end && text[this->interval.end] == '=') {
|
||||
this->interval.end++;
|
||||
|
||||
// Skip whitespace.
|
||||
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
|
||||
|
||||
if (this->m_value.match(text, this->interval.end, end, flags)) {
|
||||
// This attribute has value.
|
||||
a->value = this->m_value.content;
|
||||
this->interval.end = this->m_value.interval.end;
|
||||
this->attributes.clear();
|
||||
for (;;) {
|
||||
if (this->type == html_sequence_t::element_start &&
|
||||
this->interval.end + 1 < end &&
|
||||
text[this->interval.end] == '/' &&
|
||||
text[this->interval.end + 1] == '>')
|
||||
{
|
||||
// <tag .../>
|
||||
this->type = html_sequence_t::element;
|
||||
this->interval.end = this->interval.end + 2;
|
||||
break;
|
||||
}
|
||||
if (this->interval.end < end &&
|
||||
text[this->interval.end] == '>')
|
||||
{
|
||||
// <tag ...>
|
||||
this->interval.end++;
|
||||
break;
|
||||
}
|
||||
if (this->type == html_sequence_t::declaration &&
|
||||
this->interval.end + 1 < end &&
|
||||
text[this->interval.end] == '!' &&
|
||||
text[this->interval.end + 1] == '>')
|
||||
{
|
||||
// "<!...!>".
|
||||
this->interval.end = this->interval.end + 2;
|
||||
break;
|
||||
}
|
||||
if (this->type == html_sequence_t::declaration &&
|
||||
this->interval.end + 1 < end &&
|
||||
text[this->interval.end] == '-' &&
|
||||
text[this->interval.end + 1] == '-')
|
||||
{
|
||||
// "<! ... --...".
|
||||
this->interval.end = this->interval.end + 2;
|
||||
for (;;) {
|
||||
if (this->interval.end >= end || !text[this->interval.end])
|
||||
goto error;
|
||||
if (this->interval.end + 1 < end &&
|
||||
text[this->interval.end] == '-' &&
|
||||
text[this->interval.end + 1] == '-')
|
||||
{
|
||||
// "<! ... --...--".
|
||||
this->interval.end = this->interval.end + 2;
|
||||
break;
|
||||
}
|
||||
this->interval.end++;
|
||||
}
|
||||
|
||||
// Skip whitespace.
|
||||
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this->interval.end >= end || !text[this->interval.end])
|
||||
goto error;
|
||||
|
||||
// Attributes follow...
|
||||
html_attribute* a = nullptr;
|
||||
if (this->m_ident.match(text, this->interval.end, end, flags)) {
|
||||
this->attributes.push_back(std::move(html_attribute{ this->m_ident.interval }));
|
||||
a = &this->attributes.back();
|
||||
_Assume_(a);
|
||||
this->interval.end = this->m_ident.interval.end;
|
||||
}
|
||||
else {
|
||||
// What was that?! Skip.
|
||||
this->interval.end++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip whitespace.
|
||||
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 && text[this->interval.end] == '=') {
|
||||
this->interval.end++;
|
||||
|
||||
// Skip whitespace.
|
||||
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
|
||||
|
||||
if (this->m_value.match(text, this->interval.end, end, flags)) {
|
||||
// This attribute has value.
|
||||
a->value = this->m_value.content;
|
||||
this->interval.end = this->m_value.interval.end;
|
||||
|
||||
// Skip whitespace.
|
||||
for (; this->interval.end < end && text[this->interval.end] && ctype.is(ctype.space, text[this->interval.end]); this->interval.end++);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// This attribute has no value.
|
||||
a->value.invalidate();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// This attribute has no value.
|
||||
a->value.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8286,7 +8288,7 @@ namespace stdex
|
||||
virtual void invalidate()
|
||||
{
|
||||
this->condition.invalidate();
|
||||
basic_parser::invalidate();
|
||||
basic_parser<T>::invalidate();
|
||||
}
|
||||
|
||||
stdex::interval<size_t> condition; /// condition position in source
|
||||
@@ -8308,7 +8310,7 @@ namespace stdex
|
||||
this->interval.end = start + 3;
|
||||
|
||||
// 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++);
|
||||
|
||||
this->condition.start = this->condition.end = this->interval.end;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023-2024 Amebis
|
||||
*/
|
||||
@@ -7,7 +7,9 @@
|
||||
|
||||
#include "compat.hpp"
|
||||
#include "spinlock.hpp"
|
||||
#ifdef _WIN32
|
||||
#include "windows.h"
|
||||
#endif
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
@@ -39,11 +41,13 @@ namespace stdex
|
||||
private:
|
||||
static numaid_t numa_node()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32)
|
||||
PROCESSOR_NUMBER Processor;
|
||||
GetCurrentProcessorNumberEx(&Processor);
|
||||
USHORT NodeNumber = 0;
|
||||
return GetNumaProcessorNodeEx(&Processor, &NodeNumber) ? NodeNumber : 0;
|
||||
#elif defined(__APPLE__)
|
||||
return 0;
|
||||
#else
|
||||
return numa_node_of_cpu(sched_getcpu());
|
||||
#endif
|
||||
@@ -101,4 +105,4 @@ namespace stdex
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023-2024 Amebis
|
||||
*/
|
||||
@@ -207,7 +207,7 @@ namespace stdex
|
||||
virtual bool cancel()
|
||||
{
|
||||
return
|
||||
m_host && m_host->cancel() ||
|
||||
(m_host && m_host->cancel()) ||
|
||||
m_deadline < std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023-2024 Amebis
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ namespace stdex
|
||||
#elif _M_IX86 || _M_X64
|
||||
_mm_pause();
|
||||
#elif __aarch64__
|
||||
__yield();
|
||||
asm volatile("yield");
|
||||
#elif __i386__ || __x86_64__
|
||||
__builtin_ia32_pause();
|
||||
#endif
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023-2024 Amebis
|
||||
*/
|
||||
@@ -2408,8 +2408,8 @@ namespace stdex
|
||||
_Assume_(data || !length);
|
||||
constexpr int block_size = 0x10000000;
|
||||
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);
|
||||
if (num_read == SOCKET_ERROR) _Unlikely_ {
|
||||
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 == -1) _Unlikely_ {
|
||||
m_state = to_read < length ? state_t::ok : state_t::fail;
|
||||
return length - to_read;
|
||||
}
|
||||
@@ -2432,8 +2432,8 @@ namespace stdex
|
||||
_Assume_(data || !length);
|
||||
constexpr int block_size = 0x10000000;
|
||||
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);
|
||||
if (num_written == SOCKET_ERROR) _Unlikely_ {
|
||||
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 == -1) _Unlikely_ {
|
||||
m_state = state_t::fail;
|
||||
return length - to_write;
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2016-2024 Amebis
|
||||
*/
|
||||
@@ -2328,7 +2328,7 @@ namespace stdex
|
||||
#pragma warning(suppress: 4996)
|
||||
return _vsnprintf_l(str, capacity, format, locale, arg);
|
||||
#else
|
||||
return ::vsnprintf(str, capacity, format, arg);
|
||||
return ::vsnprintf_l(str, capacity, locale, format, arg);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2338,7 +2338,7 @@ namespace stdex
|
||||
#pragma warning(suppress: 4996)
|
||||
return _vsnwprintf_l(str, capacity, format, locale, arg);
|
||||
#else
|
||||
return vswprintf(str, capacity, format, arg);
|
||||
return ::vswprintf_l(str, capacity, locale, format, arg);
|
||||
#endif
|
||||
}
|
||||
/// \endcond
|
||||
@@ -2360,11 +2360,12 @@ namespace stdex
|
||||
|
||||
// Try with stack buffer first.
|
||||
int count = vsnprintf(buf, _countof(buf), format, locale, arg);
|
||||
if (0 <= count && count < _countof(buf)) {
|
||||
if (0 <= count && count <= _countof(buf)) {
|
||||
// Copy from stack.
|
||||
str.append(buf, count);
|
||||
return count;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (count < 0) {
|
||||
switch (errno) {
|
||||
case 0:
|
||||
@@ -2380,6 +2381,25 @@ namespace stdex
|
||||
str.resize(offset + count);
|
||||
if (vsnprintf(&str[offset], count + 1, format, locale, arg) != count) _Unlikely_
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -2538,7 +2558,6 @@ namespace stdex
|
||||
///
|
||||
/// 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 ] time Time
|
||||
/// \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>
|
||||
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>
|
||||
inline void strlwr(_Inout_ T (&str)[N], _In_ const std::locale& locale)
|
||||
{
|
||||
strlwr(str, count, locale);
|
||||
strlwr(str, N, locale);
|
||||
}
|
||||
|
||||
///
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023-2024 Amebis
|
||||
*/
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "compat.hpp"
|
||||
#include "system.hpp"
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32)
|
||||
#include "windows.h"
|
||||
#include <stdlib.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_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 == 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 && 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 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 || (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); }
|
||||
#endif
|
||||
|
||||
namespace stdex
|
||||
@@ -189,8 +189,8 @@ namespace stdex
|
||||
}
|
||||
#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)
|
||||
for (int i = 0, n = getgroups(_countof(gids), gids); i < n; ++i) {
|
||||
gid_t gids[NGROUPS_MAX];
|
||||
for (int i = 0, n = getgroups(NGROUPS_MAX, gids); i < n; ++i) {
|
||||
struct group* group = getgrgid(gids[i]);
|
||||
if (!group) continue;
|
||||
if (strcmp(group->gr_name, "admin") == 0) {
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "compat.hpp"
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32)
|
||||
#include "windows.h"
|
||||
#include <oaidl.h>
|
||||
#include <tchar.h>
|
||||
|
@@ -18,7 +18,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
@@ -976,6 +976,6 @@ namespace stdex
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user