Skip to content

Commit

Permalink
Update GeneralUtils.h (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmosewaMC authored Apr 9, 2024
1 parent db192d2 commit 1ee4563
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions dCommon/GeneralUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ namespace GeneralUtils {
template <Numeric T>
[[nodiscard]] std::optional<T> TryParse(std::string_view str) {
numeric_parse_t<T> result;
if (!str.empty()) {
while (std::isspace(str.front())) str.remove_prefix(1);
}
while (!str.empty() && std::isspace(str.front())) str.remove_prefix(1);

const char* const strEnd = str.data() + str.size();
const auto [parseEnd, ec] = std::from_chars(str.data(), strEnd, result);
Expand All @@ -186,9 +184,7 @@ namespace GeneralUtils {
template <std::floating_point T>
[[nodiscard]] std::optional<T> TryParse(std::string_view str) noexcept
try {
if (!str.empty()) {
while (std::isspace(str.front())) str.remove_prefix(1);
}
while (!str.empty() && std::isspace(str.front())) str.remove_prefix(1);

size_t parseNum;
const T result = details::_parse<T>(str, parseNum);
Expand Down

0 comments on commit 1ee4563

Please sign in to comment.