mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
AK: Allow setting both width and precision when formatting a string
This commit is contained in:
parent
df5fa8aa39
commit
06ddfcde89
Notes:
sideshowbarker
2024-07-18 22:57:59 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/06ddfcde89f Pull-request: https://github.com/SerenityOS/serenity/pull/8843
2 changed files with 3 additions and 2 deletions
|
@ -550,8 +550,6 @@ void Formatter<StringView>::format(FormatBuilder& builder, StringView value)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
if (m_mode != Mode::Default && m_mode != Mode::String && m_mode != Mode::Character && m_mode != Mode::HexDump)
|
if (m_mode != Mode::Default && m_mode != Mode::String && m_mode != Mode::Character && m_mode != Mode::HexDump)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
if (m_width.has_value() && m_precision.has_value())
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
|
|
||||||
m_width = m_width.value_or(0);
|
m_width = m_width.value_or(0);
|
||||||
m_precision = m_precision.value_or(NumericLimits<size_t>::max());
|
m_precision = m_precision.value_or(NumericLimits<size_t>::max());
|
||||||
|
|
|
@ -125,6 +125,9 @@ TEST_CASE(complex_string_specifiers)
|
||||||
EXPECT_EQ(String::formatted("{:9}", "abcd"), "abcd ");
|
EXPECT_EQ(String::formatted("{:9}", "abcd"), "abcd ");
|
||||||
EXPECT_EQ(String::formatted("{:>9}", "abcd"), " abcd");
|
EXPECT_EQ(String::formatted("{:>9}", "abcd"), " abcd");
|
||||||
EXPECT_EQ(String::formatted("{:^9}", "abcd"), " abcd ");
|
EXPECT_EQ(String::formatted("{:^9}", "abcd"), " abcd ");
|
||||||
|
EXPECT_EQ(String::formatted("{:4.6}", "a"), "a ");
|
||||||
|
EXPECT_EQ(String::formatted("{:4.6}", "abcdef"), "abcdef");
|
||||||
|
EXPECT_EQ(String::formatted("{:4.6}", "abcdefghi"), "abcdef");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(cast_integer_to_character)
|
TEST_CASE(cast_integer_to_character)
|
||||||
|
|
Loading…
Reference in a new issue