@@ -10,17 +10,23 @@
#include <iterator>
#include <optional>
#include <source_location>
#include <string_view>
#include <system_error>
namespace style {
int UnresolvedValue::resolve(int font_size, int root_font_size, std::optional<int> percent_relative_to) const {
return try_resolve(font_size, root_font_size, percent_relative_to).value_or(0);
int UnresolvedValue::resolve(int font_size,
int root_font_size,
std::optional<int> percent_relative_to,
std::source_location const &caller) const {
return try_resolve(font_size, root_font_size, percent_relative_to, caller).value_or(0);
}
std::optional<int> UnresolvedValue::try_resolve(
int font_size, int root_font_size, std::optional<int> percent_relative_to) const {
std::optional<int> UnresolvedValue::try_resolve(int font_size,
int root_font_size,
std::optional<int> percent_relative_to,
std::source_location const &caller) const {
// Special case for 0 since it won't ever have a unit that needs to be handled.
if (raw == "0") {
return 0;
@@ -29,7 +35,11 @@ std::optional<int> UnresolvedValue::try_resolve(
float res{};
auto parse_result = util::from_chars(raw.data(), raw.data() + raw.size(), res);
if (parse_result.ec != std::errc{}) {
spdlog::warn("Unable to parse property '{}' in to_px", raw);
spdlog::warn("{}({}:{}): Unable to parse property '{}' in to_px",
caller.file_name(),
caller.line(),
caller.column(),
raw);
return std::nullopt;
}
@@ -38,7 +48,10 @@ std::optional<int> UnresolvedValue::try_resolve(
if (unit == "%") {
if (!percent_relative_to.has_value()) {
spdlog::warn("Missing parent-value for property w/ '%' unit");
spdlog::warn("{}({}:{}): Missing parent-value for property w/ '%' unit",
caller.file_name(),
caller.line(),
caller.column());
return std::nullopt;
}
@@ -69,7 +82,12 @@ std::optional<int> UnresolvedValue::try_resolve(
return static_cast<int>(res * kExToEmRatio * font_size);
}
spdlog::warn("Bad property '{}' w/ unit '{}' in to_px", raw, unit);
spdlog::warn("{}({}:{}): Bad property '{}' w/ unit '{}' in to_px",
caller.file_name(),
caller.line(),
caller.column(),
raw,
unit);
return std::nullopt;
}