From de052422d82527a790edb4aa29a632e96d16ec40 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 13 Jun 2026 15:54:14 +0200 Subject: [PATCH] Adding immediate text scheme to abstract paths: 'text:blabla' will create a 'file' with content 'blabla' --- src/tl/tl/tlStream.cc | 9 +++++++ src/tl/unit_tests/tlStreamTests.cc | 42 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/tl/tl/tlStream.cc b/src/tl/tl/tlStream.cc index fce7a43ae..4eba8dfcf 100644 --- a/src/tl/tl/tlStream.cc +++ b/src/tl/tl/tlStream.cc @@ -397,6 +397,15 @@ InputStream::InputStream (const std::string &abstract_path_in, bool allow_explic memcpy (data_ptr, data.begin ().operator-> (), data.size ()); mp_delegate = new InputMemoryStream (data_ptr, data.size (), true); + } else if (ex.test ("text:")) { + + const char *text = ex.get (); + size_t text_len = abstract_path.size () - (text - abstract_path.c_str ()); + + char *data_ptr = new char [text_len]; + memcpy (data_ptr, text, text_len); + mp_delegate = new InputMemoryStream (data_ptr, text_len, true); + } else if (ex.test ("pipe:")) { mp_delegate = new InflatingInputPipe (ex.get ()); diff --git a/src/tl/unit_tests/tlStreamTests.cc b/src/tl/unit_tests/tlStreamTests.cc index 71f85030e..1213b4a8d 100644 --- a/src/tl/unit_tests/tlStreamTests.cc +++ b/src/tl/unit_tests/tlStreamTests.cc @@ -212,6 +212,48 @@ TEST(DataInputStreamWithSuffix) EXPECT_EQ (is.suffix (), "txt"); } +TEST(ImmediateTextInputStream) +{ + tl::InputStream is ("text:Hello, world!\nWith another line\n"); + tl::TextInputStream tis (is); + EXPECT_EQ (tis.get_line (), "Hello, world!"); + EXPECT_EQ (tis.line_number (), size_t (1)); + EXPECT_EQ (tis.get_line (), "With another line"); + EXPECT_EQ (tis.line_number (), size_t (2)); + EXPECT_EQ (tis.at_end (), true); + + EXPECT_EQ (is.is_explicit_suffix (), false); + EXPECT_EQ (is.suffix (), ""); +} + +TEST(ImmediateTextInputStreamWithSuffix) +{ + tl::InputStream is ("text:Hello, world!\nWith another line[xyz]"); + tl::TextInputStream tis (is); + EXPECT_EQ (tis.get_line (), "Hello, world!"); + EXPECT_EQ (tis.line_number (), size_t (1)); + EXPECT_EQ (tis.get_line (), "With another line"); + EXPECT_EQ (tis.line_number (), size_t (2)); + EXPECT_EQ (tis.at_end (), true); + + EXPECT_EQ (is.is_explicit_suffix (), true); + EXPECT_EQ (is.suffix (), "xyz"); +} + +TEST(ImmediateTextInputStreamWithoutExplicitSuffix) +{ + tl::InputStream is ("text:Hello, world!\nWith another line[xyz]", false /*no explicit suffix*/); + tl::TextInputStream tis (is); + EXPECT_EQ (tis.get_line (), "Hello, world!"); + EXPECT_EQ (tis.line_number (), size_t (1)); + EXPECT_EQ (tis.get_line (), "With another line[xyz]"); + EXPECT_EQ (tis.line_number (), size_t (2)); + EXPECT_EQ (tis.at_end (), true); + + EXPECT_EQ (is.is_explicit_suffix (), false); + EXPECT_EQ (is.suffix (), ""); +} + namespace {