emitter: Support std::string_view

Accept Emitter::operator<<(std::string_view).

ABI remains C++11 compatible by exposing new method
Emitter::Write(const char*, size_t).

All affected calls optimized to pass std::string values as pointer + size
tuple into appropriate routines.
This commit is contained in:
Daniel Levin
2024-10-20 00:36:24 -05:00
committed by Jesse Beder
parent 8a9a7b74ef
commit 7470c2d871
9 changed files with 107 additions and 60 deletions

View File

@@ -46,6 +46,26 @@ TEST_F(EmitterTest, SimpleScalar) {
ExpectEmit("Hello, World!");
}
TEST_F(EmitterTest, SimpleStdStringScalar) {
out << std::string("Hello, std string");
ExpectEmit("Hello, std string");
}
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
TEST_F(EmitterTest, SimpleStdStringViewScalar) {
out << std::string_view("Hello, std string view");
ExpectEmit("Hello, std string view");
}
TEST_F(EmitterTest, UnterminatedStdStringViewScalar) {
out << std::string_view("HelloUnterminated", 5);
ExpectEmit("Hello");
}
#endif
TEST_F(EmitterTest, SimpleQuotedScalar) {
Node n(Load("\"test\""));
out << n;