diff options
-rw-r--r-- | AK/AKString.h | 2 | ||||
-rw-r--r-- | AK/String.cpp | 10 | ||||
-rw-r--r-- | AK/Tests/TestQueue.cpp | 2 | ||||
-rw-r--r-- | Applications/ProcessManager/ProcessModel.cpp | 4 | ||||
-rw-r--r-- | Games/Minesweeper/Field.cpp | 6 | ||||
-rw-r--r-- | LibCore/CConfigFile.cpp | 2 | ||||
-rw-r--r-- | LibCore/CProcessStatisticsReader.cpp | 2 | ||||
-rw-r--r-- | LibGUI/GDirectoryModel.cpp | 4 | ||||
-rw-r--r-- | LibGUI/GSpinBox.cpp | 4 | ||||
-rw-r--r-- | LibGUI/GTextEditor.cpp | 2 | ||||
-rw-r--r-- | LibGUI/GVariant.cpp | 2 |
11 files changed, 26 insertions, 14 deletions
diff --git a/AK/AKString.h b/AK/AKString.h index a7de84b856..70e0fb0917 100644 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -181,6 +181,8 @@ public: } static String format(const char*, ...); + static String number(unsigned); + static String number(int); StringView view() const { return { characters(), length() }; } diff --git a/AK/String.cpp b/AK/String.cpp index fce8006e4d..b7e8c0cd69 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -170,6 +170,16 @@ unsigned String::to_uint(bool& ok) const return value; } +String String::number(unsigned value) +{ + return String::format("%u", value); +} + +String String::number(int value) +{ + return String::format("%d", value); +} + String String::format(const char* fmt, ...) { StringBuilder builder; diff --git a/AK/Tests/TestQueue.cpp b/AK/Tests/TestQueue.cpp index 708835f154..a604074215 100644 --- a/AK/Tests/TestQueue.cpp +++ b/AK/Tests/TestQueue.cpp @@ -28,7 +28,7 @@ int main() EXPECT(strings.is_empty()); for (int i = 0; i < 10000; ++i) { - strings.enqueue(String::format("%d", i)); + strings.enqueue(String::number(i)); EXPECT_EQ(strings.size(), i + 1); } diff --git a/Applications/ProcessManager/ProcessModel.cpp b/Applications/ProcessManager/ProcessModel.cpp index 7a75bbf8fb..9c0986d6e3 100644 --- a/Applications/ProcessManager/ProcessModel.cpp +++ b/Applications/ProcessManager/ProcessModel.cpp @@ -207,9 +207,9 @@ void ProcessModel::update() { auto it = m_usernames.find((uid_t)uid); if (it != m_usernames.end()) - state.user = String::format("%s", (*it).value.characters()); + state.user = (*it).value; else - state.user = String::format("%u", uid); + state.user = String::number(uid); } state.priority = process_object.get("priority").to_string(); state.syscalls = process_object.get("syscall_count").to_dword(); diff --git a/Games/Minesweeper/Field.cpp b/Games/Minesweeper/Field.cpp index 9baeb81315..c3fbd92667 100644 --- a/Games/Minesweeper/Field.cpp +++ b/Games/Minesweeper/Field.cpp @@ -185,7 +185,7 @@ void Field::reset() m_time_elapsed = 0; m_time_label.set_text("0"); m_flags_left = m_mine_count; - m_flag_label.set_text(String::format("%u", m_flags_left)); + m_flag_label.set_text(String::number(m_flags_left)); m_timer.stop(); set_greedy_for_hits(false); set_face(Face::Default); @@ -384,7 +384,7 @@ void Field::set_flag(Square& square, bool flag) } square.has_flag = flag; - m_flag_label.set_text(String::format("%u", m_flags_left)); + m_flag_label.set_text(String::number(m_flags_left)); square.button->set_icon(square.has_flag ? m_flag_bitmap : nullptr); square.button->update(); } @@ -396,7 +396,7 @@ void Field::on_square_middle_clicked(Square& square) if (square.has_flag) { ++m_flags_left; square.has_flag = false; - m_flag_label.set_text(String::format("%u", m_flags_left)); + m_flag_label.set_text(String::number(m_flags_left)); } square.is_considering = !square.is_considering; square.button->set_icon(square.is_considering ? m_consider_bitmap : nullptr); diff --git a/LibCore/CConfigFile.cpp b/LibCore/CConfigFile.cpp index e4b8453dd7..2f1fec736a 100644 --- a/LibCore/CConfigFile.cpp +++ b/LibCore/CConfigFile.cpp @@ -148,7 +148,7 @@ void CConfigFile::write_entry(const String& group, const String& key, const Stri void CConfigFile::write_num_entry(const String& group, const String& key, int value) { - write_entry(group, key, String::format("%d", value)); + write_entry(group, key, String::number(value)); } void CConfigFile::write_bool_entry(const String& group, const String& key, bool value) { diff --git a/LibCore/CProcessStatisticsReader.cpp b/LibCore/CProcessStatisticsReader.cpp index 599fa6ef35..67c81386a3 100644 --- a/LibCore/CProcessStatisticsReader.cpp +++ b/LibCore/CProcessStatisticsReader.cpp @@ -54,5 +54,5 @@ String CProcessStatisticsReader::get_username_from_uid(const uid_t uid) if (it != m_usernames.end()) return (*it).value; else - return String::format("%u", uid); + return String::number(uid); } diff --git a/LibGUI/GDirectoryModel.cpp b/LibGUI/GDirectoryModel.cpp index b4cc311632..2db018b97f 100644 --- a/LibGUI/GDirectoryModel.cpp +++ b/LibGUI/GDirectoryModel.cpp @@ -202,7 +202,7 @@ String GDirectoryModel::name_for_uid(uid_t uid) const { auto it = m_user_names.find(uid); if (it == m_user_names.end()) - return String::format("%u", uid); + return String::number(uid); return (*it).value; } @@ -210,7 +210,7 @@ String GDirectoryModel::name_for_gid(uid_t gid) const { auto it = m_user_names.find(gid); if (it == m_user_names.end()) - return String::format("%u", gid); + return String::number(gid); return (*it).value; } diff --git a/LibGUI/GSpinBox.cpp b/LibGUI/GSpinBox.cpp index cc9bdf8082..d37ffafcf4 100644 --- a/LibGUI/GSpinBox.cpp +++ b/LibGUI/GSpinBox.cpp @@ -13,7 +13,7 @@ GSpinBox::GSpinBox(GWidget* parent) if (ok) set_value(value); else - m_editor->set_text(String::format("%d", m_value)); + m_editor->set_text(String::number(m_value)); }; m_increment_button = new GButton(this); m_increment_button->set_focusable(false); @@ -38,7 +38,7 @@ void GSpinBox::set_value(int value) if (m_value == value) return; m_value = value; - m_editor->set_text(String::format("%d", value)); + m_editor->set_text(String::number(value)); update(); if (on_change) on_change(value); diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp index 07f6c3c923..225e942c70 100644 --- a/LibGUI/GTextEditor.cpp +++ b/LibGUI/GTextEditor.cpp @@ -292,7 +292,7 @@ void GTextEditor::paint_event(GPaintEvent& event) auto ruler_line_rect = ruler_content_rect(i); painter.draw_text( ruler_line_rect.shrunken(2, 0), - String::format("%u", i), + String::number(i), is_current_line ? Font::default_bold_font() : font(), TextAlignment::CenterRight, is_current_line ? Color::DarkGray : Color::MidGray); diff --git a/LibGUI/GVariant.cpp b/LibGUI/GVariant.cpp index 25f2d05667..a2da6d3402 100644 --- a/LibGUI/GVariant.cpp +++ b/LibGUI/GVariant.cpp @@ -289,7 +289,7 @@ String GVariant::to_string() const case Type::Bool: return as_bool() ? "true" : "false"; case Type::Int: - return String::format("%d", as_int()); + return String::number(as_int()); case Type::Float: return String::format("%f", (double)as_float()); case Type::String: |