[LyX/master] Fix more warnings and simplify a tiny bit.
Richard Kimberly Heck
rikiheck at lyx.org
Tue May 19 21:44:30 UTC 2020
commit a2b21e3cd4bbfd42e59161143eba6e7681aaa93f
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Tue May 19 18:06:20 2020 -0400
Fix more warnings and simplify a tiny bit.
---
src/graphics/PreviewLoader.cpp | 8 ++++----
src/support/convert.cpp | 14 ++++++++++----
src/support/convert.h | 1 +
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index d73e353..f15752c 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -375,8 +375,8 @@ PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
{
font_scaling_factor_ = int(buffer_.fontScalingFactor());
if (theApp()) {
- fg_color_ = strtol(theApp()->hexName(foregroundColor()).c_str(), nullptr, 16);
- bg_color_ = strtol(theApp()->hexName(backgroundColor()).c_str(), nullptr, 16);
+ fg_color_ = convert(theApp()->hexName(foregroundColor()).c_str(), 16);
+ bg_color_ = convert(theApp()->hexName(backgroundColor()).c_str(), 16);
} else {
fg_color_ = 0x0;
bg_color_ = 0xffffff;
@@ -439,8 +439,8 @@ PreviewLoader::Impl::preview(string const & latex_snippet) const
int fg = 0x0;
int bg = 0xffffff;
if (theApp()) {
- fg = strtol(theApp()->hexName(foregroundColor()).c_str(), nullptr, 16);
- bg = strtol(theApp()->hexName(backgroundColor()).c_str(), nullptr, 16);
+ fg = convert(theApp()->hexName(foregroundColor()).c_str(), 16);
+ bg = convert(theApp()->hexName(backgroundColor()).c_str(), 16);
}
if (font_scaling_factor_ != fs || fg_color_ != fg || bg_color_ != bg) {
// Schedule refresh of all previews on zoom or color changes.
diff --git a/src/support/convert.cpp b/src/support/convert.cpp
index 74b1282..af0ad62 100644
--- a/src/support/convert.cpp
+++ b/src/support/convert.cpp
@@ -179,21 +179,27 @@ docstring convert<docstring>(double d)
template<>
int convert<int>(string const s)
{
- return strtol(s.c_str(), nullptr, 10);
+ return int(strtol(s.c_str(), nullptr, 10));
+}
+
+
+int convert(std::string const & s, int base)
+{
+ return int(strtol(s.c_str(), nullptr, base));
}
template<>
int convert<int>(docstring const s)
{
- return strtol(to_ascii(s).c_str(), nullptr, 10);
+ return int(strtol(to_ascii(s).c_str(), nullptr, 10));
}
template<>
unsigned int convert<unsigned int>(string const s)
{
- return strtoul(s.c_str(), nullptr, 10);
+ return static_cast<unsigned int>(strtoul(s.c_str(), nullptr, 10));
}
@@ -214,7 +220,7 @@ double convert<double>(string const s)
template<>
int convert<int>(char const * cptr)
{
- return strtol(cptr, nullptr, 10);
+ return int(strtol(cptr, nullptr, 10));
}
diff --git a/src/support/convert.h b/src/support/convert.h
index 3b97fb6..1b3e5be 100644
--- a/src/support/convert.h
+++ b/src/support/convert.h
@@ -53,6 +53,7 @@ template<> double convert<double>(std::string const & s);
template<> int convert<int>(char const * cptr);
template<> double convert<double>(char const * cptr);
+int convert(std::string const & s, int base);
} // namespace lyx
#endif
More information about the lyx-cvs
mailing list