aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2018-09-07 20:31:04 +0200
committerGitHub <noreply@github.com>2018-09-07 20:31:04 +0200
commit66a87c4642d25f27ca24254cfeb0a0c4b21036b1 (patch)
treeccf34eaee0ac1a51e5f971af8ecd67d14c9fc735 /src/common
parent5843724debc3642434c055e5cf6f29a1eaf65358 (diff)
Scripts/Commands: New argument parsing methodology (PR #22363)
- Detect the arguments accepted by the command handler - Tokenize out those arguments automatically and feed them to the handler - Unmatched rest of the string can be accepted by trailing char const* or CommandArgs*
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Utilities/Util.cpp8
-rw-r--r--src/common/Utilities/Util.h2
-rw-r--r--src/common/Utilities/advstd.h77
3 files changed, 87 insertions, 0 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index eefa8bbf0a1..9b9474d3b59 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -22,6 +22,8 @@
#include <utf8.h>
#include <algorithm>
#include <sstream>
+#include <string>
+#include <cctype>
#include <cstdarg>
#include <ctime>
@@ -573,3 +575,9 @@ bool StringToBool(std::string const& str)
std::transform(str.begin(), str.end(), lowerStr.begin(), ::tolower);
return lowerStr == "1" || lowerStr == "true" || lowerStr == "yes";
}
+
+bool StringContainsStringI(std::string const& haystack, std::string const& needle)
+{
+ return haystack.end() !=
+ std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end(), [](char c1, char c2) { return std::toupper(c1) == std::toupper(c2); });
+}
diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h
index 195aa22ca22..07c2803395a 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -300,6 +300,8 @@ TC_COMMON_API void HexStrToByteArray(std::string const& str, uint8* out, bool re
TC_COMMON_API bool StringToBool(std::string const& str);
+TC_COMMON_API bool StringContainsStringI(std::string const& haystack, std::string const& needle);
+
// simple class for not-modifyable list
template <typename T>
class HookList final
diff --git a/src/common/Utilities/advstd.h b/src/common/Utilities/advstd.h
new file mode 100644
index 00000000000..ce32e14c335
--- /dev/null
+++ b/src/common/Utilities/advstd.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TRINITY_ADVSTD_H
+#define TRINITY_ADVSTD_H
+
+#include <cstddef>
+#include <tuple>
+#include <type_traits>
+#include <utility>
+
+// this namespace holds implementations of upcoming stdlib features that our c++ version doesn't have yet
+namespace advstd {
+ // C++17 std::apply (constrained to only function pointers, not all callable)
+ template <typename... Ts>
+ using apply_tuple_type = std::tuple<std::remove_cv_t<std::remove_reference_t<Ts>>...>;
+ template <typename R, typename... Ts, std::size_t... I>
+ R apply_impl(R(*func)(Ts...), apply_tuple_type<Ts...>&& args, std::index_sequence<I...>)
+ {
+ return func(std::get<I>(std::forward<apply_tuple_type<Ts...>>(args))...);
+ }
+ template <typename R, typename... Ts>
+ R apply(R(*func)(Ts...), apply_tuple_type<Ts...>&& args)
+ {
+ return apply_impl(func, std::forward<apply_tuple_type<Ts...>>(args), std::index_sequence_for<Ts...>{});
+ }
+
+#define forward_1v(stdname, type) template <typename T> constexpr type stdname ## _v = std::stdname<T>::value
+#define forward_2v(stdname, type) template <typename U, typename V> constexpr type stdname ## _v = std::stdname<U,V>::value
+
+ // C++17 std::is_same_v
+ forward_2v(is_same, bool);
+
+ // C++17 std::is_integral_v
+ forward_1v(is_integral, bool);
+
+ // C++17 std::is_assignable_v
+ forward_2v(is_assignable, bool);
+
+ // C++17 std::is_signed_v
+ forward_1v(is_signed, bool);
+
+ // C++17 std::is_unsigned_v
+ forward_1v(is_unsigned, bool);
+
+ // C++17 std::is_base_of_v
+ forward_2v(is_base_of, bool);
+
+ // C++17 std::is_floating_point_v
+ forward_1v(is_floating_point, bool);
+
+ // C++17 std::tuple_size_v
+ forward_1v(tuple_size, size_t);
+
+#undef forward_1v
+#undef forward_2v
+
+ // C++20 std::remove_cvref_t
+ template <class T>
+ using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
+}
+
+#endif