Skip to content

Commit

Permalink
refactor: remove redundant string
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jun 18, 2024
1 parent 9472936 commit 48a5d94
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/ll/api/plugin/PluginManagerRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Expected<> PluginManagerRegistry::unloadPlugin(std::string_view name) noexcept {
try {
std::lock_guard lock(impl->mutex);
if (!hasPlugin(name)) {
return makeStringError("Plugin not found"_tr());
return makeStringError("Plugin {0} not found"_tr(name));
}
return getManagerForPlugin(name)->unload(name).transform([&, this] {
impl->loadedPlugins.erase(std::string{name});
Expand All @@ -59,7 +59,7 @@ Expected<> PluginManagerRegistry::enablePlugin(std::string_view name) const noex
try {
std::lock_guard lock(impl->mutex);
if (!hasPlugin(name)) {
return makeStringError("Plugin not found"_tr());
return makeStringError("Plugin {0} not found"_tr(name));
}
return getManagerForPlugin(name)->enable(name);
} catch (...) {
Expand All @@ -71,7 +71,7 @@ Expected<> PluginManagerRegistry::disablePlugin(std::string_view name) const noe
try {
std::lock_guard lock(impl->mutex);
if (!hasPlugin(name)) {
return makeStringError("Plugin not found"_tr());
return makeStringError("Plugin {0} not found"_tr(name));
}
return getManagerForPlugin(name)->disable(name);
} catch (...) {
Expand Down
16 changes: 8 additions & 8 deletions src/ll/api/utils/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace ll::inline utils::string_utils {

// "2021-03-24" -> ["2021", "03", "24"] (use '-' as split pattern)
template <class T>
[[nodiscard]] inline constexpr auto
splitByPattern(T&& str, std::string_view pattern, bool keepEmpty = false) -> decltype(auto) {
[[nodiscard]] constexpr auto splitByPattern(T&& str, std::string_view pattern, bool keepEmpty = false) -> decltype(auto
) {
using ReturnTypeElement = std::conditional_t<std::is_same_v<T&&, std::string&&>, std::string, std::string_view>;
using ReturnType = std::vector<ReturnTypeElement>;
std::string_view s{str};
Expand All @@ -47,22 +47,22 @@ splitByPattern(T&& str, std::string_view pattern, bool keepEmpty = false) -> dec
* @param newValue The string to replace with
* @return std::string The modified input std::string
*/
inline constexpr std::string& replaceAll(std::string& str, std::string_view oldValue, std::string_view newValue) {
constexpr std::string& replaceAll(std::string& str, std::string_view oldValue, std::string_view newValue) {
for (std::string::size_type pos(0); pos != std::string::npos; pos += newValue.length()) {
if ((pos = str.find(oldValue, pos)) != std::string::npos) str.replace(pos, oldValue.length(), newValue);
else break;
}
return str;
}

[[nodiscard]] inline constexpr std::string
[[nodiscard]] constexpr std::string
replaceAll(std::string const& str, std::string_view oldValue, std::string_view newValue) {
std::string ret = str;
replaceAll(ret, oldValue, newValue);
return ret;
}

inline constexpr bool
constexpr bool
replaceContent(std::string& str, std::string_view before, std::string_view after, std::string_view relplaceWith) {
auto startOffset = str.find(before);
if (startOffset == std::string::npos) return false;
Expand Down Expand Up @@ -96,7 +96,7 @@ LLNDAPI std::string decompress(std::string_view);
*/
template <class T>
requires std::is_integral_v<T>
[[nodiscard]] inline constexpr std::string
[[nodiscard]] constexpr std::string
intToHexStr(T value, bool upperCase = true, bool no0x = true, bool noLeadingZero = true) {
std::string result;
if (value < 0) result += '-';
Expand All @@ -112,7 +112,7 @@ intToHexStr(T value, bool upperCase = true, bool no0x = true, bool noLeadingZero
return result;
}

[[nodiscard]]inline constexpr std::string strToHexStr(std::string_view value, bool upperCase = false, bool addSpace = false) {
[[nodiscard]] constexpr std::string strToHexStr(std::string_view value, bool upperCase = false, bool addSpace = false) {
constexpr char hexStr[2][17] = {"0123456789abcdef", "0123456789ABCDEF"};
std::string hex;
hex.reserve(value.size() * (addSpace ? 3 : 2));
Expand All @@ -125,7 +125,7 @@ intToHexStr(T value, bool upperCase = true, bool no0x = true, bool noLeadingZero
return hex;
}

[[nodiscard]] inline constexpr std::string applyTextStyle(fmt::text_style const& ts, std::string_view str) {
[[nodiscard]] constexpr std::string applyTextStyle(fmt::text_style const& ts, std::string_view str) {
std::string res;
bool has_style = false;
if (ts.has_emphasis()) {
Expand Down
2 changes: 1 addition & 1 deletion src/ll/core/command/PluginManage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void registerPluginManageCommand() {
cmd.overload<LeviCommand3>().text("load").required("plugin").execute(
[](CommandOrigin const&, CommandOutput& output, LeviCommand3 const& param) {
if (ll::plugin::PluginManagerRegistry::getInstance().hasPlugin(param.plugin)) {
output.error("Plugin already {0} loaded"_tr(param.plugin));
output.error("Plugin {0} already loaded"_tr(param.plugin));
return;
}
if (auto res = ll::plugin::PluginRegistrar::getInstance().loadPlugin(param.plugin); res) {
Expand Down
4 changes: 2 additions & 2 deletions src/ll/core/plugin/PluginRegistrar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void PluginRegistrar::loadAllPlugins() {
logger.info("{0} loaded"_tr(name));
} else {
loadErrored.emplace(name);
logger.error("Failed to load {0}"_tr(name));
logger.error("Failed to load plugin {0}"_tr(name));
res.error().log(logger.error);
}
}
Expand Down Expand Up @@ -279,7 +279,7 @@ LL_TYPE_INSTANCE_HOOK(
if (auto res = registrar.enablePlugin(name); res) {
count++;
} else {
logger.error("Failed to enable {0}"_tr(name));
logger.error("Failed to enable plugin {0}"_tr(name));
res.error().log(logger.error);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/mc/math/vector/base/CommutativeGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ struct LL_EBO CommutativeGroup : VectorBase<T, Components...>, CommutativeGroupT
};

template <IsCommutativeGroup T, std::convertible_to<typename T::first_type> V>
[[nodiscard]] inline constexpr auto operator+(V const& v, T const& t) noexcept {
[[nodiscard]] constexpr auto operator+(V const& v, T const& t) noexcept {
return T{static_cast<typename T::first_type>(v)} + t;
}

template <IsCommutativeGroup T, std::convertible_to<typename T::first_type> V>
[[nodiscard]] inline constexpr auto operator-(V const& v, T const& t) noexcept {
[[nodiscard]] constexpr auto operator-(V const& v, T const& t) noexcept {
return T{static_cast<typename T::first_type>(v)} - t;
}

Expand Down
4 changes: 2 additions & 2 deletions src/mc/math/vector/base/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ struct LL_EBO Field : CommutativeGroup<T, Components...>, FieldTag {
};

template <IsField T, std::convertible_to<typename T::first_type> V>
[[nodiscard]] inline constexpr auto operator*(V const& v, T const& t) noexcept {
[[nodiscard]] constexpr auto operator*(V const& v, T const& t) noexcept {
return T{static_cast<typename T::first_type>(v)} * t;
}

template <IsField T, std::convertible_to<typename T::first_type> V>
[[nodiscard]] inline constexpr auto operator/(V const& v, T const& t) noexcept {
[[nodiscard]] constexpr auto operator/(V const& v, T const& t) noexcept {
return T{static_cast<typename T::first_type>(v)} / t;
}

Expand Down

0 comments on commit 48a5d94

Please sign in to comment.