LibGUI: Use String::formatted() and String::number() more

This commit is contained in:
Andreas Kling 2021-01-03 15:26:47 +01:00
parent f181ddb56a
commit 7bb18215cb
Notes: sideshowbarker 2024-07-19 00:10:08 +09:00
15 changed files with 48 additions and 24 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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

View file

@ -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());
}
}

View file

@ -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&);

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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&);

View file

@ -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)