forked from OctaForge/libcubescript
use std::min, max, clamp
parent
e87b1b566c
commit
73699bd1cf
|
@ -82,7 +82,7 @@ cs_stack_state cs_error::save_stack(cs_state &cs) {
|
|||
return cs_stack_state(cs, nullptr, false);
|
||||
}
|
||||
cs_stack_state_node *st = cs.p_state->create_array<cs_stack_state_node>(
|
||||
ostd::min(total, dalias->get_value())
|
||||
std::min(total, dalias->get_value())
|
||||
);
|
||||
cs_stack_state_node *ret = st, *nd = st;
|
||||
++st;
|
||||
|
@ -429,7 +429,7 @@ static inline void callcommand(
|
|||
args[i].set_int(cs_int(lookup ? -1 : i - fakeargs));
|
||||
break;
|
||||
case 'C': {
|
||||
i = ostd::max(i + 1, numargs);
|
||||
i = std::max(i + 1, numargs);
|
||||
auto buf = ostd::appender_range<cs_string>{};
|
||||
cscript::util::tvals_concat(buf, ostd::iter(args, args + i), " ");
|
||||
cs_value tv;
|
||||
|
@ -438,7 +438,7 @@ static inline void callcommand(
|
|||
return;
|
||||
}
|
||||
case 'V':
|
||||
i = ostd::max(i + 1, numargs);
|
||||
i = std::max(i + 1, numargs);
|
||||
cs_cmd_internal::call(cs, id, ostd::iter(args, args + i), res);
|
||||
return;
|
||||
case '1':
|
||||
|
|
|
@ -736,7 +736,7 @@ void cs_state::set_var_int(
|
|||
[&iv]() { iv->p_overrideval = iv->get_value(); }
|
||||
);
|
||||
if (doclamp) {
|
||||
iv->set_value(ostd::clamp(v, iv->get_val_min(), iv->get_val_max()));
|
||||
iv->set_value(std::clamp(v, iv->get_val_min(), iv->get_val_max()));
|
||||
} else {
|
||||
iv->set_value(v);
|
||||
}
|
||||
|
@ -758,7 +758,7 @@ void cs_state::set_var_float(
|
|||
[&fv]() { fv->p_overrideval = fv->get_value(); }
|
||||
);
|
||||
if (doclamp) {
|
||||
fv->set_value(ostd::clamp(v, fv->get_val_min(), fv->get_val_max()));
|
||||
fv->set_value(std::clamp(v, fv->get_val_min(), fv->get_val_max()));
|
||||
} else {
|
||||
fv->set_value(v);
|
||||
}
|
||||
|
|
|
@ -171,8 +171,8 @@ void cs_init_lib_list(cs_state &gcs) {
|
|||
count = args[2].get_int(),
|
||||
numargs = args[3].get_int();
|
||||
|
||||
cs_int offset = ostd::max(skip, cs_int(0)),
|
||||
len = (numargs >= 3) ? ostd::max(count, cs_int(0)) : -1;
|
||||
cs_int offset = std::max(skip, cs_int(0)),
|
||||
len = (numargs >= 3) ? std::max(count, cs_int(0)) : -1;
|
||||
|
||||
util::ListParser p(cs, args[0].get_strr());
|
||||
for (cs_int i = 0; i < offset; ++i) {
|
||||
|
@ -466,8 +466,8 @@ end:
|
|||
});
|
||||
|
||||
gcs.new_command("listsplice", "ssii", [](auto &cs, auto args, auto &res) {
|
||||
cs_int offset = ostd::max(args[2].get_int(), cs_int(0));
|
||||
cs_int len = ostd::max(args[3].get_int(), cs_int(0));
|
||||
cs_int offset = std::max(args[2].get_int(), cs_int(0));
|
||||
cs_int len = std::max(args[3].get_int(), cs_int(0));
|
||||
ostd::string_range s = args[0].get_strr();
|
||||
ostd::string_range vals = args[1].get_strr();
|
||||
char const *list = s.data();
|
||||
|
@ -606,7 +606,7 @@ static void cs_list_sort(
|
|||
yval.pop();
|
||||
|
||||
cs_string sorted;
|
||||
sorted.reserve(totaluniq + ostd::max(nuniq - 1, size_t(0)));
|
||||
sorted.reserve(totaluniq + std::max(nuniq - 1, size_t(0)));
|
||||
for (size_t i = 0; i < items.size(); ++i) {
|
||||
ListSortItem &item = items[i];
|
||||
if (item.quote.empty()) {
|
||||
|
|
|
@ -125,7 +125,7 @@ void cs_init_lib_string(cs_state &cs) {
|
|||
auto r = ostd::appender_range<cs_string>{};
|
||||
try {
|
||||
ostd::format(
|
||||
r, "0x%.*X", ostd::max(args[1].get_int(), cs_int(1)),
|
||||
r, "0x%.*X", std::max(args[1].get_int(), cs_int(1)),
|
||||
args[0].get_int()
|
||||
);
|
||||
} catch (ostd::format_error const &e) {
|
||||
|
@ -138,11 +138,11 @@ void cs_init_lib_string(cs_state &cs) {
|
|||
ostd::string_range s = args[0].get_strr();
|
||||
cs_int start = args[1].get_int(), count = args[2].get_int();
|
||||
cs_int numargs = args[3].get_int();
|
||||
cs_int len = cs_int(s.size()), offset = ostd::clamp(start, cs_int(0), len);
|
||||
cs_int len = cs_int(s.size()), offset = std::clamp(start, cs_int(0), len);
|
||||
res.set_str(cs_string{
|
||||
&s[offset],
|
||||
(numargs >= 3)
|
||||
? size_t(ostd::clamp(count, cs_int(0), len - offset))
|
||||
? size_t(std::clamp(count, cs_int(0), len - offset))
|
||||
: size_t(len - offset)
|
||||
});
|
||||
});
|
||||
|
@ -208,8 +208,8 @@ void cs_init_lib_string(cs_state &cs) {
|
|||
ostd::string_range vals = args[1].get_strr();
|
||||
cs_int skip = args[2].get_int(),
|
||||
count = args[3].get_int();
|
||||
cs_int offset = ostd::clamp(skip, cs_int(0), cs_int(s.size())),
|
||||
len = ostd::clamp(count, cs_int(0), cs_int(s.size()) - offset);
|
||||
cs_int offset = std::clamp(skip, cs_int(0), cs_int(s.size())),
|
||||
len = std::clamp(count, cs_int(0), cs_int(s.size()) - offset);
|
||||
cs_string p;
|
||||
p.reserve(s.size() - len + vals.size());
|
||||
if (offset) {
|
||||
|
|
Loading…
Reference in New Issue