Title: [251325] trunk/Source/WTF
- Revision
- 251325
- Author
- [email protected]
- Date
- 2019-10-19 11:40:36 -0700 (Sat, 19 Oct 2019)
Log Message
Add support to TextStream for dumping HashMap<> and HashSet<>
https://bugs.webkit.org/show_bug.cgi?id=202969
Reviewed by Dean Jackson.
Make it possible to output HashMap<> and HashSet<> to TextStream,
so long as key and value types are streamable. Also implement operator<<(char)
so that chars show as ASCII, rather than numbers.
* wtf/text/TextStream.cpp:
(WTF::TextStream::operator<<):
* wtf/text/TextStream.h:
(WTF::operator<<):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (251324 => 251325)
--- trunk/Source/WTF/ChangeLog 2019-10-19 15:46:43 UTC (rev 251324)
+++ trunk/Source/WTF/ChangeLog 2019-10-19 18:40:36 UTC (rev 251325)
@@ -1,3 +1,19 @@
+2019-10-19 Simon Fraser <[email protected]>
+
+ Add support to TextStream for dumping HashMap<> and HashSet<>
+ https://bugs.webkit.org/show_bug.cgi?id=202969
+
+ Reviewed by Dean Jackson.
+
+ Make it possible to output HashMap<> and HashSet<> to TextStream,
+ so long as key and value types are streamable. Also implement operator<<(char)
+ so that chars show as ASCII, rather than numbers.
+
+ * wtf/text/TextStream.cpp:
+ (WTF::TextStream::operator<<):
+ * wtf/text/TextStream.h:
+ (WTF::operator<<):
+
2019-10-18 Yusuke Suzuki <[email protected]>
[JSC] Make ConcurrentJSLock Lock even if ENABLE_CONCURRENT_JS=OFF
Modified: trunk/Source/WTF/wtf/text/TextStream.cpp (251324 => 251325)
--- trunk/Source/WTF/wtf/text/TextStream.cpp 2019-10-19 15:46:43 UTC (rev 251324)
+++ trunk/Source/WTF/wtf/text/TextStream.cpp 2019-10-19 18:40:36 UTC (rev 251325)
@@ -46,6 +46,12 @@
return *this << (b ? "1" : "0");
}
+TextStream& TextStream::operator<<(char c)
+{
+ m_text.append(c);
+ return *this;
+}
+
TextStream& TextStream::operator<<(int i)
{
m_text.appendNumber(i);
Modified: trunk/Source/WTF/wtf/text/TextStream.h (251324 => 251325)
--- trunk/Source/WTF/wtf/text/TextStream.h 2019-10-19 15:46:43 UTC (rev 251324)
+++ trunk/Source/WTF/wtf/text/TextStream.h 2019-10-19 18:40:36 UTC (rev 251325)
@@ -57,6 +57,7 @@
}
WTF_EXPORT_PRIVATE TextStream& operator<<(bool);
+ WTF_EXPORT_PRIVATE TextStream& operator<<(char);
WTF_EXPORT_PRIVATE TextStream& operator<<(int);
WTF_EXPORT_PRIVATE TextStream& operator<<(unsigned);
WTF_EXPORT_PRIVATE TextStream& operator<<(long);
@@ -174,6 +175,15 @@
}
template<typename Item>
+TextStream& operator<<(TextStream& ts, const Optional<Item>& item)
+{
+ if (item)
+ return ts << item.value();
+
+ return ts << "nullopt";
+}
+
+template<typename Item>
TextStream& operator<<(TextStream& ts, const Vector<Item>& vector)
{
ts << "[";
@@ -188,6 +198,38 @@
return ts << "]";
}
+template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
+TextStream& operator<<(TextStream& ts, const HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>& map)
+{
+ ts << "{";
+
+ bool first = true;
+ for (const auto& keyValuePair : map) {
+ ts << keyValuePair.key << ": " << keyValuePair.value;
+ if (!first)
+ ts << ", ";
+ first = false;
+ }
+
+ return ts << "}";
+}
+
+template<typename ValueArg, typename HashArg, typename TraitsArg>
+TextStream& operator<<(TextStream& ts, const HashSet<ValueArg, HashArg, TraitsArg>& set)
+{
+ ts << "[";
+
+ bool first = true;
+ for (const auto& item : set) {
+ ts << item;
+ if (!first)
+ ts << ", ";
+ first = false;
+ }
+
+ return ts << "]";
+}
+
template<typename Option>
TextStream& operator<<(TextStream& ts, const OptionSet<Option>& options)
{
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes