mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 16:19:19 +02:00
Simplify len_common_prefix
This commit is contained in:
@@ -237,7 +237,7 @@ void itemproperties_panel::update_group()
|
|||||||
for (auto const &name : names)
|
for (auto const &name : names)
|
||||||
{
|
{
|
||||||
// NOTE: first calculation runs over two instances of the same name, but, eh
|
// NOTE: first calculation runs over two instances of the same name, but, eh
|
||||||
auto const prefixlength{len_common_prefix(m_groupprefix, name)};
|
auto const prefixlength{len_common_prefix(m_groupprefix, name.get())};
|
||||||
if (prefixlength > 0)
|
if (prefixlength > 0)
|
||||||
{
|
{
|
||||||
m_groupprefix = m_groupprefix.substr(0, prefixlength);
|
m_groupprefix = m_groupprefix.substr(0, prefixlength);
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ auto python_taskqueue::fetch_renderer(std::string const Renderer) -> PyObject *
|
|||||||
return lookup->second;
|
return lookup->second;
|
||||||
}
|
}
|
||||||
// try to load specified renderer class
|
// try to load specified renderer class
|
||||||
auto const path{substr_path(Renderer)};
|
std::string const path{substr_path(Renderer)};
|
||||||
auto const file{Renderer.substr(path.size())};
|
auto const file{Renderer.substr(path.size())};
|
||||||
PyObject *renderer{nullptr};
|
PyObject *renderer{nullptr};
|
||||||
PyObject *rendererarguments{nullptr};
|
PyObject *rendererarguments{nullptr};
|
||||||
|
|||||||
@@ -398,13 +398,10 @@ std::string_view substr_path(std::string const &Filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returns length of common prefix between two provided strings
|
// returns length of common prefix between two provided strings
|
||||||
std::ptrdiff_t len_common_prefix(std::string const &Left, std::string const &Right)
|
std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b)
|
||||||
{
|
{
|
||||||
|
auto [it1, it2] = std::ranges::mismatch(a, b);
|
||||||
auto const *left{Left.data()};
|
return std::distance(a.begin(), it1);
|
||||||
auto const *right{Right.data()};
|
|
||||||
// compare up to the length of the shorter string
|
|
||||||
return (Right.size() <= Left.size() ? std::distance(right, std::mismatch(right, right + Right.size(), left).first) : std::distance(left, std::mismatch(left, left + Left.size(), right).first));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if provided string ends with another provided string
|
// returns true if provided string ends with another provided string
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ void replace_slashes(std::string &Filename);
|
|||||||
std::string_view substr_path(std::string const &Filename);
|
std::string_view substr_path(std::string const &Filename);
|
||||||
|
|
||||||
// returns common prefix of two provided strings
|
// returns common prefix of two provided strings
|
||||||
std::ptrdiff_t len_common_prefix(std::string const &Left, std::string const &Right);
|
std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b);
|
||||||
|
|
||||||
// returns true if provided string ends with another provided string
|
// returns true if provided string ends with another provided string
|
||||||
bool ends_with(std::string_view String, std::string_view Suffix);
|
bool ends_with(std::string_view String, std::string_view Suffix);
|
||||||
|
|||||||
Reference in New Issue
Block a user