summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-06-02 14:58:02 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-03 20:27:05 +0200
commit1024dfa81ab391765eb8838cfc7e58b03e2cb5c6 (patch)
tree764f63dfe97dfd6dfafe70385731dd43734f38b0
parentf9ba7adae2efaa2e2bdc47a13ff22aed401261b3 (diff)
downloadserenity-1024dfa81ab391765eb8838cfc7e58b03e2cb5c6.zip
StringViewize a bunch of things -- mostly LibGUI
-rw-r--r--AK/MappedFile.cpp12
-rw-r--r--AK/MappedFile.h5
-rw-r--r--Applications/Terminal/main.cpp2
-rw-r--r--Applications/TextEditor/main.cpp2
-rw-r--r--LibGUI/GAbstractButton.cpp4
-rw-r--r--LibGUI/GAbstractButton.h4
-rw-r--r--LibGUI/GAction.cpp10
-rw-r--r--LibGUI/GAction.h20
-rw-r--r--LibGUI/GApplication.cpp4
-rw-r--r--LibGUI/GApplication.h2
-rw-r--r--LibGUI/GButton.cpp2
-rw-r--r--LibGUI/GButton.h2
-rw-r--r--LibGUI/GCheckBox.cpp2
-rw-r--r--LibGUI/GCheckBox.h2
-rw-r--r--LibGUI/GClipboard.cpp2
-rw-r--r--LibGUI/GClipboard.h2
-rw-r--r--LibGUI/GDesktop.cpp2
-rw-r--r--LibGUI/GDesktop.h2
-rw-r--r--LibGUI/GDirectoryModel.cpp2
-rw-r--r--LibGUI/GDirectoryModel.h2
-rw-r--r--LibGUI/GEvent.h4
-rw-r--r--LibGUI/GFilePicker.cpp2
-rw-r--r--LibGUI/GFilePicker.h2
-rw-r--r--LibGUI/GFileSystemModel.cpp4
-rw-r--r--LibGUI/GFileSystemModel.h6
-rw-r--r--LibGUI/GFontDatabase.cpp6
-rw-r--r--LibGUI/GFontDatabase.h8
-rw-r--r--LibGUI/GGroupBox.cpp4
-rw-r--r--LibGUI/GGroupBox.h4
-rw-r--r--LibGUI/GIcon.cpp2
-rw-r--r--LibGUI/GIcon.h2
-rw-r--r--LibGUI/GInputBox.cpp2
-rw-r--r--LibGUI/GInputBox.h2
-rw-r--r--LibGUI/GLabel.cpp4
-rw-r--r--LibGUI/GLabel.h4
-rw-r--r--LibGUI/GMenu.cpp2
-rw-r--r--LibGUI/GMenu.h2
-rw-r--r--LibGUI/GMessageBox.cpp4
-rw-r--r--LibGUI/GMessageBox.h4
-rw-r--r--LibGUI/GProgressBar.h2
-rw-r--r--LibGUI/GRadioButton.cpp2
-rw-r--r--LibGUI/GRadioButton.h2
-rw-r--r--LibGUI/GStatusBar.cpp2
-rw-r--r--LibGUI/GStatusBar.h2
-rw-r--r--LibGUI/GTabWidget.cpp2
-rw-r--r--LibGUI/GTabWidget.h2
-rw-r--r--LibGUI/GTextEditor.cpp14
-rw-r--r--LibGUI/GTextEditor.h12
-rw-r--r--LibGUI/GWidget.h2
-rw-r--r--LibGUI/GWindow.cpp4
-rw-r--r--LibGUI/GWindow.h4
-rw-r--r--SharedGraphics/Font.cpp21
-rw-r--r--SharedGraphics/Font.h11
-rw-r--r--SharedGraphics/GraphicsBitmap.cpp6
-rw-r--r--SharedGraphics/GraphicsBitmap.h7
-rw-r--r--SharedGraphics/PNGLoader.cpp2
-rw-r--r--SharedGraphics/PNGLoader.h2
-rw-r--r--SharedGraphics/Painter.cpp12
-rw-r--r--SharedGraphics/Painter.h4
59 files changed, 129 insertions, 139 deletions
diff --git a/AK/MappedFile.cpp b/AK/MappedFile.cpp
index b234fa19c6..87af44be9c 100644
--- a/AK/MappedFile.cpp
+++ b/AK/MappedFile.cpp
@@ -9,11 +9,10 @@
namespace AK {
-MappedFile::MappedFile(const String& file_name)
- : m_file_name(file_name)
+MappedFile::MappedFile(const StringView& file_name)
{
m_size = PAGE_SIZE;
- m_fd = open(m_file_name.characters(), O_RDONLY | O_CLOEXEC);
+ m_fd = open(file_name.characters(), O_RDONLY | O_CLOEXEC);
if (m_fd != -1) {
struct stat st;
@@ -26,7 +25,7 @@ MappedFile::MappedFile(const String& file_name)
}
#ifdef DEBUG_MAPPED_FILE
- dbgprintf("MappedFile{%s} := { m_fd=%d, m_size=%u, m_map=%p }\n", m_file_name.characters(), m_fd, m_size, m_map);
+ dbgprintf("MappedFile{%s} := { m_fd=%d, m_size=%u, m_map=%p }\n", file_name.characters(), m_fd, m_size, m_map);
#endif
}
@@ -44,15 +43,13 @@ void MappedFile::unmap()
ASSERT(rc == 0);
rc = close(m_fd);
ASSERT(rc == 0);
- m_file_name = {};
m_size = 0;
m_fd = -1;
m_map = (void*)-1;
}
MappedFile::MappedFile(MappedFile&& other)
- : m_file_name(move(other.m_file_name))
- , m_size(other.m_size)
+ : m_size(other.m_size)
, m_fd(other.m_fd)
, m_map(other.m_map)
{
@@ -66,7 +63,6 @@ MappedFile& MappedFile::operator=(MappedFile&& other)
if (this == &other)
return *this;
unmap();
- swap(m_file_name, other.m_file_name);
swap(m_size, other.m_size);
swap(m_fd, other.m_fd);
swap(m_map, other.m_map);
diff --git a/AK/MappedFile.h b/AK/MappedFile.h
index 513fd28e5e..82421e6e3d 100644
--- a/AK/MappedFile.h
+++ b/AK/MappedFile.h
@@ -1,13 +1,13 @@
#pragma once
-#include "AKString.h"
+#include "StringView.h"
namespace AK {
class MappedFile {
public:
MappedFile() {}
- explicit MappedFile(const String& file_name);
+ explicit MappedFile(const StringView& file_name);
MappedFile(MappedFile&&);
~MappedFile();
@@ -21,7 +21,6 @@ public:
size_t size() const { return m_size; }
private:
- String m_file_name;
size_t m_size { 0 };
int m_fd { -1 };
void* m_map { (void*)-1 };
diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp
index 2ca46803ef..ee364af217 100644
--- a/Applications/Terminal/main.cpp
+++ b/Applications/Terminal/main.cpp
@@ -184,7 +184,7 @@ int main(int argc, char** argv)
menubar->add_menu(move(app_menu));
auto font_menu = make<GMenu>("Font");
- GFontDatabase::the().for_each_fixed_width_font([&] (const String& font_name) {
+ GFontDatabase::the().for_each_fixed_width_font([&] (const StringView& font_name) {
font_menu->add_action(GAction::create(font_name, [&terminal, &config] (const GAction& action) {
terminal.set_font(GFontDatabase::the().get_by_name(action.text()));
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
diff --git a/Applications/TextEditor/main.cpp b/Applications/TextEditor/main.cpp
index 4b868a6a51..4ecba3aa97 100644
--- a/Applications/TextEditor/main.cpp
+++ b/Applications/TextEditor/main.cpp
@@ -99,7 +99,7 @@ int main(int argc, char** argv)
menubar->add_menu(move(edit_menu));
auto font_menu = make<GMenu>("Font");
- GFontDatabase::the().for_each_fixed_width_font([&] (const String& font_name) {
+ GFontDatabase::the().for_each_fixed_width_font([&] (const StringView& font_name) {
font_menu->add_action(GAction::create(font_name, [text_editor] (const GAction& action) {
text_editor->set_font(GFontDatabase::the().get_by_name(action.text()));
text_editor->update();
diff --git a/LibGUI/GAbstractButton.cpp b/LibGUI/GAbstractButton.cpp
index 03f95e0e1d..e85404fc27 100644
--- a/LibGUI/GAbstractButton.cpp
+++ b/LibGUI/GAbstractButton.cpp
@@ -6,7 +6,7 @@ GAbstractButton::GAbstractButton(GWidget* parent)
{
}
-GAbstractButton::GAbstractButton(const String& text, GWidget* parent)
+GAbstractButton::GAbstractButton(const StringView& text, GWidget* parent)
: GWidget(parent)
, m_text(text)
{
@@ -16,7 +16,7 @@ GAbstractButton::~GAbstractButton()
{
}
-void GAbstractButton::set_text(const String& text)
+void GAbstractButton::set_text(const StringView& text)
{
if (m_text == text)
return;
diff --git a/LibGUI/GAbstractButton.h b/LibGUI/GAbstractButton.h
index fdbb6a7a8c..4d96c2f00f 100644
--- a/LibGUI/GAbstractButton.h
+++ b/LibGUI/GAbstractButton.h
@@ -11,7 +11,7 @@ public:
Function<void(bool)> on_checked;
- void set_text(const String&);
+ void set_text(const StringView&);
const String& text() const { return m_text; }
bool is_checked() const { return m_checked; }
@@ -29,7 +29,7 @@ public:
protected:
explicit GAbstractButton(GWidget* parent);
- GAbstractButton(const String&, GWidget* parent);
+ GAbstractButton(const StringView&, GWidget* parent);
virtual void mousedown_event(GMouseEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
diff --git a/LibGUI/GAction.cpp b/LibGUI/GAction.cpp
index a2718690d0..2eebd748a8 100644
--- a/LibGUI/GAction.cpp
+++ b/LibGUI/GAction.cpp
@@ -3,7 +3,7 @@
#include <LibGUI/GButton.h>
#include <LibGUI/GMenuItem.h>
-GAction::GAction(const String& text, const String& custom_data, Function<void(GAction&)> on_activation_callback, GWidget* widget)
+GAction::GAction(const StringView& text, const StringView& custom_data, Function<void(GAction&)> on_activation_callback, GWidget* widget)
: on_activation(move(on_activation_callback))
, m_text(text)
, m_custom_data(custom_data)
@@ -11,12 +11,12 @@ GAction::GAction(const String& text, const String& custom_data, Function<void(GA
{
}
-GAction::GAction(const String& text, Function<void(GAction&)> on_activation_callback, GWidget* widget)
+GAction::GAction(const StringView& text, Function<void(GAction&)> on_activation_callback, GWidget* widget)
: GAction(text, String(), move(on_activation_callback), widget)
{
}
-GAction::GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
+GAction::GAction(const StringView& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
: on_activation(move(on_activation_callback))
, m_text(text)
, m_icon(move(icon))
@@ -24,13 +24,13 @@ GAction::GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<
{
}
-GAction::GAction(const String& text, const GShortcut& shortcut, Function<void(GAction&)> on_activation_callback, GWidget* widget)
+GAction::GAction(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> on_activation_callback, GWidget* widget)
: GAction(text, shortcut, nullptr, move(on_activation_callback), widget)
{
}
-GAction::GAction(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
+GAction::GAction(const StringView& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> on_activation_callback, GWidget* widget)
: on_activation(move(on_activation_callback))
, m_text(text)
, m_icon(move(icon))
diff --git a/LibGUI/GAction.h b/LibGUI/GAction.h
index 5770693a8c..e4174e0c95 100644
--- a/LibGUI/GAction.h
+++ b/LibGUI/GAction.h
@@ -24,23 +24,23 @@ public:
ApplicationGlobal,
WidgetLocal,
};
- static Retained<GAction> create(const String& text, Function<void(GAction&)> callback, GWidget* widget = nullptr)
+ static Retained<GAction> create(const StringView& text, Function<void(GAction&)> callback, GWidget* widget = nullptr)
{
return adopt(*new GAction(text, move(callback), widget));
}
- static Retained<GAction> create(const String& text, const String& custom_data, Function<void(GAction&)> callback, GWidget* widget = nullptr)
+ static Retained<GAction> create(const StringView& text, const StringView& custom_data, Function<void(GAction&)> callback, GWidget* widget = nullptr)
{
return adopt(*new GAction(text, custom_data, move(callback), widget));
}
- static Retained<GAction> create(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
+ static Retained<GAction> create(const StringView& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
{
return adopt(*new GAction(text, move(icon), move(callback), widget));
}
- static Retained<GAction> create(const String& text, const GShortcut& shortcut, Function<void(GAction&)> callback, GWidget* widget = nullptr)
+ static Retained<GAction> create(const StringView& text, const GShortcut& shortcut, Function<void(GAction&)> callback, GWidget* widget = nullptr)
{
return adopt(*new GAction(text, shortcut, move(callback), widget));
}
- static Retained<GAction> create(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
+ static Retained<GAction> create(const StringView& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr)
{
return adopt(*new GAction(text, shortcut, move(icon), move(callback), widget));
}
@@ -77,11 +77,11 @@ public:
void unregister_menu_item(Badge<GMenuItem>, GMenuItem&);
private:
- GAction(const String& text, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
- GAction(const String& text, const GShortcut&, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
- GAction(const String& text, const GShortcut&, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
- GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
- GAction(const String& text, const String& custom_data = String(), Function<void(GAction&)> = nullptr, GWidget* = nullptr);
+ GAction(const StringView& text, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
+ GAction(const StringView& text, const GShortcut&, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
+ GAction(const StringView& text, const GShortcut&, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
+ GAction(const StringView& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr);
+ GAction(const StringView& text, const StringView& custom_data = StringView(), Function<void(GAction&)> = nullptr, GWidget* = nullptr);
template<typename Callback>
void for_each_toolbar_button(Callback);
diff --git a/LibGUI/GApplication.cpp b/LibGUI/GApplication.cpp
index 8f16b07791..ef632b4d0e 100644
--- a/LibGUI/GApplication.cpp
+++ b/LibGUI/GApplication.cpp
@@ -84,7 +84,7 @@ public:
set_main_widget(m_label);
}
- void set_tooltip(const String& tooltip)
+ void set_tooltip(const StringView& tooltip)
{
// FIXME: Add some kind of GLabel auto-sizing feature.
int text_width = m_label->font().width(tooltip);
@@ -95,7 +95,7 @@ public:
GLabel* m_label { nullptr };
};
-void GApplication::show_tooltip(const String& tooltip, const Point& screen_location)
+void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_location)
{
if (!m_tooltip_window) {
m_tooltip_window = new TooltipWindow;
diff --git a/LibGUI/GApplication.h b/LibGUI/GApplication.h
index 14b9d65f59..e68ad1f690 100644
--- a/LibGUI/GApplication.h
+++ b/LibGUI/GApplication.h
@@ -26,7 +26,7 @@ public:
void register_global_shortcut_action(Badge<GAction>, GAction&);
void unregister_global_shortcut_action(Badge<GAction>, GAction&);
- void show_tooltip(const String&, const Point& screen_location);
+ void show_tooltip(const StringView&, const Point& screen_location);
void hide_tooltip();
private:
diff --git a/LibGUI/GButton.cpp b/LibGUI/GButton.cpp
index 62e521702d..ff8bc9172d 100644
--- a/LibGUI/GButton.cpp
+++ b/LibGUI/GButton.cpp
@@ -10,7 +10,7 @@ GButton::GButton(GWidget* parent)
{
}
-GButton::GButton(const String& text, GWidget* parent)
+GButton::GButton(const StringView& text, GWidget* parent)
: GAbstractButton(text, parent)
{
}
diff --git a/LibGUI/GButton.h b/LibGUI/GButton.h
index 1f62dc8d39..d7284cbe0e 100644
--- a/LibGUI/GButton.h
+++ b/LibGUI/GButton.h
@@ -11,7 +11,7 @@ class GAction;
class GButton : public GAbstractButton {
public:
- GButton(const String& text, GWidget* parent);
+ GButton(const StringView& text, GWidget* parent);
explicit GButton(GWidget* parent);
virtual ~GButton() override;
diff --git a/LibGUI/GCheckBox.cpp b/LibGUI/GCheckBox.cpp
index b40c22624e..7be710fbb3 100644
--- a/LibGUI/GCheckBox.cpp
+++ b/LibGUI/GCheckBox.cpp
@@ -27,7 +27,7 @@ GCheckBox::GCheckBox(GWidget* parent)
{
}
-GCheckBox::GCheckBox(const String& text, GWidget* parent)
+GCheckBox::GCheckBox(const StringView& text, GWidget* parent)
: GAbstractButton(text, parent)
{
}
diff --git a/LibGUI/GCheckBox.h b/LibGUI/GCheckBox.h
index 26116817e5..8235b577ba 100644
--- a/LibGUI/GCheckBox.h
+++ b/LibGUI/GCheckBox.h
@@ -6,7 +6,7 @@
class GCheckBox : public GAbstractButton {
public:
- GCheckBox(const String&, GWidget* parent);
+ GCheckBox(const StringView&, GWidget* parent);
explicit GCheckBox(GWidget* parent);
virtual ~GCheckBox() override;
diff --git a/LibGUI/GClipboard.cpp b/LibGUI/GClipboard.cpp
index 9a349a157d..2c4d38b4da 100644
--- a/LibGUI/GClipboard.cpp
+++ b/LibGUI/GClipboard.cpp
@@ -34,7 +34,7 @@ String GClipboard::data() const
return String((const char*)shared_buffer->data(), response.clipboard.contents_size);
}
-void GClipboard::set_data(const String& data)
+void GClipboard::set_data(const StringView& data)
{
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::SetClipboardContents;
diff --git a/LibGUI/GClipboard.h b/LibGUI/GClipboard.h
index fc8cb5c95f..5e18c4fea7 100644
--- a/LibGUI/GClipboard.h
+++ b/LibGUI/GClipboard.h
@@ -7,7 +7,7 @@ public:
static GClipboard& the();
String data() const;
- void set_data(const String&);
+ void set_data(const StringView&);
private:
GClipboard();
diff --git a/LibGUI/GDesktop.cpp b/LibGUI/GDesktop.cpp
index 234db21a84..809fdc80f0 100644
--- a/LibGUI/GDesktop.cpp
+++ b/LibGUI/GDesktop.cpp
@@ -24,7 +24,7 @@ void GDesktop::did_receive_screen_rect(Badge<GEventLoop>, const Rect& rect)
on_rect_change(rect);
}
-bool GDesktop::set_wallpaper(const String& path)
+bool GDesktop::set_wallpaper(const StringView& path)
{
WSAPI_ClientMessage message;
message.type = WSAPI_ClientMessage::Type::SetWallpaper;
diff --git a/LibGUI/GDesktop.h b/LibGUI/GDesktop.h
index ca90ace83c..250e7138ce 100644
--- a/LibGUI/GDesktop.h
+++ b/LibGUI/GDesktop.h
@@ -13,7 +13,7 @@ public:
GDesktop();
String wallpaper() const;
- bool set_wallpaper(const String& path);
+ bool set_wallpaper(const StringView& path);
Rect rect() const { return m_rect; }
void did_receive_screen_rect(Badge<GEventLoop>, const Rect&);
diff --git a/LibGUI/GDirectoryModel.cpp b/LibGUI/GDirectoryModel.cpp
index f1d33f87cc..e1a9c34d66 100644
--- a/LibGUI/GDirectoryModel.cpp
+++ b/LibGUI/GDirectoryModel.cpp
@@ -272,7 +272,7 @@ void GDirectoryModel::update()
did_update();
}
-void GDirectoryModel::open(const String& a_path)
+void GDirectoryModel::open(const StringView& a_path)
{
FileSystemPath canonical_path(a_path);
auto path = canonical_path.string();
diff --git a/LibGUI/GDirectoryModel.h b/LibGUI/GDirectoryModel.h
index d4f0e31073..2562b7cc32 100644
--- a/LibGUI/GDirectoryModel.h
+++ b/LibGUI/GDirectoryModel.h
@@ -31,7 +31,7 @@ public:
virtual void update() override;
String path() const { return m_path; }
- void open(const String& path);
+ void open(const StringView& path);
size_t bytes_in_files() const { return m_bytes_in_files; }
Function<void(int done, int total)> on_thumbnail_progress;
diff --git a/LibGUI/GEvent.h b/LibGUI/GEvent.h
index 54e111dfe3..70da4b4b51 100644
--- a/LibGUI/GEvent.h
+++ b/LibGUI/GEvent.h
@@ -82,7 +82,7 @@ public:
class GWMWindowStateChangedEvent : public GWMEvent {
public:
- GWMWindowStateChangedEvent(int client_id, int window_id, const String& title, const Rect& rect, bool is_active, GWindowType window_type, bool is_minimized)
+ GWMWindowStateChangedEvent(int client_id, int window_id, const StringView& title, const Rect& rect, bool is_active, GWindowType window_type, bool is_minimized)
: GWMEvent(GEvent::Type::WM_WindowStateChanged, client_id, window_id)
, m_title(title)
, m_rect(rect)
@@ -122,7 +122,7 @@ private:
class GWMWindowIconChangedEvent : public GWMEvent {
public:
- GWMWindowIconChangedEvent(int client_id, int window_id, const String& icon_path)
+ GWMWindowIconChangedEvent(int client_id, int window_id, const StringView& icon_path)
: GWMEvent(GEvent::Type::WM_WindowIconChanged, client_id, window_id)
, m_icon_path(icon_path)
{
diff --git a/LibGUI/GFilePicker.cpp b/LibGUI/GFilePicker.cpp
index ecf8b963ba..76587d9223 100644
--- a/LibGUI/GFilePicker.cpp
+++ b/LibGUI/GFilePicker.cpp
@@ -12,7 +12,7 @@
#include <LibGUI/GToolBar.h>
#include <SharedGraphics/PNGLoader.h>
-GFilePicker::GFilePicker(const String& path, CObject* parent)
+GFilePicker::GFilePicker(const StringView& path, CObject* parent)
: GDialog(parent)
, m_model(GDirectoryModel::create())
{
diff --git a/LibGUI/GFilePicker.h b/LibGUI/GFilePicker.h
index 4ec7c22859..12af7e3941 100644
--- a/LibGUI/GFilePicker.h
+++ b/LibGUI/GFilePicker.h
@@ -7,7 +7,7 @@ class GLabel;
class GFilePicker final : public GDialog {
public:
- GFilePicker(const String& path = "/", CObject* parent = nullptr);
+ GFilePicker(const StringView& path = "/", CObject* parent = nullptr);
virtual ~GFilePicker() override;
FileSystemPath selected_file() const { return m_selected_file; }
diff --git a/LibGUI/GFileSystemModel.cpp b/LibGUI/GFileSystemModel.cpp
index 406af3f20b..d56fd4777c 100644
--- a/LibGUI/GFileSystemModel.cpp
+++ b/LibGUI/GFileSystemModel.cpp
@@ -92,7 +92,7 @@ struct GFileSystemModel::Node {
}
};
-GModelIndex GFileSystemModel::index(const String& path) const
+GModelIndex GFileSystemModel::index(const StringView& path) const
{
FileSystemPath canonical_path(path);
const Node* node = m_root;
@@ -125,7 +125,7 @@ String GFileSystemModel::path(const GModelIndex& index) const
return node.full_path(*this);
}
-GFileSystemModel::GFileSystemModel(const String& root_path, Mode mode)
+GFileSystemModel::GFileSystemModel(const StringView& root_path, Mode mode)
: m_root_path(FileSystemPath(root_path).string())
, m_mode(mode)
{
diff --git a/LibGUI/GFileSystemModel.h b/LibGUI/GFileSystemModel.h
index 7f21ca7794..842f913868 100644
--- a/LibGUI/GFileSystemModel.h
+++ b/LibGUI/GFileSystemModel.h
@@ -13,7 +13,7 @@ public:
FilesAndDirectories
};
- static Retained<GFileSystemModel> create(const String& root_path = "/", Mode mode = Mode::FilesAndDirectories)
+ static Retained<GFileSystemModel> create(const StringView& root_path = "/", Mode mode = Mode::FilesAndDirectories)
{
return adopt(*new GFileSystemModel(root_path, mode));
}
@@ -21,7 +21,7 @@ public:
String root_path() const { return m_root_path; }
String path(const GModelIndex&) const;
- GModelIndex index(const String& path) const;
+ GModelIndex index(const StringView& path) const;
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
virtual int column_count(const GModelIndex& = GModelIndex()) const override;
@@ -31,7 +31,7 @@ public:
virtual GModelIndex index(int row, int column = 0, const GModelIndex& parent = GModelIndex()) const override;
private:
- GFileSystemModel(const String& root_path, Mode);
+ GFileSystemModel(const StringView& root_path, Mode);
String m_root_path;
Mode m_mode { Invalid };
diff --git a/LibGUI/GFontDatabase.cpp b/LibGUI/GFontDatabase.cpp
index b9218f36a8..7359df0994 100644
--- a/LibGUI/GFontDatabase.cpp
+++ b/LibGUI/GFontDatabase.cpp
@@ -38,14 +38,14 @@ GFontDatabase::~GFontDatabase()
{
}
-void GFontDatabase::for_each_font(Function<void(const String&)> callback)
+void GFontDatabase::for_each_font(Function<void(const StringView&)> callback)
{
for (auto& it : m_name_to_metadata) {
callback(it.key);
}
}
-void GFontDatabase::for_each_fixed_width_font(Function<void(const String&)> callback)
+void GFontDatabase::for_each_fixed_width_font(Function<void(const StringView&)> callback)
{
for (auto& it : m_name_to_metadata) {
if (it.value.is_fixed_width)
@@ -53,7 +53,7 @@ void GFontDatabase::for_each_fixed_width_font(Function<void(const String&)> call
}
}
-RetainPtr<Font> GFontDatabase::get_by_name(const String& name)
+RetainPtr<Font> GFontDatabase::get_by_name(const StringView& name)
{
auto it = m_name_to_metadata.find(name);
if (it == m_name_to_metadata.end())
diff --git a/LibGUI/GFontDatabase.h b/LibGUI/GFontDatabase.h
index af49e68875..7b22bc4d10 100644
--- a/LibGUI/GFontDatabase.h
+++ b/LibGUI/GFontDatabase.h
@@ -16,11 +16,11 @@ class GFontDatabase {
public:
static GFontDatabase& the();
- RetainPtr<Font> get_by_name(const String&);
- void for_each_font(Function<void(const String&)>);
- void for_each_fixed_width_font(Function<void(const String&)>);
+ RetainPtr<Font> get_by_name(const StringView&);
+ void for_each_font(Function<void(const StringView&)>);
+ void for_each_fixed_width_font(Function<void(const StringView&)>);
- Metadata get_metadata_by_name(const String& name) const
+ Metadata get_metadata_by_name(const StringView& name) const
{
return m_name_to_metadata.get(name);
};
diff --git a/LibGUI/GGroupBox.cpp b/LibGUI/GGroupBox.cpp
index 915b66e0dc..8633f25fe4 100644
--- a/LibGUI/GGroupBox.cpp
+++ b/LibGUI/GGroupBox.cpp
@@ -2,7 +2,7 @@
#include <LibGUI/GPainter.h>
#include <SharedGraphics/StylePainter.h>
-GGroupBox::GGroupBox(const String& title, GWidget* parent)
+GGroupBox::GGroupBox(const StringView& title, GWidget* parent)
: GWidget(parent)
, m_title(title)
{
@@ -30,7 +30,7 @@ void GGroupBox::paint_event(GPaintEvent& event)
painter.draw_text(text_rect, m_title, TextAlignment::Center, foreground_color());
}
-void GGroupBox::set_title(const String& title)
+void GGroupBox::set_title(const StringView& title)
{
if (m_title == title)
return;
diff --git a/LibGUI/GGroupBox.h b/LibGUI/GGroupBox.h
index 4b630ea365..513d52b57b 100644
--- a/LibGUI/GGroupBox.h
+++ b/LibGUI/GGroupBox.h
@@ -4,11 +4,11 @@
class GGroupBox : public GWidget {
public:
- GGroupBox(const String& title, GWidget* parent);
+ GGroupBox(const StringView& title, GWidget* parent);
virtual ~GGroupBox() override;
String title() const { return m_title; }
- void set_title(const String&);
+ void set_title(const StringView&);
virtual const char* class_name() const override { return "GGroupBox"; }
diff --git a/LibGUI/GIcon.cpp b/LibGUI/GIcon.cpp
index 0a2955ee7f..17c34e8356 100644
--- a/LibGUI/GIcon.cpp
+++ b/LibGUI/GIcon.cpp
@@ -62,7 +62,7 @@ void GIconImpl::set_bitmap_for_size(int size, RetainPtr<GraphicsBitmap>&& bitmap
m_bitmaps.set(size, move(bitmap));
}
-GIcon GIcon::default_icon(const String& name)
+GIcon GIcon::default_icon(const StringView& name)
{
auto bitmap16 = GraphicsBitmap::load_from_file(String::format("/res/icons/16x16/%s.png", name.characters()));
auto bitmap32 = GraphicsBitmap::load_from_file(String::format("/res/icons/32x32/%s.png", name.characters()));
diff --git a/LibGUI/GIcon.h b/LibGUI/GIcon.h
index 61d928127f..47c09071d9 100644
--- a/LibGUI/GIcon.h
+++ b/LibGUI/GIcon.h
@@ -25,7 +25,7 @@ public:
GIcon(const GIcon&);
~GIcon() {}
- static GIcon default_icon(const String&);
+ static GIcon default_icon(const StringView&);
GIcon& operator=(const GIcon& other)
{
diff --git a/LibGUI/GInputBox.cpp b/LibGUI/GInputBox.cpp
index 884adeabbe..9474f91617 100644
--- a/LibGUI/GInputBox.cpp
+++ b/LibGUI/GInputBox.cpp
@@ -5,7 +5,7 @@
#include <LibGUI/GTextEditor.h>
#include <stdio.h>
-GInputBox::GInputBox(const String& prompt, const String& title, CObject* parent)
+GInputBox::GInputBox(const StringView& prompt, const StringView& title, CObject* parent)
: GDialog(parent)
, m_prompt(prompt)
{
diff --git a/LibGUI/GInputBox.h b/LibGUI/GInputBox.h
index 94de894040..76672b9a80 100644
--- a/LibGUI/GInputBox.h
+++ b/LibGUI/GInputBox.h
@@ -7,7 +7,7 @@ class GTextEditor;
class GInputBox : public GDialog {
public:
- explicit GInputBox(const String& prompt, const String& title, CObject* parent = nullptr);
+ explicit GInputBox(const StringView& prompt, const StringView& title, CObject* parent = nullptr);
virtual ~GInputBox() override;
String text_value() const { return m_text_value; }
diff --git a/LibGUI/GLabel.cpp b/LibGUI/GLabel.cpp
index 003a4d2132..abab0ac09a 100644
--- a/LibGUI/GLabel.cpp
+++ b/LibGUI/GLabel.cpp
@@ -7,7 +7,7 @@ GLabel::GLabel(GWidget* parent)
{
}
-GLabel::GLabel(const String& text, GWidget* parent)
+GLabel::GLabel(const StringView& text, GWidget* parent)
: GFrame(parent)
, m_text(text)
{
@@ -22,7 +22,7 @@ void GLabel::set_icon(RetainPtr<GraphicsBitmap>&& icon)
m_icon = move(icon);
}
-void GLabel::set_text(const String& text)
+void GLabel::set_text(const StringView& text)
{
if (text == m_text)
return;
diff --git a/LibGUI/GLabel.h b/LibGUI/GLabel.h
index a67b50b90c..406595756b 100644
--- a/LibGUI/GLabel.h
+++ b/LibGUI/GLabel.h
@@ -8,11 +8,11 @@ class GraphicsBitmap;
class GLabel : public GFrame {
public:
explicit GLabel(GWidget* parent = nullptr);
- GLabel(const String& text, GWidget* parent = nullptr);
+ GLabel(const StringView& text, GWidget* parent = nullptr);
virtual ~GLabel() override;
String text() const { return m_text; }
- void set_text(const String&);
+ void set_text(const StringView&);
void set_icon(RetainPtr<GraphicsBitmap>&&);
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
diff --git a/LibGUI/GMenu.cpp b/LibGUI/GMenu.cpp
index dad8cc6f5a..039ac8ab5c 100644
--- a/LibGUI/GMenu.cpp
+++ b/LibGUI/GMenu.cpp
@@ -21,7 +21,7 @@ GMenu* GMenu::from_menu_id(int menu_id)
return (*it).value;
}
-GMenu::GMenu(const String& name)
+GMenu::GMenu(const StringView& name)
: m_name(name)
{
}
diff --git a/LibGUI/GMenu.h b/LibGUI/GMenu.h
index 97a8ed51c9..61b11c0692 100644
--- a/LibGUI/GMenu.h
+++ b/LibGUI/GMenu.h
@@ -11,7 +11,7 @@ class Point;
class GMenu {
public:
- explicit GMenu(const String& name);
+ explicit GMenu(const StringView& name);
~GMenu();
static GMenu* from_menu_id(int);
diff --git a/LibGUI/GMessageBox.cpp b/LibGUI/GMessageBox.cpp
index 71fe04f043..6e70771ab1 100644
--- a/LibGUI/GMessageBox.cpp
+++ b/LibGUI/GMessageBox.cpp
@@ -4,13 +4,13 @@
#include <LibGUI/GButton.h>
#include <stdio.h>
-void GMessageBox::show(const String& text, const String& title, Type type, CObject* parent)
+void GMessageBox::show(const StringView& text, const StringView& title, Type type, CObject* parent)
{
GMessageBox box(text, title, type, parent);
box.exec();
}
-GMessageBox::GMessageBox(const String& text, const String& title, Type type, CObject* parent)
+GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type type, CObject* parent)
: GDialog(parent)
, m_text(text)
, m_type(type)
diff --git a/LibGUI/GMessageBox.h b/LibGUI/GMessageBox.h
index 31f4983ae3..782e12eee3 100644
--- a/LibGUI/GMessageBox.h
+++ b/LibGUI/GMessageBox.h
@@ -12,10 +12,10 @@ public:
Error,
};
- explicit GMessageBox(const String& text, const String& title, Type type = Type::None, CObject* parent = nullptr);
+ explicit GMessageBox(const StringView& text, const StringView& title, Type type = Type::None, CObject* parent = nullptr);
virtual ~GMessageBox() override;
- static void show(const String& text, const String& title, Type type = Type::None, CObject* parent = nullptr);
+ static void show(const StringView& text, const StringView& title, Type type = Type::None, CObject* parent = nullptr);
virtual const char* class_name() const override { return "GMessageBox"; }
diff --git a/LibGUI/GProgressBar.h b/LibGUI/GProgressBar.h
index 42e3843403..7c4379d939 100644
--- a/LibGUI/GProgressBar.h
+++ b/LibGUI/GProgressBar.h
@@ -17,7 +17,7 @@ public:
int max() const { return m_max; }
String caption() const { return m_caption; }
- void set_caption(const String& caption) { m_caption = caption; }
+ void set_caption(const StringView& caption) { m_caption = caption; }
enum Format
{
diff --git a/LibGUI/GRadioButton.cpp b/LibGUI/GRadioButton.cpp
index afcb2d9c32..e88954dc97 100644
--- a/LibGUI/GRadioButton.cpp
+++ b/LibGUI/GRadioButton.cpp
@@ -7,7 +7,7 @@ static RetainPtr<GraphicsBitmap> s_filled_circle_bitmap;
static RetainPtr<GraphicsBitmap> s_changing_filled_circle_bitmap;
static RetainPtr<GraphicsBitmap> s_changing_unfilled_circle_bitmap;
-GRadioButton::GRadioButton(const String& text, GWidget* parent)
+GRadioButton::GRadioButton(const StringView& text, GWidget* parent)
: GAbstractButton(text, parent)
{
if (!s_unfilled_circle_bitmap) {
diff --git a/LibGUI/GRadioButton.h b/LibGUI/GRadioButton.h
index 410f0e4556..44c0cfe97b 100644
--- a/LibGUI/GRadioButton.h
+++ b/LibGUI/GRadioButton.h
@@ -4,7 +4,7 @@
class GRadioButton : public GAbstractButton {
public:
- GRadioButton(const String& text, GWidget* parent);
+ GRadioButton(const StringView& text, GWidget* parent);
virtual ~GRadioButton() override;
virtual const char* class_name() const override { return "GRadioButton"; }
diff --git a/LibGUI/GStatusBar.cpp b/LibGUI/GStatusBar.cpp
index 210622bab9..70e2552037 100644
--- a/LibGUI/GStatusBar.cpp
+++ b/LibGUI/GStatusBar.cpp
@@ -26,7 +26,7 @@ GStatusBar::~GStatusBar()
{
}
-void GStatusBar::set_text(const String& text)
+void GStatusBar::set_text(const StringView& text)
{
m_label->set_text(text);
}
diff --git a/LibGUI/GStatusBar.h b/LibGUI/GStatusBar.h
index 1ba0888179..ad1deebb61 100644
--- a/LibGUI/GStatusBar.h
+++ b/LibGUI/GStatusBar.h
@@ -11,7 +11,7 @@ public:
virtual ~GStatusBar() override;
String text() const;
- void set_text(const String&);
+ void set_text(const StringView&);
virtual const char* class_name() const override { return "GStatusBar"; }
diff --git a/LibGUI/GTabWidget.cpp b/LibGUI/GTabWidget.cpp
index 4aa94e4a6e..a465bac9e1 100644
--- a/LibGUI/GTabWidget.cpp
+++ b/LibGUI/GTabWidget.cpp
@@ -14,7 +14,7 @@ GTabWidget::~GTabWidget()
{
}
-void GTabWidget::add_widget(const String& title, GWidget* widget)
+void GTabWidget::add_widget(const StringView& title, GWidget* widget)
{
m_tabs.append({ title, widget });
add_child(*widget);
diff --git a/LibGUI/GTabWidget.h b/LibGUI/GTabWidget.h
index 7452c81da8..0b2e41ad58 100644
--- a/LibGUI/GTabWidget.h
+++ b/LibGUI/GTabWidget.h
@@ -13,7 +13,7 @@ public:
int bar_height() const { return 21; }
int container_padding() const { return 2; }
- void add_widget(const String&, GWidget*);
+ void add_widget(const StringView&, GWidget*);
virtual const char* class_name() const override { return "GTabWidget"; }
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp
index 4c85f13ae0..2402c38519 100644
--- a/LibGUI/GTextEditor.cpp
+++ b/LibGUI/GTextEditor.cpp
@@ -58,7 +58,7 @@ void GTextEditor::create_actions()
}, this);
}
-void GTextEditor::set_text(const String& text)
+void GTextEditor::set_text(const StringView& text)
{
if (is_single_line() && text.length() == m_lines[0]->length() && !memcmp(text.characters(), m_lines[0]->characters(), text.length()))
return;
@@ -71,7 +71,7 @@ void GTextEditor::set_text(const String& text)
int line_length = current_position - start_of_current_line;
auto line = make<Line>();
if (line_length)
- line->set_text(text.substring(start_of_current_line, current_position - start_of_current_line));
+ line->set_text(text.substring_view(start_of_current_line, current_position - start_of_current_line));
m_lines.append(move(line));
start_of_current_line = current_position + 1;
};
@@ -574,7 +574,7 @@ void GTextEditor::do_delete()
}
}
-void GTextEditor::insert_at_cursor(const String& text)
+void GTextEditor::insert_at_cursor(const StringView& text)
{
// FIXME: This should obviously not be implemented this way.
for (int i = 0; i < text.length(); ++i) {
@@ -756,7 +756,7 @@ GTextEditor::Line::Line()
clear();
}
-GTextEditor::Line::Line(const String& text)
+GTextEditor::Line::Line(const StringView& text)
{
set_text(text);
}
@@ -767,7 +767,7 @@ void GTextEditor::Line::clear()
m_text.append(0);
}
-void GTextEditor::Line::set_text(const String& text)
+void GTextEditor::Line::set_text(const StringView& text)
{
if (text.length() == length() && !memcmp(text.characters(), characters(), length()))
return;
@@ -828,7 +828,7 @@ void GTextEditor::Line::truncate(int length)
m_text.last() = 0;
}
-bool GTextEditor::write_to_file(const String& path)
+bool GTextEditor::write_to_file(const StringView& path)
{
int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
@@ -952,7 +952,7 @@ void GTextEditor::delete_selection()
update();
}
-void GTextEditor::insert_at_cursor_or_replace_selection(const String& text)
+void GTextEditor::insert_at_cursor_or_replace_selection(const StringView& text)
{
ASSERT(!is_readonly());
if (has_selection())
diff --git a/LibGUI/GTextEditor.h b/LibGUI/GTextEditor.h
index 648bf9d80d..d77ceaf174 100644
--- a/LibGUI/GTextEditor.h
+++ b/LibGUI/GTextEditor.h
@@ -105,7 +105,7 @@ public:
Function<void()> on_cursor_change;
Function<void()> on_selection_change;
- void set_text(const String&);
+ void set_text(const StringView&);
void scroll_cursor_into_view();
int line_count() const { return m_lines.size(); }
int line_spacing() const { return m_line_spacing; }
@@ -115,7 +115,7 @@ public:
// FIXME: This should take glyph spacing into account, no?
int glyph_width() const { return font().glyph_width('x'); }
- bool write_to_file(const String& path);
+ bool write_to_file(const StringView& path);
bool has_selection() const { return m_selection.is_valid(); }
String selected_text() const;
@@ -168,12 +168,12 @@ private:
public:
Line();
- explicit Line(const String&);
+ explicit Line(const StringView&);
const char* characters() const { return m_text.data(); }
int length() const { return m_text.size() - 1; }
int width(const Font&) const;
- void set_text(const String&);
+ void set_text(const StringView&);
void append(char);
void prepend(char);
void insert(int index, char);
@@ -197,11 +197,11 @@ private:
const Line& current_line() const { return *m_lines[m_cursor.line()]; }
GTextPosition text_position_at(const Point&) const;
void insert_at_cursor(char);
- void insert_at_cursor(const String&);
+ void insert_at_cursor(const StringView&);
int ruler_width() const;
Rect ruler_content_rect(int line) const;
void toggle_selection_if_needed_for_event(const GKeyEvent&);
- void insert_at_cursor_or_replace_selection(const String&);
+ void insert_at_cursor_or_replace_selection(const StringView&);
void delete_selection();
void did_update_selection();
int content_x_for_position(const GTextPosition&) const;
diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h
index 6e73c7e4c1..5b76187f94 100644
--- a/LibGUI/GWidget.h
+++ b/LibGUI/GWidget.h
@@ -56,7 +56,7 @@ public:
bool has_tooltip() const { return !m_tooltip.is_empty(); }
String tooltip() const { return m_tooltip; }
- void set_tooltip(const String& tooltip) { m_tooltip = tooltip; }
+ void set_tooltip(const StringView& tooltip) { m_tooltip = tooltip; }
bool is_enabled() const { return m_enabled; }
void set_enabled(bool);
diff --git a/LibGUI/GWindow.cpp b/LibGUI/GWindow.cpp
index 0e7b94e3f0..190f1e9cd2 100644
--- a/LibGUI/GWindow.cpp
+++ b/LibGUI/GWindow.cpp
@@ -104,7 +104,7 @@ void GWindow::hide()
m_front_bitmap = nullptr;
}
-void GWindow::set_title(const String& title)
+void GWindow::set_title(const StringView& title)
{
m_title_when_windowless = title;
if (!m_window_id)
@@ -502,7 +502,7 @@ void GWindow::wm_event(GWMEvent&)
{
}
-void GWindow::set_icon_path(const String& path)
+void GWindow::set_icon_path(const StringView& path)
{
if (m_icon_path == path)
return;
diff --git a/LibGUI/GWindow.h b/LibGUI/GWindow.h
index 3178e1820b..d88438016b 100644
--- a/LibGUI/GWindow.h
+++ b/LibGUI/GWindow.h
@@ -45,7 +45,7 @@ public:
int window_id() const { return m_window_id; }
String title() const;
- void set_title(const String&);
+ void set_title(const StringView&);
bool show_titlebar() const { return m_show_titlebar; };
void set_show_titlebar(bool show) { m_show_titlebar = show; };
@@ -119,7 +119,7 @@ public:
void set_override_cursor(GStandardCursor);
String icon_path() const { return m_icon_path; }
- void set_icon_path(const String&);
+ void set_icon_path(const StringView&);
Vector<GWidget*> focusable_widgets() const;
diff --git a/SharedGraphics/Font.cpp b/SharedGraphics/Font.cpp
index 615677aa13..98e5e27c0a 100644
--- a/SharedGraphics/Font.cpp
+++ b/SharedGraphics/Font.cpp
@@ -66,7 +66,7 @@ RetainPtr<Font> Font::clone() const
return adopt(*new Font(m_name, new_rows, new_widths, m_fixed_width, m_glyph_width, m_glyph_height));
}
-Font::Font(const String& name, unsigned* rows, byte* widths, bool is_fixed_width, byte glyph_width, byte glyph_height)
+Font::Font(const StringView& name, unsigned* rows, byte* widths, bool is_fixed_width, byte glyph_width, byte glyph_height)
: m_name(name)
, m_rows(rows)
, m_glyph_widths(widths)
@@ -113,7 +113,7 @@ RetainPtr<Font> Font::load_from_memory(const byte* data)
return adopt(*new Font(String(header.name), rows, widths, !header.is_variable_width, header.glyph_width, header.glyph_height));
}
-RetainPtr<Font> Font::load_from_file(const String& path)
+RetainPtr<Font> Font::load_from_file(const StringView& path)
{
MappedFile mapped_file(path);
if (!mapped_file.is_valid())
@@ -124,7 +124,7 @@ RetainPtr<Font> Font::load_from_file(const String& path)
return font;
}
-bool Font::write_to_file(const String& path)
+bool Font::write_to_file(const StringView& path)
{
int fd = creat(path.characters(), 0644);
if (fd < 0) {
@@ -158,22 +158,17 @@ bool Font::write_to_file(const String& path)
return true;
}
-int Font::width(const String& string) const
+int Font::width(const StringView& string) const
{
- return width(string.characters(), string.length());
-}
-
-int Font::width(const char* characters, int length) const
-{
- if (!length)
+ if (!string.length())
return 0;
if (m_fixed_width)
- return length * m_glyph_width;
+ return string.length() * m_glyph_width;
int width = 0;
- for (int i = 0; i < length; ++i)
- width += glyph_width(characters[i]) + 1;
+ for (int i = 0; i < string.length(); ++i)
+ width += glyph_width(string.characters()[i]) + 1;
return width - 1;
}
diff --git a/SharedGraphics/Font.h b/SharedGraphics/Font.h
index 60ecd32ba4..193c69b31c 100644
--- a/SharedGraphics/Font.h
+++ b/SharedGraphics/Font.h
@@ -48,8 +48,8 @@ public:
RetainPtr<Font> clone() const;
- static RetainPtr<Font> load_from_file(const String& path);
- bool write_to_file(const String& path);
+ static RetainPtr<Font> load_from_file(const StringView& path);
+ bool write_to_file(const StringView& path);
~Font();
@@ -60,11 +60,10 @@ public:
byte min_glyph_width() const { return m_min_glyph_width; }
byte max_glyph_width() const { return m_max_glyph_width; }
byte glyph_spacing() const { return m_fixed_width ? 0 : 1; }
- int width(const String& string) const;
- int width(const char*, int) const;
+ int width(const StringView& string) const;
String name() const { return m_name; }
- void set_name(const String& name) { m_name = name; }
+ void set_name(const StringView& name) { m_name = name; }
bool is_fixed_width() const { return m_fixed_width; }
void set_fixed_width(bool b) { m_fixed_width = b; }
@@ -76,7 +75,7 @@ public:
}
private:
- Font(const String& name, unsigned* rows, byte* widths, bool is_fixed_width, byte glyph_width, byte glyph_height);
+ Font(const StringView& name, unsigned* rows, byte* widths, bool is_fixed_width, byte glyph_width, byte glyph_height);
static RetainPtr<Font> load_from_memory(const byte*);
diff --git a/SharedGraphics/GraphicsBitmap.cpp b/SharedGraphics/GraphicsBitmap.cpp
index 027dbbdaa8..e4c861d869 100644
--- a/SharedGraphics/GraphicsBitmap.cpp
+++ b/SharedGraphics/GraphicsBitmap.cpp
@@ -29,12 +29,12 @@ Retained<GraphicsBitmap> GraphicsBitmap::create_wrapper(Format format, const Siz
return adopt(*new GraphicsBitmap(format, size, data));
}
-RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const String& path)
+RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const StringView& path)
{
return load_png(path);
}
-RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(Format format, const String& path, const Size& size)
+RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(Format format, const StringView& path, const Size& size)
{
MappedFile mapped_file(path);
if (!mapped_file.is_valid())
@@ -86,7 +86,7 @@ GraphicsBitmap::~GraphicsBitmap()
delete [] m_palette;
}
-void GraphicsBitmap::set_mmap_name(const String& name)
+void GraphicsBitmap::set_mmap_name(const StringView& name)
{
ASSERT(m_needs_munmap);
::set_mmap_name(m_data, size_in_bytes(), name.characters());
diff --git a/SharedGraphics/GraphicsBitmap.h b/SharedGraphics/GraphicsBitmap.h
index a51565e177..6f0c78c8f2 100644
--- a/SharedGraphics/GraphicsBitmap.h
+++ b/SharedGraphics/GraphicsBitmap.h
@@ -6,6 +6,7 @@
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
#include <AK/AKString.h>
+#include <AK/StringView.h>
#include <AK/MappedFile.h>
#include <SharedBuffer.h>
@@ -15,8 +16,8 @@ public:
static Retained<GraphicsBitmap> create(Format, const Size&);
static Retained<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*);
- static RetainPtr<GraphicsBitmap> load_from_file(const String& path);
- static RetainPtr<GraphicsBitmap> load_from_file(Format, const String& path, const Size&);
+ static RetainPtr<GraphicsBitmap> load_from_file(const StringView& path);
+ static RetainPtr<GraphicsBitmap> load_from_file(Format, const StringView& path, const Size&);
static Retained<GraphicsBitmap> create_with_shared_buffer(Format, Retained<SharedBuffer>&&, const Size&);
~GraphicsBitmap();
@@ -36,7 +37,7 @@ public:
bool has_alpha_channel() const { return m_format == Format::RGBA32; }
Format format() const { return m_format; }
- void set_mmap_name(const String&);
+ void set_mmap_name(const StringView&);
size_t size_in_bytes() const { return m_pitch * m_size.height(); }
diff --git a/SharedGraphics/PNGLoader.cpp b/SharedGraphics/PNGLoader.cpp
index 8e7094a8ba..37952654bb 100644
--- a/SharedGraphics/PNGLoader.cpp
+++ b/SharedGraphics/PNGLoader.cpp
@@ -101,7 +101,7 @@ private:
static RetainPtr<GraphicsBitmap> load_png_impl(const byte*, int);
static bool process_chunk(Streamer&, PNGLoadingContext& context);
-RetainPtr<GraphicsBitmap> load_png(const String& path)
+RetainPtr<GraphicsBitmap> load_png(const StringView& path)
{
MappedFile mapped_file(path);
if (!mapped_file.is_valid())
diff --git a/SharedGraphics/PNGLoader.h b/SharedGraphics/PNGLoader.h
index d4e7c0ef7f..7365977ce7 100644
--- a/SharedGraphics/PNGLoader.h
+++ b/SharedGraphics/PNGLoader.h
@@ -2,4 +2,4 @@
#include <SharedGraphics/GraphicsBitmap.h>
-RetainPtr<GraphicsBitmap> load_png(const String& path);
+RetainPtr<GraphicsBitmap> load_png(const StringView& path);
diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp
index 748963de38..889558f322 100644
--- a/SharedGraphics/Painter.cpp
+++ b/SharedGraphics/Painter.cpp
@@ -512,8 +512,8 @@ void Painter::draw_text(const Rect& rect, const char* text, int length, const Fo
{
String elided_text;
if (elision == TextElision::Right) {
- int text_width = font.width(text, length);
- if (font.width(text, length) > rect.width()) {
+ int text_width = font.width(StringView(text, length));
+ if (font.width(StringView(text, length)) > rect.width()) {
int glyph_spacing = font.glyph_spacing();
int new_length = 0;
int new_width = font.width("...");
@@ -546,10 +546,10 @@ void Painter::draw_text(const Rect& rect, const char* text, int length, const Fo
} else if (alignment == TextAlignment::CenterLeft) {
point = { rect.x(), rect.center().y() - (font.glyph_height() / 2) };
} else if (alignment == TextAlignment::CenterRight) {
- int text_width = font.width(text);
+ int text_width = font.width(StringView(text, length));
point = { rect.right() - text_width, rect.center().y() - (font.glyph_height() / 2) };
} else if (alignment == TextAlignment::Center) {
- int text_width = font.width(text);
+ int text_width = font.width(StringView(text, length));
point = rect.center();
point.move_by(-(text_width / 2), -(font.glyph_height() / 2));
} else {
@@ -568,12 +568,12 @@ void Painter::draw_text(const Rect& rect, const char* text, int length, const Fo
}
}
-void Painter::draw_text(const Rect& rect, const String& text, TextAlignment alignment, Color color, TextElision elision)
+void Painter::draw_text(const Rect& rect, const StringView& text, TextAlignment alignment, Color color, TextElision elision)
{
draw_text(rect, text.characters(), text.length(), alignment, color, elision);
}
-void Painter::draw_text(const Rect& rect, const String& text, const Font& font, TextAlignment alignment, Color color, TextElision elision)
+void Painter::draw_text(const Rect& rect, const StringView& text, const Font& font, TextAlignment alignment, Color color, TextElision elision)
{
draw_text(rect, text.characters(), text.length(), font, alignment, color, elision);
}
diff --git a/SharedGraphics/Painter.h b/SharedGraphics/Painter.h
index a9ca1750ac..1008d287ab 100644
--- a/SharedGraphics/Painter.h
+++ b/SharedGraphics/Painter.h
@@ -32,8 +32,8 @@ public:
void blit_scaled(const Point&, const GraphicsBitmap&, const Rect& src_rect, const Size&);
void draw_text(const Rect&, const char* text, int length, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
void draw_text(const Rect&, const char* text, int length, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
- void draw_text(const Rect&, const String&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
- void draw_text(const Rect&, const String&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
+ void draw_text(const Rect&, const StringView&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
+ void draw_text(const Rect&, const StringView&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
void draw_glyph(const Point&, char, Color);
void draw_glyph(const Point&, char, const Font&, Color);