Skip to content

Commit

Permalink
Allow hex() to be used with LOG_WITH_STREAM()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260945
rdar://114742843

Reviewed by Simon Fraser.

TextStream just needs to be able to use the return type of hex().

* Source/WTF/wtf/text/TextStream.cpp:
(WTF::TextStream::operator<<):
* Source/WTF/wtf/text/TextStream.h:
* Tools/TestWebKitAPI/Tests/WTF/cocoa/TextStreamCocoa.cpp:
(TEST):

Canonical link: https://commits.webkit.org/267490@main
  • Loading branch information
litherum committed Aug 31, 2023
1 parent 40a802e commit a65bf78
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Source/WTF/wtf/text/TextStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ TextStream& TextStream::operator<<(StringView string)
return *this;
}

TextStream& TextStream::operator<<(HexNumberBuffer buffer)
{
m_text.append(makeString(buffer));
return *this;
}

TextStream& TextStream::operator<<(const FormatNumberRespectingIntegers& numberToFormat)
{
if (hasFractions(numberToFormat.value)) {
Expand Down
2 changes: 2 additions & 0 deletions Source/WTF/wtf/text/TextStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include <wtf/Forward.h>
#include <wtf/HexNumber.h>
#include <wtf/Markable.h>
#include <wtf/OptionSet.h>
#include <wtf/Ref.h>
Expand Down Expand Up @@ -77,6 +78,7 @@ class TextStream {
WTF_EXPORT_PRIVATE TextStream& operator<<(const String&);
WTF_EXPORT_PRIVATE TextStream& operator<<(ASCIILiteral);
WTF_EXPORT_PRIVATE TextStream& operator<<(StringView);
WTF_EXPORT_PRIVATE TextStream& operator<<(HexNumberBuffer);
// Deprecated. Use the NumberRespectingIntegers FormattingFlag instead.
WTF_EXPORT_PRIVATE TextStream& operator<<(const FormatNumberRespectingIntegers&);

Expand Down
7 changes: 7 additions & 0 deletions Tools/TestWebKitAPI/Tests/WTF/cocoa/TextStreamCocoa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ TEST(WTF_TextStream, CFString)
ts << reinterpret_cast<id>(const_cast<CFMutableStringRef>(CFSTR("Test")));
EXPECT_EQ(ts.release(), "Test"_s);
}

TEST(WTF_TextStream, Hex)
{
TextStream ts;
ts << hex(18);
EXPECT_EQ(ts.release(), "12"_s);
}

0 comments on commit a65bf78

Please sign in to comment.