summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-03 15:26:47 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-03 15:26:47 +0100
commit7bb18215cbe60d83ea839a7565491283558d6659 (patch)
tree5dcbbd2d5ad36bffb11fafdb8752c6be0aa73100
parentf181ddb56a090aa8dec605c4302d18df6510b1d0 (diff)
downloadserenity-7bb18215cbe60d83ea839a7565491283558d6659.zip
LibGUI: Use String::formatted() and String::number() more
-rw-r--r--Libraries/LibGfx/BMPLoader.cpp4
-rw-r--r--Libraries/LibGfx/GIFLoader.cpp4
-rw-r--r--Libraries/LibGfx/ICOLoader.cpp4
-rw-r--r--Libraries/LibGfx/JPGLoader.cpp4
-rw-r--r--Libraries/LibGfx/PBMLoader.cpp2
-rw-r--r--Libraries/LibGfx/PGMLoader.cpp2
-rw-r--r--Libraries/LibGfx/PNGLoader.cpp4
-rw-r--r--Libraries/LibGfx/PPMLoader.cpp2
-rw-r--r--Libraries/LibGfx/Painter.cpp2
-rw-r--r--Libraries/LibGfx/Point.cpp4
-rw-r--r--Libraries/LibGfx/Point.h14
-rw-r--r--Libraries/LibGfx/PortableImageLoaderCommon.h6
-rw-r--r--Libraries/LibGfx/Size.cpp4
-rw-r--r--Libraries/LibGfx/Size.h14
-rw-r--r--Libraries/LibGfx/Triangle.cpp2
15 files changed, 48 insertions, 24 deletions
diff --git a/Libraries/LibGfx/BMPLoader.cpp b/Libraries/LibGfx/BMPLoader.cpp
index 6a779ae127..8f8ccc4d1c 100644
--- a/Libraries/LibGfx/BMPLoader.cpp
+++ b/Libraries/LibGfx/BMPLoader.cpp
@@ -184,7 +184,7 @@ RefPtr<Gfx::Bitmap> load_bmp(const StringView& path)
return nullptr;
auto bitmap = load_bmp_impl((const u8*)mapped_file.data(), mapped_file.size());
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded BMP: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded BMP: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
return bitmap;
}
@@ -192,7 +192,7 @@ RefPtr<Gfx::Bitmap> load_bmp_from_memory(const u8* data, size_t length)
{
auto bitmap = load_bmp_impl(data, length);
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded BMP: <memory>", bitmap->width(), bitmap->height()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded BMP: <memory>", bitmap->size()));
return bitmap;
}
diff --git a/Libraries/LibGfx/GIFLoader.cpp b/Libraries/LibGfx/GIFLoader.cpp
index 7a0480379d..10375ee35f 100644
--- a/Libraries/LibGfx/GIFLoader.cpp
+++ b/Libraries/LibGfx/GIFLoader.cpp
@@ -113,7 +113,7 @@ RefPtr<Gfx::Bitmap> load_gif(const StringView& path)
GIFImageDecoderPlugin gif_decoder((const u8*)mapped_file.data(), mapped_file.size());
auto bitmap = gif_decoder.bitmap();
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded GIF: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded GIF: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
return bitmap;
}
@@ -122,7 +122,7 @@ RefPtr<Gfx::Bitmap> load_gif_from_memory(const u8* data, size_t length)
GIFImageDecoderPlugin gif_decoder(data, length);
auto bitmap = gif_decoder.bitmap();
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded GIF: <memory>", bitmap->width(), bitmap->height()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded GIF: <memory>", bitmap->size()));
return bitmap;
}
diff --git a/Libraries/LibGfx/ICOLoader.cpp b/Libraries/LibGfx/ICOLoader.cpp
index c4f06566a0..6fc0f790e5 100644
--- a/Libraries/LibGfx/ICOLoader.cpp
+++ b/Libraries/LibGfx/ICOLoader.cpp
@@ -122,7 +122,7 @@ RefPtr<Gfx::Bitmap> load_ico(const StringView& path)
ICOImageDecoderPlugin decoder((const u8*)mapped_file.data(), mapped_file.size());
auto bitmap = decoder.bitmap();
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded ICO: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded ICO: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
return bitmap;
}
@@ -131,7 +131,7 @@ RefPtr<Gfx::Bitmap> load_ico_from_memory(const u8* data, size_t length)
ICOImageDecoderPlugin decoder(data, length);
auto bitmap = decoder.bitmap();
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded ICO: <memory>", bitmap->width(), bitmap->height()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded ICO: <memory>", bitmap->size()));
return bitmap;
}
diff --git a/Libraries/LibGfx/JPGLoader.cpp b/Libraries/LibGfx/JPGLoader.cpp
index 650227a72b..61b4bcc3a9 100644
--- a/Libraries/LibGfx/JPGLoader.cpp
+++ b/Libraries/LibGfx/JPGLoader.cpp
@@ -1327,7 +1327,7 @@ RefPtr<Gfx::Bitmap> load_jpg(const StringView& path)
auto bitmap = load_jpg_impl((const u8*)mapped_file.data(), mapped_file.size());
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded JPG: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded JPG: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
return bitmap;
}
@@ -1335,7 +1335,7 @@ RefPtr<Gfx::Bitmap> load_jpg_from_memory(const u8* data, size_t length)
{
auto bitmap = load_jpg_impl(data, length);
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded jpg: <memory>", bitmap->width(), bitmap->height()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded jpg: <memory>", bitmap->size()));
return bitmap;
}
diff --git a/Libraries/LibGfx/PBMLoader.cpp b/Libraries/LibGfx/PBMLoader.cpp
index 14694380ea..e92e093dd3 100644
--- a/Libraries/LibGfx/PBMLoader.cpp
+++ b/Libraries/LibGfx/PBMLoader.cpp
@@ -120,7 +120,7 @@ RefPtr<Gfx::Bitmap> load_pbm_from_memory(const u8* data, size_t length)
{
auto bitmap = load_impl<PBMLoadingContext>(data, length);
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PBM: <memory>", bitmap->width(), bitmap->height()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PBM: <memory>", bitmap->size()));
return bitmap;
}
diff --git a/Libraries/LibGfx/PGMLoader.cpp b/Libraries/LibGfx/PGMLoader.cpp
index 8fb94b86e2..88f50f5206 100644
--- a/Libraries/LibGfx/PGMLoader.cpp
+++ b/Libraries/LibGfx/PGMLoader.cpp
@@ -109,7 +109,7 @@ RefPtr<Gfx::Bitmap> load_pgm_from_memory(const u8* data, size_t length)
{
auto bitmap = load_impl<PGMLoadingContext>(data, length);
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PGM: <memory>", bitmap->width(), bitmap->height()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PGM: <memory>", bitmap->size()));
return bitmap;
}
diff --git a/Libraries/LibGfx/PNGLoader.cpp b/Libraries/LibGfx/PNGLoader.cpp
index 1ec4f3f7f1..7f945e55ab 100644
--- a/Libraries/LibGfx/PNGLoader.cpp
+++ b/Libraries/LibGfx/PNGLoader.cpp
@@ -198,7 +198,7 @@ RefPtr<Gfx::Bitmap> load_png(const StringView& path)
return nullptr;
auto bitmap = load_png_impl((const u8*)mapped_file.data(), mapped_file.size());
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PNG: %s", bitmap->width(), bitmap->height(), LexicalPath::canonicalized_path(path).characters()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PNG: {}", bitmap->size(), LexicalPath::canonicalized_path(path)));
return bitmap;
}
@@ -206,7 +206,7 @@ RefPtr<Gfx::Bitmap> load_png_from_memory(const u8* data, size_t length)
{
auto bitmap = load_png_impl(data, length);
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PNG: <memory>", bitmap->width(), bitmap->height()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PNG: <memory>", bitmap->size()));
return bitmap;
}
diff --git a/Libraries/LibGfx/PPMLoader.cpp b/Libraries/LibGfx/PPMLoader.cpp
index 2fb2c1c909..80d99d8966 100644
--- a/Libraries/LibGfx/PPMLoader.cpp
+++ b/Libraries/LibGfx/PPMLoader.cpp
@@ -131,7 +131,7 @@ RefPtr<Gfx::Bitmap> load_ppm_from_memory(const u8* data, size_t length)
{
auto bitmap = load_impl<PPMLoadingContext>(data, length);
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded PPM: <memory>", bitmap->width(), bitmap->height()));
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded PPM: <memory>", bitmap->size()));
return bitmap;
}
diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp
index 8baf9e97b8..7e7f5f16c7 100644
--- a/Libraries/LibGfx/Painter.cpp
+++ b/Libraries/LibGfx/Painter.cpp
@@ -1532,7 +1532,7 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule)
});
#ifdef FILL_PATH_DEBUG
if ((int)scanline % 10 == 0) {
- draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::format("%d", (int)scanline));
+ draw_text(IntRect(active_list.last().x - 20, scanline, 20, 10), String::number((int)scanline));
}
#endif
diff --git a/Libraries/LibGfx/Point.cpp b/Libraries/LibGfx/Point.cpp
index 5dba69ad00..27ae1248ba 100644
--- a/Libraries/LibGfx/Point.cpp
+++ b/Libraries/LibGfx/Point.cpp
@@ -51,13 +51,13 @@ void Point<T>::constrain(const Rect<T>& rect)
template<>
String IntPoint::to_string() const
{
- return String::format("[%d,%d]", x(), y());
+ return String::formatted("[{},{}]", x(), y());
}
template<>
String FloatPoint::to_string() const
{
- return String::format("[%f,%f]", x(), y());
+ return String::formatted("[{},{}]", x(), y());
}
}
diff --git a/Libraries/LibGfx/Point.h b/Libraries/LibGfx/Point.h
index 1fa40a6a26..753d04055a 100644
--- a/Libraries/LibGfx/Point.h
+++ b/Libraries/LibGfx/Point.h
@@ -26,7 +26,7 @@
#pragma once
-#include <AK/Forward.h>
+#include <AK/Format.h>
#include <AK/StdLibExtras.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Orientation.h>
@@ -237,6 +237,18 @@ using FloatPoint = Point<float>;
}
+namespace AK {
+
+template<typename T>
+struct Formatter<Gfx::Point<T>> : Formatter<StringView> {
+ void format(FormatBuilder& builder, const Gfx::Point<T>& value)
+ {
+ Formatter<StringView>::format(builder, value.to_string());
+ }
+};
+
+}
+
namespace IPC {
bool encode(Encoder&, const Gfx::IntPoint&);
diff --git a/Libraries/LibGfx/PortableImageLoaderCommon.h b/Libraries/LibGfx/PortableImageLoaderCommon.h
index 4703375246..63b71ca28e 100644
--- a/Libraries/LibGfx/PortableImageLoaderCommon.h
+++ b/Libraries/LibGfx/PortableImageLoaderCommon.h
@@ -317,10 +317,10 @@ static RefPtr<Gfx::Bitmap> load(const StringView& path)
auto bitmap = load_impl<TContext>((const u8*)mapped_file.data(), mapped_file.size());
if (bitmap)
- bitmap->set_mmap_name(String::format("Gfx::Bitmap [%dx%d] - Decoded %s: %s",
- bitmap->width(), bitmap->height(),
+ bitmap->set_mmap_name(String::formatted("Gfx::Bitmap [{}] - Decoded {}: {}",
+ bitmap->size(),
TContext::image_type,
- LexicalPath::canonicalized_path(path).characters()));
+ LexicalPath::canonicalized_path(path)));
return bitmap;
}
diff --git a/Libraries/LibGfx/Size.cpp b/Libraries/LibGfx/Size.cpp
index c2d809c357..e2cc6151ff 100644
--- a/Libraries/LibGfx/Size.cpp
+++ b/Libraries/LibGfx/Size.cpp
@@ -34,13 +34,13 @@ namespace Gfx {
template<>
String IntSize::to_string() const
{
- return String::format("[%dx%d]", m_width, m_height);
+ return String::formatted("[{}x{}]", m_width, m_height);
}
template<>
String FloatSize::to_string() const
{
- return String::format("[%fx%f]", m_width, m_height);
+ return String::formatted("[{}x{}]", m_width, m_height);
}
}
diff --git a/Libraries/LibGfx/Size.h b/Libraries/LibGfx/Size.h
index f91887900d..7b0cbe96fc 100644
--- a/Libraries/LibGfx/Size.h
+++ b/Libraries/LibGfx/Size.h
@@ -26,7 +26,7 @@
#pragma once
-#include <AK/Forward.h>
+#include <AK/Format.h>
#include <LibGfx/Orientation.h>
#include <LibIPC/Forward.h>
@@ -159,6 +159,18 @@ using FloatSize = Size<float>;
}
+namespace AK {
+
+template<typename T>
+struct Formatter<Gfx::Size<T>> : Formatter<StringView> {
+ void format(FormatBuilder& builder, const Gfx::Size<T>& value)
+ {
+ Formatter<StringView>::format(builder, value.to_string());
+ }
+};
+
+}
+
namespace IPC {
bool encode(Encoder&, const Gfx::IntSize&);
diff --git a/Libraries/LibGfx/Triangle.cpp b/Libraries/LibGfx/Triangle.cpp
index d36ad50f0f..f5fcab2047 100644
--- a/Libraries/LibGfx/Triangle.cpp
+++ b/Libraries/LibGfx/Triangle.cpp
@@ -31,7 +31,7 @@ namespace Gfx {
String Triangle::to_string() const
{
- return String::format("(%s,%s,%s)", m_a.to_string().characters(), m_b.to_string().characters(), m_c.to_string().characters());
+ return String::format("({},{},{})", m_a, m_b, m_c);
}
const LogStream& operator<<(const LogStream& stream, const Triangle& value)