Adding immediate text scheme to abstract paths: 'text:blabla' will create a 'file' with content 'blabla'

This commit is contained in:
Matthias Koefferlein 2026-06-13 15:54:14 +02:00
parent b4c9527347
commit de052422d8
2 changed files with 51 additions and 0 deletions

View File

@ -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 ());

View File

@ -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
{